diff --git a/packages/e2e-runner/src/executors/run/run.impl.ts b/packages/e2e-runner/src/executors/run/run.impl.ts index d0c27b67..16b7f52f 100644 --- a/packages/e2e-runner/src/executors/run/run.impl.ts +++ b/packages/e2e-runner/src/executors/run/run.impl.ts @@ -21,8 +21,6 @@ export async function endToEndRunner( options: RunOptions, context: ExecutorContext ): Promise<{ success: boolean }> { - let success: boolean - const { runner, targets, ...rest } = options runningTargets = targets.map((targetOptions) => new NxTarget(targetOptions)) @@ -30,6 +28,7 @@ export async function endToEndRunner( try { // Start all targets await Promise.all(runningTargets.map((nxTarget) => nxTarget.setup())) + } catch { await killTargets() @@ -37,41 +36,40 @@ export async function endToEndRunner( } try { - if (runner === 'cypress') { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const cypressExecutor = require('@nx/cypress/src/executors/cypress/cypress.impl').default - - success = (await cypressExecutor(rest, context)).success - } else if (runner === 'playwright') { - logger.warn('Runner "playwright" is no longer maintained in favor of @nx/playwright!') - - // eslint-disable-next-line @typescript-eslint/no-var-requires - const playwrightExecutor = require('@nx-extend/playwright/src/executors/test/test.impl').default - - success = (await playwrightExecutor(rest, context)).success - } else if (runner === '@nx/playwright') { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const playwrightExecutor = require('@nx/playwright').playwrightExecutor - - success = (await playwrightExecutor(rest, context)).success - } else if (runner === 'run-commands') { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const runCommandsExecutor = require('nx/src/executors/run-commands/run-commands.impl').default - - success = (await runCommandsExecutor(rest as RunCommandsOptions, context)).success - } else { - throw new Error(`Unknown runner "${runner}"`) - } - } catch (error) { - console.error(error) + switch (runner) { + case 'cypress': + // eslint-disable-next-line @typescript-eslint/no-var-requires + const cypressExecutor = require('@nx/cypress/src/executors/cypress/cypress.impl').default - success = false - } + return await cypressExecutor(rest, context) - // Kill all targets - await killTargets() + case 'playwright': + logger.warn('Runner "playwright" is no longer maintained in favor of @nx/playwright!') + + // eslint-disable-next-line @typescript-eslint/no-var-requires + const playwrightExecutor = require('@nx-extend/playwright/src/executors/test/test.impl').default + + return await playwrightExecutor(rest, context) - return { success } + case '@nx/playwright': + // eslint-disable-next-line @typescript-eslint/no-var-requires + const nxPlaywrightExecutor = require('@nx/playwright').playwrightExecutor + + return await nxPlaywrightExecutor(rest, context) + + case 'run-commands': + // eslint-disable-next-line @typescript-eslint/no-var-requires + const runCommandsExecutor = require('nx/src/executors/run-commands/run-commands.impl').default + + return await runCommandsExecutor(rest as RunCommandsOptions, context) + + default: + throw new Error(`Unknown runner "${runner}"`) + } + } finally { + // Kill all targets + await killTargets() + } } process.on('exit', () => killTargets())