Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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);
}
}