Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/runner/src/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,15 @@ async function resolveFixtureFunction(
await fixtureReturn
})
await useReturnPromise
}).then(() => {
// fixture returned without calling use()
if (!isUseFnArgResolved) {
useFnArgPromise.reject(
new Error(
'Fixture returned without calling "use". Make sure to call "use" in every code path of the fixture function.',
Copy link
Contributor

@hi-ogawa hi-ogawa Mar 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it surface fixture name? For the test case, it would be setup.

EDIT: ah sorry, you've already suggested that #9861 (comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, Done in 09b3f1c!

),
)
}
}).catch((e: unknown) => {
// treat fixture setup error as test failure
if (!isUseFnArgResolved) {
Expand Down
20 changes: 20 additions & 0 deletions test/cli/fixtures/fails/test-extend/fixture-without-use.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, test as base } from 'vitest'

const test = base.extend<{ value: string | undefined, setup: void }>({
value: undefined,

setup: [
async ({ value }, use) => {
if (!value) {
return
}

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

describe('fixture returned without calling use', () => {
test('should fail with descriptive error', () => {})
})
2 changes: 2 additions & 0 deletions test/cli/test/__snapshots__/fails.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ exports[`should fail test-extend/fixture-rest-props.test.ts 1`] = `"FixtureParse

exports[`should fail test-extend/fixture-without-destructuring.test.ts 1`] = `"FixtureParseError: The 1st argument inside a fixture must use object destructuring pattern, e.g. ({ task } => {}). Instead, received "context"."`;

exports[`should fail test-extend/fixture-without-use.test.ts 1`] = `"Error: Fixture returned without calling "use". Make sure to call "use" in every code path of the fixture function."`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should favor runInlineTests + stderr snapshot pattern, so we can view full error output (even if we don't have stack right now, it might in the future). Probably we can put it somewhere around

test('test fixture cannot import from file fixture', async () => {
const { stderr } = await runInlineTests({
'basic.test.ts': () => {
const extendedTest = it.extend<{
file: string
local: string
}>({
local: ({}, use) => use('local'),
file: [({ local }, use) => use(local), { scope: 'file' }],
})
extendedTest('not working', ({ file: _file }) => {})
},
}, { globals: true })
expect(stderr).toMatchInlineSnapshot(`
"
⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯
FAIL basic.test.ts [ basic.test.ts ]
FixtureDependencyError: The file "file" fixture cannot depend on a test fixture "local".
❯ basic.test.ts:2:27
1| await (() => {
2| const extendedTest = it.extend({
| ^
3| local: ({}, use) => use("local"),
4| file: [({ local }, use) => use(local), { scope: "file" }]
❯ basic.test.ts:8:1
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
"
`)
})


exports[`should fail test-extend/test-rest-params.test.ts 1`] = `"FixtureParseError: The 1st argument inside a fixture must use object destructuring pattern, e.g. ({ task } => {}). Instead, received "...rest"."`;

exports[`should fail test-extend/test-rest-props.test.ts 1`] = `"FixtureParseError: Rest parameters are not supported in fixtures, received "...rest"."`;
Expand Down
Loading