Skip to content

Commit

Permalink
feat(runner): Allow Callbacks Passed to before*/after* to Return Anyt…
Browse files Browse the repository at this point in the history
…hing
  • Loading branch information
LuciNyan committed Aug 25, 2024
1 parent 95f0203 commit c05a666
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/runner/src/types/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,14 @@ export type HookListener<T extends any[], Return = void> = (
...args: T
) => Awaitable<Return>

export type HookCleanupCallback = (() => Awaitable<unknown>) | void
export type HookCleanupCallback = (() => Awaitable<unknown>) | any

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

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

export interface BeforeEachListener<ExtraContext = object> {
Expand All @@ -519,7 +519,7 @@ export interface AfterEachListener<ExtraContext = object> {
(
context: ExtendedContext<Test | Custom> & ExtraContext,
suite: Readonly<Suite>
): Awaitable<void>
): Awaitable<any>
}

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 { beforeAll, beforeEach, afterAll, afterEach, expect, it, suite } from 'vitest'

Check failure on line 1 in test/core/test/hooks.test.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Member 'afterAll' of the import declaration should be sorted alphabetically

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)
})
})

0 comments on commit c05a666

Please sign in to comment.