Skip to content

Commit a8a3cb9

Browse files
ryanthemanueljennifer-shehanemschile
authored
fix: ensure we have marked things as stable prior to after/afterEach hooks running (#30536)
* fix: ensure we have marked things as stable prior to failing tests -- run ci * fix: ensure we have marked things as stable prior to failing tests -- run ci * add a test -- run ci * clean up * add changelog * Update CHANGELOG.md * Apply suggestions from code review * Update cli/CHANGELOG.md Co-authored-by: Matt Schile <[email protected]> * allow failure --------- Co-authored-by: Jennifer Shehane <[email protected]> Co-authored-by: Matt Schile <[email protected]>
1 parent b0b28d3 commit a8a3cb9

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
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 11/5/2024 (PENDING)_
55

6+
**Bugfixes:**
7+
8+
- 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).
9+
610
**Misc:**
711

812
- Fixed a typo in CLI `global` option help text. Addresses [#30531](https://github.com/cypress-io/cypress/issues/30531).
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
after(() => {
2+
// ensure that we're stable in the after hooks
3+
expect(cy.state('isStable')).to.be.true
4+
5+
// ensure we can enqueue a command without timing out
6+
cy.then(() => {
7+
expect(true).to.be.true
8+
})
9+
})
10+
11+
afterEach(() => {
12+
// ensure that we're stable in the after hooks
13+
expect(cy.state('isStable')).to.be.true
14+
15+
// ensure that we can enqueue a command without timing out
16+
cy.then(() => {
17+
expect(true).to.be.true
18+
})
19+
})
20+
21+
it('runs an after block without timing out when the page load times out', { pageLoadTimeout: 500 }, () => {
22+
cy.on('fail', (error) => {
23+
expect(error.message).to.include('Timed out after')
24+
25+
return false
26+
})
27+
28+
cy.on('window:before:load', (win) => {
29+
// Stop the page from loading so that the page load times out
30+
win.stop()
31+
})
32+
33+
cy.visit('/fixtures/generic.html')
34+
})

packages/driver/src/cypress/command_queue.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ export class CommandQueue extends Queue<$Command> {
223223
// end in case we have after / afterEach hooks
224224
// which need to run
225225
this.index = this.length
226+
227+
// Mark the state as stable, so that any cypress commands can be re-queued during the after / afterEach hooks
228+
this.state('isStable', true)
226229
}
227230

228231
private runCommand (command: $Command) {

0 commit comments

Comments
 (0)