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
13 changes: 8 additions & 5 deletions packages/runner/src/types/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,28 +498,31 @@ export type HookListener<T extends any[], Return = void> = (
...args: T
) => Awaitable<Return>

export type HookCleanupCallback = (() => Awaitable<unknown>) | void
/**
* @deprecated
*/
export type HookCleanupCallback = unknown

export interface BeforeAllListener {
(suite: Readonly<Suite | File>): Awaitable<HookCleanupCallback>
(suite: Readonly<Suite | File>): Awaitable<unknown>
}

export interface AfterAllListener {
(suite: Readonly<Suite | File>): Awaitable<void>
(suite: Readonly<Suite | File>): Awaitable<unknown>
}

export interface BeforeEachListener<ExtraContext = object> {
(
context: ExtendedContext<Test | Custom> & ExtraContext,
suite: Readonly<Suite>
): Awaitable<HookCleanupCallback>
): Awaitable<unknown>
}

export interface AfterEachListener<ExtraContext = object> {
(
context: ExtendedContext<Test | Custom> & ExtraContext,
suite: Readonly<Suite>
): Awaitable<void>
): Awaitable<unknown>
}

export interface SuiteHooks<ExtraContext = object> {
Expand Down
24 changes: 23 additions & 1 deletion test/core/test/hooks.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeAll, beforeEach, expect, it, suite } from 'vitest'
import { afterAll, afterEach, beforeAll, beforeEach, expect, it, suite } from 'vitest'

let count = -1

Expand Down Expand Up @@ -80,4 +80,26 @@ suite('hooks cleanup', () => {
it('end', () => {
expect(cleanUpCount).toBe(0)
})

suite('do nothing when given a non-function value as cleanupCallback', () => {
beforeAll(() => {
return 1
})
beforeEach(() => {
return null
})
afterAll(() => {
return '1'
})
afterEach(() => {
return {}
})

it('one', () => {
expect(cleanUpCount).toBe(0)
})
})
it('end', () => {
expect(cleanUpCount).toBe(0)
})
})