Skip to content

Commit c14aadd

Browse files
authored
test(material/schematics): clean up deprecated API usage (#26434)
The `runSchematicAsync` API has been replaced by `runSchematic`. These changes clean up all of our usages.
1 parent 8448a44 commit c14aadd

File tree

10 files changed

+331
-410
lines changed

10 files changed

+331
-410
lines changed

src/cdk/schematics/ng-add/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('CDK ng-add', () => {
1818
});
1919

2020
it('should update the package.json', async () => {
21-
const tree = await runner.runSchematicAsync('ng-add', {}, appTree).toPromise();
21+
const tree = await runner.runSchematic('ng-add', {}, appTree);
2222
const packageJson = JSON.parse(getFileContent(tree, '/package.json')) as PackageJson;
2323
const dependencies = packageJson.dependencies;
2424

@@ -36,7 +36,7 @@ describe('CDK ng-add', () => {
3636
// requested package version into the `package.json` before the actual schematic runs.
3737
addPackageToPackageJson(appTree, '@angular/cdk', '^9.0.0');
3838

39-
const tree = await runner.runSchematicAsync('ng-add', {}, appTree).toPromise();
39+
const tree = await runner.runSchematic('ng-add', {}, appTree);
4040
const packageJson = JSON.parse(getFileContent(tree, '/package.json')) as PackageJson;
4141
const dependencies = packageJson.dependencies;
4242

src/cdk/schematics/ng-generate/drag-drop/index.spec.ts

Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('CDK drag-drop schematic', () => {
2020

2121
it('should create drag-drop files and add them to module', async () => {
2222
const app = await createTestApp(runner);
23-
const tree = await runner.runSchematicAsync('drag-drop', baseOptions, app).toPromise();
23+
const tree = await runner.runSchematic('drag-drop', baseOptions, app);
2424
const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
2525
const files = tree.files;
2626

@@ -35,22 +35,19 @@ describe('CDK drag-drop schematic', () => {
3535

3636
it('should add drag-drop module', async () => {
3737
const app = await createTestApp(runner);
38-
const tree = await runner.runSchematicAsync('drag-drop', baseOptions, app).toPromise();
38+
const tree = await runner.runSchematic('drag-drop', baseOptions, app);
3939
const moduleContent = getFileContent(tree, '/projects/material/src/app/app.module.ts');
4040

4141
expect(moduleContent).toContain('DragDropModule');
4242
});
4343

4444
describe('style option', () => {
4545
it('should respect the option value', async () => {
46-
const tree = await runner
47-
.runSchematicAsync(
48-
'drag-drop',
49-
{style: 'scss', ...baseOptions},
50-
await createTestApp(runner),
51-
)
52-
.toPromise();
53-
46+
const tree = await runner.runSchematic(
47+
'drag-drop',
48+
{style: 'scss', ...baseOptions},
49+
await createTestApp(runner),
50+
);
5451
expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.scss');
5552
});
5653

@@ -75,20 +72,17 @@ describe('CDK drag-drop schematic', () => {
7572
},
7673
}),
7774
);
78-
tree = await runner.runSchematicAsync('drag-drop', baseOptions, tree).toPromise();
75+
tree = await runner.runSchematic('drag-drop', baseOptions, tree);
7976

8077
expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.scss');
8178
});
8279

8380
it('should not generate invalid stylesheets', async () => {
84-
const tree = await runner
85-
.runSchematicAsync(
86-
'drag-drop',
87-
{style: 'styl', ...baseOptions},
88-
await createTestApp(runner),
89-
)
90-
.toPromise();
91-
81+
const tree = await runner.runSchematic(
82+
'drag-drop',
83+
{style: 'styl', ...baseOptions},
84+
await createTestApp(runner),
85+
);
9286
// In this case we expect the schematic to generate a plain "css" file because
9387
// the component schematics are using CSS style templates which are not compatible
9488
// with all CLI supported styles (e.g. Stylus or Sass)
@@ -104,65 +98,58 @@ describe('CDK drag-drop schematic', () => {
10498
});
10599

106100
it('should fall back to the @schematics/angular:component option value', async () => {
107-
const tree = await runner
108-
.runSchematicAsync('drag-drop', baseOptions, await createTestApp(runner, {style: 'less'}))
109-
.toPromise();
110-
101+
const tree = await runner.runSchematic(
102+
'drag-drop',
103+
baseOptions,
104+
await createTestApp(runner, {style: 'less'}),
105+
);
111106
expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.less');
112107
});
113108
});
114109

115110
describe('inlineStyle option', () => {
116111
it('should respect the option value', async () => {
117112
const app = await createTestApp(runner);
118-
const tree = await runner
119-
.runSchematicAsync('drag-drop', {inlineStyle: true, ...baseOptions}, app)
120-
.toPromise();
121-
113+
const tree = await runner.runSchematic('drag-drop', {inlineStyle: true, ...baseOptions}, app);
122114
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.css');
123115
});
124116

125117
it('should fall back to the @schematics/angular:component option value', async () => {
126-
const tree = await runner
127-
.runSchematicAsync(
128-
'drag-drop',
129-
baseOptions,
130-
await createTestApp(runner, {inlineStyle: true}),
131-
)
132-
.toPromise();
133-
118+
const tree = await runner.runSchematic(
119+
'drag-drop',
120+
baseOptions,
121+
await createTestApp(runner, {inlineStyle: true}),
122+
);
134123
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.css');
135124
});
136125
});
137126

138127
describe('inlineTemplate option', () => {
139128
it('should respect the option value', async () => {
140129
const app = await createTestApp(runner);
141-
const tree = await runner
142-
.runSchematicAsync('drag-drop', {inlineTemplate: true, ...baseOptions}, app)
143-
.toPromise();
144-
130+
const tree = await runner.runSchematic(
131+
'drag-drop',
132+
{inlineTemplate: true, ...baseOptions},
133+
app,
134+
);
145135
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.html');
146136
});
147137

148138
it('should fall back to the @schematics/angular:component option value', async () => {
149139
const app = await createTestApp(runner, {inlineTemplate: true});
150-
const tree = await runner.runSchematicAsync('drag-drop', baseOptions, app).toPromise();
140+
const tree = await runner.runSchematic('drag-drop', baseOptions, app);
151141

152142
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.html');
153143
});
154144
});
155145

156146
describe('skipTests option', () => {
157147
it('should respect the option value', async () => {
158-
const tree = await runner
159-
.runSchematicAsync(
160-
'drag-drop',
161-
{skipTests: true, ...baseOptions},
162-
await createTestApp(runner),
163-
)
164-
.toPromise();
165-
148+
const tree = await runner.runSchematic(
149+
'drag-drop',
150+
{skipTests: true, ...baseOptions},
151+
await createTestApp(runner),
152+
);
166153
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
167154
});
168155

@@ -187,16 +174,17 @@ describe('CDK drag-drop schematic', () => {
187174
},
188175
}),
189176
);
190-
tree = await runner.runSchematicAsync('drag-drop', baseOptions, tree).toPromise();
177+
tree = await runner.runSchematic('drag-drop', baseOptions, tree);
191178

192179
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
193180
});
194181

195182
it('should fall back to the @schematics/angular:component option value', async () => {
196-
const tree = await runner
197-
.runSchematicAsync('drag-drop', baseOptions, await createTestApp(runner, {skipTests: true}))
198-
.toPromise();
199-
183+
const tree = await runner.runSchematic(
184+
'drag-drop',
185+
baseOptions,
186+
await createTestApp(runner, {skipTests: true}),
187+
);
200188
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
201189
});
202190
});

src/cdk/schematics/testing/test-case-setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export async function createTestCaseSetup(
105105
// TODO(devversion): RxJS version conflicts between angular-devkit and our dev deps.
106106
runner.engine.executePostTasks = () => EMPTY as any;
107107

108-
await runner.runSchematicAsync(migrationName, {}, appTree).toPromise();
108+
await runner.runSchematic(migrationName, {}, appTree);
109109

110110
return {logOutput};
111111
};

0 commit comments

Comments
 (0)