Skip to content

Commit

Permalink
fix(@schematics/schematics): replaced removed runner.runSchematic w…
Browse files Browse the repository at this point in the history
…ith `runner.runSchematicAsync`

Deprecated `runSchematic` has been removed in version 10, `runSchematicAsync` should be used instead.

Closes #18062
  • Loading branch information
alan-agius4 authored and filipesilva committed Jun 30, 2020
1 parent d24a239 commit c402c31
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 20 deletions.
Expand Up @@ -7,9 +7,9 @@ const collectionPath = path.join(__dirname, '../collection.json');


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

expect(tree.files).toEqual([]);
});
Expand Down
Expand Up @@ -11,12 +11,12 @@ describe('my-full-schematic', () => {
it('requires required option', () => {
// We test that
const runner = new SchematicTestRunner('schematics', collectionPath);
expect(() => runner.runSchematic('my-full-schematic', {}, Tree.empty())).toThrow();
expectAsync(runner.runSchematicAsync('my-full-schematic', {}, Tree.empty()).toPromise()).toBeRejected();
});

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

// Listing files
expect(tree.files.sort()).toEqual(['/allo', '/hola', '/test1', '/test2']);
Expand Down
Expand Up @@ -7,9 +7,9 @@ const collectionPath = path.join(__dirname, '../collection.json');


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

expect(tree.files.sort()).toEqual(['/allo', '/hola']);
});
Expand Down
Expand Up @@ -7,9 +7,9 @@ const collectionPath = path.join(__dirname, '../collection.json');


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

expect(tree.files).toEqual(['/hello']);
});
Expand Down
28 changes: 17 additions & 11 deletions tests/legacy-cli/e2e/tests/schematics_cli/basic.ts
@@ -1,6 +1,7 @@
import * as path from 'path';
import { getGlobalVariable } from '../../utils/env';
import { exec, execAndWaitForOutputToMatch, silentNpm } from '../../utils/process';
import { rimraf } from '../../utils/fs';

export default async function () {
// setup
Expand All @@ -9,7 +10,6 @@ export default async function () {
return;
}

const startCwd = process.cwd();
await silentNpm(
'install',
'-g',
Expand All @@ -18,17 +18,23 @@ export default async function () {
);
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');

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

process.chdir(path.join(startCwd, 'test-schematic'));
await execAndWaitForOutputToMatch(
'schematics',
['.:', '--list-schematics'],
/my-full-schematic/,
);
try {
// create blank schematic
await exec('schematics', 'schematic', '--name', 'test-schematic');

// restore path
process.chdir(startCwd);
process.chdir(path.join(startCwd, 'test-schematic'));
await execAndWaitForOutputToMatch(
'schematics',
['.:', '--list-schematics'],
/my-full-schematic/,
);

} finally {
// restore path
process.chdir(startCwd);
await rimraf(schematicPath);
}
}
37 changes: 37 additions & 0 deletions tests/legacy-cli/e2e/tests/schematics_cli/blank-test.ts
@@ -0,0 +1,37 @@
import * as path from 'path';
import { getGlobalVariable } from '../../utils/env';
import { exec, silentNpm } from '../../utils/process';
import { rimraf } from '../../utils/fs';

export default async function () {
// setup
const argv = getGlobalVariable('argv');
if (argv.noglobal) {
return;
}

await silentNpm(
'install',
'-g',
'@angular-devkit/schematics-cli',
'--registry=http://localhost:4873',
);
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');

const startCwd = process.cwd();
const schematicPath = path.join(startCwd, 'test-schematic');

try {
// create schematic
await exec('schematics', 'blank', '--name', 'test-schematic');

process.chdir(schematicPath);

await silentNpm('install');
await silentNpm('test');
} finally {
// restore path
process.chdir(startCwd);
await rimraf(schematicPath);
}
}
37 changes: 37 additions & 0 deletions tests/legacy-cli/e2e/tests/schematics_cli/schematic-test.ts
@@ -0,0 +1,37 @@
import * as path from 'path';
import { getGlobalVariable } from '../../utils/env';
import { exec, silentNpm } from '../../utils/process';
import { rimraf } from '../../utils/fs';

export default async function () {
// setup
const argv = getGlobalVariable('argv');
if (argv.noglobal) {
return;
}

await silentNpm(
'install',
'-g',
'@angular-devkit/schematics-cli',
'--registry=http://localhost:4873',
);
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');

const startCwd = process.cwd();
const schematicPath = path.join(startCwd, 'test-schematic');

try {
// create schematic
await exec('schematics', 'schematic', '--name', 'test-schematic');

process.chdir(schematicPath);

await silentNpm('install');
await silentNpm('test');
} finally {
// restore path
process.chdir(startCwd);
await rimraf(schematicPath);
}
}

0 comments on commit c402c31

Please sign in to comment.