@vitest/runner 3.0.8 → 3.0.9

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.js CHANGED
@@ -31,7 +31,7 @@ async function runWithSuite(suite, fn) {
31
31
  await fn();
32
32
  collectorContext.currentSuite = prev;
33
33
  }
34
- function withTimeout(fn, timeout, isHook = false) {
34
+ function withTimeout(fn, timeout, isHook = false, stackTraceError) {
35
35
  if (timeout <= 0 || timeout === Number.POSITIVE_INFINITY) {
36
36
  return fn;
37
37
  }
@@ -42,13 +42,16 @@ function withTimeout(fn, timeout, isHook = false) {
42
42
  var _a;
43
43
  const timer = setTimeout(() => {
44
44
  clearTimeout(timer);
45
- reject(new Error(makeTimeoutMsg(isHook, timeout)));
45
+ rejectTimeoutError();
46
46
  }, timeout);
47
47
  (_a = timer.unref) == null ? void 0 : _a.call(timer);
48
+ function rejectTimeoutError() {
49
+ reject_(makeTimeoutError(isHook, timeout, stackTraceError));
50
+ }
48
51
  function resolve(result) {
49
52
  clearTimeout(timer);
50
53
  if (now$2() - startTime >= timeout) {
51
- reject_(new Error(makeTimeoutMsg(isHook, timeout)));
54
+ rejectTimeoutError();
52
55
  return;
53
56
  }
54
57
  resolve_(result);
@@ -84,20 +87,25 @@ function createTestContext(test, runner) {
84
87
  context.onTestFailed = (handler, timeout) => {
85
88
  test.onFailed || (test.onFailed = []);
86
89
  test.onFailed.push(
87
- withTimeout(handler, timeout ?? runner.config.hookTimeout, true)
90
+ withTimeout(handler, timeout ?? runner.config.hookTimeout, true, new Error("STACK_TRACE_ERROR"))
88
91
  );
89
92
  };
90
93
  context.onTestFinished = (handler, timeout) => {
91
94
  test.onFinished || (test.onFinished = []);
92
95
  test.onFinished.push(
93
- withTimeout(handler, timeout ?? runner.config.hookTimeout, true)
96
+ withTimeout(handler, timeout ?? runner.config.hookTimeout, true, new Error("STACK_TRACE_ERROR"))
94
97
  );
95
98
  };
96
99
  return ((_a = runner.extendTaskContext) == null ? void 0 : _a.call(runner, context)) || context;
97
100
  }
98
- function makeTimeoutMsg(isHook, timeout) {
99
- return `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.
101
+ function makeTimeoutError(isHook, timeout, stackTraceError) {
102
+ const message = `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.
100
103
  If this is a long-running ${isHook ? "hook" : "test"}, pass a timeout value as the last argument or configure it globally with "${isHook ? "hookTimeout" : "testTimeout"}".`;
104
+ const error = new Error(message);
105
+ if (stackTraceError == null ? void 0 : stackTraceError.stack) {
106
+ error.stack = stackTraceError.stack.replace(error.message, stackTraceError.message);
107
+ }
108
+ return error;
101
109
  }
102
110
 
103
111
  const fnMap = /* @__PURE__ */ new WeakMap();
@@ -426,6 +434,7 @@ function createSuiteCollector(name, factory = () => {
426
434
  initSuite(true);
427
435
  const task = function(name2 = "", options = {}) {
428
436
  var _a;
437
+ const timeout = (options == null ? void 0 : options.timeout) ?? runner.config.testTimeout;
429
438
  const task2 = {
430
439
  id: "",
431
440
  name: name2,
@@ -435,6 +444,7 @@ function createSuiteCollector(name, factory = () => {
435
444
  context: void 0,
436
445
  type: "test",
437
446
  file: void 0,
447
+ timeout,
438
448
  retry: options.retry ?? runner.config.retry,
439
449
  repeats: options.repeats,
440
450
  mode: options.only ? "only" : options.skip ? "skip" : options.todo ? "todo" : "run",
@@ -456,7 +466,7 @@ function createSuiteCollector(name, factory = () => {
456
466
  task2,
457
467
  withTimeout(
458
468
  withAwaitAsyncAssertions(withFixtures(handler, context), task2),
459
- (options == null ? void 0 : options.timeout) ?? runner.config.testTimeout
469
+ timeout
460
470
  )
461
471
  );
462
472
  }
@@ -741,7 +751,7 @@ function createTest(fn, context) {
741
751
  return createTaskCollector(fn, context);
742
752
  }
743
753
  function formatName(name) {
744
- return typeof name === "string" ? name : name instanceof Function ? name.name || "<anonymous>" : String(name);
754
+ return typeof name === "string" ? name : typeof name === "function" ? name.name || "<anonymous>" : String(name);
745
755
  }
746
756
  function formatTitle(template, items, idx) {
747
757
  if (template.includes("%#")) {
@@ -810,33 +820,61 @@ function getDefaultHookTimeout() {
810
820
  return getRunner().config.hookTimeout;
811
821
  }
812
822
  const CLEANUP_TIMEOUT_KEY = Symbol.for("VITEST_CLEANUP_TIMEOUT");
823
+ const CLEANUP_STACK_TRACE_KEY = Symbol.for("VITEST_CLEANUP_STACK_TRACE");
813
824
  function getBeforeHookCleanupCallback(hook, result) {
814
825
  if (typeof result === "function") {
815
826
  const timeout = CLEANUP_TIMEOUT_KEY in hook && typeof hook[CLEANUP_TIMEOUT_KEY] === "number" ? hook[CLEANUP_TIMEOUT_KEY] : getDefaultHookTimeout();
816
- return withTimeout(result, timeout, true);
827
+ const stackTraceError = CLEANUP_STACK_TRACE_KEY in hook && hook[CLEANUP_STACK_TRACE_KEY] instanceof Error ? hook[CLEANUP_STACK_TRACE_KEY] : void 0;
828
+ return withTimeout(result, timeout, true, stackTraceError);
817
829
  }
818
830
  }
819
831
  function beforeAll(fn, timeout = getDefaultHookTimeout()) {
820
832
  assertTypes(fn, '"beforeAll" callback', ["function"]);
833
+ const stackTraceError = new Error("STACK_TRACE_ERROR");
821
834
  return getCurrentSuite().on(
822
835
  "beforeAll",
823
- Object.assign(withTimeout(fn, timeout, true), { [CLEANUP_TIMEOUT_KEY]: timeout })
836
+ Object.assign(
837
+ withTimeout(
838
+ fn,
839
+ timeout,
840
+ true,
841
+ stackTraceError
842
+ ),
843
+ {
844
+ [CLEANUP_TIMEOUT_KEY]: timeout,
845
+ [CLEANUP_STACK_TRACE_KEY]: stackTraceError
846
+ }
847
+ )
824
848
  );
825
849
  }
826
850
  function afterAll(fn, timeout) {
827
851
  assertTypes(fn, '"afterAll" callback', ["function"]);
828
852
  return getCurrentSuite().on(
829
853
  "afterAll",
830
- withTimeout(fn, timeout ?? getDefaultHookTimeout(), true)
854
+ withTimeout(
855
+ fn,
856
+ timeout ?? getDefaultHookTimeout(),
857
+ true,
858
+ new Error("STACK_TRACE_ERROR")
859
+ )
831
860
  );
832
861
  }
833
862
  function beforeEach(fn, timeout = getDefaultHookTimeout()) {
834
863
  assertTypes(fn, '"beforeEach" callback', ["function"]);
864
+ const stackTraceError = new Error("STACK_TRACE_ERROR");
835
865
  return getCurrentSuite().on(
836
866
  "beforeEach",
837
867
  Object.assign(
838
- withTimeout(withFixtures(fn), timeout ?? getDefaultHookTimeout(), true),
839
- { [CLEANUP_TIMEOUT_KEY]: timeout }
868
+ withTimeout(
869
+ withFixtures(fn),
870
+ timeout ?? getDefaultHookTimeout(),
871
+ true,
872
+ stackTraceError
873
+ ),
874
+ {
875
+ [CLEANUP_TIMEOUT_KEY]: timeout,
876
+ [CLEANUP_STACK_TRACE_KEY]: stackTraceError
877
+ }
840
878
  )
841
879
  );
842
880
  }
@@ -844,7 +882,12 @@ function afterEach(fn, timeout) {
844
882
  assertTypes(fn, '"afterEach" callback', ["function"]);
845
883
  return getCurrentSuite().on(
846
884
  "afterEach",
847
- withTimeout(withFixtures(fn), timeout ?? getDefaultHookTimeout(), true)
885
+ withTimeout(
886
+ withFixtures(fn),
887
+ timeout ?? getDefaultHookTimeout(),
888
+ true,
889
+ new Error("STACK_TRACE_ERROR")
890
+ )
848
891
  );
849
892
  }
850
893
  const onTestFailed = createTestHook(
@@ -852,7 +895,12 @@ const onTestFailed = createTestHook(
852
895
  (test, handler, timeout) => {
853
896
  test.onFailed || (test.onFailed = []);
854
897
  test.onFailed.push(
855
- withTimeout(handler, timeout ?? getDefaultHookTimeout(), true)
898
+ withTimeout(
899
+ handler,
900
+ timeout ?? getDefaultHookTimeout(),
901
+ true,
902
+ new Error("STACK_TRACE_ERROR")
903
+ )
856
904
  );
857
905
  }
858
906
  );
@@ -861,7 +909,12 @@ const onTestFinished = createTestHook(
861
909
  (test, handler, timeout) => {
862
910
  test.onFinished || (test.onFinished = []);
863
911
  test.onFinished.push(
864
- withTimeout(handler, timeout ?? getDefaultHookTimeout(), true)
912
+ withTimeout(
913
+ handler,
914
+ timeout ?? getDefaultHookTimeout(),
915
+ true,
916
+ new Error("STACK_TRACE_ERROR")
917
+ )
865
918
  );
866
919
  }
867
920
  );
@@ -0,0 +1,484 @@
1
+ import { ErrorWithDiff, Awaitable } from '@vitest/utils';
2
+
3
+ interface FixtureItem extends FixtureOptions {
4
+ prop: string;
5
+ value: any;
6
+ /**
7
+ * Indicates whether the fixture is a function
8
+ */
9
+ isFn: boolean;
10
+ /**
11
+ * The dependencies(fixtures) of current fixture function.
12
+ */
13
+ deps?: FixtureItem[];
14
+ }
15
+
16
+ type ChainableFunction<
17
+ T extends string,
18
+ F extends (...args: any) => any,
19
+ C = object
20
+ > = F & { [x in T] : ChainableFunction<T, F, C> } & {
21
+ fn: (this: Record<T, any>, ...args: Parameters<F>) => ReturnType<F>
22
+ } & C;
23
+ declare function createChainable<
24
+ T extends string,
25
+ Args extends any[],
26
+ R = any
27
+ >(keys: T[], fn: (this: Record<T, any>, ...args: Args) => R): ChainableFunction<T, (...args: Args) => R>;
28
+
29
+ type RunMode = "run" | "skip" | "only" | "todo" | "queued";
30
+ type TaskState = RunMode | "pass" | "fail";
31
+ interface TaskBase {
32
+ /**
33
+ * Unique task identifier. Based on the file id and the position of the task.
34
+ * The id of the file task is based on the file path relative to root and project name.
35
+ * It will not change between runs.
36
+ * @example `1201091390`, `1201091390_0`, `1201091390_0_1`
37
+ */
38
+ id: string;
39
+ /**
40
+ * Task name provided by the user. If no name was provided, it will be an empty string.
41
+ */
42
+ name: string;
43
+ /**
44
+ * Task mode.
45
+ * - **skip**: task is skipped
46
+ * - **only**: only this task and other tasks with `only` mode will run
47
+ * - **todo**: task is marked as a todo, alias for `skip`
48
+ * - **run**: task will run or already ran
49
+ * - **queued**: task will start running next. It can only exist on the File
50
+ */
51
+ mode: RunMode;
52
+ /**
53
+ * Custom metadata for the task. JSON reporter will save this data.
54
+ */
55
+ meta: TaskMeta;
56
+ /**
57
+ * Whether the task was produced with `.each()` method.
58
+ */
59
+ each?: boolean;
60
+ /**
61
+ * Whether the task should run concurrently with other tasks.
62
+ */
63
+ concurrent?: boolean;
64
+ /**
65
+ * Whether the tasks of the suite run in a random order.
66
+ */
67
+ shuffle?: boolean;
68
+ /**
69
+ * Suite that this task is part of. File task or the global suite will have no parent.
70
+ */
71
+ suite?: Suite;
72
+ /**
73
+ * Result of the task. Suite and file tasks will only have the result if there
74
+ * was an error during collection or inside `afterAll`/`beforeAll`.
75
+ */
76
+ result?: TaskResult;
77
+ /**
78
+ * The amount of times the task should be retried if it fails.
79
+ * @default 0
80
+ */
81
+ retry?: number;
82
+ /**
83
+ * The amount of times the task should be repeated after the successful run.
84
+ * If the task fails, it will not be retried unless `retry` is specified.
85
+ * @default 0
86
+ */
87
+ repeats?: number;
88
+ /**
89
+ * Location of the task in the file. This field is populated only if
90
+ * `includeTaskLocation` option is set. It is generated by calling `new Error`
91
+ * and parsing the stack trace, so the location might differ depending on the runtime.
92
+ */
93
+ location?: {
94
+ line: number
95
+ column: number
96
+ };
97
+ }
98
+ interface TaskPopulated extends TaskBase {
99
+ /**
100
+ * File task. It's the root task of the file.
101
+ */
102
+ file: File;
103
+ /**
104
+ * Whether the task should succeed if it fails. If the task fails, it will be marked as passed.
105
+ */
106
+ fails?: boolean;
107
+ /**
108
+ * Store promises (from async expects) to wait for them before finishing the test
109
+ */
110
+ promises?: Promise<any>[];
111
+ }
112
+ /**
113
+ * Custom metadata that can be used in reporters.
114
+ */
115
+ interface TaskMeta {}
116
+ /**
117
+ * The result of calling a task.
118
+ */
119
+ interface TaskResult {
120
+ /**
121
+ * State of the task. Inherits the `task.mode` during collection.
122
+ * When the task has finished, it will be changed to `pass` or `fail`.
123
+ * - **pass**: task ran successfully
124
+ * - **fail**: task failed
125
+ */
126
+ state: TaskState;
127
+ /**
128
+ * Errors that occurred during the task execution. It is possible to have several errors
129
+ * if `expect.soft()` failed multiple times or `retry` was triggered.
130
+ */
131
+ errors?: ErrorWithDiff[];
132
+ /**
133
+ * How long in milliseconds the task took to run.
134
+ */
135
+ duration?: number;
136
+ /**
137
+ * Time in milliseconds when the task started running.
138
+ */
139
+ startTime?: number;
140
+ /**
141
+ * Heap size in bytes after the task finished.
142
+ * Only available if `logHeapUsage` option is set and `process.memoryUsage` is defined.
143
+ */
144
+ heap?: number;
145
+ /**
146
+ * State of related to this task hooks. Useful during reporting.
147
+ */
148
+ hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
149
+ /**
150
+ * The amount of times the task was retried. The task is retried only if it
151
+ * failed and `retry` option is set.
152
+ */
153
+ retryCount?: number;
154
+ /**
155
+ * The amount of times the task was repeated. The task is repeated only if
156
+ * `repeats` option is set. This number also contains `retryCount`.
157
+ */
158
+ repeatCount?: number;
159
+ /** @private */
160
+ note?: string;
161
+ }
162
+ /**
163
+ * The tuple representing a single task update.
164
+ * Usually reported after the task finishes.
165
+ */
166
+ type TaskResultPack = [id: string, result: TaskResult | undefined, meta: TaskMeta];
167
+ type TaskEventPack = [id: string, event: TaskUpdateEvent];
168
+ type TaskUpdateEvent = "test-failed-early" | "suite-failed-early" | "test-prepare" | "test-finished" | "test-retried" | "suite-prepare" | "suite-finished" | "before-hook-start" | "before-hook-end" | "after-hook-start" | "after-hook-end";
169
+ interface Suite extends TaskBase {
170
+ type: "suite";
171
+ /**
172
+ * File task. It's the root task of the file.
173
+ */
174
+ file: File;
175
+ /**
176
+ * An array of tasks that are part of the suite.
177
+ */
178
+ tasks: Task[];
179
+ }
180
+ interface File extends Suite {
181
+ /**
182
+ * The name of the pool that the file belongs to.
183
+ * @default 'forks'
184
+ */
185
+ pool?: string;
186
+ /**
187
+ * The path to the file in UNIX format.
188
+ */
189
+ filepath: string;
190
+ /**
191
+ * The name of the workspace project the file belongs to.
192
+ */
193
+ projectName: string | undefined;
194
+ /**
195
+ * The time it took to collect all tests in the file.
196
+ * This time also includes importing all the file dependencies.
197
+ */
198
+ collectDuration?: number;
199
+ /**
200
+ * The time it took to import the setup file.
201
+ */
202
+ setupDuration?: number;
203
+ }
204
+ interface Test<ExtraContext = object> extends TaskPopulated {
205
+ type: "test";
206
+ /**
207
+ * Test context that will be passed to the test function.
208
+ */
209
+ context: TestContext & ExtraContext;
210
+ /**
211
+ * The test timeout in milliseconds.
212
+ */
213
+ timeout: number;
214
+ }
215
+ /**
216
+ * @deprecated Use `Test` instead. `type: 'custom'` is not used since 2.2
217
+ */
218
+ type Custom<ExtraContext = object> = Test<ExtraContext>;
219
+ type Task = Test | Suite | File;
220
+ /**
221
+ * @deprecated Vitest doesn't provide `done()` anymore
222
+ */
223
+ type DoneCallback = (error?: any) => void;
224
+ type TestFunction<ExtraContext = object> = (context: TestContext & ExtraContext) => Awaitable<any> | void;
225
+ type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
226
+ 1: [T[0]]
227
+ 2: [T[0], T[1]]
228
+ 3: [T[0], T[1], T[2]]
229
+ 4: [T[0], T[1], T[2], T[3]]
230
+ 5: [T[0], T[1], T[2], T[3], T[4]]
231
+ 6: [T[0], T[1], T[2], T[3], T[4], T[5]]
232
+ 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6]]
233
+ 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7]]
234
+ 9: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8]]
235
+ 10: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8], T[9]]
236
+ fallback: Array<T extends ReadonlyArray<infer U> ? U : any>
237
+ }[T extends Readonly<[any]> ? 1 : T extends Readonly<[any, any]> ? 2 : T extends Readonly<[any, any, any]> ? 3 : T extends Readonly<[any, any, any, any]> ? 4 : T extends Readonly<[any, any, any, any, any]> ? 5 : T extends Readonly<[any, any, any, any, any, any]> ? 6 : T extends Readonly<[any, any, any, any, any, any, any]> ? 7 : T extends Readonly<[any, any, any, any, any, any, any, any]> ? 8 : T extends Readonly<[any, any, any, any, any, any, any, any, any]> ? 9 : T extends Readonly<[any, any, any, any, any, any, any, any, any, any]> ? 10 : "fallback"];
238
+ interface EachFunctionReturn<T extends any[]> {
239
+ /**
240
+ * @deprecated Use options as the second argument instead
241
+ */
242
+ (name: string | Function, fn: (...args: T) => Awaitable<void>, options: TestCollectorOptions): void;
243
+ (name: string | Function, fn: (...args: T) => Awaitable<void>, options?: number | TestCollectorOptions): void;
244
+ (name: string | Function, options: TestCollectorOptions, fn: (...args: T) => Awaitable<void>): void;
245
+ }
246
+ interface TestEachFunction {
247
+ <T extends any[] | [any]>(cases: ReadonlyArray<T>): EachFunctionReturn<T>;
248
+ <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): EachFunctionReturn<ExtractEachCallbackArgs<T>>;
249
+ <T>(cases: ReadonlyArray<T>): EachFunctionReturn<T[]>;
250
+ (...args: [TemplateStringsArray, ...any]): EachFunctionReturn<any[]>;
251
+ }
252
+ interface TestForFunctionReturn<
253
+ Arg,
254
+ Context
255
+ > {
256
+ (name: string | Function, fn: (arg: Arg, context: Context) => Awaitable<void>): void;
257
+ (name: string | Function, options: TestCollectorOptions, fn: (args: Arg, context: Context) => Awaitable<void>): void;
258
+ }
259
+ interface TestForFunction<ExtraContext> {
260
+ <T>(cases: ReadonlyArray<T>): TestForFunctionReturn<T, TestContext & ExtraContext>;
261
+ (strings: TemplateStringsArray, ...values: any[]): TestForFunctionReturn<any, TestContext & ExtraContext>;
262
+ }
263
+ interface SuiteForFunction {
264
+ <T>(cases: ReadonlyArray<T>): EachFunctionReturn<[T]>;
265
+ (...args: [TemplateStringsArray, ...any]): EachFunctionReturn<any[]>;
266
+ }
267
+ interface TestCollectorCallable<C = object> {
268
+ /**
269
+ * @deprecated Use options as the second argument instead
270
+ */
271
+ <ExtraContext extends C>(name: string | Function, fn: TestFunction<ExtraContext>, options: TestCollectorOptions): void;
272
+ <ExtraContext extends C>(name: string | Function, fn?: TestFunction<ExtraContext>, options?: number | TestCollectorOptions): void;
273
+ <ExtraContext extends C>(name: string | Function, options?: TestCollectorOptions, fn?: TestFunction<ExtraContext>): void;
274
+ }
275
+ type ChainableTestAPI<ExtraContext = object> = ChainableFunction<"concurrent" | "sequential" | "only" | "skip" | "todo" | "fails", TestCollectorCallable<ExtraContext>, {
276
+ each: TestEachFunction
277
+ for: TestForFunction<ExtraContext>
278
+ }>;
279
+ type TestCollectorOptions = Omit<TestOptions, "shuffle">;
280
+ interface TestOptions {
281
+ /**
282
+ * Test timeout.
283
+ */
284
+ timeout?: number;
285
+ /**
286
+ * Times to retry the test if fails. Useful for making flaky tests more stable.
287
+ * When retries is up, the last test error will be thrown.
288
+ *
289
+ * @default 0
290
+ */
291
+ retry?: number;
292
+ /**
293
+ * How many times the test will run again.
294
+ * Only inner tests will repeat if set on `describe()`, nested `describe()` will inherit parent's repeat by default.
295
+ *
296
+ * @default 0
297
+ */
298
+ repeats?: number;
299
+ /**
300
+ * Whether suites and tests run concurrently.
301
+ * Tests inherit `concurrent` from `describe()` and nested `describe()` will inherit from parent's `concurrent`.
302
+ */
303
+ concurrent?: boolean;
304
+ /**
305
+ * Whether tests run sequentially.
306
+ * Tests inherit `sequential` from `describe()` and nested `describe()` will inherit from parent's `sequential`.
307
+ */
308
+ sequential?: boolean;
309
+ /**
310
+ * Whether the tasks of the suite run in a random order.
311
+ */
312
+ shuffle?: boolean;
313
+ /**
314
+ * Whether the test should be skipped.
315
+ */
316
+ skip?: boolean;
317
+ /**
318
+ * Should this test be the only one running in a suite.
319
+ */
320
+ only?: boolean;
321
+ /**
322
+ * Whether the test should be skipped and marked as a todo.
323
+ */
324
+ todo?: boolean;
325
+ /**
326
+ * Whether the test is expected to fail. If it does, the test will pass, otherwise it will fail.
327
+ */
328
+ fails?: boolean;
329
+ }
330
+ interface ExtendedAPI<ExtraContext> {
331
+ skipIf: (condition: any) => ChainableTestAPI<ExtraContext>;
332
+ runIf: (condition: any) => ChainableTestAPI<ExtraContext>;
333
+ }
334
+ type TestAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
335
+ extend: <T extends Record<string, any> = object>(fixtures: Fixtures<T, ExtraContext>) => TestAPI<{ [K in keyof T | keyof ExtraContext] : K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never }>
336
+ };
337
+
338
+ interface FixtureOptions {
339
+ /**
340
+ * Whether to automatically set up current fixture, even though it's not being used in tests.
341
+ */
342
+ auto?: boolean;
343
+ /**
344
+ * Indicated if the injected value from the config should be preferred over the fixture value
345
+ */
346
+ injected?: boolean;
347
+ }
348
+ type Use<T> = (value: T) => Promise<void>;
349
+ type FixtureFn<
350
+ T,
351
+ K extends keyof T,
352
+ ExtraContext
353
+ > = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
354
+ type Fixture<
355
+ T,
356
+ K extends keyof T,
357
+ ExtraContext = object
358
+ > = ((...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);
359
+ type Fixtures<
360
+ T extends Record<string, any>,
361
+ ExtraContext = object
362
+ > = { [K in keyof T] : Fixture<T, K, ExtraContext & TestContext> | [Fixture<T, K, ExtraContext & TestContext>, FixtureOptions?] };
363
+ type InferFixturesTypes<T> = T extends TestAPI<infer C> ? C : T;
364
+ interface SuiteCollectorCallable<ExtraContext = object> {
365
+ /**
366
+ * @deprecated Use options as the second argument instead
367
+ */
368
+ <OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, fn: SuiteFactory<OverrideExtraContext>, options: TestOptions): SuiteCollector<OverrideExtraContext>;
369
+ <OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, fn?: SuiteFactory<OverrideExtraContext>, options?: number | TestOptions): SuiteCollector<OverrideExtraContext>;
370
+ <OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, options: TestOptions, fn?: SuiteFactory<OverrideExtraContext>): SuiteCollector<OverrideExtraContext>;
371
+ }
372
+ type ChainableSuiteAPI<ExtraContext = object> = ChainableFunction<"concurrent" | "sequential" | "only" | "skip" | "todo" | "shuffle", SuiteCollectorCallable<ExtraContext>, {
373
+ each: TestEachFunction
374
+ for: SuiteForFunction
375
+ }>;
376
+ type SuiteAPI<ExtraContext = object> = ChainableSuiteAPI<ExtraContext> & {
377
+ skipIf: (condition: any) => ChainableSuiteAPI<ExtraContext>
378
+ runIf: (condition: any) => ChainableSuiteAPI<ExtraContext>
379
+ };
380
+ /**
381
+ * @deprecated
382
+ */
383
+ type HookListener<
384
+ T extends any[],
385
+ Return = void
386
+ > = (...args: T) => Awaitable<Return>;
387
+ /**
388
+ * @deprecated
389
+ */
390
+ type HookCleanupCallback = unknown;
391
+ interface BeforeAllListener {
392
+ (suite: Readonly<Suite | File>): Awaitable<unknown>;
393
+ }
394
+ interface AfterAllListener {
395
+ (suite: Readonly<Suite | File>): Awaitable<unknown>;
396
+ }
397
+ interface BeforeEachListener<ExtraContext = object> {
398
+ (context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
399
+ }
400
+ interface AfterEachListener<ExtraContext = object> {
401
+ (context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
402
+ }
403
+ interface SuiteHooks<ExtraContext = object> {
404
+ beforeAll: BeforeAllListener[];
405
+ afterAll: AfterAllListener[];
406
+ beforeEach: BeforeEachListener<ExtraContext>[];
407
+ afterEach: AfterEachListener<ExtraContext>[];
408
+ }
409
+ interface TaskCustomOptions extends TestOptions {
410
+ /**
411
+ * Whether the task was produced with `.each()` method.
412
+ */
413
+ each?: boolean;
414
+ /**
415
+ * Custom metadata for the task that will be assigned to `task.meta`.
416
+ */
417
+ meta?: Record<string, unknown>;
418
+ /**
419
+ * Task fixtures.
420
+ */
421
+ fixtures?: FixtureItem[];
422
+ /**
423
+ * Function that will be called when the task is executed.
424
+ * If nothing is provided, the runner will try to get the function using `getFn(task)`.
425
+ * If the runner cannot find the function, the task will be marked as failed.
426
+ */
427
+ handler?: (context: TestContext) => Awaitable<void>;
428
+ }
429
+ interface SuiteCollector<ExtraContext = object> {
430
+ readonly name: string;
431
+ readonly mode: RunMode;
432
+ options?: TestOptions;
433
+ type: "collector";
434
+ test: TestAPI<ExtraContext>;
435
+ tasks: (Suite | Test<ExtraContext> | SuiteCollector<ExtraContext>)[];
436
+ suite?: Suite;
437
+ task: (name: string, options?: TaskCustomOptions) => Test<ExtraContext>;
438
+ collect: (file: File) => Promise<Suite>;
439
+ clear: () => void;
440
+ on: <T extends keyof SuiteHooks<ExtraContext>>(name: T, ...fn: SuiteHooks<ExtraContext>[T]) => void;
441
+ }
442
+ type SuiteFactory<ExtraContext = object> = (test: TestAPI<ExtraContext>) => Awaitable<void>;
443
+ interface RuntimeContext {
444
+ tasks: (SuiteCollector | Test)[];
445
+ currentSuite: SuiteCollector | null;
446
+ }
447
+ /**
448
+ * User's custom test context.
449
+ */
450
+ interface TestContext {
451
+ /**
452
+ * Metadata of the current test
453
+ */
454
+ task: Readonly<Task>;
455
+ /**
456
+ * Extract hooks on test failed
457
+ */
458
+ onTestFailed: (fn: OnTestFailedHandler, timeout?: number) => void;
459
+ /**
460
+ * Extract hooks on test failed
461
+ */
462
+ onTestFinished: (fn: OnTestFinishedHandler, timeout?: number) => void;
463
+ /**
464
+ * Mark tests as skipped. All execution after this call will be skipped.
465
+ * This function throws an error, so make sure you are not catching it accidentally.
466
+ */
467
+ skip: (note?: string) => never;
468
+ }
469
+ /**
470
+ * Context that's always available in the test function.
471
+ * @deprecated use `TestContext` instead
472
+ */
473
+ interface TaskContext extends TestContext {}
474
+ /** @deprecated use `TestContext` instead */
475
+ type ExtendedContext = TaskContext & TestContext;
476
+ type OnTestFailedHandler = (context: TestContext) => Awaitable<void>;
477
+ type OnTestFinishedHandler = (context: TestContext) => Awaitable<void>;
478
+ interface TaskHook<HookListener> {
479
+ (fn: HookListener, timeout?: number): void;
480
+ }
481
+ type SequenceHooks = "stack" | "list" | "parallel";
482
+ type SequenceSetupFiles = "list" | "parallel";
483
+
484
+ export { type AfterAllListener as A, type BeforeAllListener as B, type ChainableFunction as C, type DoneCallback as D, type ExtendedContext as E, type File as F, type TaskPopulated as G, type HookCleanupCallback as H, type InferFixturesTypes as I, type TaskResult as J, type TaskResultPack as K, type TaskState as L, type TestContext as M, type TestFunction as N, type OnTestFailedHandler as O, type TestOptions as P, type RunMode as R, type Suite as S, type Task as T, type Use as U, type Test as a, type AfterEachListener as b, createChainable as c, type BeforeEachListener as d, type TaskHook as e, type OnTestFinishedHandler as f, type Custom as g, type SuiteHooks as h, type TaskUpdateEvent as i, type TestAPI as j, type SuiteAPI as k, type SuiteCollector as l, type Fixture as m, type FixtureFn as n, type FixtureOptions as o, type Fixtures as p, type HookListener as q, type RuntimeContext as r, type SequenceHooks as s, type SequenceSetupFiles as t, type SuiteFactory as u, type TaskBase as v, type TaskContext as w, type TaskCustomOptions as x, type TaskEventPack as y, type TaskMeta as z };