feat: add global test timeout configuration option #33256
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new
testTimeoutconfiguration option that allows setting a global maximum duration for tests. Unlike existing command-level timeouts (defaultCommandTimeout,responseTimeout, etc.), this option limits the total duration of a test including all its hooks.Problem
Currently, Cypress has no way to enforce a global test timeout. Each individual command has its own timeout, but a test could theoretically run indefinitely if each command completes within its respective timeout. Users have requested the ability to fail tests that exceed a certain total duration.
Solution
Add a new
testTimeoutconfiguration option:0(disabled, for backward compatibility)it('test', { testTimeout: 30000 }, ...)Example Usage
Diagnostics on Timeout
When a test times out, the following diagnostic information is captured and logged to the browser console:
Example console output:
The diagnostics are also attached to the error object as
err.diagnosticsfor programmatic access.Changes
packages/config/src/options.tstestTimeoutconfig option with default0cli/types/cypress.d.tspackages/driver/src/cypress/error_messages.tspackages/driver/src/cypress/runner.tsImplementation Details
wallClockStartedAtis first set)testAfterRun)cy.fail()to properly fail the test and trigger cleanupTesting
Note: This is a proof-of-concept implementation. Additional testing and edge case handling may be needed for production readiness.