@vitest/runner 2.0.3 → 2.0.5

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,244 @@ 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
+ * @example
20
+ * ```ts
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
+ * ```ts
34
+ * // Define nested suites
35
+ * suite('String operations', () => {
36
+ * suite('Trimming', () => {
37
+ * test('should trim whitespace from start and end', () => {
38
+ * expect(' hello '.trim()).toBe('hello');
39
+ * });
40
+ * });
41
+ *
42
+ * suite('Concatenation', () => {
43
+ * test('should concatenate two strings', () => {
44
+ * expect('hello' + ' ' + 'world').toBe('hello world');
45
+ * });
46
+ * });
47
+ * });
48
+ * ```
49
+ */
13
50
  declare const suite: SuiteAPI;
51
+ /**
52
+ * Defines a test case with a given name and test function. The test function can optionally be configured with test options.
53
+ *
54
+ * @param {string | Function} name - The name of the test or a function that will be used as a test name.
55
+ * @param {TestOptions | TestFunction} [optionsOrFn] - Optional. The test options or the test function if no explicit name is provided.
56
+ * @param {number | TestOptions | TestFunction} [optionsOrTest] - Optional. The test function or options, depending on the previous parameters.
57
+ * @throws {Error} If called inside another test function.
58
+ * @example
59
+ * ```ts
60
+ * // Define a simple test
61
+ * test('should add two numbers', () => {
62
+ * expect(add(1, 2)).toBe(3);
63
+ * });
64
+ * ```
65
+ * @example
66
+ * ```ts
67
+ * // Define a test with options
68
+ * test('should subtract two numbers', { retry: 3 }, () => {
69
+ * expect(subtract(5, 2)).toBe(3);
70
+ * });
71
+ * ```
72
+ */
14
73
  declare const test: TestAPI;
74
+ /**
75
+ * Creates a suite of tests, allowing for grouping and hierarchical organization of tests.
76
+ * Suites can contain both tests and other suites, enabling complex test structures.
77
+ *
78
+ * @param {string} name - The name of the suite, used for identification and reporting.
79
+ * @param {Function} fn - A function that defines the tests and suites within this suite.
80
+ * @example
81
+ * ```ts
82
+ * // Define a suite with two tests
83
+ * describe('Math operations', () => {
84
+ * test('should add two numbers', () => {
85
+ * expect(add(1, 2)).toBe(3);
86
+ * });
87
+ *
88
+ * test('should subtract two numbers', () => {
89
+ * expect(subtract(5, 2)).toBe(3);
90
+ * });
91
+ * });
92
+ * ```
93
+ * @example
94
+ * ```ts
95
+ * // Define nested suites
96
+ * describe('String operations', () => {
97
+ * describe('Trimming', () => {
98
+ * test('should trim whitespace from start and end', () => {
99
+ * expect(' hello '.trim()).toBe('hello');
100
+ * });
101
+ * });
102
+ *
103
+ * describe('Concatenation', () => {
104
+ * test('should concatenate two strings', () => {
105
+ * expect('hello' + ' ' + 'world').toBe('hello world');
106
+ * });
107
+ * });
108
+ * });
109
+ * ```
110
+ */
15
111
  declare const describe: SuiteAPI;
112
+ /**
113
+ * Defines a test case with a given name and test function. The test function can optionally be configured with test options.
114
+ *
115
+ * @param {string | Function} name - The name of the test or a function that will be used as a test name.
116
+ * @param {TestOptions | TestFunction} [optionsOrFn] - Optional. The test options or the test function if no explicit name is provided.
117
+ * @param {number | TestOptions | TestFunction} [optionsOrTest] - Optional. The test function or options, depending on the previous parameters.
118
+ * @throws {Error} If called inside another test function.
119
+ * @example
120
+ * ```ts
121
+ * // Define a simple test
122
+ * it('adds two numbers', () => {
123
+ * expect(add(1, 2)).toBe(3);
124
+ * });
125
+ * ```
126
+ * @example
127
+ * ```ts
128
+ * // Define a test with options
129
+ * it('subtracts two numbers', { retry: 3 }, () => {
130
+ * expect(subtract(5, 2)).toBe(3);
131
+ * });
132
+ * ```
133
+ */
16
134
  declare const it: TestAPI;
17
- declare function getCurrentSuite<ExtraContext = {}>(): SuiteCollector<ExtraContext>;
135
+ declare function getCurrentSuite<ExtraContext = object>(): SuiteCollector<ExtraContext>;
18
136
  declare function createTaskCollector(fn: (...args: any[]) => any, context?: Record<string, unknown>): CustomAPI;
19
137
 
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;
138
+ /**
139
+ * Registers a callback function to be executed once before all tests within the current suite.
140
+ * 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.
141
+ *
142
+ * **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.
143
+ *
144
+ * @param {Function} fn - The callback function to be executed before all tests.
145
+ * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
146
+ * @returns {void}
147
+ * @example
148
+ * ```ts
149
+ * // Example of using beforeAll to set up a database connection
150
+ * beforeAll(async () => {
151
+ * await database.connect();
152
+ * });
153
+ * ```
154
+ */
155
+ declare function beforeAll(fn: BeforeAllListener, timeout?: number): void;
156
+ /**
157
+ * Registers a callback function to be executed once after all tests within the current suite have completed.
158
+ * 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.
159
+ *
160
+ * **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.
161
+ *
162
+ * @param {Function} fn - The callback function to be executed after all tests.
163
+ * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
164
+ * @returns {void}
165
+ * @example
166
+ * ```ts
167
+ * // Example of using afterAll to close a database connection
168
+ * afterAll(async () => {
169
+ * await database.disconnect();
170
+ * });
171
+ * ```
172
+ */
173
+ declare function afterAll(fn: AfterAllListener, timeout?: number): void;
174
+ /**
175
+ * Registers a callback function to be executed before each test within the current suite.
176
+ * 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.
177
+ *
178
+ * **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.
179
+ *
180
+ * @param {Function} fn - The callback function to be executed before each test. This function receives an `TestContext` parameter if additional test context is needed.
181
+ * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
182
+ * @returns {void}
183
+ * @example
184
+ * ```ts
185
+ * // Example of using beforeEach to reset a database state
186
+ * beforeEach(async () => {
187
+ * await database.reset();
188
+ * });
189
+ * ```
190
+ */
191
+ declare function beforeEach<ExtraContext = object>(fn: BeforeEachListener<ExtraContext>, timeout?: number): void;
192
+ /**
193
+ * Registers a callback function to be executed after each test within the current suite has completed.
194
+ * 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.
195
+ *
196
+ * **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.
197
+ *
198
+ * @param {Function} fn - The callback function to be executed after each test. This function receives an `TestContext` parameter if additional test context is needed.
199
+ * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
200
+ * @returns {void}
201
+ * @example
202
+ * ```ts
203
+ * // Example of using afterEach to delete temporary files created during a test
204
+ * afterEach(async () => {
205
+ * await fileSystem.deleteTempFiles();
206
+ * });
207
+ * ```
208
+ */
209
+ declare function afterEach<ExtraContext = object>(fn: AfterEachListener<ExtraContext>, timeout?: number): void;
210
+ /**
211
+ * Registers a callback function to be executed when a test fails within the current suite.
212
+ * This function allows for custom actions to be performed in response to test failures, such as logging, cleanup, or additional diagnostics.
213
+ *
214
+ * **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.
215
+ *
216
+ * @param {Function} fn - The callback function to be executed upon a test failure. The function receives the test result (including errors).
217
+ * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
218
+ * @throws {Error} Throws an error if the function is not called within a test.
219
+ * @returns {void}
220
+ * @example
221
+ * ```ts
222
+ * // Example of using onTestFailed to log failure details
223
+ * onTestFailed(({ errors }) => {
224
+ * console.log(`Test failed: ${test.name}`, errors);
225
+ * });
226
+ * ```
227
+ */
228
+ declare const onTestFailed: TaskHook<OnTestFailedHandler>;
229
+ /**
230
+ * Registers a callback function to be executed when the current test finishes, regardless of the outcome (pass or fail).
231
+ * This function is ideal for performing actions that should occur after every test execution, such as cleanup, logging, or resetting shared resources.
232
+ *
233
+ * 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`.
234
+ *
235
+ * **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.
236
+ *
237
+ * @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.
238
+ * @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
239
+ * @throws {Error} Throws an error if the function is not called within a test.
240
+ * @returns {void}
241
+ * @example
242
+ * ```ts
243
+ * // Example of using onTestFinished for cleanup
244
+ * const db = await connectToDatabase();
245
+ * onTestFinished(async () => {
246
+ * await db.disconnect();
247
+ * });
248
+ * ```
249
+ */
250
+ declare const onTestFinished: TaskHook<OnTestFinishedHandler>;
26
251
 
