-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: detect fixture that returns without calling use (#9831)
#9861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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', () => {}) | ||
| }) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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."`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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]⎯ | |
| " | |
| `) | |
| }) |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, Done in 09b3f1c!