Skip to content

Commit f6217a2

Browse files
authored
fix(types): Allow Callbacks Passed to before*/after* to Return Anything (#6393)
1 parent fe48943 commit f6217a2

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

packages/runner/src/types/tasks.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,28 +498,31 @@ export type HookListener<T extends any[], Return = void> = (
498498
...args: T
499499
) => Awaitable<Return>
500500

501-
export type HookCleanupCallback = (() => Awaitable<unknown>) | void
501+
/**
502+
* @deprecated
503+
*/
504+
export type HookCleanupCallback = unknown
502505

503506
export interface BeforeAllListener {
504-
(suite: Readonly<Suite | File>): Awaitable<HookCleanupCallback>
507+
(suite: Readonly<Suite | File>): Awaitable<unknown>
505508
}
506509

507510
export interface AfterAllListener {
508-
(suite: Readonly<Suite | File>): Awaitable<void>
511+
(suite: Readonly<Suite | File>): Awaitable<unknown>
509512
}
510513

511514
export interface BeforeEachListener<ExtraContext = object> {
512515
(
513516
context: ExtendedContext<Test | Custom> & ExtraContext,
514517
suite: Readonly<Suite>
515-
): Awaitable<HookCleanupCallback>
518+
): Awaitable<unknown>
516519
}
517520

518521
export interface AfterEachListener<ExtraContext = object> {
519522
(
520523
context: ExtendedContext<Test | Custom> & ExtraContext,
521524
suite: Readonly<Suite>
522-
): Awaitable<void>
525+
): Awaitable<unknown>
523526
}
524527

525528
export interface SuiteHooks<ExtraContext = object> {

test/core/test/hooks.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeAll, beforeEach, expect, it, suite } from 'vitest'
1+
import { afterAll, afterEach, beforeAll, beforeEach, expect, it, suite } from 'vitest'
22

33
let count = -1
44

@@ -80,4 +80,26 @@ suite('hooks cleanup', () => {
8080
it('end', () => {
8181
expect(cleanUpCount).toBe(0)
8282
})
83+
84+
suite('do nothing when given a non-function value as cleanupCallback', () => {
85+
beforeAll(() => {
86+
return 1
87+
})
88+
beforeEach(() => {
89+
return null
90+
})
91+
afterAll(() => {
92+
return '1'
93+
})
94+
afterEach(() => {
95+
return {}
96+
})
97+
98+
it('one', () => {
99+
expect(cleanUpCount).toBe(0)
100+
})
101+
})
102+
it('end', () => {
103+
expect(cleanUpCount).toBe(0)
104+
})
83105
})

0 commit comments

Comments
 (0)