From c794abc8f6de5dc7c2ea804d027294f83e62643e Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Fri, 18 Aug 2023 14:56:12 +0200 Subject: [PATCH] chore: fix issue with build files (#10754) --- .../src/builders/puppeteer/index.ts | 30 +++++++++---------- .../jasmine/e2e/{support => }/jasmine.json | 0 .../ng-add/files/jest/e2e/jest.config.js | 2 +- .../ng-add/files/mocha/e2e/.mocharc.js | 2 +- .../ng-schematics/test/src/ng-add.spec.ts | 6 ++-- 5 files changed, 19 insertions(+), 21 deletions(-) rename packages/ng-schematics/src/schematics/ng-add/files/jasmine/e2e/{support => }/jasmine.json (100%) diff --git a/packages/ng-schematics/src/builders/puppeteer/index.ts b/packages/ng-schematics/src/builders/puppeteer/index.ts index a2f9df18aee..c34d8de5816 100644 --- a/packages/ng-schematics/src/builders/puppeteer/index.ts +++ b/packages/ng-schematics/src/builders/puppeteer/index.ts @@ -25,7 +25,7 @@ const terminalStyles = { export function getCommandForRunner(runner: TestRunner): [string, ...string[]] { switch (runner) { case TestRunner.Jasmine: - return [`jasmine`, '--config=./e2e/support/jasmine.json']; + return [`jasmine`, '--config=./e2e/jasmine.json']; case TestRunner.Jest: return [`jest`, '-c', 'e2e/jest.config.js']; case TestRunner.Mocha: @@ -37,28 +37,27 @@ export function getCommandForRunner(runner: TestRunner): [string, ...string[]] { throw new Error(`Unknown test runner ${runner}!`); } -function getError(executable: string, args: string[]) { - return ( - `Error running '${executable}' with arguments '${args.join(' ')}'.` + - `\n` + - 'Please look at the output above to determine the issue!' - ); -} - function getExecutable(command: string[]) { const executable = command.shift()!; - const error = getError(executable, command); + const debugError = `Error running '${executable}' with arguments '${command.join( + ' ' + )}'.`; return { executable, args: command, - error, + debugError, + error: 'Please look at the output above to determine the issue!', }; } function updateExecutablePath(command: string, root?: string) { + if (command === TestRunner.Node) { + return command; + } + let path = 'node_modules/.bin/'; - if (root && root !== '' && command === TestRunner.Node) { + if (root && root !== '') { const nested = root .split('/') .map(() => { @@ -82,7 +81,7 @@ async function executeCommand(context: BuilderContext, command: string[]) { await new Promise(async (resolve, reject) => { context.logger.debug(`Trying to execute command - ${command.join(' ')}.`); - const {executable, args, error} = getExecutable(command); + const {executable, args, debugError, error} = getExecutable(command); let path = context.workspaceRoot; if (context.target) { path = `${path}/${project['root']}`; @@ -94,6 +93,7 @@ async function executeCommand(context: BuilderContext, command: string[]) { }); child.on('error', message => { + context.logger.debug(debugError); console.log(message); reject(error); }); @@ -160,11 +160,11 @@ async function executeE2ETest( ): Promise { let server: BuilderRun | null = null; try { - server = await startServer(options, context); - message('\n Building tests 🛠️ ... \n', context); await executeCommand(context, [`tsc`, '-p', 'e2e/tsconfig.json']); + server = await startServer(options, context); + message('\n Running tests 🧪 ... \n', context); const testRunnerCommand = getCommandForRunner(options.testRunner); await executeCommand(context, testRunnerCommand); diff --git a/packages/ng-schematics/src/schematics/ng-add/files/jasmine/e2e/support/jasmine.json b/packages/ng-schematics/src/schematics/ng-add/files/jasmine/e2e/jasmine.json similarity index 100% rename from packages/ng-schematics/src/schematics/ng-add/files/jasmine/e2e/support/jasmine.json rename to packages/ng-schematics/src/schematics/ng-add/files/jasmine/e2e/jasmine.json diff --git a/packages/ng-schematics/src/schematics/ng-add/files/jest/e2e/jest.config.js b/packages/ng-schematics/src/schematics/ng-add/files/jest/e2e/jest.config.js index ca6f51dd9dc..ee5fc51695f 100644 --- a/packages/ng-schematics/src/schematics/ng-add/files/jest/e2e/jest.config.js +++ b/packages/ng-schematics/src/schematics/ng-add/files/jest/e2e/jest.config.js @@ -5,6 +5,6 @@ /** @type {import('jest').Config} */ module.exports = { - testMatch: ['/tests/**/?(*.)+(e2e).js?(x)'], + testMatch: ['/build/**/?(*.)+(e2e).js?(x)'], testEnvironment: 'node', }; diff --git a/packages/ng-schematics/src/schematics/ng-add/files/mocha/e2e/.mocharc.js b/packages/ng-schematics/src/schematics/ng-add/files/mocha/e2e/.mocharc.js index 09e0f7382ea..e751ec07450 100644 --- a/packages/ng-schematics/src/schematics/ng-add/files/mocha/e2e/.mocharc.js +++ b/packages/ng-schematics/src/schematics/ng-add/files/mocha/e2e/.mocharc.js @@ -1,3 +1,3 @@ module.exports = { - spec: './e2e/tests/**/*.e2e.js', + spec: './e2e/build/**/*.e2e.js', }; diff --git a/packages/ng-schematics/test/src/ng-add.spec.ts b/packages/ng-schematics/test/src/ng-add.spec.ts index cf4d18004fe..4f8a6fcf490 100644 --- a/packages/ng-schematics/test/src/ng-add.spec.ts +++ b/packages/ng-schematics/test/src/ng-add.spec.ts @@ -52,7 +52,7 @@ describe('@puppeteer/ng-schematics: ng-add', () => { const {devDependencies} = getPackageJson(tree); const {options} = getAngularJsonScripts(tree); - expect(tree.files).toContain('/e2e/support/jasmine.json'); + expect(tree.files).toContain('/e2e/jasmine.json'); expect(devDependencies).toContain('jasmine'); expect(options['testRunner']).toBe('jasmine'); }); @@ -140,9 +140,7 @@ describe('@puppeteer/ng-schematics: ng-add', () => { const {devDependencies} = getPackageJson(tree); const {options} = getAngularJsonScripts(tree); - expect(tree.files).toContain( - getMultiProjectFile('e2e/support/jasmine.json') - ); + expect(tree.files).toContain(getMultiProjectFile('e2e/jasmine.json')); expect(devDependencies).toContain('jasmine'); expect(options['testRunner']).toBe('jasmine'); });