Skip to content
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

fix: ensure we have marked things as stable prior to after/afterEach hooks running #30536

Merged
merged 10 commits into from
Nov 4, 2024
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 11/5/2024 (PENDING)_

**Bugfixes:**

- Fixed an issue where the Cypress runner could hang in `after` or `afterEach` hooks that run Cypress commands after a page load timeout error occurs. Addresses [#30238](https://github.com/cypress-io/cypress/issues/30238).

**Misc:**

- Fixed a typo in CLI `global` option help text. Addresses [#30531](https://github.com/cypress-io/cypress/issues/30531).
Expand Down
34 changes: 34 additions & 0 deletions packages/driver/cypress/e2e/issues/30238.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
after(() => {
// ensure that we're stable in the after hooks
expect(cy.state('isStable')).to.be.true

// ensure we can enqueue a command without timing out
cy.then(() => {
expect(true).to.be.true
})
})

afterEach(() => {
// ensure that we're stable in the after hooks
expect(cy.state('isStable')).to.be.true

// ensure that we can enqueue a command without timing out
cy.then(() => {
expect(true).to.be.true
})
})

it('runs an after block without timing out when the page load times out', { pageLoadTimeout: 500 }, () => {
cy.on('fail', (error) => {
expect(error.message).to.include('Timed out after')

return false
})

cy.on('window:before:load', (win) => {
// Stop the page from loading so that the page load times out
win.stop()
})

cy.visit('/fixtures/generic.html')
})
3 changes: 3 additions & 0 deletions packages/driver/src/cypress/command_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ export class CommandQueue extends Queue<$Command> {
// end in case we have after / afterEach hooks
// which need to run
this.index = this.length

// Mark the state as stable, so that any cypress commands can be re-queued during the after / afterEach hooks
this.state('isStable', true)
}

private runCommand (command: $Command) {
Expand Down
Loading