diff --git a/packages/server/lib/modes/run.ts b/packages/server/lib/modes/run.ts index 2dbee21338a6..77719b283b4d 100644 --- a/packages/server/lib/modes/run.ts +++ b/packages/server/lib/modes/run.ts @@ -545,10 +545,10 @@ function waitForSocketConnection (project: Project, id: string) { }) } -async function waitForTestsToFinishRunning (options: { project: Project, screenshots: ScreenshotMetadata[], videoCompression: number | boolean, exit: boolean, spec: SpecWithRelativeRoot, estimated: number, quiet: boolean, config: Cfg, shouldKeepTabOpen: boolean, testingType: TestingType, videoRecording?: VideoRecording, protocolManager?: ProtocolManager }) { +async function waitForTestsToFinishRunning (options: { project: Project, screenshots: ScreenshotMetadata[], videoCompression: number | boolean, exit: boolean, spec: SpecWithRelativeRoot, estimated: number, quiet: boolean, config: Cfg, shouldKeepTabOpen: boolean, isLastSpec: boolean, testingType: TestingType, videoRecording?: VideoRecording, protocolManager?: ProtocolManager }) { if (globalThis.CY_TEST_MOCK?.waitForTestsToFinishRunning) return Promise.resolve(globalThis.CY_TEST_MOCK.waitForTestsToFinishRunning) - const { project, screenshots, videoRecording, videoCompression, exit, spec, estimated, quiet, config, shouldKeepTabOpen, testingType, protocolManager } = options + const { project, screenshots, videoRecording, videoCompression, exit, spec, estimated, quiet, config, shouldKeepTabOpen, isLastSpec, testingType, protocolManager } = options const results = await listenForProjectEnd(project, exit) @@ -644,12 +644,12 @@ async function waitForTestsToFinishRunning (options: { project: Project, screens // @ts-expect-error experimentalSingleTabRunMode only exists on the CT-specific config type const usingExperimentalSingleTabMode = testingType === 'component' && config.experimentalSingleTabRunMode - if (usingExperimentalSingleTabMode) { + if (usingExperimentalSingleTabMode && !isLastSpec) { await project.server.destroyAut() } - // we do not support experimentalSingleTabRunMode for e2e - if (!usingExperimentalSingleTabMode) { + // we do not support experimentalSingleTabRunMode for e2e. We always want to close the tab on the last spec to ensure that things get cleaned up properly at the end of the run + if (!usingExperimentalSingleTabMode || isLastSpec) { debug('attempting to close the browser tab') await openProject.resetBrowserTabsForNextTest(shouldKeepTabOpen) @@ -920,6 +920,7 @@ async function runSpec (config, spec: SpecWithRelativeRoot, options: { project: videoCompression: options.videoCompression, quiet: options.quiet, shouldKeepTabOpen: !isLastSpec, + isLastSpec, protocolManager: options.protocolManager, }), waitForBrowserToConnect({