cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.87k stars 3.17k forks source link

Generic CypressError Emitted after `before` async function takes longer than 4 seconds to fully complete. #29889

Open cybernihil opened 3 months ago

cybernihil commented 3 months ago

Current behavior

The mocha before hook will timeout after 4 seconds. This is not documented, to my understanding, anywhere, and is not default mocha behavior. It seems that Cypress is setting this timeout, but when it occurs, a generic CypressError exception is the only indication of the problem: CypressError: Cypress test was stopped while running this command.

I haven't been able to locate the timeout set in your source code after a brief scan, but our canary failure logs were consistently failing at 4 seconds before the fix included below.

The below diff in cypress/support/e2e.ts fixed the issue for us.

- before(async () => {

+ before(async function () {
+   // REMOVE WITH CAUTION: Setting a long timeout for this before logic so the hidden 4s timeout from + Cypress doesn't bite us.
+   this.timeout(20000);

Desired behavior

My request: determine whether this is expected behavior. If it is, improve the error log so the timeout is the clear root cause, and document this default timeout publicly. If it is not expected behavior, remove the 4 second timeout for the before hook (I'm not sure if this is applied to other hooks).

Test code to reproduce

The below diff in cypress/support/e2e.ts fixed the issue for us.

- before(async () => {

+ before(async function () {
+   // REMOVE WITH CAUTION: Setting a long timeout for this before logic so the hidden 4s timeout from + Cypress doesn't bite us.
+   this.timeout(20000);

Cypress Version

12.5.1

Node version

v18.20.4

Operating System

macOS 14.5 (repro'd on Amazon Linux 2 as well)

Debug Logs

CypressError: Cypress test was stopped while running this command

Other

No response

jennifer-shehane commented 2 months ago

@cybernihil Can you provide an example of code to run that show this behavior with the before timing out in 4 seconds?