Skip to content

Commit 7205fb4

Browse files
amysortommalerba
authored andcommitted
refactor(material/schematics): move some general scss migration testing logic to separate file
1 parent 8e2a666 commit 7205fb4

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

src/material/schematics/ng-generate/mdc-migration/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ts_library(
1616
deps = [
1717
"//src/cdk/schematics",
1818
"@npm//@angular-devkit/schematics",
19+
"@npm//@bazel/runfiles",
1920
"@npm//@types/node",
2021
"@npm//postcss",
2122
"@npm//postcss-scss",
@@ -56,7 +57,6 @@ ts_library(
5657
"//src/cdk/schematics/testing",
5758
"@npm//@angular-devkit/core",
5859
"@npm//@angular-devkit/schematics",
59-
"@npm//@bazel/runfiles",
6060
"@npm//@types/jasmine",
6161
"@npm//@types/node",
6262
],

src/material/schematics/ng-generate/mdc-migration/rules/components/button/button-styles.spec.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing';
22
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
3-
import {Schema} from '../../../schema';
4-
import {runfiles} from '@bazel/runfiles';
3+
import {createNewTestRunner, migrateComponent, THEME_FILE} from '../util';
54

65
describe('button styles', () => {
76
let runner: SchematicTestRunner;
87
let cliAppTree: UnitTestTree;
9-
const tsconfig = '/projects/material/tsconfig.app.json';
10-
const themeFile = '/projects/material/src/theme.scss';
118

129
async function runMigrationTest(oldFileContent: string, newFileContent: string) {
13-
cliAppTree.create(themeFile, oldFileContent);
14-
const tree = await migrate({tsconfig, components: ['button']});
15-
expect(tree.readContent(themeFile)).toBe(newFileContent);
10+
cliAppTree.create(THEME_FILE, oldFileContent);
11+
const tree = await migrateComponent('button', runner, cliAppTree);
12+
expect(tree.readContent(THEME_FILE)).toBe(newFileContent);
1613
}
1714

1815
beforeEach(async () => {
19-
runner = new SchematicTestRunner(
20-
'@angular/material',
21-
runfiles.resolveWorkspaceRelative('src/material/schematics/collection.json'),
22-
);
16+
runner = createNewTestRunner();
2317
cliAppTree = patchDevkitTreeToExposeTypeScript(await createTestApp(runner));
2418
});
2519

26-
async function migrate(options: Schema): Promise<UnitTestTree> {
27-
return await runner.runSchematicAsync('mdcMigration', options, cliAppTree).toPromise();
28-
}
29-
3020
describe('mixin migrations', () => {
3121
it('should replace the old theme with the new ones', async () => {
3222
await runMigrationTest(
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
10+
import {runfiles} from '@bazel/runfiles';
11+
12+
const TS_CONFIG = '/projects/material/tsconfig.app.json';
13+
14+
export const THEME_FILE = '/projects/material/src/theme.scss';
15+
16+
export function createNewTestRunner(): SchematicTestRunner {
17+
return new SchematicTestRunner(
18+
'@angular/material',
19+
runfiles.resolveWorkspaceRelative('src/material/schematics/collection.json'),
20+
);
21+
}
22+
23+
export async function migrateComponent(
24+
component: string,
25+
runner: SchematicTestRunner,
26+
tree: UnitTestTree,
27+
): Promise<UnitTestTree> {
28+
return await runner
29+
.runSchematicAsync('mdcMigration', {TS_CONFIG, components: [component]}, tree)
30+
.toPromise();
31+
}

0 commit comments

Comments
 (0)