@vitest/runner 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { VitestRunner } from './types.js';
2
2
  export { CancelReason, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource } from './types.js';
3
- import { T as Task, F as File, d as SuiteAPI, e as TestAPI, f as SuiteCollector, g as CustomAPI, h as SuiteHooks, O as OnTestFailedHandler, i as OnTestFinishedHandler, a as Test, C as Custom, S as Suite } from './tasks-WAKtRuk9.js';
4
- export { D as DoneCallback, E as ExtendedContext, t as Fixture, s as FixtureFn, r as FixtureOptions, u as Fixtures, v as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, y as RuntimeContext, B as SequenceHooks, G as SequenceSetupFiles, x as SuiteFactory, k as TaskBase, A as TaskContext, w as TaskCustomOptions, m as TaskMeta, l as TaskPopulated, n as TaskResult, o as TaskResultPack, j as TaskState, z as TestContext, p as TestFunction, q as TestOptions, U as Use } from './tasks-WAKtRuk9.js';
3
+ import { T as Task, F as File, d as SuiteAPI, e as TestAPI, f as SuiteCollector, g as CustomAPI, B as BeforeAllListener, A as AfterAllListener, h as BeforeEachListener, i as AfterEachListener, j as TaskHook, O as OnTestFailedHandler, k as OnTestFinishedHandler, a as Test, C as Custom, S as Suite, l as SuiteHooks } from './tasks-zB5uPauP.js';
4
+ export { D as DoneCallback, L as ExtendedContext, w as Fixture, v as FixtureFn, u as FixtureOptions, x as Fixtures, y as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, G as RuntimeContext, M as SequenceHooks, N as SequenceSetupFiles, E as SuiteFactory, n as TaskBase, K as TaskContext, z as TaskCustomOptions, p as TaskMeta, o as TaskPopulated, q as TaskResult, r as TaskResultPack, m as TaskState, J as TestContext, s as TestFunction, t as TestOptions, U as Use } from './tasks-zB5uPauP.js';
5
5
  import { Awaitable } from '@vitest/utils';
6
6
  export { processError } from '@vitest/utils/error';
7
7
  import '@vitest/utils/diff';
@@ -10,19 +10,230 @@ declare function updateTask(task: Task, runner: VitestRunner): void;
10
10
  declare function startTests(paths: string[], runner: VitestRunner): Promise<File[]>;
11
11
  declare function publicCollect(paths: string[], runner: VitestRunner): Promise<File[]>;
12
12
 
13
+ /**
14
+ * Creates a suite of tests, allowing for grouping and hierarchical organization of tests.
15
+ * Suites can contain both tests and other suites, enabling complex test structures.
16
+ *
17
+ * @param {string} name - The name of the suite, used for identification and reporting.
18
+ * @param {Function} fn - A function that defines the tests and suites within this suite.
19
+ *
20
+ * @example
21
+ * // Define a suite with two tests
22
+ * suite('Math operations', () => {
23
+ * test('should add two numbers', () => {
24
+ * expect(add(1, 2)).toBe(3);
25
+ * });
26
+ *
27
+ * test('should subtract two numbers', () => {
28
+ * expect(subtract(5, 2)).toBe(3);
29
+ * });
30
+ * });
31
+ *
32
+ * @example
33
+ * // Define nested suites
34
+ * suite('String operations', () => {
35
+ * suite('Trimming', () => {
36
+ * test('should trim whitespace from start and end', () => {
37
+ * expect(' hello '.trim()).toBe('hello');
38
+ * });
39
+ * });
40
+ *
41
+ * suite('Concatenation', () => {
42
+ * test('should concatenate two strings', () => {
43
+ * expect('hello' + ' ' + 'world').toBe('hello world');
44
+ * });
45
+ * });
46
+ * });
47
+ */
13
48
  declare const suite: SuiteAPI;
