@@ -545,10 +545,10 @@ function waitForSocketConnection (project: Project, id: string) {
545
545
} )
546
546
}
547
547
548
- 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 } ) {
548
+ 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 } ) {
549
549
if ( globalThis . CY_TEST_MOCK ?. waitForTestsToFinishRunning ) return Promise . resolve ( globalThis . CY_TEST_MOCK . waitForTestsToFinishRunning )
550
550
551
- const { project, screenshots, videoRecording, videoCompression, exit, spec, estimated, quiet, config, shouldKeepTabOpen, testingType, protocolManager } = options
551
+ const { project, screenshots, videoRecording, videoCompression, exit, spec, estimated, quiet, config, shouldKeepTabOpen, isLastSpec , testingType, protocolManager } = options
552
552
553
553
const results = await listenForProjectEnd ( project , exit )
554
554
@@ -644,12 +644,12 @@ async function waitForTestsToFinishRunning (options: { project: Project, screens
644
644
// @ts -expect-error experimentalSingleTabRunMode only exists on the CT-specific config type
645
645
const usingExperimentalSingleTabMode = testingType === 'component' && config . experimentalSingleTabRunMode
646
646
647
- if ( usingExperimentalSingleTabMode ) {
647
+ if ( usingExperimentalSingleTabMode && ! isLastSpec ) {
648
648
await project . server . destroyAut ( )
649
649
}
650
650
651
- // we do not support experimentalSingleTabRunMode for e2e
652
- if ( ! usingExperimentalSingleTabMode ) {
651
+ // 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
652
+ if ( ! usingExperimentalSingleTabMode || isLastSpec ) {
653
653
debug ( 'attempting to close the browser tab' )
654
654
655
655
await openProject . resetBrowserTabsForNextTest ( shouldKeepTabOpen )
@@ -920,6 +920,7 @@ async function runSpec (config, spec: SpecWithRelativeRoot, options: { project:
920
920
videoCompression : options . videoCompression ,
921
921
quiet : options . quiet ,
922
922
shouldKeepTabOpen : ! isLastSpec ,
923
+ isLastSpec,
923
924
protocolManager : options . protocolManager ,
924
925
} ) ,
925
926
waitForBrowserToConnect ( {
0 commit comments