Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 5 additions & 7 deletions packages/runner/src/suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,8 @@ export function createTaskCollector(
runner,
)

return createTest(function fn(
const originalWrapper = fn
return createTest(function (
name: string | Function,
optionsOrFn?: TestOptions | TestFunction,
optionsOrTest?: number | TestOptions | TestFunction,
Expand All @@ -784,12 +785,9 @@ export function createTaskCollector(
scopedFixtures,
)
}
collector.test.fn.call(
context,
formatName(name),
optionsOrFn as TestOptions,
optionsOrTest as TestFunction,
)
const { handler, options } = parseArguments(optionsOrFn, optionsOrTest)
const timeout = options.timeout ?? runner?.config.testTimeout
originalWrapper.call(context, formatName(name), handler, timeout)
}, _context)
}

Expand Down
30 changes: 28 additions & 2 deletions test/core/test/task-collector.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test, vi } from 'vitest'
import { createTaskCollector } from 'vitest/suite'
import { assert, describe, expect, test, vi } from 'vitest'
import { createTaskCollector, getCurrentSuite } from 'vitest/suite'

test('collector keeps the order of arguments', () => {
const fn = vi.fn()
Expand All @@ -23,3 +23,29 @@ test('collector keeps the order of arguments', () => {

expect(fn).toHaveBeenNthCalledWith(4, 'a', options, expect.any(Function))
})

describe('collector.extend should preserve handler wrapping', () => {
let flag = false

const flagTest = createTaskCollector(function (
this: object,
name: string,
fn: () => void,
) {
const handler = async () => {
flag = false
await fn()
assert(flag)
}
getCurrentSuite().task(name, { ...this, handler })
})

const extendedTest = flagTest.extend({})

extendedTest.fails('should fail when flag is never set', {}, () => {})

flagTest('should pass when flag is set', () => {
flag = true
expect(flag).toBe(true)
})
})