Skip to content

Commit 8b14771

Browse files
wagnermacielmmalerba
authored andcommitted
feat(material/schematics): initial setup for v15 ng-update (#25102)
1 parent ef4a360 commit 8b14771

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

src/material/schematics/ng-update/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {MiscTemplateMigration} from './migrations/misc-checks/misc-template';
2121
import {RippleSpeedFactorMigration} from './migrations/misc-ripples-v7/ripple-speed-factor-migration';
2222
import {SecondaryEntryPointsMigration} from './migrations/package-imports-v8/secondary-entry-points-migration';
2323
import {ThemingApiMigration} from './migrations/theming-api-v12/theming-api-migration';
24+
import {LegacyComponentsMigration} from './migrations/legacy-components-v15';
2425

2526
import {materialUpgradeData} from './upgrade-data';
2627

@@ -34,6 +35,7 @@ const materialMigrations: NullableDevkitMigration[] = [
3435
SecondaryEntryPointsMigration,
3536
HammerGesturesMigration,
3637
ThemingApiMigration,
38+
LegacyComponentsMigration,
3739
];
3840

3941
/** Entry point for the migration schematics with target of Angular Material v6 */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Migration, TargetVersion} from '@angular/cdk/schematics';
10+
11+
export class LegacyComponentsMigration extends Migration<null> {
12+
enabled = this.targetVersion === TargetVersion.V15;
13+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {UnitTestTree} from '@angular-devkit/schematics/testing';
2+
import {createTestCaseSetup} from '@angular/cdk/schematics/testing';
3+
import {join} from 'path';
4+
import {MIGRATION_PATH} from '../../../paths';
5+
6+
const PROJECT_ROOT_DIR = '/projects/cdk-testing';
7+
const THEME_FILE_PATH = join(PROJECT_ROOT_DIR, 'src/theme.scss');
8+
const TS_FILE_PATH = join(PROJECT_ROOT_DIR, 'src/app/app.component.ts');
9+
10+
describe('v15 legacy components migration', () => {
11+
let tree: UnitTestTree;
12+
13+
/** Writes an array of lines as a single file. */
14+
let writeLines: (path: string, lines: string[]) => void;
15+
16+
/** Reads a file and split it into an array where each item is a new line. */
17+
let splitFile: (path: string) => string[];
18+
19+
/** Runs the v15 migration on the test application. */
20+
let runMigration: () => Promise<{logOutput: string}>;
21+
22+
beforeEach(async () => {
23+
const testSetup = await createTestCaseSetup('migration-v15', MIGRATION_PATH, []);
24+
tree = testSetup.appTree;
25+
runMigration = testSetup.runFixers;
26+
splitFile = (path: string) => tree.readContent(path).split('\n');
27+
writeLines = (path: string, lines: string[]) => testSetup.writeFile(path, lines.join('\n'));
28+
});
29+
30+
describe('typescript migrations', () => {
31+
it('should do nothing yet', async () => {
32+
writeLines(TS_FILE_PATH, [' ']);
33+
await runMigration();
34+
expect(splitFile(TS_FILE_PATH)).toEqual([' ']);
35+
});
36+
});
37+
38+
describe('style migrations', () => {
39+
it('should do nothing yet', async () => {
40+
writeLines(THEME_FILE_PATH, [' ']);
41+
await runMigration();
42+
expect(splitFile(THEME_FILE_PATH)).toEqual([' ']);
43+
});
44+
});
45+
});

0 commit comments

Comments
 (0)