refactor: break circular dependency in integration tests (#64091)

The lsp integration tests had a circular dependency with other integration tests, which made the build setup complex and fragile. This was previously handled by using 'copy_to_bin', which is not ideal as it hides the true dependency graph.

This commit refactors the build configuration to break this cycle by introducing a dedicated 'ts_project' for the lsp tests with its own 'tsconfig.json'. This change simplifies the build logic and makes dependencies explicit.

PR Close #64091
This commit is contained in:
Alan Agius 2025-09-25 19:46:31 +00:00 committed by kirjs
parent 3d2e1a670f
commit 6fee508dab
7 changed files with 55 additions and 43 deletions

View file

@ -10,25 +10,35 @@ ts_config(
],
)
ts_config(
name = "tsconfig-test",
src = "tsconfig-test.json",
visibility = ["//vscode-ng-language-service/integration:__subpackages__"],
deps = [
":tsconfig",
"//vscode-ng-language-service:tsconfig",
"//vscode-ng-language-service/server:tsconfig",
],
)
ts_project(
name = "integration",
# NB: there is an import cycle between integration/lsp/*.ts and integration/test_constants.ts so
# they cannot be broken up into separate ts_project targets
srcs = glob([
"*.ts",
]) + ["//vscode-ng-language-service/integration/lsp:srcs"],
]),
declaration = True,
source_map = True,
tsconfig = ":tsconfig",
visibility = [
"//vscode-ng-language-service/integration:__subpackages__",
],
visibility = ["//vscode-ng-language-service/integration:__subpackages__"],
deps = [
"//vscode-ng-language-service:node_modules/@types/jasmine",
"//vscode-ng-language-service:node_modules/@types/node",
"//vscode-ng-language-service:node_modules/vscode-jsonrpc",
"//vscode-ng-language-service:node_modules/vscode-languageserver-protocol",
"//vscode-ng-language-service:node_modules/vscode-uri",
"//vscode-ng-language-service/common",
"//vscode-ng-language-service/integration/pre_standalone_project",
"//vscode-ng-language-service/integration/pre_standalone_project:node_modules/@angular/common",
"//vscode-ng-language-service/integration/pre_standalone_project:node_modules/@angular/core",
"//vscode-ng-language-service/integration/project",
"//vscode-ng-language-service/integration/project:node_modules/@angular/common",
"//vscode-ng-language-service/integration/project:node_modules/@angular/core",
"//vscode-ng-language-service/server:index",
],
)

View file

