Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@schematics/schematics): replaced removed runner.runSchematic w… #18064

Merged
merged 1 commit into from Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
}