Skip to content

A fixture whose setup throws is never set up again #11237

Closed

Description

@hamed-bavar

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.0

Used Package Manager

npm

Validations

Activity

  1. added
    p3-minor-bug
    on Sep 15, 2026
  2. added theissue type on Sep 15, 2026
  3. added a commit that references this issue on Oct 3, 2026
    4ee66c0
  4. locked and limited conversation to collaborators on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions