From 6a42c538eede117021b8d94565b4a01065901d56 Mon Sep 17 00:00:00 2001 From: Luci <22126563+LuciNyan@users.noreply.github.com> Date: Tue, 27 Aug 2024 17:27:14 +0800 Subject: [PATCH] feat(runner): Allow Callbacks Passed to before*/after* to Return Anything --- packages/runner/src/types/tasks.ts | 13 ++++++++----- test/core/test/hooks.test.ts | 24 +++++++++++++++++++++++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/packages/runner/src/types/tasks.ts b/packages/runner/src/types/tasks.ts index c345d4622147..eb3e34d8f558 100644 --- a/packages/runner/src/types/tasks.ts +++ b/packages/runner/src/types/tasks.ts @@ -498,28 +498,31 @@ export type HookListener = ( ...args: T ) => Awaitable -export type HookCleanupCallback = (() => Awaitable) | void +/** + * @deprecated + */ +export type HookCleanupCallback = unknown export interface BeforeAllListener { - (suite: Readonly): Awaitable + (suite: Readonly): Awaitable } export interface AfterAllListener { - (suite: Readonly): Awaitable + (suite: Readonly): Awaitable } export interface BeforeEachListener { ( context: ExtendedContext & ExtraContext, suite: Readonly - ): Awaitable + ): Awaitable } export interface AfterEachListener { ( context: ExtendedContext & ExtraContext, suite: Readonly - ): Awaitable + ): Awaitable } export interface SuiteHooks { diff --git a/test/core/test/hooks.test.ts b/test/core/test/hooks.test.ts index d9df35c96335..5f2ceffedc81 100644 --- a/test/core/test/hooks.test.ts +++ b/test/core/test/hooks.test.ts @@ -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 @@ -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) + }) })