Support different retry configurations for browser mode vs jsdom
Clear and concise description of the problem
Currently, the retry option in vitest.config.ts applies globally to all test environments. It would be valuable to have different retry configurations for browser tests versus jsdom tests.
Use Case:
Browser tests (via Playwright/WebDriver) are often more prone to flakiness due to:
- Timing issues with real DOM rendering
- Network requests
- Animation/transition delays
- Browser-specific rendering differences
Meanwhile, jsdom tests are typically more stable and deterministic. Having the ability to retry browser tests while keeping jsdom tests strict would improve CI reliability without masking issues in unit tests.
Suggested solution
This would probably be the best and easiest option:
export default defineConfig({
test: {
retry: 0, // Default for jsdom
browser: {
provider: playwright(),
enabled: true,
retry: 1, // Specific to browser tests
instances: [{ browser: 'chromium' }],
},
},
});
Alternative
An alternative setup could be an environment-specific retry:
export default defineConfig({
test: {
retry: {
browser: 1,
jsdom: 0,
},
},
});
Additional context
No response
Validations
- [x] Follow our Code of Conduct
- [x] Read the Contributing Guidelines.
- [x] Read the docs.
- [x] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
I think this should be working when using projects. Could you try following?
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
projects: [
{
test: {
name: "Browser",
retry: 1,
browser: {
enabled: true,
// ...rest of the config
},
},
},
{
test: {
name: "JSDOM",
environment: "jsdom",
retry: 0,
},
},
],
},
});
Thank you @AriPerkkio for the response. Yes, in theory that works but there are a few drawbacks as opposed to not separating them into different projects. Every test is duplicated in the test explorer (one for jsdom and one for playwright), you also have to use --project flag in the command line to differentiate between projects or else every project will spawn causing playwright to fail because the dev server is not active (if enabled:false). When trying to run a test from within a test file (using the icons to the left "... click here to run test"), both jsdom and playwright will run unless you right click and specifically select one of them.
I am quite new to vitest so there is a chance that I might have misunderstood something along the way. In that case, I beg for your patience :)
I am quite new to vitest so there is a chance that I might have misunderstood something along the way. In that case, I beg for your patience :)
You should use include to scope the project setting to specific files:
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
projects: [
{
test: {
include: ['./tests/*.browser.test.ts'] // as an EXAMPLE, include only files with browser.test
name: "Browser",
retry: 1,
browser: {
enabled: true,
// ...rest of the config
},
},
},
{
test: {
include: ['./tests/*.jsdom.test.ts'] // as an EXAMPLE, include only files with jsdom.test
name: "JSDOM",
environment: "jsdom",
retry: 0,
},
},
],
},
});
@sheremet-va doesn't that require two sets of tests, given that:
include: ['./tests/*.**browser.test.ts**'] // as an EXAMPLE, include only files with browser.test
and
include: ['./tests/*.**jsdom.test.ts**'] // as an EXAMPLE, include only files with jsdom.test
@l0king-alt doesn't your current configuration define different patterns for Browser and JSDOM? It should not be any different.
Vitest projects is the correct way to define configruation changes like this. I'm quite sure we won't be extending test.browser option to support more options.