Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c402c31

Browse files
alan-agius4filipesilva
authored andcommittedJun 30, 2020
fix(@schematics/schematics): replaced removed runner.runSchematic with runner.runSchematicAsync
Deprecated `runSchematic` has been removed in version 10, `runSchematicAsync` should be used instead. Closes #18062
1 parent d24a239 commit c402c31

File tree

7 files changed

+100
-20
lines changed

7 files changed

+100
-20
lines changed
 

‎packages/schematics/schematics/blank/schematic-files/src/__name@dasherize__/index_spec.ts.template

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ const collectionPath = path.join(__dirname, '../collection.json');
77

88

99
describe('<%= dasherize(name) %>', () => {
10-
it('works', () => {
10+
it('works', async () => {
1111
const runner = new SchematicTestRunner('schematics', collectionPath);
12-
const tree = runner.runSchematic('<%= dasherize(name) %>', {}, Tree.empty());
12+
const tree = await runner.runSchematicAsync('<%= dasherize(name) %>', {}, Tree.empty()).toPromise();
1313

1414
expect(tree.files).toEqual([]);
1515
});

‎packages/schematics/schematics/schematic/files/src/my-full-schematic/index_spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ describe('my-full-schematic', () => {
1111
it('requires required option', () => {
1212
// We test that
1313
const runner = new SchematicTestRunner('schematics', collectionPath);
14-
expect(() => runner.runSchematic('my-full-schematic', {}, Tree.empty())).toThrow();
14+
expectAsync(runner.runSchematicAsync('my-full-schematic', {}, Tree.empty()).toPromise()).toBeRejected();
1515
});
1616

17-
it('works', () => {
17+
it('works', async () => {
1818
const runner = new SchematicTestRunner('schematics', collectionPath);
19-
const tree = runner.runSchematic('my-full-schematic', { name: 'str' }, Tree.empty());
19+
const tree = await runner.runSchematicAsync('my-full-schematic', { name: 'str' }, Tree.empty()).toPromise();
2020

2121
// Listing files
2222
expect(tree.files.sort()).toEqual(['/allo', '/hola', '/test1', '/test2']);

‎packages/schematics/schematics/schematic/files/src/my-other-schematic/index_spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ const collectionPath = path.join(__dirname, '../collection.json');
77

88

99
describe('my-other-schematic', () => {
10-
it('works', () => {
10+
it('works', async () => {
1111
const runner = new SchematicTestRunner('schematics', collectionPath);
12-
const tree = runner.runSchematic('my-other-schematic', {}, Tree.empty());
12+
const tree = await runner.runSchematicAsync('my-other-schematic', {}, Tree.empty()).toPromise();
1313

1414
expect(tree.files.sort()).toEqual(['/allo', '/hola']);
1515
});

‎packages/schematics/schematics/schematic/files/src/my-schematic/index_spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ const collectionPath = path.join(__dirname, '../collection.json');
77

88

99
describe('my-schematic', () => {
10-
it('works', () => {
10+
it('works', async () => {
1111
const runner = new SchematicTestRunner('schematics', collectionPath);
12-
const tree = runner.runSchematic('my-schematic', {}, Tree.empty());
12+
const tree = await runner.runSchematicAsync('my-schematic', {}, Tree.empty()).toPromise();
1313

1414
expect(tree.files).toEqual(['/hello']);
1515
});
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from 'path';
22
import { getGlobalVariable } from '../../utils/env';
33
import { exec, execAndWaitForOutputToMatch, silentNpm } from '../../utils/process';
4+
import { rimraf } from '../../utils/fs';
45

56
export default async function () {
67
// setup
@@ -9,7 +10,6 @@ export default async function () {
910
return;
1011
}
1112

12-
const startCwd = process.cwd();
1313
await silentNpm(
1414
'install',
1515
'-g',
@@ -18,17 +18,23 @@ export default async function () {
1818
);
1919
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');
2020

21-
// create blank schematic
22-
await exec('schematics', 'schematic', '--name', 'test-schematic');
21+
const startCwd = process.cwd();
22+
const schematicPath = path.join(startCwd, 'test-schematic');
2323

24-
process.chdir(path.join(startCwd, 'test-schematic'));
25-
await execAndWaitForOutputToMatch(
26-
'schematics',
27-
['.:', '--list-schematics'],
28-
/my-full-schematic/,
29-
);
24+
try {
25+
// create blank schematic
26+
await exec('schematics', 'schematic', '--name', 'test-schematic');
3027

31-
// restore path
32-
process.chdir(startCwd);
28+
process.chdir(path.join(startCwd, 'test-schematic'));
29+
await execAndWaitForOutputToMatch(
30+
'schematics',
31+
['.:', '--list-schematics'],
32+
/my-full-schematic/,
33+
);
3334

35+
} finally {
36+
// restore path
37+
process.chdir(startCwd);
38+
await rimraf(schematicPath);
39+
}
3440
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as path from 'path';
2+
import { getGlobalVariable } from '../../utils/env';
3+
import { exec, silentNpm } from '../../utils/process';
4+
import { rimraf } from '../../utils/fs';
5+
6+
export default async function () {
7+
// setup
8+
const argv = getGlobalVariable('argv');
9+
if (argv.noglobal) {
10+
return;
11+
}
12+
13+
await silentNpm(
14+
'install',
15+
'-g',
16+
'@angular-devkit/schematics-cli',
17+
'--registry=http://localhost:4873',
18+
);
19+
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');
20+
21+
const startCwd = process.cwd();
22+
const schematicPath = path.join(startCwd, 'test-schematic');
23+
24+
try {
25+
// create schematic
26+
await exec('schematics', 'blank', '--name', 'test-schematic');
27+
28+
process.chdir(schematicPath);
29+
30+
await silentNpm('install');
31+
await silentNpm('test');
32+
} finally {
33+
// restore path
34+
process.chdir(startCwd);
35+
await rimraf(schematicPath);
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as path from 'path';
2+
import { getGlobalVariable } from '../../utils/env';
3+
import { exec, silentNpm } from '../../utils/process';
4+
import { rimraf } from '../../utils/fs';
5+
6+
export default async function () {
7+
// setup
8+
const argv = getGlobalVariable('argv');
9+
if (argv.noglobal) {
10+
return;
11+
}
12+
13+
await silentNpm(
14+
'install',
15+
'-g',
16+
'@angular-devkit/schematics-cli',
17+
'--registry=http://localhost:4873',
18+
);
19+
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');
20+
21+
const startCwd = process.cwd();
22+
const schematicPath = path.join(startCwd, 'test-schematic');
23+
24+
try {
25+
// create schematic
26+
await exec('schematics', 'schematic', '--name', 'test-schematic');
27+
28+
process.chdir(schematicPath);
29+
30+
await silentNpm('install');
31+
await silentNpm('test');
32+
} finally {
33+
// restore path
34+
process.chdir(startCwd);
35+
await rimraf(schematicPath);
36+
}
37+
}

0 commit comments

Comments
 (0)
Please sign in to comment.