49
+ /**
50
+ * Defines a test case with a given name and test function. The test function can optionally be configured with test options.
51
+ *
52
+ * @param {string | Function} name - The name of the test or a function that will be used as a test name.
53
+ * @param {TestOptions | TestFunction} [optionsOrFn] - Optional. The test options or the test function if no explicit name is provided.
54
+ * @param {number | TestOptions | TestFunction} [optionsOrTest] - Optional. The test function or options, depending on the previous parameters.
55
+ * @throws {Error} If called inside another test function.
56
+ *
57
+ * @example
58
+ * // Define a simple test
59
+ * test('should add two numbers', () => {
60
+ * expect(add(1, 2)).toBe(3);
61
+ * });
62
+ *
63
+ * @example
64
+ * // Define a test with options
65
+ * test('should subtract two numbers', { retry: 3 }, () => {
66
+ * expect(subtract(5, 2)).toBe(3);
67
+ * });
68
+ */
14
69
  declare const test: TestAPI;
70
+ /**
71
+ * Creates a suite of tests, allowing for grouping and hierarchical organization of tests.
72
+ * Suites can contain both tests and other suites, enabling complex test structures.
73
+ *
74
+ * @param {string} name - The name of the suite, used for identification and reporting.
75
+ * @param {Function} fn - A function that defines the tests and suites within this suite.
76
+ *
77
+ * @example
78
+ * // Define a suite with two tests
79
+ * describe('Math operations', () => {
80
+ * test('should add two numbers', () => {
81
+ * expect(add(1, 2)).toBe(3);
82
+ * });
83
+ *
84
+ * test('should subtract two numbers', () => {
85
+ * expect(subtract(5, 2)).toBe(3);
86
+ * });
87
+ * });
88
+ *
89
+ * @example
90
+ * // Define nested suites
91
+ * describe('String operations', () => {
92
+ * describe('Trimming', () => {
93
+ * test('should trim whitespace from start and end', () => {
94
+ * expect(' hello '.trim()).toBe('hello');
95
+ * });
96
+ * });
97
+ *
98
+ * describe('Concatenation', () => {
99
+ * test('should concatenate two strings', () => {
100
+ * expect('hello' + ' ' + 'world').toBe('hello world');
101
+ * });
102
+ * });
103
+ * });
104
+ */
15
105
  declare const describe: SuiteAPI;
106
+ /**
107
+ * Defines a test case with a given name and test function. The test function can optionally be configured with test options.
108
+ *
109
+ * @param {string | Function} name - The name of the test or a function that will be used as a test name.
110
+ * @param {TestOptions | TestFunction} [optionsOrFn] - Optional. The test options or the test function if no explicit name is provided.
111
+ * @param {number | TestOptions | TestFunction} [optionsOrTest] - Optional. The test function or options, depending on the previous parameters.
112
+ * @throws {Error} If called inside another test function.
113
+ *
114
+ * @example
115
+ * // Define a simple test
116
+ * it('adds two numbers', () => {
117
+ * expect(add(1, 2)).toBe(3);
118
+ * });
119
+ *
120
+ * @example
121
+ * // Define a test with options
122
+ * it('subtracts two numbers', { retry: 3 }, () => {
123
+ * expect(subtract(5, 2)).toBe(3);
124
+ * });
125
+ */
16
126
  declare const it: TestAPI;
17
- declare function getCurrentSuite<ExtraContext = {}>(): SuiteCollector<ExtraContext>;
127
+ declare function getCurrentSuite<ExtraContext = object>(): SuiteCollector<ExtraContext>;
18
128
  declare function createTaskCollector(fn: (...args: any[]) => any, context?: Record<string, unknown>): CustomAPI;
19
129
 
