@@ -1046,11 +1046,16 @@ module.exports = {
10461046 return this . currentWriteVideoFrameCallback ( ...arguments )
10471047 } ,
10481048
1049- waitForBrowserToConnect ( options = { } , shouldLaunchBrowser = true ) {
1049+ waitForBrowserToConnect ( options = { } , isFirstSpec = false ) {
10501050 const { project, socketId, timeout, onError, writeVideoFrame, spec } = options
10511051 const browserTimeout = process . env . CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUT || timeout || 60000
10521052 let attempts = 0
10531053
1054+ const shouldLaunchBrowser = project . shouldLaunchBrowser || isFirstSpec
1055+
1056+ // Reset to e2e only once we've gotten the state for this run
1057+ project . shouldLaunchBrowser = options . testingType === 'e2e'
1058+
10541059 // short circuit current browser callback so that we
10551060 // can rewire it without relaunching the browser
10561061 if ( writeVideoFrame ) {
@@ -1081,6 +1086,12 @@ module.exports = {
10811086 return Promise . resolve ( this . navigateToNextSpec ( options . spec ) )
10821087 }
10831088
1089+ if ( ! project . shouldLaunchBrowser ) {
1090+ project . on ( 'socket:disconnect' , ( ) => {
1091+ project . shouldLaunchBrowser = true
1092+ } )
1093+ }
1094+
10841095 return Promise . join (
10851096 this . waitForSocketConnection ( project , socketId )
10861097 . tap ( ( ) => {
@@ -1406,6 +1417,8 @@ module.exports = {
14061417 runSpec ( config , spec = { } , options = { } , estimated , firstSpec ) {
14071418 const { project, browser, onError } = options
14081419
1420+ project . shouldLaunchBrowser = options . testingType === 'e2e'
1421+
14091422 const { isHeadless } = browser
14101423
14111424 debug ( 'about to run spec %o' , {
@@ -1464,7 +1477,7 @@ module.exports = {
14641477 socketId : options . socketId ,
14651478 webSecurity : options . webSecurity ,
14661479 projectRoot : options . projectRoot ,
1467- } , options . testingType === 'e2e' || firstSpec ) ,
1480+ } , firstSpec ) ,
14681481 } )
14691482 } )
14701483 } ,
0 commit comments