Repository navigation
Description
Describe the bug
If a fixture's setup throws, Vitest keeps treating the fixture as resolved and never runs the setup again.
let attempts = 0
const flaky = test.extend({
value: async ({}, use) => {
if (attempts++ === 0) throw new Error('setup failed once')
await use('ready')
},
})
flaky('x', { retry: 1 }, ({ value }) => {
expect(value).toBe('ready') // retry gets undefined
})For test scope, withFixtures marks the fixture in cachedFixtures before awaiting setup and only unmarks it after success. The retry sees the mark, skips setup, and the test gets undefined.
For file and worker scope, the in-flight promise is cached and only deleted in a .then. A rejection stays cached and is handed to every later test, across files under isolate: false.
Both are in packages/vitest/src/runtime/runner/fixture.ts, since e53854f (#9550). I have a fix and tests, and will open a PR.
Reproduction
https://github.com/hamed-bavar/vitest-fixture-failed-setup
After npm install, npx vitest run fails on the retry with expected 1 to be 2: setup ran once and the retry skipped it.
System Info
System:
OS: Windows 11 10.0.26200
CPU: (12) x64 AMD Ryzen 5 7535HS with Radeon Graphics
Memory: 12.66 GB / 31.24 GB
Binaries:
Node: 22.18.0
Yarn: 1.22.22
npm: 10.9.3
pnpm: 11.24.0
Browsers:
Chrome: 152.0.7977.65
Edge: Chromium (152.0.4191.53)
Firefox: 155.0
npmPackages:
vitest: 5.0.0 => 5.0.0Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Activity
fix(runner): don't cache failed fixture setups (fix vitest-dev#11237) (…