Skip to content

Commit

Permalink
feat(material/schematics): initial setup for v15 ng-update (#25102)
Browse files Browse the repository at this point in the history
  • Loading branch information
wagnermaciel authored and mmalerba committed Jul 15, 2022
1 parent ef4a360 commit 8b14771
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/material/schematics/ng-update/index.ts
Expand Up @@ -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';

Expand All @@ -34,6 +35,7 @@ const materialMigrations: NullableDevkitMigration[] = [
SecondaryEntryPointsMigration,
HammerGesturesMigration,
ThemingApiMigration,
LegacyComponentsMigration,
];

/** Entry point for the migration schematics with target of Angular Material v6 */
Expand Down
@@ -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<null> {
enabled = this.targetVersion === TargetVersion.V15;
}
@@ -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([' ']);
});
});
});

0 comments on commit 8b14771

Please sign in to comment.