27
252
  declare function setFn(key: Test | Custom, fn: () => Awaitable<void>): void;
28
253
  declare function getFn<Task = Test | Custom>(key: Task): () => Awaitable<void>;
@@ -31,4 +256,4 @@ declare function getHooks(key: Suite): SuiteHooks;
31
256
 
32
257
  declare function getCurrentTest<T extends Test | Custom | undefined>(): T;
33
258
 
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 };
259
+ 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);
@@ -711,8 +727,7 @@ function findTestFileStackTrace(error, each) {
711
727
  }
712
728
  }
713
729
 
714
- async function runSetupFiles(config, runner) {
715
- const files = toArray(config.setupFiles);
730
+ async function runSetupFiles(config, files, runner) {
716
731
  if (config.sequence.setupFiles === "parallel") {
717
732
  await Promise.all(
718
733
  files.map(async (fsPath) => {
@@ -736,10 +751,16 @@ async function collectTests(paths, runner) {
736
751
  (_a = runner.onCollectStart) == null ? void 0 : _a.call(runner, file);
737
752
  clearCollectorContext(filepath, runner);
738
753
  try {
739
- const setupStart = now$1();
740
- await runSetupFiles(config, runner);
754
+ const setupFiles = toArray(config.setupFiles);
755
+ if (setupFiles.length) {
756
+ const setupStart = now$1();
757
+ await runSetupFiles(config, setupFiles, runner);
758
+ const setupEnd = now$1();
759
+ file.setupDuration = setupEnd - setupStart;
760
+ } else {
761
+ file.setupDuration = 0;
762
+ }
741
763
  const collectStart = now$1();
742
- file.setupDuration = collectStart - setupStart;
743
764
  await runner.importFile(filepath, "collect");
744
765
  const defaultTasks = await getDefaultSuite().collect(file);
745
766
  const fileHooks = createSuiteHooks();
@@ -767,6 +788,12 @@ async function collectTests(paths, runner) {
767
788
  };
768
789
  }
769
790
  calculateSuiteHash(file);
791
+ file.tasks.forEach((task) => {
792
+ var _a2;
793
+ if (((_a2 = task.suite) == null ? void 0 : _a2.id) === "") {
794
+ delete task.suite;
795
+ }
796
+ });
770
797
  const hasOnlyTasks = someTasksAreOnly(file);
771
798
  interpretTaskModes(
772
799
  file,
@@ -775,12 +802,6 @@ async function collectTests(paths, runner) {
775
802
  false,
776
803
  config.allowOnly
777
804
  );
778
- file.tasks.forEach((task) => {
779
- var _a2;
780
- if (((_a2 = task.suite) == null ? void 0 : _a2.id) === "") {
781
- delete task.suite;
782
- }
783
- });
784
805
  files.push(file);
785
806
  }
786
807
  return files;
@@ -840,7 +861,7 @@ async function callSuiteHook(suite, currentTask, name, runner, args) {
840
861
  const hooks = getSuiteHooks(suite, name, sequence);
841
862
  if (sequence === "parallel") {
842
863
  callbacks.push(
843
- ...await Promise.all(hooks.map((fn) => fn(...args)))
864
+ ...await Promise.all(hooks.map((hook) => hook(...args)))
844
865
  );
845
866
  } else {
846
867
  for (const hook of hooks) {
@@ -1200,25 +1221,29 @@ function afterEach(fn, timeout) {
1200
1221
  }
1201
1222
  const onTestFailed = createTestHook(
1202
1223
  "onTestFailed",
1203
- (test, handler) => {
1224
+ (test, handler, timeout) => {
1204
1225
  test.onFailed || (test.onFailed = []);
1205
- test.onFailed.push(handler);
1226
+ test.onFailed.push(
1227
+ withTimeout(handler, timeout ?? getDefaultHookTimeout(), true)
1228
+ );
1206
1229
  }
1207
1230
  );
1208
1231
  const onTestFinished = createTestHook(
1209
1232
  "onTestFinished",
1210
- (test, handler) => {
1233
+ (test, handler, timeout) => {
1211
1234
  test.onFinished || (test.onFinished = []);
1212
- test.onFinished.push(handler);
1235
+ test.onFinished.push(
1236
+ withTimeout(handler, timeout ?? getDefaultHookTimeout(), true)
1237
+ );
1213
1238
  }
1214
1239
  );
1215
1240
  function createTestHook(name, handler) {
1216
- return (fn) => {
1241
+ return (fn, timeout) => {
1217
1242
  const current = getCurrentTest();
1218
1243
  if (!current) {
1219
1244
  throw new Error(`Hook ${name}() can only be called inside a test`);
1220
1245
  }
1221
- return handler(current, fn);
1246
+ return handler(current, fn, timeout);
1222
1247
  };
1223
1248
  }
1224
1249
 
@@ -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,12 +1,12 @@
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
 
6
6
  interface VitestRunnerConfig {
7
7
  root: string;
8
- setupFiles: string[] | string;
9
- name: string;
8
+ setupFiles: string[];
9
+ name?: string;
10
10
  passWithNoTests: boolean;
11
11
  testNamePattern?: RegExp;
12
12
  allowOnly?: boolean;
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
  /**
@@ -9,7 +9,7 @@ declare function interpretTaskModes(suite: Suite, namePattern?: string | RegExp,
9
9
  declare function someTasksAreOnly(suite: Suite): boolean;
10
10
  declare function generateHash(str: string): string;
11
11
  declare function calculateSuiteHash(parent: Suite): void;
12
- declare function createFileTask(filepath: string, root: string, projectName: string, pool?: string): File;
12
+ declare function createFileTask(filepath: string, root: string, projectName: string | undefined, pool?: string): File;
13
13
 
14
14
  /**
15
15
  * Partition in tasks groups by consecutive concurrent
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "2.0.3",
4
+ "version": "2.0.5",
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.3"
42
+ "@vitest/utils": "2.0.5"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "rimraf dist && rollup -c",