20
- declare function beforeAll(fn: SuiteHooks['beforeAll'][0], timeout?: number): void;
21
- declare function afterAll(fn: SuiteHooks['afterAll'][0], timeout?: number): void;
22
- declare function beforeEach<ExtraContext = {}>(fn: SuiteHooks<ExtraContext>['beforeEach'][0], timeout?: number): void;
23
- declare function afterEach<ExtraContext = {}>(fn: SuiteHooks<ExtraContext>['afterEach'][0], timeout?: number): void;
24
- declare const onTestFailed: (fn: OnTestFailedHandler) => void;
25
- declare const onTestFinished: (fn: OnTestFinishedHandler) => void;
130
+ /**
131
+ * Registers a callback function to be executed once before all tests within the current suite.
132
+ * This hook is useful for scenarios where you need to perform setup operations that are common to all tests in a suite, such as initializing a database connection or setting up a test environment.
133
+ *
134
+ * **Note:** The `beforeAll` hooks are executed in the order they are defined one after another. You can configure this by changing the `sequence.hooks` option in the config file.
135
+ *
136
+ * @param {Function} fn - The callback function to be executed before all tests.
137
+ * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
138
+ * @returns {void}
139
+ *
140
+ * @example
141
+ * // Example of using beforeAll to set up a database connection
142
+ * beforeAll(async () => {
143
+ * await database.connect();
144
+ * });
145
+ */
146
+ declare function beforeAll(fn: BeforeAllListener, timeout?: number): void;
147
+ /**
148
+ * Registers a callback function to be executed once after all tests within the current suite have completed.
149
+ * This hook is useful for scenarios where you need to perform cleanup operations after all tests in a suite have run, such as closing database connections or cleaning up temporary files.
150
+ *
151
+ * **Note:** The `afterAll` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
152
+ *
153
+ * @param {Function} fn - The callback function to be executed after all tests.
154
+ * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
155
+ * @returns {void}
156
+ *
157
+ * @example
158
+ * // Example of using afterAll to close a database connection
159
+ * afterAll(async () => {
160
+ * await database.disconnect();
161
+ * });
162
+ */
163
+ declare function afterAll(fn: AfterAllListener, timeout?: number): void;
164
+ /**
165
+ * Registers a callback function to be executed before each test within the current suite.
166
+ * This hook is useful for scenarios where you need to reset or reinitialize the test environment before each test runs, such as resetting database states, clearing caches, or reinitializing variables.
167
+ *
168
+ * **Note:** The `beforeEach` hooks are executed in the order they are defined one after another. You can configure this by changing the `sequence.hooks` option in the config file.
169
+ *
170
+ * @param {Function} fn - The callback function to be executed before each test. This function receives an `TestContext` parameter if additional test context is needed.
171
+ * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
172
+ * @returns {void}
173
+ *
174
+ * @example
175
+ * // Example of using beforeEach to reset a database state
176
+ * beforeEach(async () => {
177
+ * await database.reset();
178
+ * });
179
+ */
180
+ declare function beforeEach<ExtraContext = object>(fn: BeforeEachListener<ExtraContext>, timeout?: number): void;
181
+ /**
182
+ * Registers a callback function to be executed after each test within the current suite has completed.
183
+ * This hook is useful for scenarios where you need to clean up or reset the test environment after each test runs, such as deleting temporary files, clearing test-specific database entries, or resetting mocked functions.
184
+ *
185
+ * **Note:** The `afterEach` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
186
+ *
187
+ * @param {Function} fn - The callback function to be executed after each test. This function receives an `TestContext` parameter if additional test context is needed.
188
+ * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
189
+ * @returns {void}
190
+ *
191
+ * @example
192
+ * // Example of using afterEach to delete temporary files created during a test
193
+ * afterEach(async () => {
194
+ * await fileSystem.deleteTempFiles();
195
+ * });
196
+ */
197
+ declare function afterEach<ExtraContext = object>(fn: AfterEachListener<ExtraContext>, timeout?: number): void;
198
+ /**
199
+ * Registers a callback function to be executed when a test fails within the current suite.
200
+ * This function allows for custom actions to be performed in response to test failures, such as logging, cleanup, or additional diagnostics.
201
+ *
202
+ * **Note:** The `onTestFailed` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
203
+ *
204
+ * @param {Function} fn - The callback function to be executed upon a test failure. The function receives the test result (including errors).
205
+ * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
206
+ * @throws {Error} Throws an error if the function is not called within a test.
207
+ * @returns {void}
208
+ *
209
+ * @example
210
+ * // Example of using onTestFailed to log failure details
211
+ * onTestFailed(({ errors }) => {
212
+ * console.log(`Test failed: ${test.name}`, errors);
213
+ * });
214
+ */
215
+ declare const onTestFailed: TaskHook<OnTestFailedHandler>;
216
+ /**
217
+ * Registers a callback function to be executed when the current test finishes, regardless of the outcome (pass or fail).
218
+ * This function is ideal for performing actions that should occur after every test execution, such as cleanup, logging, or resetting shared resources.
219
+ *
220
+ * This hook is useful if you have access to a resource in the test itself and you want to clean it up after the test finishes. It is a more compact way to clean up resources than using the combination of `beforeEach` and `afterEach`.
221
+ *
222
+ * **Note:** The `onTestFinished` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
223
+ *
224
+ * @param {Function} fn - The callback function to be executed after a test finishes. The function can receive parameters providing details about the completed test, including its success or failure status.
225
+ * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
226
+ * @throws {Error} Throws an error if the function is not called within a test.
227
+ * @returns {void}
228
+ *
229
+ * @example
230
+ * // Example of using onTestFinished for cleanup
231
+ * const db = await connectToDatabase();
232
+ * onTestFinished(async () => {
233
+ * await db.disconnect();
234
+ * });
235
+ */
236
+ declare const onTestFinished: TaskHook<OnTestFinishedHandler>;
26
237
 
