From 09ba30ef2960f2b4394e13d776ca3921e670f457 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 2 Dec 2020 14:12:03 +0000 Subject: [PATCH] test(compiler-cli): improve compliance test compile mode filtering (#39939) Previously one could set a flag in a `TEST_CASES.json` file to exclude the test-cases from being run if the input files were being compiled partially and then linked. There are also scenarios where one might want to exclude test-cases from "full compile" mode test runs. This commit changes the compliance test tooling to support a new property `compilationModeFilter`, which is an array containing one or more of `"full compile"` and `"linked compile"`. Only the tests whose `compilationModeFilter` array contains the current compilation mode will be run. PR Close #39939 --- .../compiler-cli/test/compliance/README.md | 2 +- .../compliance/linked/linked_compile_spec.ts | 2 +- .../components_and_directives/TEST_CASES.json | 4 +++- .../errors/TEST_CASES.json | 12 +++++++++--- .../es5_support/TEST_CASES.json | 4 +++- .../invalid/TEST_CASES.json | 4 +++- .../test_cases/test_case_schema.json | 18 ++++++++++++++---- .../test_helpers/get_compliance_tests.ts | 16 ++++++++++++---- .../compliance/test_helpers/test_runner.ts | 13 +++++-------- 9 files changed, 51 insertions(+), 24 deletions(-) diff --git a/packages/compiler-cli/test/compliance/README.md b/packages/compiler-cli/test/compliance/README.md index d7f25bc316..f7124d851a 100644 --- a/packages/compiler-cli/test/compliance/README.md +++ b/packages/compiler-cli/test/compliance/README.md @@ -38,7 +38,7 @@ Each test-case can specify: * A `description` of the test. * The `inputFiles` that will be compiled. * Additional `compilerOptions` and `angularCompilerOptions` that are passed to the compiler. -* Whether to exclude this test-case from partial compilation tests (`excludeFromPartialTests`). +* Whether to exclude this test-case from certain tests running under certain compilation modes (`compilationModeFilter`). * A collection of `expectations` definitions that will be checked against the generated files. Note that there is a JSON schema for the `TEST_CASES.json` file stored at `test_cases/test_case_schema.json`. diff --git a/packages/compiler-cli/test/compliance/linked/linked_compile_spec.ts b/packages/compiler-cli/test/compliance/linked/linked_compile_spec.ts index 1dd362fb9c..d5cdbb80cf 100644 --- a/packages/compiler-cli/test/compliance/linked/linked_compile_spec.ts +++ b/packages/compiler-cli/test/compliance/linked/linked_compile_spec.ts @@ -14,7 +14,7 @@ import {ComplianceTest} from '../test_helpers/get_compliance_tests'; import {parseGoldenPartial} from '../test_helpers/golden_partials'; import {runTests} from '../test_helpers/test_runner'; -runTests('partial compile + link', linkPartials); +runTests('linked compile', linkPartials); /** * Link all the partials specified in the given `test`. diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/TEST_CASES.json b/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/TEST_CASES.json index 05de96b415..e21aaad044 100644 --- a/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/TEST_CASES.json +++ b/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/TEST_CASES.json @@ -135,7 +135,9 @@ "compilerOptions": { "target": "ES5" }, - "excludeFromPartialTests": true, + "compilationModeFilter": [ + "full compile" + ], "expectations": [ { "failureMessage": "Incorrect setClassMetadata call", diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/TEST_CASES.json b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/TEST_CASES.json index 14825ea3e3..ef9628442d 100644 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/TEST_CASES.json +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/TEST_CASES.json @@ -6,7 +6,9 @@ "inputFiles": [ "nested_i18n_msg.ts" ], - "excludeFromPartialTests": true, + "compilationModeFilter": [ + "full compile" + ], "expectations": [ { "expectedErrors": [ @@ -23,7 +25,9 @@ "inputFiles": [ "nested_i18n_msg_with_tags.ts" ], - "excludeFromPartialTests": true, + "compilationModeFilter": [ + "full compile" + ], "expectations": [ { "expectedErrors": [ @@ -40,7 +44,9 @@ "inputFiles": [ "nested_i18n_msg_with_ng-containers.ts" ], - "excludeFromPartialTests": true, + "compilationModeFilter": [ + "full compile" + ], "expectations": [ { "expectedErrors": [ diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/es5_support/TEST_CASES.json b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/es5_support/TEST_CASES.json index 16ed8ed14e..b55b561088 100644 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/es5_support/TEST_CASES.json +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/es5_support/TEST_CASES.json @@ -6,7 +6,9 @@ "compilerOptions": { "target": "ES5" }, - "excludeFromPartialTests": true, + "compilationModeFilter": [ + "full compile" + ], "expectations": [ { "extraChecks": [ diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/invalid/TEST_CASES.json b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/invalid/TEST_CASES.json index da0acdeaae..60b2540ba3 100644 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/invalid/TEST_CASES.json +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/invalid/TEST_CASES.json @@ -15,7 +15,9 @@ ] } ], - "excludeFromPartialTests": true + "compilationModeFilter": [ + "full compile" + ] } ] } diff --git a/packages/compiler-cli/test/compliance/test_cases/test_case_schema.json b/packages/compiler-cli/test/compliance/test_cases/test_case_schema.json index f426084473..f6f30e1ffe 100644 --- a/packages/compiler-cli/test/compliance/test_cases/test_case_schema.json +++ b/packages/compiler-cli/test/compliance/test_cases/test_case_schema.json @@ -20,10 +20,20 @@ "description": "This will be used as the message in an `it()` clause.", "type": "string" }, - "excludeFromPartialTests": { - "title": "If set to true then do not check this test-case expectations in partial tests.", - "type": "boolean", - "default": false + "compilationModeFilter": { + "title": "An array of compilation modes under which this test-case should be run.", + "type": "array", + "items": { + "type": "string", + "enum": [ + "full compile", + "linked compile" + ] + }, + "default": [ + "full compile", + "linked compile" + ] }, "inputFiles": { "title": "A collection of source files to compile", diff --git a/packages/compiler-cli/test/compliance/test_helpers/get_compliance_tests.ts b/packages/compiler-cli/test/compliance/test_helpers/get_compliance_tests.ts index 065415311f..ae20cb9ad6 100644 --- a/packages/compiler-cli/test/compliance/test_helpers/get_compliance_tests.ts +++ b/packages/compiler-cli/test/compliance/test_helpers/get_compliance_tests.ts @@ -35,13 +35,16 @@ export function* getComplianceTests(testConfigPath: string): Generator CompileResult) { - const isPartial = type === 'partial compile + link'; - + type: CompilationMode, compileFn: (fs: FileSystem, test: ComplianceTest) => CompileResult) { describe(`compliance tests (${type})`, () => { for (const test of getAllComplianceTests()) { - if (isPartial && test.excludeFromPartialTests) { + if (!test.compilationModeFilter.includes(type)) { continue; } describe(`[${test.relativePath}]`, () => { const itFn = test.focusTest ? fit : test.excludeTest ? xit : it; itFn(test.description, () => { - if (isPartial && test.compilerOptions?.target === 'ES5') { + if (type === 'linked compile' && test.compilerOptions?.target === 'ES5') { throw new Error( `The "${type}" scenario does not support ES5 output.\n` + - `Did you mean to set \`"excludeFromPartialTests": true\` in "${ + `Did you mean to set \`"compilationModeFilter": ["full compile"]\` in "${ test.relativePath}"?`); }