-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Copy link
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
Describe the bug
Lets say you create a Custom Task Function with createTaskCollector
, the same way as demonstrated both in the docs and in the original PR.
If you then want to add test fixtures via .extend
, whatever you did to wrap the handler will not be used, instead using the original fn
passed in.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-yw1snj5a?file=test%2Fsuite.test.ts
And just in case that link doesn't work, this is an example test file:
import { assert, describe, expect } from 'vitest'
import { createTaskCollector, getCurrentSuite } from 'vitest/suite';
let shouldBeTrueAfterTest: boolean = false;
const wrappedInLogs = createTaskCollector(function(
this: object,
name: string,
fn: () => void,
timeout: number
) {
const handler = async () => {
shouldBeTrueAfterTest = false;
const ret = await fn();
assert(shouldBeTrueAfterTest);
return ret;
}
getCurrentSuite().task(name, {
...this,
meta: {
ignoreme: true,
},
handler,
timeout
})
})
describe('suite name', () => {
wrappedInLogs('foo', () => {
assert.equal(Math.sqrt(4), 2)
shouldBeTrueAfterTest = true;
})
wrappedInLogs('bar', () => {
expect(1 + 1).eq(2)
shouldBeTrueAfterTest = true;
})
wrappedInLogs('snapshot', () => {
expect({ foo: 'bar' }).toMatchSnapshot()
shouldBeTrueAfterTest = true;
})
})
type User = {
id: number;
email: string;
}
type UserContext = {
user: User
}
const userTest = wrappedInLogs.extend({
user: async ({}, use) => {
await use({
id: 1,
email: 'foo@example.com'
})
}
})
describe('suite name', () => {
userTest('foo', () => {
assert.equal(Math.sqrt(4), 2)
})
userTest('bar', () => {
expect(1 + 1).eq(2)
})
userTest('snapshot', () => {
expect({ foo: 'bar' }).toMatchSnapshot()
})
})
System Info
❯ npx envinfo --system --npmPackages '{vitest*,@vitest/*,vite,@vitejs/*,playwright,webdriverio}' --binaries --browser
Need to install the following packages:
envinfo@7.14.0
Ok to proceed? (y) y
System:
OS: macOS 15.5
CPU: (12) arm64 Apple M3 Pro
Memory: 134.72 MB / 36.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.13.0 - ~/.asdf/installs/nodejs/22.13.0/bin/node
Yarn: 1.22.22 - ~/.asdf/installs/nodejs/22.13.0/bin/yarn
npm: 10.9.2 - ~/.asdf/plugins/nodejs/shims/npm
pnpm: 9.12.2 - ~/.asdf/installs/nodejs/22.13.0/bin/pnpm
~ took 10s
Used Package Manager
yarn
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Type
Projects
Status
Approved