Skip to content

Commit 68469a6

Browse files
authored
fix: add cy.then timeouts to cy.session (#31788)
1 parent fc629c5 commit 68469a6

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

cli/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
_Released 6/3/2025 (PENDING)_
55

6+
**Bugfixes:**
7+
8+
- Fixed an issue where `cy.session()` may fail internally if navigating to `about:blank` takes longer than the `defaultCommandTimeout`. Addresses [#29496](https://github.com/cypress-io/cypress/issues/29496).
9+
610
**Misc:**
711

812
- The design of commands that display as grouped (such as `.within()` and `cy.session()`) has been updated to provide better clarity when collapsing groups. Addressed in [#31739](https://github.com/cypress-io/cypress/pull/31739).

packages/app/src/runner/aut-iframe.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ export class AutIframe {
126126
visitBlankPage = (testIsolation?: boolean) => {
127127
return new Promise<void>((resolve) => {
128128
if (!this.$iframe) {
129+
resolve()
130+
129131
return
130132
}
131133

packages/driver/src/cy/commands/sessions/index.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import {
2121
* - session data SHOULD be cleared between specs in run mode
2222
*/
2323
export default function (Commands, Cypress, cy) {
24+
// 20s timeout used for internal cy commands within the session command
25+
const INTERNAL_COMMAND_TIMEOUT = 20_000
26+
2427
const sessionsManager = new SessionsManager(Cypress, cy)
2528
const sessions = sessionsManager.sessions
2629

@@ -149,7 +152,7 @@ export default function (Commands, Cypress, cy) {
149152
message: '',
150153
type: 'system',
151154
}, (setupLogGroup) => {
152-
return cy.then(async () => {
155+
return cy.then({ timeout: INTERNAL_COMMAND_TIMEOUT }, async () => {
153156
// Catch when a cypress command fails in the setup function to correctly update log status
154157
// before failing command and ending command queue.
155158
cy.state('onQueueFailed', (err, _queue) => {
@@ -180,7 +183,7 @@ export default function (Commands, Cypress, cy) {
180183
cy.breakSubjectLinksToCurrentChainer()
181184
}
182185
})
183-
.then(async () => {
186+
.then({ timeout: INTERNAL_COMMAND_TIMEOUT }, async () => {
184187
cy.state('onQueueFailed', null)
185188
const data = await sessions.getCurrentSessionData()
186189

@@ -241,7 +244,7 @@ export default function (Commands, Cypress, cy) {
241244
}
242245
},
243246
}, (validateLog) => {
244-
return cy.then(async () => {
247+
return cy.then({ timeout: INTERNAL_COMMAND_TIMEOUT }, async () => {
245248
const isValidSession = true
246249
let caughtCommandErr = false
247250
let _commandToRunAfterValidation
@@ -350,7 +353,7 @@ export default function (Commands, Cypress, cy) {
350353
throw err
351354
}
352355

353-
_commandToRunAfterValidation = cy.then(async () => {
356+
_commandToRunAfterValidation = cy.then({ timeout: INTERNAL_COMMAND_TIMEOUT }, async () => {
354357
Cypress.state('onQueueFailed', null)
355358

356359
if (caughtCommandErr) {
@@ -434,16 +437,16 @@ export default function (Commands, Cypress, cy) {
434437
* 2. validate session
435438
*/
436439
const createSessionWorkflow = (existingSession, step: 'create' | 'recreate') => {
437-
return cy.then(async () => {
440+
return cy.then({ timeout: INTERNAL_COMMAND_TIMEOUT }, async () => {
438441
setSessionLogStatus(statusMap.inProgress(step))
439442

440443
await navigateAboutBlank()
441444
await sessions.clearCurrentSessionData()
442445

443446
return cy.whenStable(() => createSession(existingSession, step))
444447
})
445-
.then(() => validateSession(existingSession, step))
446-
.then(async (isValidSession: boolean) => {
448+
.then({ timeout: INTERNAL_COMMAND_TIMEOUT }, () => validateSession(existingSession, step))
449+
.then({ timeout: INTERNAL_COMMAND_TIMEOUT }, async (isValidSession: boolean) => {
447450
if (!isValidSession) {
448451
return 'failed'
449452
}
@@ -462,15 +465,15 @@ export default function (Commands, Cypress, cy) {
462465
* 3. if validation fails, catch error and recreate session
463466
*/
464467
const restoreSessionWorkflow = (existingSession: Cypress.SessionData) => {
465-
return cy.then(async () => {
468+
return cy.then({ timeout: INTERNAL_COMMAND_TIMEOUT }, async () => {
466469
setSessionLogStatus(statusMap.inProgress(SESSION_STEPS.restore))
467470
await navigateAboutBlank()
468471
await sessions.clearCurrentSessionData()
469472

470473
return restoreSession(existingSession)
471474
})
472-
.then(() => validateSession(existingSession, SESSION_STEPS.restore))
473-
.then((isValidSession: boolean) => {
475+
.then({ timeout: INTERNAL_COMMAND_TIMEOUT }, () => validateSession(existingSession, SESSION_STEPS.restore))
476+
.then({ timeout: INTERNAL_COMMAND_TIMEOUT }, (isValidSession: boolean) => {
474477
if (!isValidSession) {
475478
return createSessionWorkflow(existingSession, SESSION_STEPS.recreate)
476479
}
@@ -495,7 +498,7 @@ export default function (Commands, Cypress, cy) {
495498
}
496499

497500
return logGroup(Cypress, groupDetails, (log) => {
498-
return cy.then(async () => {
501+
return cy.then({ timeout: INTERNAL_COMMAND_TIMEOUT }, async () => {
499502
_log = log
500503

501504
if (!session.hydrated) {
@@ -511,7 +514,7 @@ export default function (Commands, Cypress, cy) {
511514
}
512515

513516
return restoreSessionWorkflow(session)
514-
}).then((status: 'created' | 'restored' | 'recreated' | 'failed') => {
517+
}).then({ timeout: INTERNAL_COMMAND_TIMEOUT }, (status: 'created' | 'restored' | 'recreated' | 'failed') => {
515518
return navigateAboutBlank()
516519
.then(() => {
517520
setSessionLogStatus(status)

0 commit comments

Comments
 (0)