Skip to content

fix: add cy.then timeouts to cy.session #31788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

_Released 6/3/2025 (PENDING)_

**Bugfixes:**

- 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).

**Dependency Updates:**

- Updated `@sinonjs/fake-timers` from `10.3.0` to `11.3.1`. Addressed in [#31746](https://github.com/cypress-io/cypress/pull/31746).
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/runner/aut-iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export class AutIframe {
visitBlankPage = (testIsolation?: boolean) => {
return new Promise<void>((resolve) => {
if (!this.$iframe) {
resolve()

return
}

Expand Down
26 changes: 14 additions & 12 deletions packages/driver/src/cy/commands/sessions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
* - session data SHOULD be cleared between specs in run mode
*/
export default function (Commands, Cypress, cy) {
const COMMAND_TIMEOUT = 20000

const sessionsManager = new SessionsManager(Cypress, cy)
const sessions = sessionsManager.sessions

Expand Down Expand Up @@ -149,7 +151,7 @@ export default function (Commands, Cypress, cy) {
message: '',
type: 'system',
}, (setupLogGroup) => {
return cy.then(async () => {
return cy.then({ timeout: COMMAND_TIMEOUT }, async () => {
// Catch when a cypress command fails in the setup function to correctly update log status
// before failing command and ending command queue.
cy.state('onQueueFailed', (err, _queue) => {
Expand Down Expand Up @@ -180,7 +182,7 @@ export default function (Commands, Cypress, cy) {
cy.breakSubjectLinksToCurrentChainer()
}
})
.then(async () => {
.then({ timeout: COMMAND_TIMEOUT }, async () => {
cy.state('onQueueFailed', null)
const data = await sessions.getCurrentSessionData()

Expand Down Expand Up @@ -241,7 +243,7 @@ export default function (Commands, Cypress, cy) {
}
},
}, (validateLog) => {
return cy.then(async () => {
return cy.then({ timeout: COMMAND_TIMEOUT }, async () => {
const isValidSession = true
let caughtCommandErr = false
let _commandToRunAfterValidation
Expand Down Expand Up @@ -350,7 +352,7 @@ export default function (Commands, Cypress, cy) {
throw err
}

_commandToRunAfterValidation = cy.then(async () => {
_commandToRunAfterValidation = cy.then({ timeout: COMMAND_TIMEOUT }, async () => {
Cypress.state('onQueueFailed', null)

if (caughtCommandErr) {
Expand Down Expand Up @@ -434,16 +436,16 @@ export default function (Commands, Cypress, cy) {
* 2. validate session
*/
const createSessionWorkflow = (existingSession, step: 'create' | 'recreate') => {
return cy.then(async () => {
return cy.then({ timeout: COMMAND_TIMEOUT }, async () => {
setSessionLogStatus(statusMap.inProgress(step))

await navigateAboutBlank()
await sessions.clearCurrentSessionData()

return cy.whenStable(() => createSession(existingSession, step))
})
.then(() => validateSession(existingSession, step))
.then(async (isValidSession: boolean) => {
.then({ timeout: COMMAND_TIMEOUT }, () => validateSession(existingSession, step))
.then({ timeout: COMMAND_TIMEOUT }, async (isValidSession: boolean) => {
if (!isValidSession) {
return 'failed'
}
Expand All @@ -462,15 +464,15 @@ export default function (Commands, Cypress, cy) {
* 3. if validation fails, catch error and recreate session
*/
const restoreSessionWorkflow = (existingSession: Cypress.SessionData) => {
return cy.then(async () => {
return cy.then({ timeout: COMMAND_TIMEOUT }, async () => {
setSessionLogStatus(statusMap.inProgress(SESSION_STEPS.restore))
await navigateAboutBlank()
await sessions.clearCurrentSessionData()

return restoreSession(existingSession)
})
.then(() => validateSession(existingSession, SESSION_STEPS.restore))
.then((isValidSession: boolean) => {
.then({ timeout: COMMAND_TIMEOUT }, () => validateSession(existingSession, SESSION_STEPS.restore))
.then({ timeout: COMMAND_TIMEOUT }, (isValidSession: boolean) => {
if (!isValidSession) {
return createSessionWorkflow(existingSession, SESSION_STEPS.recreate)
}
Expand All @@ -495,7 +497,7 @@ export default function (Commands, Cypress, cy) {
}

return logGroup(Cypress, groupDetails, (log) => {
return cy.then(async () => {
return cy.then({ timeout: COMMAND_TIMEOUT }, async () => {
_log = log

if (!session.hydrated) {
Expand All @@ -511,7 +513,7 @@ export default function (Commands, Cypress, cy) {
}

return restoreSessionWorkflow(session)
}).then((status: 'created' | 'restored' | 'recreated' | 'failed') => {
}).then({ timeout: COMMAND_TIMEOUT }, (status: 'created' | 'restored' | 'recreated' | 'failed') => {
return navigateAboutBlank()
.then(() => {
setSessionLogStatus(status)
Expand Down
Loading