Skip to content

Commit

Permalink
test(material/schematics): clean up deprecated API usage (#26434)
Browse files Browse the repository at this point in the history
The `runSchematicAsync` API has been replaced by `runSchematic`. These changes clean up all of our usages.

(cherry picked from commit c14aadd)
  • Loading branch information
crisbeto committed Jan 15, 2023
1 parent a84c423 commit 93f0f9c
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 410 deletions.
4 changes: 2 additions & 2 deletions src/cdk/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('CDK ng-add', () => {
});

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

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

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

Expand Down
94 changes: 41 additions & 53 deletions src/cdk/schematics/ng-generate/drag-drop/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('CDK drag-drop schematic', () => {

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

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

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

expect(moduleContent).toContain('DragDropModule');
});

describe('style option', () => {
it('should respect the option value', async () => {
const tree = await runner
.runSchematicAsync(
'drag-drop',
{style: 'scss', ...baseOptions},
await createTestApp(runner),
)
.toPromise();

const tree = await runner.runSchematic(
'drag-drop',
{style: 'scss', ...baseOptions},
await createTestApp(runner),
);
expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.scss');
});

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

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

it('should not generate invalid stylesheets', async () => {
const tree = await runner
.runSchematicAsync(
'drag-drop',
{style: 'styl', ...baseOptions},
await createTestApp(runner),
)
.toPromise();

const tree = await runner.runSchematic(
'drag-drop',
{style: 'styl', ...baseOptions},
await createTestApp(runner),
);
// In this case we expect the schematic to generate a plain "css" file because
// the component schematics are using CSS style templates which are not compatible
// with all CLI supported styles (e.g. Stylus or Sass)
Expand All @@ -104,65 +98,58 @@ describe('CDK drag-drop schematic', () => {
});

it('should fall back to the @schematics/angular:component option value', async () => {
const tree = await runner
.runSchematicAsync('drag-drop', baseOptions, await createTestApp(runner, {style: 'less'}))
.toPromise();

const tree = await runner.runSchematic(
'drag-drop',
baseOptions,
await createTestApp(runner, {style: 'less'}),
);
expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.less');
});
});

describe('inlineStyle option', () => {
it('should respect the option value', async () => {
const app = await createTestApp(runner);
const tree = await runner
.runSchematicAsync('drag-drop', {inlineStyle: true, ...baseOptions}, app)
.toPromise();

const tree = await runner.runSchematic('drag-drop', {inlineStyle: true, ...baseOptions}, app);
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.css');
});

it('should fall back to the @schematics/angular:component option value', async () => {
const tree = await runner
.runSchematicAsync(
'drag-drop',
baseOptions,
await createTestApp(runner, {inlineStyle: true}),
)
.toPromise();

const tree = await runner.runSchematic(
'drag-drop',
baseOptions,
await createTestApp(runner, {inlineStyle: true}),
);
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.css');
});
});

describe('inlineTemplate option', () => {
it('should respect the option value', async () => {
const app = await createTestApp(runner);
const tree = await runner
.runSchematicAsync('drag-drop', {inlineTemplate: true, ...baseOptions}, app)
.toPromise();

const tree = await runner.runSchematic(
'drag-drop',
{inlineTemplate: true, ...baseOptions},
app,
);
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.html');
});

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

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

describe('skipTests option', () => {
it('should respect the option value', async () => {
const tree = await runner
.runSchematicAsync(
'drag-drop',
{skipTests: true, ...baseOptions},
await createTestApp(runner),
)
.toPromise();

const tree = await runner.runSchematic(
'drag-drop',
{skipTests: true, ...baseOptions},
await createTestApp(runner),
);
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
});

Expand All @@ -187,16 +174,17 @@ describe('CDK drag-drop schematic', () => {
},
}),
);
tree = await runner.runSchematicAsync('drag-drop', baseOptions, tree).toPromise();
tree = await runner.runSchematic('drag-drop', baseOptions, tree);

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

it('should fall back to the @schematics/angular:component option value', async () => {
const tree = await runner
.runSchematicAsync('drag-drop', baseOptions, await createTestApp(runner, {skipTests: true}))
.toPromise();

const tree = await runner.runSchematic(
'drag-drop',
baseOptions,
await createTestApp(runner, {skipTests: true}),
);
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/schematics/testing/test-case-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export async function createTestCaseSetup(
// TODO(devversion): RxJS version conflicts between angular-devkit and our dev deps.
runner.engine.executePostTasks = () => EMPTY as any;

await runner.runSchematicAsync(migrationName, {}, appTree).toPromise();
await runner.runSchematic(migrationName, {}, appTree);

return {logOutput};
};
Expand Down
Loading

0 comments on commit 93f0f9c

Please sign in to comment.