-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Run failed tests in a clean environment on retry #7834
Description
Clear and concise description of the problem
When using retry on a failing test, tests are re-run within the same runtime environment. However, many intermittent or flaky tests (especially those involving side effects, DOM manipulation, async operations, or mocked dependencies) require a full environment reset to succeed. Re-running in the same context doesn’t help when the failure stems from shared or mutated state, event listeners, or global mocks that need cleanup.
Suggested solution
Introduce a new option (e.g., --retry-isolated, --retry-clean, or --reload-on-retry) that allows Vitest to:
1. Detect failing tests on the first run.
2. For each failed test (or test file), spawn a new isolated Vitest process to re-run only those tests.
3. Report the combined result of both runs, clearly indicating which tests passed only on retry.
Alternative
Without built in support, users must:
• Run the test suite with a reporter that outputs failed test names
• Parse the output manually
• Re-run Vitest, filtering for the tests that failed
However, where this would be most helpful is in CI environments, where these types of failures introduce a significant delay
Additional context
This is particularly valuable in CI environments and with UI feature / integration tests that rely on mocked endpoints and DOM queries.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status