Skip to content

Commit

Permalink
refactor(e2e-runner): Improve implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Dec 19, 2023
1 parent 321e745 commit 3cc8ff2
Showing 1 changed file with 32 additions and 34 deletions.
66 changes: 32 additions & 34 deletions packages/e2e-runner/src/executors/run/run.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,57 +21,55 @@ 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))

try {
// Start all targets
await Promise.all(runningTargets.map((nxTarget) => nxTarget.setup()))

} catch {
await killTargets()

return { success: false }
}

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())
Expand Down

0 comments on commit 3cc8ff2

Please sign in to comment.