From 2804e6eab788e556cf4c7b39ecbde49432cfc109 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Sat, 2 Nov 2024 08:05:41 -0500 Subject: [PATCH 1/9] fix: ensure we have marked things as stable prior to failing tests -- run ci --- packages/driver/src/cypress/command_queue.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/driver/src/cypress/command_queue.ts b/packages/driver/src/cypress/command_queue.ts index 3b692c51b413..88d7d74b1ddf 100644 --- a/packages/driver/src/cypress/command_queue.ts +++ b/packages/driver/src/cypress/command_queue.ts @@ -545,6 +545,8 @@ export class CommandQueue extends Queue<$Command> { Cypress.action('cy:command:failed', current, err) this.cleanup() + this.state('isStable', true) + return this.cy.fail(err) } From 2fe6ae19e61d7bba6b98fb7d59f312ed03ed023a Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Sat, 2 Nov 2024 08:15:57 -0500 Subject: [PATCH 2/9] fix: ensure we have marked things as stable prior to failing tests -- run ci --- packages/driver/src/cypress/command_queue.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/driver/src/cypress/command_queue.ts b/packages/driver/src/cypress/command_queue.ts index 88d7d74b1ddf..09ac6e460bf2 100644 --- a/packages/driver/src/cypress/command_queue.ts +++ b/packages/driver/src/cypress/command_queue.ts @@ -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) { @@ -545,8 +548,6 @@ export class CommandQueue extends Queue<$Command> { Cypress.action('cy:command:failed', current, err) this.cleanup() - this.state('isStable', true) - return this.cy.fail(err) } From baed02e8cb931d285349b5f988d79b0bb2b60be1 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Sun, 3 Nov 2024 19:54:19 -0600 Subject: [PATCH 3/9] add a test -- run ci --- .../driver/cypress/e2e/issues/30238.cy.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 packages/driver/cypress/e2e/issues/30238.cy.js diff --git a/packages/driver/cypress/e2e/issues/30238.cy.js b/packages/driver/cypress/e2e/issues/30238.cy.js new file mode 100644 index 000000000000..b51d5484580e --- /dev/null +++ b/packages/driver/cypress/e2e/issues/30238.cy.js @@ -0,0 +1,27 @@ +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.window().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.window().then(() => { + expect(true).to.be.true + }) +}) + +it('runs an after block without timing out when the page load times out', { pageLoadTimeout: 500 }, () => { + cy.on('window:before:load', (win) => { + win.stop() + }) + + cy.visit('/fixtures/generic.html') +}) From b850f9ed67b5ac08e5e1662276c454a84cdc7b17 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Mon, 4 Nov 2024 10:28:46 -0600 Subject: [PATCH 4/9] clean up --- packages/driver/cypress/e2e/issues/30238.cy.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/driver/cypress/e2e/issues/30238.cy.js b/packages/driver/cypress/e2e/issues/30238.cy.js index b51d5484580e..e41ea5bc6ade 100644 --- a/packages/driver/cypress/e2e/issues/30238.cy.js +++ b/packages/driver/cypress/e2e/issues/30238.cy.js @@ -3,7 +3,7 @@ after(() => { expect(cy.state('isStable')).to.be.true // ensure we can enqueue a command without timing out - cy.window().then(() => { + cy.then(() => { expect(true).to.be.true }) }) @@ -13,13 +13,14 @@ afterEach(() => { expect(cy.state('isStable')).to.be.true // ensure that we can enqueue a command without timing out - cy.window().then(() => { + 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('window:before:load', (win) => { + // Stop the page from loading so that the page load times out win.stop() }) From d57751815a3111c542952f7888c65dd407a32fc4 Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Mon, 4 Nov 2024 11:00:30 -0600 Subject: [PATCH 5/9] add changelog --- cli/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 7747c11e8a79..a40827583217 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -7,6 +7,7 @@ _Released 10/1/2024 (PENDING)_ - Patched [find-process](https://github.com/yibn2008/find-process) to fix an issue where trying to clean up browser profiles can throw an error on Windows. Addresses [#30378](https://github.com/cypress-io/cypress/issues/30378). - Fixed an issue where requests to the same resource in rapid succession may not have the appropriate static response intercept applied if there are multiple intercepts that apply for that resource. Addresses [#30375](https://github.com/cypress-io/cypress/issues/30375). +- Fixed an issue where the Cypres 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:** From 21bd618a17539d32b2d5365d50f762fbe518a8ba Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Mon, 4 Nov 2024 11:02:32 -0600 Subject: [PATCH 6/9] Update CHANGELOG.md --- cli/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 61fcee84b2b0..6e2aa044c5a8 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -3,6 +3,10 @@ _Released 11/5/2024 (PENDING)_ +**Bugfixes:** + +- Fixed an issue where the Cypres 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). From 655d3fb2cca0870ce80ea8203dfe6d01973e344e Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Mon, 4 Nov 2024 11:02:51 -0600 Subject: [PATCH 7/9] Apply suggestions from code review --- cli/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 6e2aa044c5a8..33d8014c3d3c 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -23,7 +23,6 @@ _Released 10/24/2024_ - Patched [find-process](https://github.com/yibn2008/find-process) to fix an issue where trying to clean up browser profiles can throw an error on Windows. Addresses [#30378](https://github.com/cypress-io/cypress/issues/30378). - Fixed an issue where requests to the same resource in rapid succession may not have the appropriate static response intercept applied if there are multiple intercepts that apply for that resource. Addresses [#30375](https://github.com/cypress-io/cypress/issues/30375). -- Fixed an issue where the Cypres 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:** From 33684874b7f091efe46fc97f574b578638725997 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Mon, 4 Nov 2024 12:21:16 -0500 Subject: [PATCH 8/9] Update cli/CHANGELOG.md Co-authored-by: Matt Schile --- cli/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 33d8014c3d3c..9690711f9a55 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -5,7 +5,7 @@ _Released 11/5/2024 (PENDING)_ **Bugfixes:** -- Fixed an issue where the Cypres 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). +- 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:** From a856e5ced6c966637c9d92d3a86d0790bf22ba6b Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Mon, 4 Nov 2024 12:35:09 -0600 Subject: [PATCH 9/9] allow failure --- packages/driver/cypress/e2e/issues/30238.cy.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/driver/cypress/e2e/issues/30238.cy.js b/packages/driver/cypress/e2e/issues/30238.cy.js index e41ea5bc6ade..f9a66b2adb65 100644 --- a/packages/driver/cypress/e2e/issues/30238.cy.js +++ b/packages/driver/cypress/e2e/issues/30238.cy.js @@ -19,6 +19,12 @@ afterEach(() => { }) 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()