Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(compiler-cli): run compiler-cli tests in bazel #22997

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/compiler-cli/src/transformers/api.ts
Expand Up @@ -262,9 +262,6 @@ export interface TsEmitArguments {
export interface TsEmitCallback { (args: TsEmitArguments): ts.EmitResult; }
export interface TsMergeEmitResultsCallback { (results: ts.EmitResult[]): ts.EmitResult; }

/**
* @internal
*/
export interface LibrarySummary {
fileName: string;
text: string;
Expand Down Expand Up @@ -367,8 +364,6 @@ export interface Program {
* Returns the .d.ts / .ngsummary.json / .ngfactory.d.ts files of libraries that have been emitted
* in this program or previous programs with paths that emulate the fact that these libraries
* have been compiled before with no outDir.
*
* @internal
*/
getLibrarySummaries(): Map<string, LibrarySummary>;

Expand Down
130 changes: 130 additions & 0 deletions packages/compiler-cli/test/BUILD.bazel
@@ -0,0 +1,130 @@
load("//tools:defaults.bzl", "ts_library", "ts_web_test")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")

# Uses separate test rules to allow the tests to run in parallel

ts_library(
name = "test_utils",
testonly = 1,
srcs = [
"mocks.ts",
"test_support.ts",
],
visibility = [":__subpackages__"],
deps = [
"//packages:types",
"//packages/compiler",
"//packages/compiler-cli",
],
)

# extract_18n_spec
ts_library(
name = "extract_i18n_lib",
testonly = 1,
srcs = [
"extract_i18n_spec.ts",
],
deps = [
":test_utils",
"//packages/compiler",
"//packages/compiler-cli",
],
)

jasmine_node_test(
name = "extract_i18n",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
data = [
"//packages/core:npm_package",
],
deps = [
":extract_i18n_lib",
"//packages/core",
"//tools/testing:node",
],
)

# ngc_spec
ts_library(
name = "ngc_lib",
testonly = 1,
srcs = [
"ngc_spec.ts",
],
deps = [
":test_utils",
"//packages/compiler",
"//packages/compiler-cli",
],
)

jasmine_node_test(
name = "ngc",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
data = [
"//packages/common:npm_package",
"//packages/core:npm_package",
"//packages/platform-browser:npm_package",
],
deps = [
":ngc_lib",
"//packages/core",
"//tools/testing:node",
],
)

# ngctools_api_spec
ts_library(
name = "ngtools_api_lib",
testonly = 1,
srcs = [
"ngtools_api_spec.ts",
],
deps = [
":test_utils",
"//packages/compiler",
"//packages/compiler-cli",
],
)

jasmine_node_test(
name = "ngtools_api",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
data = [
"//packages/core:npm_package",
"//packages/router:npm_package",
],
deps = [
":ngtools_api_lib",
"//packages/core",
"//tools/testing:node",
],
)

# perform_watch_spec
ts_library(
name = "perform_watch_lib",
testonly = 1,
srcs = [
"perform_watch_spec.ts",
],
deps = [
":test_utils",
"//packages/compiler",
"//packages/compiler-cli",
],
)

jasmine_node_test(
name = "perform_watch",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
data = [
"//packages/core:npm_package",
],
deps = [
":perform_watch_lib",
"//packages/core",
"//tools/testing:node",
],
)
99 changes: 99 additions & 0 deletions packages/compiler-cli/test/diagnostics/BUILD.bazel
@@ -0,0 +1,99 @@
load("//tools:defaults.bzl", "ts_library", "ts_web_test")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")

ts_library(
name = "mocks",
testonly = 1,
srcs = [
"mocks.ts",
],
deps = [
"//packages:types",
"//packages/compiler",
"//packages/compiler-cli",
"//packages/compiler-cli/test:test_utils",
"//packages/core",
],
)

# check_types_spec
ts_library(
name = "check_types_lib",
testonly = 1,
srcs = ["check_types_spec.ts"],
deps = [
":mocks",
"//packages/compiler-cli",
"//packages/compiler-cli/test:test_utils",
],
)

jasmine_node_test(
name = "check_types",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
data = [
"//packages/common:npm_package",
"//packages/core:npm_package",
],
deps = [
":check_types_lib",
"//packages/core",
"//tools/testing:node",
],
)

# expression_diagnostics_spec
ts_library(
name = "expression_diagnostics_lib",
testonly = 1,
srcs = ["expression_diagnostics_spec.ts"],
deps = [
":mocks",
"//packages/compiler",
"//packages/compiler-cli",
"//packages/compiler-cli/test:test_utils",
"//packages/language-service",
],
)

jasmine_node_test(
name = "expression_diagnostics",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
data = [
"//packages/common:npm_package",
"//packages/core:npm_package",
"//packages/forms:npm_package",
],
deps = [
":expression_diagnostics_lib",
"//packages/core",
"//tools/testing:node",
],
)

# symbol_query_spec
ts_library(
name = "symbol_query_lib",
testonly = 1,
srcs = ["symbol_query_spec.ts"],
deps = [
":mocks",
"//packages/compiler",
"//packages/compiler-cli",
"//packages/compiler-cli/test:test_utils",
"//packages/compiler/test:test_utils",
"//packages/language-service",
],
)

jasmine_node_test(
name = "symbol_query",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
data = [
],
deps = [
":symbol_query_lib",
"//packages/core",
"//tools/testing:node",
],
)
Expand Up @@ -19,6 +19,7 @@ import {DiagnosticContext, MockLanguageServiceHost, getDiagnosticTemplateInfo} f

describe('expression diagnostics', () => {
let registry: ts.DocumentRegistry;

let host: MockLanguageServiceHost;
let service: ts.LanguageService;
let context: DiagnosticContext;
Expand Down
16 changes: 11 additions & 5 deletions packages/compiler-cli/test/diagnostics/mocks.ts
Expand Up @@ -15,11 +15,17 @@ import * as ts from 'typescript';
import {DiagnosticTemplateInfo} from '../../src/diagnostics/expression_diagnostics';
import {getClassFromStaticSymbol, getClassMembers, getPipesTable, getSymbolQuery} from '../../src/diagnostics/typescript_symbols';
import {Directory, MockAotContext} from '../mocks';
import {isInBazel, setup} from '../test_support';

function calcRootPath() {
const moduleFilename = module.filename.replace(/\\/g, '/');
const distIndex = moduleFilename.indexOf('/dist/all');
return moduleFilename.substr(0, distIndex);
function calculateAngularPath() {
if (isInBazel()) {
const support = setup();
return path.join(support.basePath, 'node_modules/@angular/*');
} else {
const moduleFilename = module.filename.replace(/\\/g, '/');
const distIndex = moduleFilename.indexOf('/dist/all');
return moduleFilename.substr(0, distIndex) + '/packages/*';
}
}

const realFiles = new Map<string, string>();
Expand All @@ -43,7 +49,7 @@ export class MockLanguageServiceHost implements ts.LanguageServiceHost {
strictNullChecks: true,
baseUrl: currentDirectory,
lib: ['lib.es2015.d.ts', 'lib.dom.d.ts'],
paths: {'@angular/*': [calcRootPath() + '/packages/*']}
paths: {'@angular/*': [calculateAngularPath()]}
};
this.context = new MockAotContext(currentDirectory, files);
}
Expand Down
45 changes: 26 additions & 19 deletions packages/compiler-cli/test/extract_i18n_spec.ts
Expand Up @@ -12,7 +12,7 @@ import * as ts from 'typescript';

import {mainXi18n} from '../src/extract_i18n';

import {makeTempDir} from './test_support';
import {isInBazel, makeTempDir, setup} from './test_support';

function getNgRootDir() {
const moduleFilename = module.filename.replace(/\\/g, '/');
Expand Down Expand Up @@ -110,15 +110,31 @@ describe('extract_i18n command line', () => {

beforeEach(() => {
errorSpy = jasmine.createSpy('consoleError').and.callFake(console.error);
basePath = makeTempDir();
write = (fileName: string, content: string) => {
const dir = path.dirname(fileName);
if (dir != '.') {
const newDir = path.join(basePath, dir);
if (!fs.existsSync(newDir)) fs.mkdirSync(newDir);
}
fs.writeFileSync(path.join(basePath, fileName), content, {encoding: 'utf-8'});
};
if (isInBazel()) {
const support = setup();
write = (fileName: string, content: string) => { support.write(fileName, content); };
basePath = support.basePath;
outDir = path.join(basePath, 'built');
} else {
basePath = makeTempDir();
write = (fileName: string, content: string) => {
const dir = path.dirname(fileName);
if (dir != '.') {
const newDir = path.join(basePath, dir);
if (!fs.existsSync(newDir)) fs.mkdirSync(newDir);
}
fs.writeFileSync(path.join(basePath, fileName), content, {encoding: 'utf-8'});
};
outDir = path.resolve(basePath, 'built');
const ngRootDir = getNgRootDir();
const nodeModulesPath = path.resolve(basePath, 'node_modules');
fs.mkdirSync(nodeModulesPath);
fs.symlinkSync(
path.resolve(ngRootDir, 'dist', 'all', '@angular'),
path.resolve(nodeModulesPath, '@angular'));
fs.symlinkSync(
path.resolve(ngRootDir, 'node_modules', 'rxjs'), path.resolve(nodeModulesPath, 'rxjs'));
}
write('tsconfig-base.json', `{
"compilerOptions": {
"experimentalDecorators": true,
Expand All @@ -136,15 +152,6 @@ describe('extract_i18n command line', () => {
"typeRoots": ["node_modules/@types"]
}
}`);
outDir = path.resolve(basePath, 'built');
const ngRootDir = getNgRootDir();
const nodeModulesPath = path.resolve(basePath, 'node_modules');
fs.mkdirSync(nodeModulesPath);
fs.symlinkSync(
path.resolve(ngRootDir, 'dist', 'all', '@angular'),
path.resolve(nodeModulesPath, '@angular'));
fs.symlinkSync(
path.resolve(ngRootDir, 'node_modules', 'rxjs'), path.resolve(nodeModulesPath, 'rxjs'));
});

function writeSources() {
Expand Down
26 changes: 26 additions & 0 deletions packages/compiler-cli/test/metadata/BUILD.bazel
@@ -0,0 +1,26 @@
load("//tools:defaults.bzl", "ts_library", "ts_web_test")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")

ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.ts"]),
deps = [
"//packages:types",
"//packages/compiler",
"//packages/compiler-cli",
"//packages/core",
],
)

jasmine_node_test(
name = "test",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
data = [
],
deps = [
":test_lib",
"//packages/core",
"//tools/testing:node",
],
)
2 changes: 1 addition & 1 deletion packages/compiler-cli/test/metadata/collector_spec.ts
Expand Up @@ -877,7 +877,7 @@ describe('Collector', () => {
export const InjectionToken: {new<T>(desc: string): InjectionToken<T>;} = class {
constructor(protected _desc: string) {}

toString(): string { return \`InjectionToken ${this._desc}\`; }
toString(): string { return \`InjectionToken \${this._desc}\`; }
} as any;`,
ts.ScriptTarget.Latest, true);
const metadata = collector.getMetadata(source) !;
Expand Down