diff --git a/packages/cypress/src/executors/cypress/cypress.impl.ts b/packages/cypress/src/executors/cypress/cypress.impl.ts index 81c68afd2ba6f4..b41b68e99fd7b8 100644 --- a/packages/cypress/src/executors/cypress/cypress.impl.ts +++ b/packages/cypress/src/executors/cypress/cypress.impl.ts @@ -67,19 +67,26 @@ export default async function cypressExecutor( options = normalizeOptions(options, context); // this is used by cypress component testing presets to build the executor contexts with the correct configuration options. process.env.NX_CYPRESS_TARGET_CONFIGURATION = context.configurationName; - let success; + let success: boolean; + const devServerIter = startDevServer(options, context); - for await (const devServerValues of startDevServer(options, context)) { + for await (const devServerValues of devServerIter) { try { success = await runCypress(devServerValues.baseUrl, { ...options, portLockFilePath: devServerValues.portLockFilePath, }); - if (!options.watch) break; + if (!options.watch) { + devServerIter.return(); + break; + } } catch (e) { logger.error(e.message); success = false; - if (!options.watch) break; + if (!options.watch) { + devServerIter.return(); + break; + } } }