A fixture whose setup throws is never set up again

Open
#11,237 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
testing

Research direction

Start with packages/vitest/src/runtime/runner/fixture.ts and run the linked reproduction with npm install followed by npx vitest run. Trace fixture setup caching for test, file, and worker scopes, then verify that a failed setup is retried and does not remain cached for later tests, including with isolate: false.

Written by the indexing model from the issue text.

Description

p3-minor-bug
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 e53854fcc (#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.0
Used Package Manager

npm

Validations
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 21h
Merged PRs (30d)
92

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vitest-dev/vitest

All issues in vitest-dev/vitest

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.