@ -1,22 +1,11 @@
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@aspect_rules_jasmine//jasmine:defs.bzl", "jasmine_test")
load("//tools:defaults.bzl", "jasmine_test", "ts_project")
jasmine_test(
name = "test",
args = ["*_spec.js"],
chdir = package_name(),
data = [
"//vscode-ng-language-service/integration",
"//vscode-ng-language-service/integration/pre_standalone_project",
"//vscode-ng-language-service/integration/pre_standalone_project:node_modules/@angular/common",
"//vscode-ng-language-service/integration/pre_standalone_project:node_modules/@angular/core",
"//vscode-ng-language-service/integration/project",
"//vscode-ng-language-service/integration/project:node_modules/@angular/common",
"//vscode-ng-language-service/integration/project:node_modules/@angular/core",
"//vscode-ng-language-service/server:index",
":test_lib",
],
flaky = True,
node_modules = "//vscode-ng-language-service:node_modules",
shard_count = 2,
tags = [
"e2e",
@ -25,10 +14,20 @@ jasmine_test(
],
)
copy_to_bin(
name = "srcs",
srcs = glob(["*.ts"]),
# NB: there is an import cycle between integration/lsp/*.ts and integration/test_constants.ts so
# they cannot be broken up into separate ts_project targets
visibility = ["//vscode-ng-language-service/integration:__subpackages__"],
ts_project(
name = "test_lib",
testonly = True,
srcs = glob([
"*.ts",
]),
tsconfig = "//vscode-ng-language-service/integration:tsconfig-test",
deps = [
"//vscode-ng-language-service:node_modules/@types/jasmine",
"//vscode-ng-language-service:node_modules/@types/node",
"//vscode-ng-language-service:node_modules/vscode-jsonrpc",
"//vscode-ng-language-service:node_modules/vscode-languageserver-protocol",
"//vscode-ng-language-service:node_modules/vscode-uri",
"//vscode-ng-language-service/common",
"//vscode-ng-language-service/integration",
],
)

View file

@ -6,12 +6,12 @@
* found in the LICENSE file at https://angular.io/license
*/
import {fileURLToPath, pathToFileURL} from 'node:url';
import * as fs from 'node:fs';
import {join} from 'node:path';
import {promisify} from 'node:util';
import {MessageConnection} from 'vscode-jsonrpc';
import * as lsp from 'vscode-languageserver-protocol';
import {URI} from 'vscode-uri';
import {
ProjectLanguageService,
@ -42,7 +42,6 @@ import {
} from '../test_constants';
import {
convertPathToFileUrl,
createConnection,
createTracer,
initializeServer,
@ -161,7 +160,7 @@ describe('Angular Ivy language server', () => {
expect(targetUri).toMatch(/angular\/common\/common_module.*\.d\.ts$/);
// Open the `.d.ts` file
openTextDocument(client, URI.parse(targetUri).fsPath);
openTextDocument(client, fileURLToPath(targetUri));
// try a hover operation again on *ngIf
const hoverResponse = await client.sendRequest(lsp.HoverRequest.type, {
textDocument: {
@ -998,7 +997,7 @@ function getDiagnosticsForFile(
client.onNotification(
lsp.PublishDiagnosticsNotification.type,
(params: lsp.PublishDiagnosticsParams) => {
if (params.uri === convertPathToFileUrl(fileName)) {
if (params.uri === pathToFileURL(fileName).href) {
resolve(params.diagnostics);
}
},

View file

@ -7,6 +7,6 @@ copy_to_bin(
name = "pre_standalone_project",
srcs = glob(["**"]),
visibility = [
"//vscode-ng-language-service/integration/lsp:__pkg__",
"//vscode-ng-language-service/integration:__pkg__",
],
)

View file

@ -1,6 +1,5 @@
import {join, resolve} from 'path';
import {convertPathToFileUrl} from './lsp/test_utils';
import {join, resolve} from 'node:path';
import {pathToFileURL} from 'node:url';
export const IS_BAZEL = !!process.env['TEST_TARGET'];
export const PACKAGE_ROOT = IS_BAZEL ? resolve(__dirname, '..') : resolve(__dirname, '../..');
@ -15,13 +14,13 @@ export const PRE_STANDALONE_PROJECT_PATH = join(
);
export const APP_COMPONENT = join(PROJECT_PATH, 'app', 'app.component.ts');
export const APP_COMPONENT_URI = convertPathToFileUrl(APP_COMPONENT);
export const APP_COMPONENT_URI = pathToFileURL(APP_COMPONENT).href;
export const BAR_COMPONENT = join(PROJECT_PATH, 'app', 'bar.component.ts');
export const BAR_COMPONENT_URI = convertPathToFileUrl(BAR_COMPONENT);
export const BAR_COMPONENT_URI = pathToFileURL(BAR_COMPONENT).href;
export const APP_COMPONENT_MODULE = join(PROJECT_PATH, 'app', 'app.module.ts');
export const APP_COMPONENT_MODULE_URI = convertPathToFileUrl(APP_COMPONENT_MODULE);
export const APP_COMPONENT_MODULE_URI = pathToFileURL(APP_COMPONENT_MODULE).href;
export const FOO_TEMPLATE = join(PROJECT_PATH, 'app', 'foo.component.html');
export const FOO_TEMPLATE_URI = convertPathToFileUrl(FOO_TEMPLATE);
export const FOO_TEMPLATE_URI = pathToFileURL(FOO_TEMPLATE).href;
export const FOO_COMPONENT = join(PROJECT_PATH, 'app', 'foo.component.ts');
export const FOO_COMPONENT_URI = convertPathToFileUrl(FOO_COMPONENT);
export const FOO_COMPONENT_URI = pathToFileURL(FOO_COMPONENT).href;
export const TSCONFIG = join(PROJECT_PATH, 'tsconfig.json');

View file

@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"types": ["node", "jasmine"]
}
}

View file

@ -1 +0,0 @@
{"root":["./test_constants.ts","./e2e/completion_spec.ts","./e2e/definition_spec.ts","./e2e/helper.ts","./e2e/hover_spec.ts","./e2e/index.ts","./e2e/jasmine.ts","./lsp/ivy_spec.ts","./lsp/test_utils.ts","./pre_apf_project/app/app.component.ts","./pre_apf_project/app/app.module.ts","./pre_apf_project/app/foo.component.ts","./pre_standalone_project/app/app.component.ts","./pre_standalone_project/app/app.module.ts","./pre_standalone_project/app/foo.component.ts","./project/app/app.component.ts","./project/app/app.module.ts","./project/app/bar.component.ts","./project/app/foo.component.ts","./project/dist/post/index.d.ts","./project/dist/post/lib/post.component.d.ts","./project/libs/post/src/index.ts","./project/libs/post/src/lib/post.component.ts","./workspace/projects/demo/src/app/app.component.ts","./workspace/projects/demo/src/app/app.module.ts"],"errors":true,"version":"5.9.2"}