test(compiler-cli): run compliance tests for two compilation modes … (#38938)

To verify the correctness of the linker output, we leverage the existing
compliance tests. The plan is to test the linker by running all compliance
tests using a full round trip of pre-linking and subsequently post-linking,
where the generated code should be identical to a full AOT compile.

This commit adds an additional Bazel target that runs the compliance
tests in partial mode. Follow-up work is required to implement the logic
for running the linker round trip.

PR Close #38938
This commit is contained in:
Pete Bacon Darwin 2020-09-22 15:42:33 +01:00 committed by Joey Perrott
parent 9d04b95166
commit 5903e8ad65
5 changed files with 99 additions and 9 deletions

View File

@ -6,11 +6,15 @@ ts_library(
srcs = glob(
["**/*.ts"],
),
visibility = [
":__subpackages__",
],
deps = [
"//packages:types",
"//packages/compiler",
"//packages/compiler-cli",
"//packages/compiler-cli/src/ngtsc/file_system",
"//packages/compiler-cli/test/compliance/mock_compile",
"//packages/compiler/test:test_utils",
"@npm//typescript",
],

View File

@ -0,0 +1,19 @@
load("//tools:defaults.bzl", "ts_library")
ts_library(
name = "mock_compile",
testonly = True,
srcs = ["index.ts"],
visibility = [
"//packages/compiler-cli/test/compliance:__subpackages__",
],
deps = [
"//packages:types",
"//packages/compiler",
"//packages/compiler-cli",
"//packages/compiler-cli/src/ngtsc/core:api",
"//packages/compiler-cli/src/ngtsc/file_system",
"//packages/compiler/test:test_utils",
"@npm//typescript",
],
)

View File

@ -5,13 +5,13 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {AotCompilerOptions} from '@angular/compiler';
import {escapeRegExp} from '@angular/compiler/src/util';
import {arrayToMockDir, MockCompilerHost, MockData, MockDirectory, toMockFileArray} from '@angular/compiler/test/aot/test_util';
import * as ts from 'typescript';
import {NodeJSFileSystem, setFileSystem} from '../../src/ngtsc/file_system';
import {NgtscProgram} from '../../src/ngtsc/program';
import {NgCompilerOptions} from '../../../src/ngtsc/core/api';
import {NodeJSFileSystem, setFileSystem} from '../../../src/ngtsc/file_system';
import {NgtscProgram} from '../../../src/ngtsc/program';
const IDENTIFIER = /[A-Za-z_$ɵ][A-Za-z0-9_$]*/;
const OPERATOR =
@ -196,12 +196,8 @@ function buildMatcher(pieces: (string|RegExp)[]): {regexp: RegExp, groups: Map<s
};
}
export function compile(
data: MockDirectory, angularFiles: MockData, options: AotCompilerOptions = {},
errorCollector: (error: any, fileName?: string) => void = error => {
throw error;
}): {
export function doCompile(
data: MockDirectory, angularFiles: MockData, options: NgCompilerOptions = {}): {
source: string,
} {
setFileSystem(new NodeJSFileSystem());
@ -226,3 +222,18 @@ export function compile(
return {source};
}
export type CompileFn = typeof doCompile;
/**
* The actual compile function that will be used to compile the test code.
* This can be updated by a test bootstrap script to provide an alternative compile function.
*/
export let compile: CompileFn = doCompile;
/**
* Update the `compile` exported function to use a new implementation.
*/
export function setCompileFn(compileFn: CompileFn) {
compile = compileFn;
}

View File

@ -0,0 +1,29 @@
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
ts_library(
name = "prelink_bootstrap",
testonly = True,
srcs = ["bootstrap.ts"],
deps = [
"//packages:types",
"//packages/compiler-cli/test/compliance/mock_compile",
],
)
jasmine_node_test(
name = "prelink",
bootstrap = [
"//tools/testing:node_no_angular_es5",
":prelink_bootstrap_es5",
],
data = [
"//packages/compiler-cli/test/ngtsc/fake_core:npm_package",
],
shard_count = 4,
tags = [
"ivy-only",
],
deps = [
"//packages/compiler-cli/test/compliance:test_lib",
],
)

View File

@ -0,0 +1,27 @@
/**
* @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.io/license
*/
import {CompileFn, doCompile, setCompileFn} from '../mock_compile';
/**
* A function to compile the given code in two steps:
*
* - first compile the code in partial mode
* - then compile the partially compiled code using the linker
*
* This should produce the same output as the full AOT compilation
*/
const linkedCompile: CompileFn = (data, angularFiles, options) => {
const result = doCompile(data, angularFiles, {...options, compilationMode: 'partial'});
// TODO: additional post linking
return result;
};
// Update the function that will do the compiling with this specialised version that
// runs the prelink and postlink parts of AOT compilation, to check it produces the
// same result as a normal full AOT compile.
setCompileFn(linkedCompile);