Skip to content

Commit b153c77

Browse files
committed
feat(ivy): add //packages/compiler-cli/test/ngcc
$ bazel test //packages/compiler-cli/test/ngcc This commit adds ngcc_spec.ts which sets up a test environment that includes ngc-compiled versions of @angular/core and @angular/common, and invokes ngcc against @angular/common. It's a starting point for additional ngcc testing.
1 parent d701209 commit b153c77

File tree

4 files changed

+89
-13
lines changed

4 files changed

+89
-13
lines changed

Diff for: packages/compiler-cli/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ts_library(
2525
tsconfig = ":tsconfig",
2626
deps = [
2727
"//packages/compiler",
28+
"//packages/compiler-cli/src/ngcc",
2829
"//packages/compiler-cli/src/ngtsc/annotations",
2930
"//packages/compiler-cli/src/ngtsc/metadata",
3031
"//packages/compiler-cli/src/ngtsc/transform",

Diff for: packages/compiler-cli/src/ngcc/BUILD.bazel

+3-12
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,14 @@ load("//tools:defaults.bzl", "ts_library")
44
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
55

66
ts_library(
7-
name = "test_lib",
8-
testonly = 1,
7+
name = "ngcc",
98
srcs = glob([
9+
"*.ts",
1010
"**/*.ts",
1111
]),
1212
deps = [
1313
"//packages:types",
14+
"//packages/compiler-cli/src/ngtsc/host",
1415
"//packages/compiler-cli/src/ngtsc/metadata",
15-
"//packages/compiler-cli/src/ngtsc/testing",
16-
],
17-
)
18-
19-
jasmine_node_test(
20-
name = "test",
21-
bootstrap = ["angular/tools/testing/init_node_no_angular_spec.js"],
22-
deps = [
23-
":test_lib",
24-
"//tools/testing:node_no_angular",
2516
],
2617
)

Diff for: packages/compiler-cli/test/ngcc/BUILD.bazel

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ts_library(
1010
deps = [
1111
"//packages/compiler",
1212
"//packages/compiler-cli",
13+
"//packages/compiler-cli/src/ngcc",
1314
"//packages/compiler-cli/test:test_utils",
1415
],
1516
)
@@ -18,7 +19,8 @@ jasmine_node_test(
1819
name = "ngcc",
1920
bootstrap = ["angular/tools/testing/init_node_no_angular_spec.js"],
2021
data = [
21-
"//packages/compiler-cli/test/ngcc/fake_core:npm_package",
22+
"//packages/core:npm_package",
23+
"//packages/common:npm_package",
2224
],
2325
deps = [
2426
":ngcc_lib",

Diff for: packages/compiler-cli/test/ngcc/ngcc_spec.ts

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import * as fs from 'fs';
10+
import * as path from 'path';
11+
12+
import {mainNgcc} from '../../src/ngcc/src/main';
13+
14+
import {TestSupport, isInBazel, setup} from '../test_support';
15+
16+
function setupNodeModules(support: TestSupport): void {
17+
const corePath = path.join(process.env.TEST_SRCDIR, 'angular/packages/core/npm_package');
18+
const commonPath = path.join(process.env.TEST_SRCDIR, 'angular/packages/common/npm_package');
19+
20+
const nodeModulesPath = path.join(support.basePath, 'node_modules');
21+
const angularCoreDirectory = path.join(nodeModulesPath, '@angular/core');
22+
const angularCommonDirectory = path.join(nodeModulesPath, '@angular/common');
23+
24+
// fs.symlinkSync(corePath, angularCoreDirectory);
25+
// fs.symlinkSync(commonPath, angularCommonDirectory);
26+
}
27+
28+
describe('ngcc behavioral tests', () => {
29+
if (!isInBazel()) {
30+
// These tests should be excluded from the non-Bazel build.
31+
return;
32+
}
33+
34+
let basePath: string;
35+
let outDir: string;
36+
let write: (fileName: string, content: string) => void;
37+
let errorSpy: jasmine.Spy&((s: string) => void);
38+
39+
function shouldExist(fileName: string) {
40+
if (!fs.existsSync(path.resolve(outDir, fileName))) {
41+
throw new Error(`Expected ${fileName} to be emitted (outDir: ${outDir})`);
42+
}
43+
}
44+
45+
function shouldNotExist(fileName: string) {
46+
if (fs.existsSync(path.resolve(outDir, fileName))) {
47+
throw new Error(`Did not expect ${fileName} to be emitted (outDir: ${outDir})`);
48+
}
49+
}
50+
51+
function getContents(fileName: string): string {
52+
shouldExist(fileName);
53+
const modulePath = path.resolve(outDir, fileName);
54+
return fs.readFileSync(modulePath, 'utf8');
55+
}
56+
57+
function writeConfig(
58+
tsconfig: string =
59+
'{"extends": "./tsconfig-base.json", "angularCompilerOptions": {"enableIvy": "ngtsc"}}') {
60+
write('tsconfig.json', tsconfig);
61+
}
62+
63+
beforeEach(() => {
64+
errorSpy = jasmine.createSpy('consoleError').and.callFake(console.error);
65+
const support = setup();
66+
basePath = support.basePath;
67+
outDir = path.join(basePath, 'built');
68+
process.chdir(basePath);
69+
write = (fileName: string, content: string) => { support.write(fileName, content); };
70+
71+
setupNodeModules(support);
72+
});
73+
74+
it('should run ngcc without errors', () => {
75+
const nodeModulesPath = path.join(basePath, 'node_modules');
76+
console.error(nodeModulesPath);
77+
const commonPath = path.join(nodeModulesPath, '@angular/common');
78+
const exitCode = mainNgcc([commonPath]);
79+
80+
expect(exitCode).toBe(0);
81+
});
82+
});

0 commit comments

Comments
 (0)