chore: make builder find command (#10751)
This commit is contained in:
parent
35dc2d8840
commit
683e18189c
@ -22,6 +22,21 @@ const terminalStyles = {
|
|||||||
clear: '\u001b[0m',
|
clear: '\u001b[0m',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function getCommandForRunner(runner: TestRunner): [string, ...string[]] {
|
||||||
|
switch (runner) {
|
||||||
|
case TestRunner.Jasmine:
|
||||||
|
return [`jasmine`, '--config=./e2e/support/jasmine.json'];
|
||||||
|
case TestRunner.Jest:
|
||||||
|
return [`jest`, '-c', 'e2e/jest.config.js'];
|
||||||
|
case TestRunner.Mocha:
|
||||||
|
return [`mocha`, '--config=./e2e/.mocharc.js'];
|
||||||
|
case TestRunner.Node:
|
||||||
|
return ['node', '--test', '--test-reporter', 'spec', 'e2e/build/'];
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Unknown test runner ${runner}!`);
|
||||||
|
}
|
||||||
|
|
||||||
function getError(executable: string, args: string[]) {
|
function getError(executable: string, args: string[]) {
|
||||||
return (
|
return (
|
||||||
`Error running '${executable}' with arguments '${args.join(' ')}'.` +
|
`Error running '${executable}' with arguments '${args.join(' ')}'.` +
|
||||||
@ -147,15 +162,12 @@ async function executeE2ETest(
|
|||||||
try {
|
try {
|
||||||
server = await startServer(options, context);
|
server = await startServer(options, context);
|
||||||
|
|
||||||
const commands = options.commands;
|
|
||||||
|
|
||||||
message('\n Building tests 🛠️ ... \n', context);
|
message('\n Building tests 🛠️ ... \n', context);
|
||||||
await executeCommand(context, [`tsc`, '-p', 'e2e/tsconfig.json']);
|
await executeCommand(context, [`tsc`, '-p', 'e2e/tsconfig.json']);
|
||||||
|
|
||||||
message('\n Running tests 🧪 ... \n', context);
|
message('\n Running tests 🧪 ... \n', context);
|
||||||
for (const command of commands) {
|
const testRunnerCommand = getCommandForRunner(options.testRunner);
|
||||||
await executeCommand(context, command);
|
await executeCommand(context, testRunnerCommand);
|
||||||
}
|
|
||||||
|
|
||||||
message('\n 🚀 Test ran successfully! 🚀 ', context, 'success');
|
message('\n 🚀 Test ran successfully! 🚀 ', context, 'success');
|
||||||
return {success: true};
|
return {success: true};
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
import {JsonObject} from '@angular-devkit/core';
|
import {JsonObject} from '@angular-devkit/core';
|
||||||
|
|
||||||
type Command = [string, ...string[]];
|
import {TestRunner} from '../../schematics/utils/types.js';
|
||||||
|
|
||||||
export interface PuppeteerBuilderOptions extends JsonObject {
|
export interface PuppeteerBuilderOptions extends JsonObject {
|
||||||
commands: Command[];
|
testRunner: TestRunner;
|
||||||
devServerTarget: string;
|
devServerTarget: string;
|
||||||
port: number | null;
|
port: number | null;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ import {
|
|||||||
url,
|
url,
|
||||||
} from '@angular-devkit/schematics';
|
} from '@angular-devkit/schematics';
|
||||||
|
|
||||||
import {AngularProject, SchematicsOptions, TestRunner} from './types.js';
|
import {AngularProject, TestRunner} from './types.js';
|
||||||
|
|
||||||
export interface FilesOptions {
|
export interface FilesOptions {
|
||||||
options: {
|
options: {
|
||||||
@ -148,19 +148,6 @@ export function addFrameworkFiles(
|
|||||||
return addFilesToProjects(tree, context, projects, options);
|
return addFilesToProjects(tree, context, projects, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getScriptFromOptions(options: SchematicsOptions): string[][] {
|
|
||||||
switch (options.testRunner) {
|
|
||||||
case TestRunner.Jasmine:
|
|
||||||
return [[`jasmine`, '--config=./e2e/support/jasmine.json']];
|
|
||||||
case TestRunner.Jest:
|
|
||||||
return [[`jest`, '-c', 'e2e/jest.config.js']];
|
|
||||||
case TestRunner.Mocha:
|
|
||||||
return [[`mocha`, '--config=./e2e/.mocharc.js']];
|
|
||||||
case TestRunner.Node:
|
|
||||||
return [['node', '--test', '--test-reporter', 'spec', 'e2e/build/']];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function hasE2ETester(
|
export function hasE2ETester(
|
||||||
projects: Record<string, AngularProject>
|
projects: Record<string, AngularProject>
|
||||||
): boolean {
|
): boolean {
|
||||||
|
@ -18,7 +18,7 @@ import {get} from 'https';
|
|||||||
|
|
||||||
import {Tree} from '@angular-devkit/schematics';
|
import {Tree} from '@angular-devkit/schematics';
|
||||||
|
|
||||||
import {getNgCommandName, getScriptFromOptions} from './files.js';
|
import {getNgCommandName} from './files.js';
|
||||||
import {
|
import {
|
||||||
getAngularConfig,
|
getAngularConfig,
|
||||||
getJsonFileAsObject,
|
getJsonFileAsObject,
|
||||||
@ -165,14 +165,12 @@ export function updateAngularJsonScripts(
|
|||||||
const name = getNgCommandName(angularJson.projects);
|
const name = getNgCommandName(angularJson.projects);
|
||||||
|
|
||||||
Object.keys(angularJson['projects']).forEach(project => {
|
Object.keys(angularJson['projects']).forEach(project => {
|
||||||
const commands = getScriptFromOptions(options);
|
|
||||||
const e2eScript = [
|
const e2eScript = [
|
||||||
{
|
{
|
||||||
name,
|
name,
|
||||||
value: {
|
value: {
|
||||||
builder: '@puppeteer/ng-schematics:puppeteer',
|
builder: '@puppeteer/ng-schematics:puppeteer',
|
||||||
options: {
|
options: {
|
||||||
commands,
|
|
||||||
devServerTarget: `${project}:serve`,
|
devServerTarget: `${project}:serve`,
|
||||||
testRunner: options.testRunner,
|
testRunner: options.testRunner,
|
||||||
},
|
},
|
||||||
|
@ -54,9 +54,7 @@ describe('@puppeteer/ng-schematics: ng-add', () => {
|
|||||||
|
|
||||||
expect(tree.files).toContain('/e2e/support/jasmine.json');
|
expect(tree.files).toContain('/e2e/support/jasmine.json');
|
||||||
expect(devDependencies).toContain('jasmine');
|
expect(devDependencies).toContain('jasmine');
|
||||||
expect(options['commands']).toEqual([
|
expect(options['testRunner']).toBe('jasmine');
|
||||||
[`jasmine`, '--config=./e2e/support/jasmine.json'],
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
it('should create Jest files and update "package.json"', async () => {
|
it('should create Jest files and update "package.json"', async () => {
|
||||||
const tree = await buildTestingTree('ng-add', 'single', {
|
const tree = await buildTestingTree('ng-add', 'single', {
|
||||||
@ -68,9 +66,7 @@ describe('@puppeteer/ng-schematics: ng-add', () => {
|
|||||||
expect(tree.files).toContain('/e2e/jest.config.js');
|
expect(tree.files).toContain('/e2e/jest.config.js');
|
||||||
expect(devDependencies).toContain('jest');
|
expect(devDependencies).toContain('jest');
|
||||||
expect(devDependencies).toContain('@types/jest');
|
expect(devDependencies).toContain('@types/jest');
|
||||||
expect(options['commands']).toEqual([
|
expect(options['testRunner']).toBe('jest');
|
||||||
[`jest`, '-c', 'e2e/jest.config.js'],
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
it('should create Mocha files and update "package.json"', async () => {
|
it('should create Mocha files and update "package.json"', async () => {
|
||||||
const tree = await buildTestingTree('ng-add', 'single', {
|
const tree = await buildTestingTree('ng-add', 'single', {
|
||||||
@ -82,9 +78,7 @@ describe('@puppeteer/ng-schematics: ng-add', () => {
|
|||||||
expect(tree.files).toContain('/e2e/.mocharc.js');
|
expect(tree.files).toContain('/e2e/.mocharc.js');
|
||||||
expect(devDependencies).toContain('mocha');
|
expect(devDependencies).toContain('mocha');
|
||||||
expect(devDependencies).toContain('@types/mocha');
|
expect(devDependencies).toContain('@types/mocha');
|
||||||
expect(options['commands']).toEqual([
|
expect(options['testRunner']).toBe('mocha');
|
||||||
[`mocha`, '--config=./e2e/.mocharc.js'],
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
it('should create Node files', async () => {
|
it('should create Node files', async () => {
|
||||||
const tree = await buildTestingTree('ng-add', 'single', {
|
const tree = await buildTestingTree('ng-add', 'single', {
|
||||||
@ -95,9 +89,7 @@ describe('@puppeteer/ng-schematics: ng-add', () => {
|
|||||||
expect(tree.files).toContain('/e2e/.gitignore');
|
expect(tree.files).toContain('/e2e/.gitignore');
|
||||||
expect(tree.files).not.toContain('/e2e/tests/app.e2e.ts');
|
expect(tree.files).not.toContain('/e2e/tests/app.e2e.ts');
|
||||||
expect(tree.files).toContain('/e2e/tests/app.test.ts');
|
expect(tree.files).toContain('/e2e/tests/app.test.ts');
|
||||||
expect(options['commands']).toEqual([
|
expect(options['testRunner']).toBe('node');
|
||||||
['node', '--test', '--test-reporter', 'spec', 'e2e/build/'],
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
it('should not create port value', async () => {
|
it('should not create port value', async () => {
|
||||||
const tree = await buildTestingTree('ng-add');
|
const tree = await buildTestingTree('ng-add');
|
||||||
@ -152,9 +144,7 @@ describe('@puppeteer/ng-schematics: ng-add', () => {
|
|||||||
getMultiProjectFile('e2e/support/jasmine.json')
|
getMultiProjectFile('e2e/support/jasmine.json')
|
||||||
);
|
);
|
||||||
expect(devDependencies).toContain('jasmine');
|
expect(devDependencies).toContain('jasmine');
|
||||||
expect(options['commands']).toEqual([
|
expect(options['testRunner']).toBe('jasmine');
|
||||||
[`jasmine`, '--config=./e2e/support/jasmine.json'],
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
it('should create Jest files and update "package.json"', async () => {
|
it('should create Jest files and update "package.json"', async () => {
|
||||||
const tree = await buildTestingTree('ng-add', 'multi', {
|
const tree = await buildTestingTree('ng-add', 'multi', {
|
||||||
@ -166,9 +156,7 @@ describe('@puppeteer/ng-schematics: ng-add', () => {
|
|||||||
expect(tree.files).toContain(getMultiProjectFile('e2e/jest.config.js'));
|
expect(tree.files).toContain(getMultiProjectFile('e2e/jest.config.js'));
|
||||||
expect(devDependencies).toContain('jest');
|
expect(devDependencies).toContain('jest');
|
||||||
expect(devDependencies).toContain('@types/jest');
|
expect(devDependencies).toContain('@types/jest');
|
||||||
expect(options['commands']).toEqual([
|
expect(options['testRunner']).toBe('jest');
|
||||||
[`jest`, '-c', 'e2e/jest.config.js'],
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
it('should create Mocha files and update "package.json"', async () => {
|
it('should create Mocha files and update "package.json"', async () => {
|
||||||
const tree = await buildTestingTree('ng-add', 'multi', {
|
const tree = await buildTestingTree('ng-add', 'multi', {
|
||||||
@ -180,9 +168,7 @@ describe('@puppeteer/ng-schematics: ng-add', () => {
|
|||||||
expect(tree.files).toContain(getMultiProjectFile('e2e/.mocharc.js'));
|
expect(tree.files).toContain(getMultiProjectFile('e2e/.mocharc.js'));
|
||||||
expect(devDependencies).toContain('mocha');
|
expect(devDependencies).toContain('mocha');
|
||||||
expect(devDependencies).toContain('@types/mocha');
|
expect(devDependencies).toContain('@types/mocha');
|
||||||
expect(options['commands']).toEqual([
|
expect(options['testRunner']).toBe('mocha');
|
||||||
[`mocha`, '--config=./e2e/.mocharc.js'],
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
it('should create Node files', async () => {
|
it('should create Node files', async () => {
|
||||||
const tree = await buildTestingTree('ng-add', 'multi', {
|
const tree = await buildTestingTree('ng-add', 'multi', {
|
||||||
@ -197,9 +183,7 @@ describe('@puppeteer/ng-schematics: ng-add', () => {
|
|||||||
expect(tree.files).toContain(
|
expect(tree.files).toContain(
|
||||||
getMultiProjectFile('e2e/tests/app.test.ts')
|
getMultiProjectFile('e2e/tests/app.test.ts')
|
||||||
);
|
);
|
||||||
expect(options['commands']).toEqual([
|
expect(options['testRunner']).toBe('node');
|
||||||
['node', '--test', '--test-reporter', 'spec', 'e2e/build/'],
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
it('should not create port value', async () => {
|
it('should not create port value', async () => {
|
||||||
const tree = await buildTestingTree('ng-add');
|
const tree = await buildTestingTree('ng-add');
|
||||||
|
Loading…
Reference in New Issue
Block a user