diff --git a/src/material/schematics/ng-update/index.ts b/src/material/schematics/ng-update/index.ts index ce710ab79417..15ef1abaccb0 100644 --- a/src/material/schematics/ng-update/index.ts +++ b/src/material/schematics/ng-update/index.ts @@ -21,6 +21,7 @@ import {MiscTemplateMigration} from './migrations/misc-checks/misc-template'; import {RippleSpeedFactorMigration} from './migrations/misc-ripples-v7/ripple-speed-factor-migration'; import {SecondaryEntryPointsMigration} from './migrations/package-imports-v8/secondary-entry-points-migration'; import {ThemingApiMigration} from './migrations/theming-api-v12/theming-api-migration'; +import {LegacyComponentsMigration} from './migrations/legacy-components-v15'; import {materialUpgradeData} from './upgrade-data'; @@ -34,6 +35,7 @@ const materialMigrations: NullableDevkitMigration[] = [ SecondaryEntryPointsMigration, HammerGesturesMigration, ThemingApiMigration, + LegacyComponentsMigration, ]; /** Entry point for the migration schematics with target of Angular Material v6 */ diff --git a/src/material/schematics/ng-update/migrations/legacy-components-v15/index.ts b/src/material/schematics/ng-update/migrations/legacy-components-v15/index.ts new file mode 100644 index 000000000000..0fb8376df0ff --- /dev/null +++ b/src/material/schematics/ng-update/migrations/legacy-components-v15/index.ts @@ -0,0 +1,13 @@ +/** + * @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 {Migration, TargetVersion} from '@angular/cdk/schematics'; + +export class LegacyComponentsMigration extends Migration { + enabled = this.targetVersion === TargetVersion.V15; +} diff --git a/src/material/schematics/ng-update/test-cases/v15/legacy-components-v15.spec.ts b/src/material/schematics/ng-update/test-cases/v15/legacy-components-v15.spec.ts new file mode 100644 index 000000000000..f3dc6d94ba4f --- /dev/null +++ b/src/material/schematics/ng-update/test-cases/v15/legacy-components-v15.spec.ts @@ -0,0 +1,45 @@ +import {UnitTestTree} from '@angular-devkit/schematics/testing'; +import {createTestCaseSetup} from '@angular/cdk/schematics/testing'; +import {join} from 'path'; +import {MIGRATION_PATH} from '../../../paths'; + +const PROJECT_ROOT_DIR = '/projects/cdk-testing'; +const THEME_FILE_PATH = join(PROJECT_ROOT_DIR, 'src/theme.scss'); +const TS_FILE_PATH = join(PROJECT_ROOT_DIR, 'src/app/app.component.ts'); + +describe('v15 legacy components migration', () => { + let tree: UnitTestTree; + + /** Writes an array of lines as a single file. */ + let writeLines: (path: string, lines: string[]) => void; + + /** Reads a file and split it into an array where each item is a new line. */ + let splitFile: (path: string) => string[]; + + /** Runs the v15 migration on the test application. */ + let runMigration: () => Promise<{logOutput: string}>; + + beforeEach(async () => { + const testSetup = await createTestCaseSetup('migration-v15', MIGRATION_PATH, []); + tree = testSetup.appTree; + runMigration = testSetup.runFixers; + splitFile = (path: string) => tree.readContent(path).split('\n'); + writeLines = (path: string, lines: string[]) => testSetup.writeFile(path, lines.join('\n')); + }); + + describe('typescript migrations', () => { + it('should do nothing yet', async () => { + writeLines(TS_FILE_PATH, [' ']); + await runMigration(); + expect(splitFile(TS_FILE_PATH)).toEqual([' ']); + }); + }); + + describe('style migrations', () => { + it('should do nothing yet', async () => { + writeLines(THEME_FILE_PATH, [' ']); + await runMigration(); + expect(splitFile(THEME_FILE_PATH)).toEqual([' ']); + }); + }); +});