diff --git a/.circleci/config.yml b/.circleci/config.yml index 9b4d307941..f88cbea571 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -753,11 +753,11 @@ jobs: - setup_win - run: name: Build all windows CI targets - command: yarn bazel build --build_tag_filters=-ivy-only //packages/compiler-cli/... //tools/ts-api-guardian/... + command: yarn bazel build --build_tag_filters=-ivy-only,-no-windows //packages/compiler-cli/... //tools/ts-api-guardian/... no_output_timeout: 15m - run: name: Test all windows CI targets - command: yarn bazel test --test_tag_filters="-ivy-only,-browser:chromium-local" //packages/compiler-cli/... //tools/ts-api-guardian/... + command: yarn bazel test --build_tag_filters=-no-windows --test_tag_filters="-ivy-only,-no-windows,-browser:chromium-local" //packages/compiler-cli/... //tools/ts-api-guardian/... no_output_timeout: 15m test_ivy_aot_win: @@ -766,11 +766,11 @@ jobs: - setup_win - run: name: Build all windows CI targets - command: yarn bazel build --config=ivy --build_tag_filters=-no-ivy-aot,-fixme-ivy-aot //packages/compiler-cli/... //tools/ts-api-guardian/... + command: yarn bazel build --config=ivy --build_tag_filters=-no-ivy-aot,-no-windows,-fixme-ivy-aot //packages/compiler-cli/... //tools/ts-api-guardian/... no_output_timeout: 15m - run: name: Test all windows CI targets - command: yarn bazel test --config=ivy --test_tag_filters="-no-ivy-aot,-fixme-ivy-aot,-browser:chromium-local" //packages/compiler-cli/... //tools/ts-api-guardian/... + command: yarn bazel test --config=ivy --build_tag_filters=-no-windows --test_tag_filters="-no-ivy-aot,-no-windows,-fixme-ivy-aot,-browser:chromium-local" //packages/compiler-cli/... //tools/ts-api-guardian/... no_output_timeout: 15m diff --git a/packages/compiler-cli/test/compliance/partial/BUILD.bazel b/packages/compiler-cli/test/compliance/partial/BUILD.bazel new file mode 100644 index 0000000000..f9cee03174 --- /dev/null +++ b/packages/compiler-cli/test/compliance/partial/BUILD.bazel @@ -0,0 +1,19 @@ +load("//tools:defaults.bzl", "ts_library") + +ts_library( + name = "generate_golden_partial_lib", + testonly = True, + srcs = [ + "cli.ts", + "generate_golden_partial.ts", + ], + visibility = ["//packages/compiler-cli/test/compliance:__subpackages__"], + deps = [ + "//packages/compiler-cli/src/ngtsc/file_system", + "//packages/compiler-cli/test/compliance/test_helpers", + ], +) + +exports_files([ + "cli.ts", +]) diff --git a/packages/compiler-cli/test/compliance/partial/cli.ts b/packages/compiler-cli/test/compliance/partial/cli.ts new file mode 100644 index 0000000000..afcd0eb002 --- /dev/null +++ b/packages/compiler-cli/test/compliance/partial/cli.ts @@ -0,0 +1,10 @@ +/** + * @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 {generateGoldenPartial} from './generate_golden_partial'; + +generateGoldenPartial(process.argv[2]); diff --git a/packages/compiler-cli/test/compliance/partial/generate_golden_partial.ts b/packages/compiler-cli/test/compliance/partial/generate_golden_partial.ts new file mode 100644 index 0000000000..4daa4926e3 --- /dev/null +++ b/packages/compiler-cli/test/compliance/partial/generate_golden_partial.ts @@ -0,0 +1,59 @@ +/** + * @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 {FileSystem} from '../../../src/ngtsc/file_system'; +import {compileTest, getBuildOutputDirectory, initMockTestFileSystem} from '../test_helpers/compile_test'; +import {ComplianceTest, getComplianceTests} from '../test_helpers/get_compliance_tests'; +import {PartiallyCompiledFile, renderGoldenPartial} from '../test_helpers/golden_partials'; + +/** + * Generate the golden partial output for the tests described in the `testConfigPath` config file. + * + * @param testConfigPath Path (relative to the `test_cases` directory) of the `TEST_CASES.json` file + * that describes the tests. + */ +export function generateGoldenPartial(testConfigPath: string): void { + const files: PartiallyCompiledFile[] = []; + const tests = getComplianceTests(testConfigPath); + for (const test of tests) { + const fs = initMockTestFileSystem(test.realTestPath); + for (const file of compilePartials(fs, test)) { + files.push(file); + } + } + writeGoldenPartial(files); +} + +/** + * Partially compile the source files specified by the given `test`. + * + * @param fs The mock file-system to use when compiling partials. + * @param test The information about the test being compiled. + */ +function* compilePartials(fs: FileSystem, test: ComplianceTest): Generator { + const builtDirectory = getBuildOutputDirectory(fs); + for (const generatedPath of compileTest( + fs, test.inputFiles, test.compilerOptions, + {compilationMode: 'partial', ...test.angularCompilerOptions})) { + yield { + path: fs.relative(builtDirectory, generatedPath), + content: fs.readFile(generatedPath), + }; + } +} + +/** + * Write the partially compiled files to the appropriate output destination. + * + * For now just push the concatenated partial files to standard out. + * + * @param files The partially compiled files. + */ +function writeGoldenPartial(files: PartiallyCompiledFile[]): void { + // tslint:disable-next-line: no-console + console.log(renderGoldenPartial(files)); +} diff --git a/packages/compiler-cli/test/compliance/partial/partial_compliance_goldens.bzl b/packages/compiler-cli/test/compliance/partial/partial_compliance_goldens.bzl new file mode 100644 index 0000000000..edbf9029dc --- /dev/null +++ b/packages/compiler-cli/test/compliance/partial/partial_compliance_goldens.bzl @@ -0,0 +1,54 @@ +load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test", "nodejs_binary", "npm_package_bin") + +def partial_compliance_golden(filePath): + """Creates the generate and testing targets for partial compile results. + """ + + # Remove the "TEST_CASES.json" substring from the end of the provided path. + path = filePath[:-len("/TEST_CASES.json")] + + nodejs_binary( + name = "_generate_%s" % path, + testonly = True, + data = [ + "//packages/compiler-cli/test/compliance/partial:generate_golden_partial_lib", + "//packages/compiler-cli/test/compliance/test_cases", + "//packages/compiler-cli/test/ngtsc/fake_core:npm_package", + ], + visibility = [":__pkg__"], + entry_point = "//packages/compiler-cli/test/compliance/partial:cli.ts", + templated_args = [ + # "--node_options=--inspect-brk", + filePath, + ], + ) + + npm_package_bin( + name = "_generated_%s" % path, + tool = "_generate_%s" % path, + testonly = True, + stdout = "%s/this_file_should_not_be_committed" % path, + link_workspace_root = True, + tags = [ + # TODO(josephperrott): Begin running these tests on windows after updating to rules_nodejs 3.0 + "no-windows", + ], + visibility = [":__pkg__"], + data = [ + "//packages/compiler-cli/test/compliance/partial:generate_golden_partial_lib", + "//packages/compiler-cli/test/compliance/test_cases", + "//packages/compiler-cli/test/ngtsc/fake_core:npm_package", + ], + ) + + generated_file_test( + visibility = ["//visibility:public"], + tags = [ + "ivy-only", + # TODO(josephperrott): Begin running these tests on windows after updating to rules_nodejs 3.0 + "no-windows", + ], + name = "%s.golden" % path, + src = "//packages/compiler-cli/test/compliance/test_cases:%s/GOLDEN_PARTIAL.js" % path, + generated = "_generated_%s" % path, + ) diff --git a/packages/compiler-cli/test/compliance/test_cases/BUILD.bazel b/packages/compiler-cli/test/compliance/test_cases/BUILD.bazel index c69d46110a..51d995fb08 100644 --- a/packages/compiler-cli/test/compliance/test_cases/BUILD.bazel +++ b/packages/compiler-cli/test/compliance/test_cases/BUILD.bazel @@ -1,4 +1,5 @@ load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin") +load("//packages/compiler-cli/test/compliance/partial:partial_compliance_goldens.bzl", "partial_compliance_golden") package(default_visibility = ["//packages/compiler-cli/test/compliance:__subpackages__"]) @@ -9,3 +10,5 @@ copy_to_bin( name = "test_cases", srcs = glob(["*/**"]), ) + +[partial_compliance_golden(filePath = path) for path in glob(include = ["**/TEST_CASES.json"])] diff --git a/packages/compiler-cli/test/compliance/test_helpers/golden_partials.ts b/packages/compiler-cli/test/compliance/test_helpers/golden_partials.ts new file mode 100644 index 0000000000..579d9cdb06 --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_helpers/golden_partials.ts @@ -0,0 +1,49 @@ +/** + * @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 + */ + +const headerStart = + '/****************************************************************************************************\n' + + ' * PARTIAL FILE: '; + +const headerEnd = + '\n ****************************************************************************************************/'; + +/** + * Render the partially compiled files into a single golden partial output string. + * + * @param files The partially compiled files to be rendered. + */ +export function renderGoldenPartial(files: PartiallyCompiledFile[]): string { + return files.map(file => `${headerStart + file.path + headerEnd}\n${file.content}`).join('\n'); +} + +/** + * Parse the `partialContent` into a set of partially compiled files. + * + * The `partialContent` is a single string that can contains multiple files. + * Each file is delimited by a header comment that also contains its original path. + * + * @param partialContent The partial content to parse. + */ +export function parseGoldenPartial(partialContent: string): PartiallyCompiledFile[] { + const files: PartiallyCompiledFile[] = []; + const partials = partialContent.split(headerStart); + for (const partial of partials) { + const [path, content] = partial.split(headerEnd); + files.push({path, content}); + } + return files; +} + +/** + * Represents the path and contents of a partially compiled file. + */ +export interface PartiallyCompiledFile { + path: string; + content: string; +}