@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.
@@ -1,485 +0,0 @@
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<T extends string, F extends (...args: any) => any, C = object> = F & {
17
- [x in T]: ChainableFunction<T, F, C>;
18
- } & {
19
- fn: (this: Record<T, any>, ...args: Parameters<F>) => ReturnType<F>;
20
- } & C;
21
- declare function createChainable<T extends string, Args extends any[], R = any>(keys: T[], fn: (this: Record<T, any>, ...args: Args) => R): ChainableFunction<T, (...args: Args) => R>;
22
-
23
- type RunMode = 'run' | 'skip' | 'only' | 'todo' | 'queued';
24
- type TaskState = RunMode | 'pass' | 'fail';
25
- interface TaskBase {
26
- /**
27
- * Unique task identifier. Based on the file id and the position of the task.
28
- * The id of the file task is based on the file path relative to root and project name.
29
- * It will not change between runs.
30
- * @example `1201091390`, `1201091390_0`, `1201091390_0_1`
31
- */
32
- id: string;
33
- /**
34
- * Task name provided by the user. If no name was provided, it will be an empty string.
35
- */
36
- name: string;
37
- /**
38
- * Task mode.
39
- * - **skip**: task is skipped
40
- * - **only**: only this task and other tasks with `only` mode will run
41
- * - **todo**: task is marked as a todo, alias for `skip`
42
- * - **run**: task will run or already ran
43
- * - **queued**: task will start running next. It can only exist on the File
44
- */
45
- mode: RunMode;
46
- /**
47
- * Custom metadata for the task. JSON reporter will save this data.
48
- */
49
- meta: TaskMeta;
50
- /**
51
- * Whether the task was produced with `.each()` method.
52
- */
53
- each?: boolean;
54
- /**
55
- * Whether the task should run concurrently with other tasks.
56
- */
57
- concurrent?: boolean;
58
- /**
59
- * Whether the tasks of the suite run in a random order.
60
- */
61
- shuffle?: boolean;
62
- /**
63
- * Suite that this task is part of. File task or the global suite will have no parent.
64
- */
65
- suite?: Suite;
66
- /**
67
- * Result of the task. Suite and file tasks will only have the result if there
68
- * was an error during collection or inside `afterAll`/`beforeAll`.
69
- */
70
- result?: TaskResult;
71
- /**
72
- * The amount of times the task should be retried if it fails.
73
- * @default 0
74
- */
75
- retry?: number;
76
- /**
77
- * The amount of times the task should be repeated after the successful run.
78
- * If the task fails, it will not be retried unless `retry` is specified.
79
- * @default 0
80
- */
81
- repeats?: number;
82
- /**
83
- * Location of the task in the file. This field is populated only if
84
- * `includeTaskLocation` option is set. It is generated by calling `new Error`
85
- * and parsing the stack trace, so the location might differ depending on the runtime.
86
- */
87
- location?: {
88
- line: number;
89
- column: number;
90
- };
91
- }
92
- interface TaskPopulated extends TaskBase {
93
- /**
94
- * File task. It's the root task of the file.
95
- */
96
- file: File;
97
- /**
98
- * Whether the task should succeed if it fails. If the task fails, it will be marked as passed.
99
- */
100
- fails?: boolean;
101
- /**
102
- * Store promises (from async expects) to wait for them before finishing the test
103
- */
104
- promises?: Promise<any>[];
105
- }
106
- /**
107
- * Custom metadata that can be used in reporters.
108
- */
109
- interface TaskMeta {
110
- }
111
- /**
112
- * The result of calling a task.
113
- */
114
- interface TaskResult {
115
- /**
116
- * State of the task. Inherits the `task.mode` during collection.
117
- * When the task has finished, it will be changed to `pass` or `fail`.
118
- * - **pass**: task ran successfully
119
- * - **fail**: task failed
120
- */
121
- state: TaskState;
122
- /**
123
- * Errors that occurred during the task execution. It is possible to have several errors
124
- * if `expect.soft()` failed multiple times or `retry` was triggered.
125
- */
126
- errors?: ErrorWithDiff[];
127
- /**
128
- * How long in milliseconds the task took to run.
129
- */
130
- duration?: number;
131
- /**
132
- * Time in milliseconds when the task started running.
133
- */
134
- startTime?: number;
135
- /**
136
- * Heap size in bytes after the task finished.
137
- * Only available if `logHeapUsage` option is set and `process.memoryUsage` is defined.
138
- */
139
- heap?: number;
140
- /**
141
- * State of related to this task hooks. Useful during reporting.
142
- */
143
- hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
144
- /**
145
- * The amount of times the task was retried. The task is retried only if it
146
- * failed and `retry` option is set.
147
- */
148
- retryCount?: number;
149
- /**
150
- * The amount of times the task was repeated. The task is repeated only if
151
- * `repeats` option is set. This number also contains `retryCount`.
152
- */
153
- repeatCount?: number;
154
- /** @private */
155
- note?: string;
156
- }
157
- /**
158
- * The tuple representing a single task update.
159
- * Usually reported after the task finishes.
160
- */
161
- type TaskResultPack = [
162
- /**
163
- * Unique task identifier from `task.id`.
164
- */
165
- id: string,
166
- /**
167
- * The result of running the task from `task.result`.
168
- */
169
- result: TaskResult | undefined,
170
- /**
171
- * Custom metadata from `task.meta`.
172
- */
173
- meta: TaskMeta
174
- ];
175
- type TaskEventPack = [
176
- /**
177
- * Unique task identifier from `task.id`.
178
- */
179
- id: string,
180
- /**
181
- * The name of the event that triggered the update.
182
- */
183
- event: TaskUpdateEvent
184
- ];
185
- 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';
186
- interface Suite extends TaskBase {
187
- type: 'suite';
188
- /**
189
- * File task. It's the root task of the file.
190
- */
191
- file: File;
192
- /**
193
- * An array of tasks that are part of the suite.
194
- */
195
- tasks: Task[];
196
- }
197
- interface File extends Suite {
198
- /**
199
- * The name of the pool that the file belongs to.
200
- * @default 'forks'
201
- */
202
- pool?: string;
203
- /**
204
- * The path to the file in UNIX format.
205
- */
206
- filepath: string;
207
- /**
208
- * The name of the workspace project the file belongs to.
209
- */
210
- projectName: string | undefined;
211
- /**
212
- * The time it took to collect all tests in the file.
213
- * This time also includes importing all the file dependencies.
214
- */
215
- collectDuration?: number;
216
- /**
217
- * The time it took to import the setup file.
218
- */
219
- setupDuration?: number;
220
- }
221
- interface Test<ExtraContext = object> extends TaskPopulated {
222
- type: 'test';
223
- /**
224
- * Test context that will be passed to the test function.
225
- */
226
- context: TestContext & ExtraContext;
227
- }
228
- /**
229
- * @deprecated Use `Test` instead. `type: 'custom'` is not used since 2.2
230
- */
231
- type Custom<ExtraContext = object> = Test<ExtraContext>;
232
- type Task = Test | Suite | File;
233
- /**
234
- * @deprecated Vitest doesn't provide `done()` anymore
235
- */
236
- type DoneCallback = (error?: any) => void;
237
- type TestFunction<ExtraContext = object> = (context: TestContext & ExtraContext) => Awaitable<any> | void;
238
- type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
239
- 1: [T[0]];
240
- 2: [T[0], T[1]];
241
- 3: [T[0], T[1], T[2]];
242
- 4: [T[0], T[1], T[2], T[3]];
243
- 5: [T[0], T[1], T[2], T[3], T[4]];
244
- 6: [T[0], T[1], T[2], T[3], T[4], T[5]];
245
- 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6]];
246
- 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7]];
247
- 9: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8]];
248
- 10: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8], T[9]];
249
- fallback: Array<T extends ReadonlyArray<infer U> ? U : any>;
250
- }[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'];
251
- interface EachFunctionReturn<T extends any[]> {
252
- /**
253
- * @deprecated Use options as the second argument instead
254
- */
255
- (name: string | Function, fn: (...args: T) => Awaitable<void>, options: TestCollectorOptions): void;
256
- (name: string | Function, fn: (...args: T) => Awaitable<void>, options?: number | TestCollectorOptions): void;
257
- (name: string | Function, options: TestCollectorOptions, fn: (...args: T) => Awaitable<void>): void;
258
- }
259
- interface TestEachFunction {
260
- <T extends any[] | [any]>(cases: ReadonlyArray<T>): EachFunctionReturn<T>;
261
- <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): EachFunctionReturn<ExtractEachCallbackArgs<T>>;
262
- <T>(cases: ReadonlyArray<T>): EachFunctionReturn<T[]>;
263
- (...args: [TemplateStringsArray, ...any]): EachFunctionReturn<any[]>;
264
- }
265
- interface TestForFunctionReturn<Arg, Context> {
266
- (name: string | Function, fn: (arg: Arg, context: Context) => Awaitable<void>): void;
267
- (name: string | Function, options: TestCollectorOptions, fn: (args: Arg, context: Context) => Awaitable<void>): void;
268
- }
269
- interface TestForFunction<ExtraContext> {
270
- <T>(cases: ReadonlyArray<T>): TestForFunctionReturn<T, TestContext & ExtraContext>;
271
- (strings: TemplateStringsArray, ...values: any[]): TestForFunctionReturn<any, TestContext & ExtraContext>;
272
- }
273
- interface SuiteForFunction {
274
- <T>(cases: ReadonlyArray<T>): EachFunctionReturn<[T]>;
275
- (...args: [TemplateStringsArray, ...any]): EachFunctionReturn<any[]>;
276
- }
277
- interface TestCollectorCallable<C = object> {
278
- /**
279
- * @deprecated Use options as the second argument instead
280
- */
281
- <ExtraContext extends C>(name: string | Function, fn: TestFunction<ExtraContext>, options: TestCollectorOptions): void;
282
- <ExtraContext extends C>(name: string | Function, fn?: TestFunction<ExtraContext>, options?: number | TestCollectorOptions): void;
283
- <ExtraContext extends C>(name: string | Function, options?: TestCollectorOptions, fn?: TestFunction<ExtraContext>): void;
284
- }
285
- type ChainableTestAPI<ExtraContext = object> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'fails', TestCollectorCallable<ExtraContext>, {
286
- each: TestEachFunction;
287
- for: TestForFunction<ExtraContext>;
288
- }>;
289
- type TestCollectorOptions = Omit<TestOptions, 'shuffle'>;
290
- interface TestOptions {
291
- /**
292
- * Test timeout.
293
- */
294
- timeout?: number;
295
- /**
296
- * Times to retry the test if fails. Useful for making flaky tests more stable.
297
- * When retries is up, the last test error will be thrown.
298
- *
299
- * @default 0
300
- */
301
- retry?: number;
302
- /**
303
- * How many times the test will run again.
304
- * Only inner tests will repeat if set on `describe()`, nested `describe()` will inherit parent's repeat by default.
305
- *
306
- * @default 0
307
- */
308
- repeats?: number;
309
- /**
310
- * Whether suites and tests run concurrently.
311
- * Tests inherit `concurrent` from `describe()` and nested `describe()` will inherit from parent's `concurrent`.
312
- */
313
- concurrent?: boolean;
314
- /**
315
- * Whether tests run sequentially.
316
- * Tests inherit `sequential` from `describe()` and nested `describe()` will inherit from parent's `sequential`.
317
- */
318
- sequential?: boolean;
319
- /**
320
- * Whether the tasks of the suite run in a random order.
321
- */
322
- shuffle?: boolean;
323
- /**
324
- * Whether the test should be skipped.
325
- */
326
- skip?: boolean;
327
- /**
328
- * Should this test be the only one running in a suite.
329
- */
330
- only?: boolean;
331
- /**
332
- * Whether the test should be skipped and marked as a todo.
333
- */
334
- todo?: boolean;
335
- /**
336
- * Whether the test is expected to fail. If it does, the test will pass, otherwise it will fail.
337
- */
338
- fails?: boolean;
339
- }
340
- interface ExtendedAPI<ExtraContext> {
341
- skipIf: (condition: any) => ChainableTestAPI<ExtraContext>;
342
- runIf: (condition: any) => ChainableTestAPI<ExtraContext>;
343
- }
344
- type TestAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
345
- extend: <T extends Record<string, any> = object>(fixtures: Fixtures<T, ExtraContext>) => TestAPI<{
346
- [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
347
- }>;
348
- };
349
-
350
- interface FixtureOptions {
351
- /**
352
- * Whether to automatically set up current fixture, even though it's not being used in tests.
353
- */
354
- auto?: boolean;
355
- /**
356
- * Indicated if the injected value from the config should be preferred over the fixture value
357
- */
358
- injected?: boolean;
359
- }
360
- type Use<T> = (value: T) => Promise<void>;
361
- type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
362
- 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);
363
- type Fixtures<T extends Record<string, any>, ExtraContext = object> = {
364
- [K in keyof T]: Fixture<T, K, ExtraContext & TestContext> | [Fixture<T, K, ExtraContext & TestContext>, FixtureOptions?];
365
- };
366
- type InferFixturesTypes<T> = T extends TestAPI<infer C> ? C : T;
367
- interface SuiteCollectorCallable<ExtraContext = object> {
368
- /**
369
- * @deprecated Use options as the second argument instead
370
- */
371
- <OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, fn: SuiteFactory<OverrideExtraContext>, options: TestOptions): SuiteCollector<OverrideExtraContext>;
372
- <OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, fn?: SuiteFactory<OverrideExtraContext>, options?: number | TestOptions): SuiteCollector<OverrideExtraContext>;
373
- <OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, options: TestOptions, fn?: SuiteFactory<OverrideExtraContext>): SuiteCollector<OverrideExtraContext>;
374
- }
375
- type ChainableSuiteAPI<ExtraContext = object> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'shuffle', SuiteCollectorCallable<ExtraContext>, {
376
- each: TestEachFunction;
377
- for: SuiteForFunction;
378
- }>;
379
- type SuiteAPI<ExtraContext = object> = ChainableSuiteAPI<ExtraContext> & {
380
- skipIf: (condition: any) => ChainableSuiteAPI<ExtraContext>;
381
- runIf: (condition: any) => ChainableSuiteAPI<ExtraContext>;
382
- };
383
- /**
384
- * @deprecated
385
- */
386
- type HookListener<T extends any[], Return = void> = (...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) => void;
468
- }
469
- /**
470
- * Context that's always available in the test function.
471
- * @deprecated use `TestContext` instead
472
- */
473
- interface TaskContext extends TestContext {
474
- }
475
- /** @deprecated use `TestContext` instead */
476
- type ExtendedContext = TaskContext & TestContext;
477
- type OnTestFailedHandler = (context: TestContext) => Awaitable<void>;
478
- type OnTestFinishedHandler = (context: TestContext) => Awaitable<void>;
479
- interface TaskHook<HookListener> {
480
- (fn: HookListener, timeout?: number): void;
481
- }
482
- type SequenceHooks = 'stack' | 'list' | 'parallel';
483
- type SequenceSetupFiles = 'list' | 'parallel';
484
-
485
- 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 };