27
238
  declare function setFn(key: Test | Custom, fn: () => Awaitable<void>): void;
28
239
  declare function getFn<Task = Test | Custom>(key: Task): () => Awaitable<void>;
@@ -31,4 +242,4 @@ declare function getHooks(key: Suite): SuiteHooks;
31
242
 
32
243
  declare function getCurrentTest<T extends Test | Custom | undefined>(): T;
33
244
 
34
- export { Custom, CustomAPI, File, OnTestFailedHandler, OnTestFinishedHandler, Suite, SuiteAPI, SuiteCollector, SuiteHooks, Task, Test, TestAPI, VitestRunner, afterAll, afterEach, beforeAll, beforeEach, publicCollect as collectTests, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, onTestFinished, setFn, setHooks, startTests, suite, test, updateTask };
245
+ export { AfterAllListener, AfterEachListener, BeforeAllListener, BeforeEachListener, Custom, CustomAPI, File, OnTestFailedHandler, OnTestFinishedHandler, Suite, SuiteAPI, SuiteCollector, SuiteHooks, Task, TaskHook, Test, TestAPI, VitestRunner, afterAll, afterEach, beforeAll, beforeEach, publicCollect as collectTests, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, onTestFinished, setFn, setHooks, startTests, suite, test, updateTask };
package/dist/index.js CHANGED
@@ -553,13 +553,21 @@ function createSuite() {
553
553
  cases.forEach((i, idx) => {
554
554
  const items = Array.isArray(i) ? i : [i];
555
555
  if (fnFirst) {
556
- arrayOnlyCases ? suite2(
557
- formatTitle(_name, items, idx),
558
- () => handler(...items),
559
- options
560
- ) : suite2(formatTitle(_name, items, idx), () => handler(i), options);
556
+ if (arrayOnlyCases) {
557
+ suite2(
558
+ formatTitle(_name, items, idx),
559
+ () => handler(...items),
560
+ options
561
+ );
562
+ } else {
563
+ suite2(formatTitle(_name, items, idx), () => handler(i), options);
564
+ }
561
565
  } else {
562
- arrayOnlyCases ? suite2(formatTitle(_name, items, idx), options, () => handler(...items)) : suite2(formatTitle(_name, items, idx), options, () => handler(i));
566
+ if (arrayOnlyCases) {
567
+ suite2(formatTitle(_name, items, idx), options, () => handler(...items));
568
+ } else {
569
+ suite2(formatTitle(_name, items, idx), options, () => handler(i));
570
+ }
563
571
  }
564
572
  });
565
573
  this.setContext("each", void 0);
@@ -588,13 +596,21 @@ function createTaskCollector(fn, context) {
588
596
  cases.forEach((i, idx) => {
589
597
  const items = Array.isArray(i) ? i : [i];
590
598
  if (fnFirst) {
591
- arrayOnlyCases ? test2(
592
- formatTitle(_name, items, idx),
593
- () => handler(...items),
594
- options
595
- ) : test2(formatTitle(_name, items, idx), () => handler(i), options);
599
+ if (arrayOnlyCases) {
600
+ test2(
601
+ formatTitle(_name, items, idx),
602
+ () => handler(...items),
603
+ options
604
+ );
605
+ } else {
606
+ test2(formatTitle(_name, items, idx), () => handler(i), options);
607
+ }
596
608
  } else {
597
- arrayOnlyCases ? test2(formatTitle(_name, items, idx), options, () => handler(...items)) : test2(formatTitle(_name, items, idx), options, () => handler(i));
609
+ if (arrayOnlyCases) {
610
+ test2(formatTitle(_name, items, idx), options, () => handler(...items));
611
+ } else {
612
+ test2(formatTitle(_name, items, idx), options, () => handler(i));
613
+ }
598
614
  }
599
615
  });
600
616
  this.setContext("each", void 0);
@@ -840,7 +856,7 @@ async function callSuiteHook(suite, currentTask, name, runner, args) {
840
856
  const hooks = getSuiteHooks(suite, name, sequence);
841
857
  if (sequence === "parallel") {
842
858
  callbacks.push(
843
- ...await Promise.all(hooks.map((fn) => fn(...args)))
859
+ ...await Promise.all(hooks.map((hook) => hook(...args)))
844
860
  );
845
861
  } else {
846
862
  for (const hook of hooks) {
@@ -1200,25 +1216,29 @@ function afterEach(fn, timeout) {
1200
1216
  }
1201
1217
  const onTestFailed = createTestHook(
1202
1218
  "onTestFailed",
1203
- (test, handler) => {
1219
+ (test, handler, timeout) => {
1204
1220
  test.onFailed || (test.onFailed = []);
1205
- test.onFailed.push(handler);
1221
+ test.onFailed.push(
1222
+ withTimeout(handler, timeout ?? getDefaultHookTimeout(), true)
1223
+ );
1206
1224
  }
1207
1225
  );
1208
1226
  const onTestFinished = createTestHook(
1209
1227
  "onTestFinished",
1210
- (test, handler) => {
1228
+ (test, handler, timeout) => {
1211
1229
  test.onFinished || (test.onFinished = []);
1212
- test.onFinished.push(handler);
1230
+ test.onFinished.push(
1231
+ withTimeout(handler, timeout ?? getDefaultHookTimeout(), true)
1232
+ );
1213
1233
  }
1214
1234
  );
1215
1235
  function createTestHook(name, handler) {
1216
- return (fn) => {
1236
+ return (fn, timeout) => {
1217
1237
  const current = getCurrentTest();
1218
1238
  if (!current) {
1219
1239
  throw new Error(`Hook ${name}() can only be called inside a test`);
1220
1240
  }
1221
- return handler(current, fn);
1241
+ return handler(current, fn, timeout);
1222
1242
  };
1223
1243
  }
1224
1244
 
@@ -1,6 +1,6 @@
1
1
  import { ErrorWithDiff, Awaitable } from '@vitest/utils';
2
2
 
3
- type ChainableFunction<T extends string, F extends (...args: any) => any, C = {}> = F & {
3
+ type ChainableFunction<T extends string, F extends (...args: any) => any, C = object> = F & {
4
4
  [x in T]: ChainableFunction<T, F, C>;
5
5
  } & {
6
6
  fn: (this: Record<T, any>, ...args: Parameters<F>) => ReturnType<F>;
@@ -85,17 +85,17 @@ interface File extends Suite {
85
85
  */
86
86
  local?: boolean;
87
87
  }
88
- interface Test<ExtraContext = {}> extends TaskPopulated {
88
+ interface Test<ExtraContext = object> extends TaskPopulated {
89
89
  type: 'test';
90
90
  context: TaskContext<Test> & ExtraContext & TestContext;
91
91
  }
92
- interface Custom<ExtraContext = {}> extends TaskPopulated {
92
+ interface Custom<ExtraContext = object> extends TaskPopulated {
93
93
  type: 'custom';
94
94
  context: TaskContext<Custom> & ExtraContext & TestContext;
95
95
  }
96
96
  type Task = Test | Suite | Custom | File;
97
97
  type DoneCallback = (error?: any) => void;
98
- type TestFunction<ExtraContext = {}> = (context: ExtendedContext<Test> & ExtraContext) => Awaitable<any> | void;
98
+ type TestFunction<ExtraContext = object> = (context: ExtendedContext<Test> & ExtraContext) => Awaitable<any> | void;
99
99
  type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
100
100
  1: [T[0]];
101
101
  2: [T[0], T[1]];
@@ -131,7 +131,7 @@ interface TestForFunction<ExtraContext> {
131
131
  <T>(cases: ReadonlyArray<T>): TestForFunctionReturn<T, ExtendedContext<Test> & ExtraContext>;
132
132
  (strings: TemplateStringsArray, ...values: any[]): TestForFunctionReturn<any, ExtendedContext<Test> & ExtraContext>;
133
133
  }
134
- interface TestCollectorCallable<C = {}> {
134
+ interface TestCollectorCallable<C = object> {
135
135
  /**
136
136
  * @deprecated Use options as the second argument instead
137
137
  */
@@ -139,7 +139,7 @@ interface TestCollectorCallable<C = {}> {
139
139
  <ExtraContext extends C>(name: string | Function, fn?: TestFunction<ExtraContext>, options?: number | TestOptions): void;
140
140
  <ExtraContext extends C>(name: string | Function, options?: TestOptions, fn?: TestFunction<ExtraContext>): void;
141
141
  }
142
- type ChainableTestAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'fails', TestCollectorCallable<ExtraContext>, {
142
+ type ChainableTestAPI<ExtraContext = object> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'fails', TestCollectorCallable<ExtraContext>, {
143
143
  each: TestEachFunction;
144
144
  for: TestForFunction<ExtraContext>;
145
145
  }>;
@@ -193,13 +193,13 @@ interface ExtendedAPI<ExtraContext> {
193
193
  skipIf: (condition: any) => ChainableTestAPI<ExtraContext>;
194
194
  runIf: (condition: any) => ChainableTestAPI<ExtraContext>;
195
195
  }
196
- type CustomAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
197
- extend: <T extends Record<string, any> = {}>(fixtures: Fixtures<T, ExtraContext>) => CustomAPI<{
196
+ type CustomAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
197
+ extend: <T extends Record<string, any> = object>(fixtures: Fixtures<T, ExtraContext>) => CustomAPI<{
198
198
  [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
199
199
  }>;
200
200
  };
201
- type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
202
- extend: <T extends Record<string, any> = {}>(fixtures: Fixtures<T, ExtraContext>) => TestAPI<{
201
+ type TestAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
202
+ extend: <T extends Record<string, any> = object>(fixtures: Fixtures<T, ExtraContext>) => TestAPI<{
203
203
  [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
204
204
  }>;
205
205
  };
@@ -211,12 +211,12 @@ interface FixtureOptions {
211
211
  }
212
212
  type Use<T> = (value: T) => Promise<void>;
213
213
  type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
214
- type Fixture<T, K extends keyof T, ExtraContext = {}> = ((...args: any) => any) extends T[K] ? T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never : T[K] | (T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never);
215
- type Fixtures<T extends Record<string, any>, ExtraContext = {}> = {
214
+ type Fixture<T, K extends keyof T, ExtraContext = object> = ((...args: any) => any) extends T[K] ? T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never : T[K] | (T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never);
215
+ type Fixtures<T extends Record<string, any>, ExtraContext = object> = {
216
216
  [K in keyof T]: Fixture<T, K, ExtraContext & ExtendedContext<Test>> | [Fixture<T, K, ExtraContext & ExtendedContext<Test>>, FixtureOptions?];
217
217
  };
218
218
  type InferFixturesTypes<T> = T extends TestAPI<infer C> ? C : T;
219
- interface SuiteCollectorCallable<ExtraContext = {}> {
219
+ interface SuiteCollectorCallable<ExtraContext = object> {
220
220
  /**
221
221
  * @deprecated Use options as the second argument instead
222
222
  */
@@ -224,26 +224,35 @@ interface SuiteCollectorCallable<ExtraContext = {}> {
224
224
  <OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, fn?: SuiteFactory<OverrideExtraContext>, options?: number | TestOptions): SuiteCollector<OverrideExtraContext>;
225
225
  <OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, options: TestOptions, fn?: SuiteFactory<OverrideExtraContext>): SuiteCollector<OverrideExtraContext>;
226
226
  }
227
- type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'shuffle', SuiteCollectorCallable<ExtraContext>, {
227
+ type ChainableSuiteAPI<ExtraContext = object> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'shuffle', SuiteCollectorCallable<ExtraContext>, {
228
228
  each: TestEachFunction;
229
229
  }>;
230
- type SuiteAPI<ExtraContext = {}> = ChainableSuiteAPI<ExtraContext> & {
230
+ type SuiteAPI<ExtraContext = object> = ChainableSuiteAPI<ExtraContext> & {
231
231
  skipIf: (condition: any) => ChainableSuiteAPI<ExtraContext>;
232
232
  runIf: (condition: any) => ChainableSuiteAPI<ExtraContext>;
233
233
  };
234
+ /**
235
+ * @deprecated
236
+ */
234
237
  type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>;
235
238
  type HookCleanupCallback = (() => Awaitable<unknown>) | void;
236
- interface SuiteHooks<ExtraContext = {}> {
237
- beforeAll: HookListener<[Readonly<Suite | File>], HookCleanupCallback>[];
238
- afterAll: HookListener<[Readonly<Suite | File>]>[];
239
- beforeEach: HookListener<[
240
- ExtendedContext<Test | Custom> & ExtraContext,
241
- Readonly<Suite>
242
- ], HookCleanupCallback>[];
243
- afterEach: HookListener<[
244
- ExtendedContext<Test | Custom> & ExtraContext,
245
- Readonly<Suite>
246
- ]>[];
239
+ interface BeforeAllListener {
240
+ (suite: Readonly<Suite | File>): Awaitable<HookCleanupCallback>;
241
+ }
242
+ interface AfterAllListener {
243
+ (suite: Readonly<Suite | File>): Awaitable<void>;
244
+ }
245
+ interface BeforeEachListener<ExtraContext = object> {
246
+ (context: ExtendedContext<Test | Custom> & ExtraContext, suite: Readonly<Suite>): Awaitable<HookCleanupCallback>;
247
+ }
248
+ interface AfterEachListener<ExtraContext = object> {
249
+ (context: ExtendedContext<Test | Custom> & ExtraContext, suite: Readonly<Suite>): Awaitable<void>;
250
+ }
251
+ interface SuiteHooks<ExtraContext = object> {
252
+ beforeAll: BeforeAllListener[];
253
+ afterAll: AfterAllListener[];
254
+ beforeEach: BeforeEachListener<ExtraContext>[];
255
+ afterEach: AfterEachListener<ExtraContext>[];
247
256
  }
248
257
  interface TaskCustomOptions extends TestOptions {
249
258
  concurrent?: boolean;
@@ -257,7 +266,7 @@ interface TaskCustomOptions extends TestOptions {
257
266
  fixtures?: FixtureItem[];
258
267
  handler?: (context: TaskContext<Custom>) => Awaitable<void>;
259
268
  }
260
- interface SuiteCollector<ExtraContext = {}> {
269
+ interface SuiteCollector<ExtraContext = object> {
261
270
  readonly name: string;
262
271
  readonly mode: RunMode;
263
272
  options?: TestOptions;
@@ -269,7 +278,7 @@ interface SuiteCollector<ExtraContext = {}> {
269
278
  clear: () => void;
270
279
  on: <T extends keyof SuiteHooks<ExtraContext>>(name: T, ...fn: SuiteHooks<ExtraContext>[T]) => void;
271
280
  }
272
- type SuiteFactory<ExtraContext = {}> = (test: TestAPI<ExtraContext>) => Awaitable<void>;
281
+ type SuiteFactory<ExtraContext = object> = (test: TestAPI<ExtraContext>) => Awaitable<void>;
273
282
  interface RuntimeContext {
274
283
  tasks: (SuiteCollector | Test)[];
275
284
  currentSuite: SuiteCollector | null;
@@ -297,7 +306,10 @@ interface TaskContext<Task extends Custom | Test = Custom | Test> {
297
306
  type ExtendedContext<T extends Custom | Test> = TaskContext<T> & TestContext;
298
307
  type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
299
308
  type OnTestFinishedHandler = (result: TaskResult) => Awaitable<void>;
309
+ interface TaskHook<HookListener> {
310
+ (fn: HookListener, timeout?: number): void;
311
+ }
300
312
  type SequenceHooks = 'stack' | 'list' | 'parallel';
301
313
  type SequenceSetupFiles = 'list' | 'parallel';
302
314
 
303
- export { type TaskContext as A, type SequenceHooks as B, type Custom as C, type DoneCallback as D, type ExtendedContext as E, type File as F, type SequenceSetupFiles as G, type HookListener as H, type InferFixturesTypes as I, type OnTestFailedHandler as O, type RunMode as R, type Suite as S, type Task as T, type Use as U, type Test as a, type ChainableFunction as b, createChainable as c, type SuiteAPI as d, type TestAPI as e, type SuiteCollector as f, type CustomAPI as g, type SuiteHooks as h, type OnTestFinishedHandler as i, type TaskState as j, type TaskBase as k, type TaskPopulated as l, type TaskMeta as m, type TaskResult as n, type TaskResultPack as o, type TestFunction as p, type TestOptions as q, type FixtureOptions as r, type FixtureFn as s, type Fixture as t, type Fixtures as u, type HookCleanupCallback as v, type TaskCustomOptions as w, type SuiteFactory as x, type RuntimeContext as y, type TestContext as z };
315
+ export { type AfterAllListener as A, type BeforeAllListener as B, type Custom as C, type DoneCallback as D, type SuiteFactory as E, type File as F, type RuntimeContext as G, type HookListener as H, type InferFixturesTypes as I, type TestContext as J, type TaskContext as K, type ExtendedContext as L, type SequenceHooks as M, type SequenceSetupFiles as N, type OnTestFailedHandler as O, type RunMode as R, type Suite as S, type Task as T, type Use as U, type Test as a, type ChainableFunction as b, createChainable as c, type SuiteAPI as d, type TestAPI as e, type SuiteCollector as f, type CustomAPI as g, type BeforeEachListener as h, type AfterEachListener as i, type TaskHook as j, type OnTestFinishedHandler as k, type SuiteHooks as l, type TaskState as m, type TaskBase as n, type TaskPopulated as o, type TaskMeta as p, type TaskResult as q, type TaskResultPack as r, type TestFunction as s, type TestOptions as t, type FixtureOptions as u, type FixtureFn as v, type Fixture as w, type Fixtures as x, type HookCleanupCallback as y, type TaskCustomOptions as z };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as SequenceHooks, G as SequenceSetupFiles, F as File, T as Task, S as Suite, o as TaskResultPack, a as Test, C as Custom, A as TaskContext, E as ExtendedContext } from './tasks-WAKtRuk9.js';
2
- export { g as CustomAPI, D as DoneCallback, t as Fixture, s as FixtureFn, r as FixtureOptions, u as Fixtures, v as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, i as OnTestFinishedHandler, R as RunMode, y as RuntimeContext, d as SuiteAPI, f as SuiteCollector, x as SuiteFactory, h as SuiteHooks, k as TaskBase, w as TaskCustomOptions, m as TaskMeta, l as TaskPopulated, n as TaskResult, j as TaskState, e as TestAPI, z as TestContext, p as TestFunction, q as TestOptions, U as Use } from './tasks-WAKtRuk9.js';
1
+ import { M as SequenceHooks, N as SequenceSetupFiles, F as File, T as Task, S as Suite, r as TaskResultPack, a as Test, C as Custom, K as TaskContext, L as ExtendedContext } from './tasks-zB5uPauP.js';
2
+ export { A as AfterAllListener, i as AfterEachListener, B as BeforeAllListener, h as BeforeEachListener, g as CustomAPI, D as DoneCallback, w as Fixture, v as FixtureFn, u as FixtureOptions, x as Fixtures, y as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, k as OnTestFinishedHandler, R as RunMode, G as RuntimeContext, d as SuiteAPI, f as SuiteCollector, E as SuiteFactory, l as SuiteHooks, n as TaskBase, z as TaskCustomOptions, j as TaskHook, p as TaskMeta, o as TaskPopulated, q as TaskResult, m as TaskState, e as TestAPI, J as TestContext, s as TestFunction, t as TestOptions, U as Use } from './tasks-zB5uPauP.js';
3
3
  import { DiffOptions } from '@vitest/utils/diff';
4
4
  import '@vitest/utils';
5
5
 
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Suite, F as File, T as Task, a as Test, C as Custom } from './tasks-WAKtRuk9.js';
2
- export { b as ChainableFunction, c as createChainable } from './tasks-WAKtRuk9.js';
1
+ import { S as Suite, F as File, T as Task, a as Test, C as Custom } from './tasks-zB5uPauP.js';
2
+ export { b as ChainableFunction, c as createChainable } from './tasks-zB5uPauP.js';
3
3
  import { Arrayable } from '@vitest/utils';
4
4
 
5
5
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "2.0.2",
4
+ "version": "2.0.4",
5
5
  "description": "Vitest test runner",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -39,7 +39,7 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "pathe": "^1.1.2",
42
- "@vitest/utils": "2.0.2"
42
+ "@vitest/utils": "2.0.4"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "rimraf dist && rollup -c",