mirror of
https://github.com/angular/angular.git
synced 2026-11-22 22:55:25 -05:00
build: switch ngp language service tests to bazel
Reworks the ngp language service tests to fully run in Bazel.
This commit is contained in:
committed by
Kristiyan Kostadinov
parent
458f1d76b8
commit
9cefc5e2a1
@@ -80,8 +80,6 @@ jobs:
|
||||
run: pnpm install --frozen-lockfile
|
||||
- name: Run CI tests for framework
|
||||
run: pnpm test:ci
|
||||
- name: Run hybrid language service tests
|
||||
run: pnpm test:ngp:language-service
|
||||
- name: Run hybrid language service LSP tests
|
||||
run: pnpm test:ngp:vscode
|
||||
|
||||
|
||||
@@ -86,8 +86,6 @@ jobs:
|
||||
# Ensures Aspect lock files are up-to-date.
|
||||
# TODO(devversion): Remove when removing pnpm.
|
||||
ASPECT_RULES_JS_FROZEN_PNPM_LOCK: '1'
|
||||
- name: Run hybrid language service tests
|
||||
run: pnpm test:ngp:language-service
|
||||
- name: Run hybrid language service LSP tests
|
||||
run: pnpm test:ngp:vscode
|
||||
- name: Upload GRPC logs (for debugging of RBE issues)
|
||||
|
||||
@@ -96,6 +96,7 @@ npm.npm_translate_lock(
|
||||
"//packages/compiler:package.json",
|
||||
"//packages/compiler-cli:package.json",
|
||||
"//packages/compiler-cli/linker/babel/test:package.json",
|
||||
"//packages/compiler-cli/preprocessor/language-service:package.json",
|
||||
"//packages/core:package.json",
|
||||
"//packages/core/test/bundling:package.json",
|
||||
"//packages/elements:package.json",
|
||||
|
||||
@@ -5,7 +5,7 @@ import fs from 'node:fs/promises';
|
||||
import Jasmine from 'jasmine';
|
||||
import cp from 'node:child_process';
|
||||
import {createRequire} from 'node:module';
|
||||
import {ensureWasmBinding} from '../../packages/compiler-cli/preprocessor/language-service/tests/wasm_binding.mjs';
|
||||
import {ensureWasmBinding} from './wasm_binding.mjs';
|
||||
|
||||
const req = createRequire(import.meta.url);
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
"build": "node scripts/build/build-packages-dist.mts",
|
||||
"test": "bazelisk test",
|
||||
"test:ci": "bazelisk test -- //... -//integration/... -//adev/... -//vscode-ng-language-service/... -//devtools/... -//modules/ssr-benchmarks/...",
|
||||
"test:ngp:language-service": "pnpm bazel build //packages/compiler-cli/preprocessor/ng-analyze:wasm && pnpm --prefix packages/compiler-cli/preprocessor/language-service test",
|
||||
"test:ngp:vscode": "pnpm bazel build //packages/compiler-cli/preprocessor/ng-analyze:wasm && pnpm --prefix ngp-vscode-ng-language-service run test:lsp",
|
||||
"integration-tests:ci": "bazelisk test -- //integration/...",
|
||||
"test-tsec": "bazelisk test //... --build_tag_filters=tsec --test_tag_filters=tsec",
|
||||
|
||||
@@ -12,15 +12,10 @@ ts_config(
|
||||
|
||||
ts_project(
|
||||
name = "preprocessor",
|
||||
srcs = glob(
|
||||
include = [
|
||||
"*.ts",
|
||||
"src/**/*.ts",
|
||||
],
|
||||
exclude = [
|
||||
"src/diagnostics.ts",
|
||||
],
|
||||
),
|
||||
srcs = glob([
|
||||
"*.ts",
|
||||
"src/**/*.ts",
|
||||
]),
|
||||
tsconfig = ":tsconfig",
|
||||
deps = [
|
||||
"//:node_modules/@types/node",
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
load("@npm//:defs.bzl", "npm_link_all_packages")
|
||||
load("//tools:defaults.bzl", "ts_project")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
npm_link_all_packages(name = "node_modules")
|
||||
|
||||
ts_project(
|
||||
name = "language-service",
|
||||
srcs = glob(["src/**/*.ts"]),
|
||||
tsconfig = "//packages/compiler-cli/preprocessor:tsconfig",
|
||||
deps = [
|
||||
":node_modules/vscode-jsonrpc",
|
||||
":node_modules/vscode-languageserver",
|
||||
":node_modules/vscode-uri",
|
||||
"//:node_modules/@types/node",
|
||||
"//:node_modules/typescript",
|
||||
"//packages/compiler",
|
||||
"//packages/compiler-cli/preprocessor",
|
||||
"//packages/compiler-cli/private",
|
||||
"//packages/language-service:private",
|
||||
],
|
||||
)
|
||||
@@ -6,8 +6,7 @@
|
||||
"scripts": {
|
||||
"compile": "tsc -p .",
|
||||
"watch": "tsc -p . -w",
|
||||
"typecheck": "tsc -p . --noEmit",
|
||||
"test": "node tests/run_jasmine.mjs"
|
||||
"typecheck": "tsc -p . --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
||||
|
||||
@@ -232,6 +232,8 @@ export class DefinitionBuilder {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-13
@@ -7,14 +7,8 @@
|
||||
*/
|
||||
|
||||
import ts from 'typescript';
|
||||
import {HybridCompiler} from './hybrid_compiler.js';
|
||||
import {
|
||||
Diagnostic,
|
||||
DiagnosticSeverity,
|
||||
DiagnosticTag,
|
||||
DiagnosticRelatedInformation,
|
||||
Position,
|
||||
} from 'vscode-languageserver';
|
||||
import {HybridCompiler} from '../../src/hybrid_compiler.js';
|
||||
import {Diagnostic, Position} from 'vscode-languageserver';
|
||||
import * as path from 'node:path';
|
||||
import {URI} from 'vscode-uri';
|
||||
|
||||
@@ -24,11 +18,9 @@ import {
|
||||
getTemplateLocationFromTcbLocation,
|
||||
getTcbPath,
|
||||
isTcbFunction,
|
||||
} from './tcb_ls_util.js';
|
||||
import {hasIgnoreForDiagnosticsMarker} from './comments.js';
|
||||
import {makeClassKey} from './compiler-utils.js';
|
||||
|
||||
const IGNORE_MARKER_REGEX = /\/\*\s*D:ignore\s*\*\//;
|
||||
} from '../../src/tcb_ls_util.js';
|
||||
import {hasIgnoreForDiagnosticsMarker} from '../../src/comments.js';
|
||||
import {makeClassKey} from '../../src/compiler-utils.js';
|
||||
|
||||
/**
|
||||
* Fallback check for ignore markers when the AST is broken due to syntax errors
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {HybridCompiler} from '../../src/hybrid_compiler.js';
|
||||
import {mapDiagnostics} from '../../src/diagnostics.js';
|
||||
import {mapDiagnostics} from './diagnostic_mapping.js';
|
||||
import {Diagnostic} from 'vscode-languageserver';
|
||||
|
||||
export async function handleDiagnostics(
|
||||
|
||||
@@ -109,6 +109,8 @@ export async function getSignatureHelp(
|
||||
shimPosition = shimNode.arguments.pos;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
const tcbPath = getTcbPath(tsFilePath);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
load("//tools:defaults.bzl", "jasmine_test", "ts_project")
|
||||
|
||||
ts_project(
|
||||
name = "test_lib",
|
||||
testonly = True,
|
||||
srcs = glob(["*.ts"]),
|
||||
deps = [
|
||||
"//:node_modules/@types/jasmine",
|
||||
"//:node_modules/@types/node",
|
||||
"//packages/compiler-cli/preprocessor",
|
||||
"//packages/compiler-cli/preprocessor/language-service",
|
||||
"//packages/compiler-cli/preprocessor/language-service:node_modules/vscode-jsonrpc",
|
||||
"//packages/compiler-cli/preprocessor/language-service:node_modules/vscode-languageserver",
|
||||
"//packages/compiler-cli/preprocessor/language-service:node_modules/vscode-languageserver-textdocument",
|
||||
"//packages/compiler-cli/preprocessor/language-service:node_modules/vscode-uri",
|
||||
],
|
||||
)
|
||||
|
||||
jasmine_test(
|
||||
name = "test",
|
||||
timeout = "long",
|
||||
data = [
|
||||
":test_lib",
|
||||
# Provides the `tsgo` binary that backs the language service.
|
||||
"//packages/compiler-cli/preprocessor/language-service:node_modules/@typescript/native-preview",
|
||||
"//packages/compiler-cli/preprocessor/ng-analyze:ng_analyze_wasm",
|
||||
"//packages/compiler-cli/preprocessor/ng-analyze:package_json",
|
||||
] + glob(["test-workspace/**"]),
|
||||
shard_count = 4,
|
||||
)
|
||||
@@ -7,19 +7,17 @@
|
||||
*/
|
||||
|
||||
import {TsGoFacade} from '../src/facade';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import * as rpc from 'vscode-jsonrpc/node';
|
||||
import {CompletionItemKind} from 'vscode-languageserver';
|
||||
|
||||
import {
|
||||
TestEnv,
|
||||
getTestWorkspacePath,
|
||||
startTestServer,
|
||||
expectContain,
|
||||
expectAll,
|
||||
expectDoesNotContain,
|
||||
expectReplacementText,
|
||||
expectContainInsertText,
|
||||
expectContainInsertTextWithSnippet,
|
||||
expectDoesNotContainInsertTextWithSnippet,
|
||||
toText,
|
||||
@@ -32,7 +30,7 @@ describe('Completions with TS 7 binary', () => {
|
||||
let serverCleanup: () => Promise<void>;
|
||||
let env: TestEnv;
|
||||
|
||||
const testWorkspacePath = path.resolve(__dirname, 'test-workspace');
|
||||
const testWorkspacePath = getTestWorkspacePath();
|
||||
|
||||
beforeAll(async () => {
|
||||
await fs.mkdir(testWorkspacePath, {recursive: true});
|
||||
|
||||
@@ -12,7 +12,7 @@ import * as fs from 'node:fs/promises';
|
||||
import * as rpc from 'vscode-jsonrpc/node';
|
||||
import {TextDocument} from 'vscode-languageserver-textdocument';
|
||||
|
||||
import {TestEnv, startTestServer} from './test_helpers';
|
||||
import {TestEnv, getTestWorkspacePath, startTestServer} from './test_helpers';
|
||||
import {TestFileManager} from './test_file_manager';
|
||||
|
||||
describe('Definitions with TS 7 binary', () => {
|
||||
@@ -21,7 +21,7 @@ describe('Definitions with TS 7 binary', () => {
|
||||
let serverCleanup: () => Promise<void>;
|
||||
let env: TestEnv;
|
||||
|
||||
const testWorkspacePath = path.resolve(__dirname, 'test-workspace');
|
||||
const testWorkspacePath = getTestWorkspacePath();
|
||||
|
||||
beforeAll(async () => {
|
||||
await fs.mkdir(testWorkspacePath, {recursive: true});
|
||||
|
||||
@@ -13,7 +13,7 @@ import * as rpc from 'vscode-jsonrpc/node';
|
||||
import {TextDocument} from 'vscode-languageserver-textdocument';
|
||||
import {DiagnosticSeverity} from 'vscode-languageserver';
|
||||
|
||||
import {TestEnv, startTestServer} from './test_helpers';
|
||||
import {TestEnv, getTestWorkspacePath, startTestServer} from './test_helpers';
|
||||
import {TestFileManager} from './test_file_manager';
|
||||
|
||||
describe('Diagnostics Mapping', () => {
|
||||
@@ -21,7 +21,7 @@ describe('Diagnostics Mapping', () => {
|
||||
let facade: TsGoFacade;
|
||||
let serverCleanup: () => Promise<void>;
|
||||
|
||||
const testWorkspacePath = path.resolve(__dirname, 'test-workspace');
|
||||
const testWorkspacePath = getTestWorkspacePath();
|
||||
|
||||
beforeAll(async () => {
|
||||
await fs.mkdir(testWorkspacePath, {recursive: true});
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
|
||||
import * as path from 'path';
|
||||
import * as rpc from 'vscode-jsonrpc/node';
|
||||
import {TestEnv, startTestServer} from './test_helpers';
|
||||
import {TestEnv, getTestWorkspacePath, startTestServer} from './test_helpers';
|
||||
import {TestFileManager} from './test_file_manager';
|
||||
|
||||
import {TsGoFacade} from '../src/facade';
|
||||
|
||||
const testWorkspacePath = path.join(__dirname, 'test-workspace');
|
||||
const testWorkspacePath = getTestWorkspacePath();
|
||||
|
||||
describe('Incremental Analysis', () => {
|
||||
let connection: rpc.MessageConnection;
|
||||
|
||||
@@ -7,12 +7,10 @@
|
||||
*/
|
||||
|
||||
import {TsGoFacade} from '../src/facade';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import * as rpc from 'vscode-jsonrpc/node';
|
||||
import {TextDocument} from 'vscode-languageserver-textdocument';
|
||||
|
||||
import {TestEnv, startTestServer} from './test_helpers';
|
||||
import {TestEnv, getTestWorkspacePath, startTestServer} from './test_helpers';
|
||||
import {TestFileManager} from './test_file_manager';
|
||||
|
||||
describe('QuickInfo with TS 7 binary', () => {
|
||||
@@ -21,7 +19,7 @@ describe('QuickInfo with TS 7 binary', () => {
|
||||
let serverCleanup: () => Promise<void>;
|
||||
let env: TestEnv;
|
||||
|
||||
const testWorkspacePath = path.resolve(__dirname, 'test-workspace');
|
||||
const testWorkspacePath = getTestWorkspacePath();
|
||||
|
||||
beforeAll(async () => {
|
||||
await fs.mkdir(testWorkspacePath, {recursive: true});
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ import * as rpc from 'vscode-jsonrpc/node';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import {Location} from 'vscode-languageserver';
|
||||
|
||||
import {TestEnv, startTestServer} from './test_helpers';
|
||||
import {TestEnv, getTestWorkspacePath, startTestServer} from './test_helpers';
|
||||
import {TestFileManager} from './test_file_manager';
|
||||
import {positionToOffset} from '../../src/tcb_ls_util.js';
|
||||
|
||||
@@ -50,7 +50,7 @@ describe('References and Rename with TS 7 binary', () => {
|
||||
let serverCleanup: () => Promise<void>;
|
||||
let env: TestEnv;
|
||||
|
||||
const testWorkspacePath = path.resolve(__dirname, 'test-workspace');
|
||||
const testWorkspacePath = getTestWorkspacePath();
|
||||
|
||||
beforeAll(async () => {
|
||||
await fs.mkdir(testWorkspacePath, {recursive: true});
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
|
||||
import esbuild from 'esbuild';
|
||||
import path from 'node:path';
|
||||
import {fileURLToPath, pathToFileURL} from 'node:url';
|
||||
import fs from 'node:fs/promises';
|
||||
import Jasmine from 'jasmine';
|
||||
import cp from 'node:child_process';
|
||||
import {createRequire} from 'node:module';
|
||||
import {ensureWasmBinding} from './wasm_binding.mjs';
|
||||
|
||||
const req = createRequire(import.meta.url);
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const repoRoot = path.resolve(__dirname, '../../../../..');
|
||||
const outDir = path.join(__dirname, '.jasmine_build');
|
||||
|
||||
ensureWasmBinding(repoRoot);
|
||||
|
||||
// If no arguments, run each spec in its own child process sequentially for clean isolation
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length === 0) {
|
||||
const entries = await fs.readdir(__dirname);
|
||||
const specFiles = entries
|
||||
.filter((f) => (f.endsWith('_spec.ts') || f.endsWith('.test.ts')) && !f.endsWith('.d.ts'))
|
||||
.sort()
|
||||
.map((f) => path.join(__dirname, f));
|
||||
|
||||
let failed = false;
|
||||
for (const specFile of specFiles) {
|
||||
const result = cp.spawnSync(process.execPath, [fileURLToPath(import.meta.url), specFile], {
|
||||
stdio: 'inherit',
|
||||
cwd: repoRoot,
|
||||
});
|
||||
if (result.status !== 0) {
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
process.exit(failed ? 1 : 0);
|
||||
}
|
||||
|
||||
// Single spec run mode
|
||||
const specFile = path.resolve(args[0]);
|
||||
|
||||
// Resolve tsgo binary path
|
||||
try {
|
||||
const previewPkg = req.resolve('@typescript/native-preview/package.json');
|
||||
const previewReq = createRequire(previewPkg);
|
||||
const platformPkg = `@typescript/native-preview-${process.platform}-${process.arch}`;
|
||||
const platPkgJson = previewReq.resolve(`${platformPkg}/package.json`);
|
||||
process.env['TSGO_BINARY_PATH'] = path.join(
|
||||
path.dirname(platPkgJson),
|
||||
'lib',
|
||||
process.platform === 'win32' ? 'tsgo.exe' : 'tsgo',
|
||||
);
|
||||
} catch (e) {
|
||||
console.warn('Could not resolve tsgo binary:', e);
|
||||
}
|
||||
|
||||
// Clean and create outDir
|
||||
await fs.rm(outDir, {recursive: true, force: true});
|
||||
await fs.mkdir(outDir, {recursive: true});
|
||||
|
||||
try {
|
||||
const baseName = path.basename(specFile).replace(/\.ts$/, '.cjs');
|
||||
const outFile = path.join(outDir, baseName);
|
||||
|
||||
await esbuild.build({
|
||||
entryPoints: [specFile],
|
||||
bundle: true,
|
||||
platform: 'node',
|
||||
format: 'cjs',
|
||||
target: 'node20',
|
||||
outfile: outFile,
|
||||
external: [
|
||||
'vscode-languageserver',
|
||||
'vscode-languageserver/*',
|
||||
'vscode-languageserver-textdocument',
|
||||
'vscode-languageserver-types',
|
||||
'vscode-jsonrpc',
|
||||
'vscode-jsonrpc/*',
|
||||
'vscode-uri',
|
||||
'typescript',
|
||||
'@typescript/native-preview',
|
||||
'@typescript/native-preview/*',
|
||||
'jasmine',
|
||||
path.join(repoRoot, 'packages/compiler-cli/preprocessor/ng-analyze-wasm/ng_analyze.js'),
|
||||
path.join(repoRoot, 'packages/compiler-cli/preprocessor/ng-analyze/index.js'),
|
||||
],
|
||||
alias: {
|
||||
'@angular/compiler-cli/private/hybrid_analysis': path.join(
|
||||
repoRoot,
|
||||
'packages/compiler-cli/private/hybrid_analysis.ts',
|
||||
),
|
||||
'@angular/compiler-cli/private/migrations': path.join(
|
||||
repoRoot,
|
||||
'packages/compiler-cli/private/migrations.ts',
|
||||
),
|
||||
'@angular/compiler-cli': path.join(repoRoot, 'packages/compiler-cli/index.ts'),
|
||||
'@angular/compiler': path.join(repoRoot, 'packages/compiler/index.ts'),
|
||||
'@angular/language-service/private': path.join(
|
||||
repoRoot,
|
||||
'packages/language-service/private.ts',
|
||||
),
|
||||
'@angular/language-service/api': path.join(repoRoot, 'packages/language-service/api.ts'),
|
||||
'@angular/language-service': path.join(repoRoot, 'packages/language-service/api.ts'),
|
||||
'@angular/core': path.join(repoRoot, 'packages/core/index.ts'),
|
||||
},
|
||||
define: {
|
||||
__dirname: JSON.stringify(path.dirname(specFile)),
|
||||
'import.meta.url': JSON.stringify(pathToFileURL(specFile).href),
|
||||
},
|
||||
logOverride: {
|
||||
'empty-import-meta': 'silent',
|
||||
},
|
||||
});
|
||||
|
||||
// tslint:disable-next-line:no-console
|
||||
console.log(`\nRunning ${path.basename(specFile)} with Jasmine:`);
|
||||
const jasmine = new Jasmine();
|
||||
jasmine.exitOnCompletion = false;
|
||||
// The timeout lives on jasmine-core (`runner.jasmine`), not on the runner itself.
|
||||
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
||||
jasmine.env.configure({random: false});
|
||||
jasmine.loadConfig({
|
||||
spec_files: [outFile],
|
||||
});
|
||||
const result = await jasmine.execute();
|
||||
if (result.overallStatus !== 'passed') {
|
||||
process.exit(1);
|
||||
}
|
||||
} finally {
|
||||
await fs.rm(outDir, {recursive: true, force: true});
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import * as path from 'path';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import * as rpc from 'vscode-jsonrpc/node';
|
||||
|
||||
import {TestEnv, startTestServer} from './test_helpers';
|
||||
import {TestEnv, getTestWorkspacePath, startTestServer} from './test_helpers';
|
||||
import {TestFileManager} from './test_file_manager';
|
||||
|
||||
describe('Signature Help with TS 7 binary', () => {
|
||||
@@ -20,7 +20,7 @@ describe('Signature Help with TS 7 binary', () => {
|
||||
let serverCleanup: () => Promise<void>;
|
||||
let env: TestEnv;
|
||||
|
||||
const testWorkspacePath = path.resolve(__dirname, 'test-workspace');
|
||||
const testWorkspacePath = getTestWorkspacePath();
|
||||
|
||||
beforeAll(async () => {
|
||||
await fs.mkdir(testWorkspacePath, {recursive: true});
|
||||
|
||||
@@ -8,9 +8,11 @@
|
||||
|
||||
import * as path from 'path';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import * as fsSync from 'node:fs';
|
||||
import * as cp from 'child_process';
|
||||
import {HybridCompiler} from '../../src/hybrid_compiler.js';
|
||||
import {NapiAnalyzer} from '../../src/analyzer_napi.js';
|
||||
import {FileUpdateType} from '../../src/types.js';
|
||||
import {LanguageService} from '../src/language_service';
|
||||
import {buildTypeCheckingConfig} from '../../src/tcb';
|
||||
import {TsGoFacade} from '../src/facade';
|
||||
@@ -32,6 +34,14 @@ import {URI} from 'vscode-uri';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import {createRequire} from 'node:module';
|
||||
import {canonicalizePath} from '../src/utils.js';
|
||||
import {TestFileManager} from './test_file_manager';
|
||||
|
||||
/** Directory containing this file (and the spec files). */
|
||||
const TESTS_DIR = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
/** Relative path to the wasm engine, from the root of the Bazel runfiles tree. */
|
||||
const WASM_RUNFILES_PATH =
|
||||
'packages/compiler-cli/preprocessor/ng-analyze/ng_analyze_wasm/ng_analyze_wasm.js';
|
||||
|
||||
async function pathExists(p: string): Promise<boolean> {
|
||||
try {
|
||||
@@ -42,6 +52,58 @@ async function pathExists(p: string): Promise<boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
function runfilesDir(): string | undefined {
|
||||
return process.env['JS_BINARY__RUNFILES'] || process.env['RUNFILES_DIR'];
|
||||
}
|
||||
|
||||
let testWorkspacePath: string | null = null;
|
||||
|
||||
/**
|
||||
* Returns the directory the specs use as their project workspace.
|
||||
*
|
||||
* Under Bazel the runfiles tree is read-only, so the checked-in `test-workspace` is copied
|
||||
* into `TEST_TMPDIR` once per process. Outside Bazel the source directory is used directly.
|
||||
*/
|
||||
export function getTestWorkspacePath(): string {
|
||||
if (testWorkspacePath !== null) {
|
||||
return testWorkspacePath;
|
||||
}
|
||||
const source = path.join(TESTS_DIR, 'test-workspace');
|
||||
const tmpDir = process.env['TEST_TMPDIR'];
|
||||
if (tmpDir && runfilesDir()) {
|
||||
const dest = path.join(tmpDir, 'ngp-language-service-test-workspace');
|
||||
fsSync.cpSync(source, dest, {recursive: true, dereference: true});
|
||||
testWorkspacePath = fsSync.realpathSync(dest);
|
||||
} else {
|
||||
testWorkspacePath = source;
|
||||
}
|
||||
return testWorkspacePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates the wasm-bindgen build of the analysis engine.
|
||||
*
|
||||
* Honors the same overrides as the standalone runner, then falls back to the Bazel
|
||||
* runfiles tree. Returns `undefined` to let the analyzer loader use its own discovery.
|
||||
*/
|
||||
export function resolveWasmBinding(): string | undefined {
|
||||
const fromEnv = process.env['NG_EXP_COMPILER_WASM_BINDING'] || process.env['NGP_WASM_BINDING'];
|
||||
if (fromEnv) {
|
||||
return fromEnv;
|
||||
}
|
||||
const runfiles = runfilesDir();
|
||||
if (!runfiles) {
|
||||
return undefined;
|
||||
}
|
||||
for (const workspace of ['_main', 'angular', '']) {
|
||||
const candidate = path.join(runfiles, workspace, WASM_RUNFILES_PATH);
|
||||
if (fsSync.existsSync(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function toUri(filePath: string): Promise<string> {
|
||||
try {
|
||||
const rawPath = filePath.startsWith('file://') ? fileURLToPath(filePath) : filePath;
|
||||
@@ -72,7 +134,7 @@ export async function resolveTsGoPath(): Promise<string> {
|
||||
}
|
||||
} catch {}
|
||||
|
||||
const workspaceRoot = path.resolve(__dirname, '../..');
|
||||
const workspaceRoot = path.resolve(TESTS_DIR, '../..');
|
||||
const platformName = `@typescript/native-preview-${process.platform}-${process.arch}`;
|
||||
const localCandidates = [
|
||||
path.join(workspaceRoot, 'node_modules', platformName, 'lib', 'tsgo'),
|
||||
@@ -288,9 +350,11 @@ export class TestEnv {
|
||||
},
|
||||
): Promise<LanguageService> {
|
||||
const tsconfigPath = path.join(this.fileManager.getWorkspacePath(), 'tsconfig.json');
|
||||
const wasmBinding = resolveWasmBinding();
|
||||
const analyzer = await NapiAnalyzer.create(tsconfigPath, {
|
||||
nodeModulesPathOverride: path.resolve(__dirname, '../../node_modules'),
|
||||
ngAnalyzeDir: path.resolve(__dirname, '../../ng-analyze'),
|
||||
nodeModulesPathOverride: path.resolve(TESTS_DIR, '../../node_modules'),
|
||||
ngAnalyzeDir: path.resolve(TESTS_DIR, '../../ng-analyze'),
|
||||
...(wasmBinding ? {backend: 'wasm', wasmBinding} : {}),
|
||||
});
|
||||
this.compiler = new HybridCompiler(analyzer, {
|
||||
tcbConfig: buildTypeCheckingConfig(options, true),
|
||||
@@ -394,7 +458,7 @@ export class TestEnv {
|
||||
await this.closeFile(uri);
|
||||
}
|
||||
this.openedFiles = [];
|
||||
this.compiler = undefined;
|
||||
this.compiler = null;
|
||||
await this.fileManager.cleanup();
|
||||
}
|
||||
|
||||
@@ -454,10 +518,11 @@ export function expectContain(
|
||||
expect(completions).toBeDefined();
|
||||
for (const name of names) {
|
||||
const found = completions!.items.some((e) => e.label === name && matchesKind(e.kind, kind));
|
||||
expect(
|
||||
found,
|
||||
`Expected completions to contain entry "${name}" of kind "${kind}", but entries were: ${JSON.stringify(completions!.items.map((e) => ({label: e.label, kind: e.kind})))}`,
|
||||
).toBe(true);
|
||||
expect(found)
|
||||
.withContext(
|
||||
`Expected completions to contain entry "${name}" of kind "${kind}", but entries were: ${JSON.stringify(completions!.items.map((e) => ({label: e.label, kind: e.kind})))}`,
|
||||
)
|
||||
.toBe(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,10 +582,9 @@ export function expectContainInsertText(
|
||||
const found = completions!.items.some(
|
||||
(e) => (e.insertText === insertText || e.label === insertText) && matchesKind(e.kind, kind),
|
||||
);
|
||||
expect(
|
||||
found,
|
||||
`Expected completions to contain insertText "${insertText}" of kind "${kind}"`,
|
||||
).toBe(true);
|
||||
expect(found)
|
||||
.withContext(`Expected completions to contain insertText "${insertText}" of kind "${kind}"`)
|
||||
.toBe(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,10 +601,11 @@ export function expectContainInsertTextWithSnippet(
|
||||
matchesKind(e.kind, kind) &&
|
||||
e.insertTextFormat === InsertTextFormat.Snippet,
|
||||
);
|
||||
expect(
|
||||
found,
|
||||
`Expected completions to contain snippet insertText "${insertText}" of kind "${kind}"`,
|
||||
).toBe(true);
|
||||
expect(found)
|
||||
.withContext(
|
||||
`Expected completions to contain snippet insertText "${insertText}" of kind "${kind}"`,
|
||||
)
|
||||
.toBe(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -557,10 +622,11 @@ export function expectDoesNotContainInsertTextWithSnippet(
|
||||
matchesKind(e.kind, kind) &&
|
||||
e.insertTextFormat === InsertTextFormat.Snippet,
|
||||
);
|
||||
expect(
|
||||
found,
|
||||
`Expected completions NOT to contain snippet insertText "${insertText}" of kind "${kind}"`,
|
||||
).toBe(false);
|
||||
expect(found)
|
||||
.withContext(
|
||||
`Expected completions NOT to contain snippet insertText "${insertText}" of kind "${kind}"`,
|
||||
)
|
||||
.toBe(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,3 +109,9 @@ rust_test(
|
||||
"@crates//:tempfile",
|
||||
],
|
||||
)
|
||||
|
||||
# `main.rs` is excluded from `:ng_analyze`, so its tests need their own target.
|
||||
rust_test(
|
||||
name = "bin_test",
|
||||
crate = ":ng_analyze_bin",
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"extends": "../../tsconfig-build.json",
|
||||
"compilerOptions": {
|
||||
"types": ["node"]
|
||||
"types": ["node", "jasmine"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"@angular/compiler-cli/src/ngtsc/reflection": ["./compiler-cli/src/ngtsc/reflection/index"],
|
||||
"@angular/compiler-cli/src/ngtsc/metadata": ["./compiler-cli/src/ngtsc/metadata/index"],
|
||||
"@angular/compiler-cli/private/migrations": ["./compiler-cli/private/migrations"],
|
||||
"@angular/language-service/private": ["./language-service/private"],
|
||||
"@angular/core/schematics/utils/tsurge/*": ["./core/schematics/utils/tsurge/*"]
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user