Skip to content

Improve error message when fixture doesn't call use before timeout #9831

@AriPerkkio

Description

@AriPerkkio

Describe the bug

Had difficult time debugging why a test is timing out. Root cause was that I was returning from fixture when specific condition is met, without calling use. Let's improve the error message in these cases by saying something like Fixture returned value but didn't call 'use'. Hook will timeout.

const test = base.extend({
  value: undefined as string | undefined,

  setup: [
    async ({ value }, use) => {
      // optional value, no setups if it's missing
      if (!value) {
        return; // Forgot to call use here 🙃 
        // return await use(undefined)
      }

      await prepare(value);
      await use(undefined);
    },
    { auto: true },
  ],
});

describe("working example", () => {
  test.scoped({ value: "something" })
  test('example 1', () => {});
})

test('example 2', () => {});

Reproduction

https://stackblitz.com/~/edit/vitest-dev-vitest-inffnahb?file=basic.test.ts:L1-L35&initialPath=/__vitest__/

System Info

Stackblitz, Vitest 4.0.18

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: contextp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions