From f094bb54a76efb675e00e9a19837fb3df39b8389 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Mon, 29 Apr 2019 21:17:03 +0200 Subject: [PATCH] test(core): run schematic tests with public migration collection (#30198) 572b54967c969c88c61970650fb857afc1d74f8a changed how the schematic tests are executed. Tests no longer use the schematic collection that is also used by the CLI `ng update` command and therefore the migration collection could technically be invalid. In order to ensure that the public migration collection is guaranteed to work and to avoid duplication within two schematic collections, the changes are partially reverted and only the disabled `injectable-pipe` schematic has its own collection. PR Close #30198 --- packages/core/schematics/BUILD.bazel | 1 - packages/core/schematics/test-migrations.json | 20 ------------------- packages/core/schematics/test/BUILD.bazel | 3 ++- .../test/injectable_pipe_migration_spec.ts | 2 +- .../test/move_document_migration_spec.ts | 4 ++-- .../static_queries_migration_template_spec.ts | 4 ++-- .../static_queries_migration_usage_spec.ts | 4 ++-- .../template_var_assignment_migration_spec.ts | 6 ++++-- .../core/schematics/test/test-migrations.json | 10 ++++++++++ 9 files changed, 23 insertions(+), 31 deletions(-) delete mode 100644 packages/core/schematics/test-migrations.json create mode 100644 packages/core/schematics/test/test-migrations.json diff --git a/packages/core/schematics/BUILD.bazel b/packages/core/schematics/BUILD.bazel index f83cb584a8..29546e0172 100644 --- a/packages/core/schematics/BUILD.bazel +++ b/packages/core/schematics/BUILD.bazel @@ -3,7 +3,6 @@ load("//tools:defaults.bzl", "npm_package") exports_files([ "tsconfig.json", "migrations.json", - "test-migrations.json", ]) npm_package( diff --git a/packages/core/schematics/test-migrations.json b/packages/core/schematics/test-migrations.json deleted file mode 100644 index c057a763a4..0000000000 --- a/packages/core/schematics/test-migrations.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "schematics": { - "migration-move-document": { - "description": "Migrates DOCUMENT Injection token from platform-browser imports to common import", - "factory": "./migrations/move-document/index" - }, - "migration-static-queries": { - "description": "Migrates ViewChild and ContentChild to explicit query timing", - "factory": "./migrations/static-queries/index" - }, - "migration-template-local-variables": { - "description": "Warns developers if values are assigned to template variables", - "factory": "./migrations/template-var-assignment/index" - }, - "migration-injectable-pipe": { - "description": "Migrates all Pipe classes so that they have an Injectable annotation", - "factory": "./migrations/injectable-pipe/index" - } - } -} diff --git a/packages/core/schematics/test/BUILD.bazel b/packages/core/schematics/test/BUILD.bazel index cdb4814bc6..f61d48e0dc 100644 --- a/packages/core/schematics/test/BUILD.bazel +++ b/packages/core/schematics/test/BUILD.bazel @@ -5,7 +5,8 @@ ts_library( testonly = True, srcs = glob(["**/*.ts"]), data = [ - "//packages/core/schematics:test-migrations.json", + "test-migrations.json", + "//packages/core/schematics:migrations.json", ], deps = [ "//packages/core/schematics/migrations/injectable-pipe", diff --git a/packages/core/schematics/test/injectable_pipe_migration_spec.ts b/packages/core/schematics/test/injectable_pipe_migration_spec.ts index ba73bf49b9..a37399414e 100644 --- a/packages/core/schematics/test/injectable_pipe_migration_spec.ts +++ b/packages/core/schematics/test/injectable_pipe_migration_spec.ts @@ -20,7 +20,7 @@ describe('injectable pipe migration', () => { let previousWorkingDir: string; beforeEach(() => { - runner = new SchematicTestRunner('test', require.resolve('../test-migrations.json')); + runner = new SchematicTestRunner('test', require.resolve('./test-migrations.json')); host = new TempScopedNodeJsSyncHost(); tree = new UnitTestTree(new HostTree(host)); diff --git a/packages/core/schematics/test/move_document_migration_spec.ts b/packages/core/schematics/test/move_document_migration_spec.ts index 2cd3df8ec3..85f55411ac 100644 --- a/packages/core/schematics/test/move_document_migration_spec.ts +++ b/packages/core/schematics/test/move_document_migration_spec.ts @@ -20,7 +20,7 @@ describe('move-document migration', () => { let previousWorkingDir: string; beforeEach(() => { - runner = new SchematicTestRunner('test', require.resolve('../test-migrations.json')); + runner = new SchematicTestRunner('test', require.resolve('../migrations.json')); host = new TempScopedNodeJsSyncHost(); tree = new UnitTestTree(new HostTree(host)); @@ -151,5 +151,5 @@ describe('move-document migration', () => { host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents)); } - function runMigration() { runner.runSchematic('migration-move-document', {}, tree); } + function runMigration() { runner.runSchematic('migration-v8-move-document', {}, tree); } }); diff --git a/packages/core/schematics/test/static_queries_migration_template_spec.ts b/packages/core/schematics/test/static_queries_migration_template_spec.ts index e9ae5ad0a3..cdb8b62061 100644 --- a/packages/core/schematics/test/static_queries_migration_template_spec.ts +++ b/packages/core/schematics/test/static_queries_migration_template_spec.ts @@ -21,7 +21,7 @@ describe('static-queries migration with template strategy', () => { let warnOutput: string[]; beforeEach(() => { - runner = new SchematicTestRunner('test', require.resolve('../test-migrations.json')); + runner = new SchematicTestRunner('test', require.resolve('../migrations.json')); host = new TempScopedNodeJsSyncHost(); tree = new UnitTestTree(new HostTree(host)); @@ -97,7 +97,7 @@ describe('static-queries migration with template strategy', () => { } async function runMigration() { - await runner.runSchematicAsync('migration-static-queries', {}, tree).toPromise(); + await runner.runSchematicAsync('migration-v8-static-queries', {}, tree).toPromise(); } describe('ViewChild', () => { diff --git a/packages/core/schematics/test/static_queries_migration_usage_spec.ts b/packages/core/schematics/test/static_queries_migration_usage_spec.ts index 258d7ff9e7..1b30aadf8b 100644 --- a/packages/core/schematics/test/static_queries_migration_usage_spec.ts +++ b/packages/core/schematics/test/static_queries_migration_usage_spec.ts @@ -26,7 +26,7 @@ describe('static-queries migration with usage strategy', () => { afterAll(() => process.env['NG_STATIC_QUERY_USAGE_STRATEGY'] = ''); beforeEach(() => { - runner = new SchematicTestRunner('test', require.resolve('../test-migrations.json')); + runner = new SchematicTestRunner('test', require.resolve('../migrations.json')); host = new TempScopedNodeJsSyncHost(); tree = new UnitTestTree(new HostTree(host)); @@ -145,7 +145,7 @@ describe('static-queries migration with usage strategy', () => { } async function runMigration() { - await runner.runSchematicAsync('migration-static-queries', {}, tree).toPromise(); + await runner.runSchematicAsync('migration-v8-static-queries', {}, tree).toPromise(); } function createQueryTests(queryType: 'ViewChild' | 'ContentChild') { diff --git a/packages/core/schematics/test/template_var_assignment_migration_spec.ts b/packages/core/schematics/test/template_var_assignment_migration_spec.ts index 5797cfdaaf..742ced7e15 100644 --- a/packages/core/schematics/test/template_var_assignment_migration_spec.ts +++ b/packages/core/schematics/test/template_var_assignment_migration_spec.ts @@ -21,7 +21,7 @@ describe('template variable assignment migration', () => { let warnOutput: string[]; beforeEach(() => { - runner = new SchematicTestRunner('test', require.resolve('../test-migrations.json')); + runner = new SchematicTestRunner('test', require.resolve('../migrations.json')); host = new TempScopedNodeJsSyncHost(); tree = new UnitTestTree(new HostTree(host)); @@ -58,7 +58,9 @@ describe('template variable assignment migration', () => { host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents)); } - function runMigration() { runner.runSchematic('migration-template-local-variables', {}, tree); } + function runMigration() { + runner.runSchematic('migration-v8-template-local-variables', {}, tree); + } it('should warn for two-way data binding variable assignment', () => { writeFile('/index.ts', ` diff --git a/packages/core/schematics/test/test-migrations.json b/packages/core/schematics/test/test-migrations.json new file mode 100644 index 0000000000..cdb97750a4 --- /dev/null +++ b/packages/core/schematics/test/test-migrations.json @@ -0,0 +1,10 @@ +{ + // Migrations which are not publicly enabled but still run as part of tests need to + // be part of a schematic collection in order to be able to run it. + "schematics": { + "migration-injectable-pipe": { + "description": "Migrates all Pipe classes so that they have an Injectable annotation", + "factory": "../migrations/injectable-pipe/index" + } + } +}