vitest 5.0.0-beta.5 → 5.0.0-beta.7

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.
Files changed (76) hide show
  1. package/LICENSE.md +165 -1
  2. package/dist/browser.d.ts +27 -14
  3. package/dist/browser.js +11 -14
  4. package/dist/chunks/{artifact.C0OHWdod.js → artifact.DC5WoEgy.js} +1310 -13
  5. package/dist/chunks/{base.BPbmtl-C.js → base.B0fUxpj9.js} +17 -13
  6. package/dist/chunks/{browser.d.B-p-y0sB.d.ts → browser.d.BFOby8YL.d.ts} +3 -3
  7. package/dist/chunks/{cac.DYQRhgb-.js → cac.B41kXwyU.js} +22 -24
  8. package/dist/chunks/check.Cz_-YojU.js +15 -0
  9. package/dist/chunks/cli-api.bqNN5viV.js +519 -0
  10. package/dist/chunks/{config.d.Bkl6J5iR.d.ts → config.d.DsC1jkby.d.ts} +877 -27
  11. package/dist/chunks/{console.DjVIMaXT.js → console.omGxyKMT.js} +5 -5
  12. package/dist/chunks/{coverage.CTzCuANN.js → coverage.BVb1JqW7.js} +7 -2
  13. package/dist/chunks/coverage.BfSEMtie.js +26 -0
  14. package/dist/chunks/coverage.d.ByaAMV4A.d.ts +88 -0
  15. package/dist/chunks/{creator.CJiHagNv.js → creator.BzMFaPC-.js} +54 -30
  16. package/dist/chunks/{defaults.CUUnbOrq.js → defaults.BJUmAuaO.js} +3 -2
  17. package/dist/chunks/display.CYwyMF4S.js +192 -0
  18. package/dist/chunks/{env.BKKtU2WC.js → env.DzFJjrmK.js} +1 -1
  19. package/dist/chunks/{environment.d.CrsxCzP1.d.ts → environment.d.4-rzQgpt.d.ts} +1 -1
  20. package/dist/chunks/globals.sd6Qutmc.js +28 -0
  21. package/dist/chunks/{cli-api.SMst4llK.js → index.5krd73UD.js} +14591 -13056
  22. package/dist/chunks/{index.CXzZ7KB8.js → index.CLtI1k_4.js} +627 -214
  23. package/dist/chunks/{index.DzNNaFWy.js → index.DxR-nMjO.js} +63 -10
  24. package/dist/chunks/index.DzTmMrSM.js +940 -0
  25. package/dist/chunks/{index.DugGyGng.js → index.JaztIWgW.js} +6 -5
  26. package/dist/chunks/{init-forks.CDWjf0q6.js → init-forks.CXzT841o.js} +1 -1
  27. package/dist/chunks/{init-threads.B-vZ8N2q.js → init-threads.Ch-Bw5j3.js} +1 -1
  28. package/dist/chunks/{init.gslB1aqB.js → init.CfiYZpFg.js} +41 -25
  29. package/dist/chunks/{native.DPzPHdi5.js → native.BUCvPRKp.js} +3 -4
  30. package/dist/chunks/{nativeModuleMocker.CrcWvO03.js → nativeModuleMocker.Uot80PXb.js} +2 -3
  31. package/dist/chunks/{index.CesbTg1C.js → nativeModuleRunner.BDnwGb8g.js} +39 -3
  32. package/dist/chunks/{node.C9I1sbE9.js → node.BPMnm_Q2.js} +1 -1
  33. package/dist/chunks/offset.Dy-5Fdfn.js +24 -0
  34. package/dist/chunks/pathe.M-eThtNZ.CbK_Vbae.js +489 -0
  35. package/dist/chunks/{plugin.d.BuiCQSo8.d.ts → plugin.d.BOjbmxWW.d.ts} +1757 -1566
  36. package/dist/chunks/{plugins.DrsmdUE2.js → plugins.CsoX-42X.js} +1 -1
  37. package/dist/chunks/resolver.CERfsKE-.js +48 -0
  38. package/dist/chunks/{rpc.d.BLxNuPAq.d.ts → rpc.d.BeasqWpO.d.ts} +14 -1
  39. package/dist/chunks/{rpc.DZEh5xnQ.js → rpc.iNjF664v.js} +2 -2
  40. package/dist/chunks/setup-common.vxjAyUtK.js +36 -0
  41. package/dist/chunks/setup.DasACXvo.js +5409 -0
  42. package/dist/chunks/source-map.DZdIqpIJ.js +1776 -0
  43. package/dist/chunks/spy.B8mHA9qu.js +422 -0
  44. package/dist/chunks/{task-utils.d.CLWcZaUf.d.ts → task-utils.d.BKHiHxSN.d.ts} +20 -2
  45. package/dist/chunks/tinyrainbow.Ht9iggcq.js +95 -0
  46. package/dist/chunks/{utils.DKODp04v.js → utils.CO-iLyCr.js} +41 -42
  47. package/dist/chunks/{vm._FqKqltU.js → vm.DoQh8CN9.js} +110 -11
  48. package/dist/chunks/{worker.d.Cb0Z-SnE.d.ts → worker.d.s_RdeZtI.d.ts} +14 -11
  49. package/dist/cli.js +4 -5
  50. package/dist/config.cjs +2 -1
  51. package/dist/config.d.ts +19 -17
  52. package/dist/config.js +2 -2
  53. package/dist/index.d.ts +241 -31
  54. package/dist/index.js +11 -16
  55. package/dist/module-evaluator.d.ts +40 -8
  56. package/dist/module-evaluator.js +73 -22
  57. package/dist/node.d.ts +225 -86
  58. package/dist/node.js +30 -66
  59. package/dist/runtime.d.ts +6 -11
  60. package/dist/runtime.js +4 -5
  61. package/dist/spy.js +1 -1
  62. package/dist/task-utils.js +1 -2
  63. package/dist/worker.d.ts +5 -10
  64. package/dist/worker.js +24 -36
  65. package/dist/workers/forks.js +21 -33
  66. package/dist/workers/runVmTests.js +15 -20
  67. package/dist/workers/threads.js +21 -33
  68. package/dist/workers/vmForks.js +13 -15
  69. package/dist/workers/vmThreads.js +13 -15
  70. package/package.json +20 -20
  71. package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +0 -6
  72. package/dist/chunks/coverage.d.Dn6XbyQq.d.ts +0 -43
  73. package/dist/chunks/globals.D2wDMk06.js +0 -33
  74. package/dist/chunks/index.6dZyLbho.js +0 -6918
  75. package/dist/chunks/nativeModuleRunner.WlMdOB52.js +0 -36
  76. package/dist/chunks/setup-common.DRlwpHsL.js +0 -64
@@ -1,10 +1,5 @@
1
- import { OptionsReceived, Plugin, PrettyFormatOptions } from '@vitest/pretty-format';
2
- import { ParsedStack, TestError, Awaitable } from '@vitest/utils';
3
- import { diff, printDiffOrStringify, SerializedDiffOptions } from '@vitest/utils/diff';
4
- import { MockInstance } from '@vitest/spy';
5
- import { Formatter } from 'tinyrainbow';
6
- import { stringify } from '@vitest/utils/display';
7
- import { Fn, FnOptions, BenchOptions, TaskResultCompleted, TaskResultRuntimeInfo, TaskResultTimestampProviderInfo, Statistics } from 'tinybench';
1
+ import { Disposable } from 'vitest/optional-runtime-types.js';
2
+ import { Fn, FnOptions, BenchOptions as BenchOptions$1, TaskResultCompleted, TaskResultRuntimeInfo, TaskResultTimestampProviderInfo, Statistics } from 'tinybench';
8
3
 
9
4
  type VoidVarArgsFunc = (...args: unknown[]) => void;
10
5
  type SetImmediate = (callback: VoidVarArgsFunc, ...args: unknown[]) => NodeImmediate;
@@ -27,7 +22,10 @@ type RequestAnimationFrame = (callback: AnimationFrameCallback) => TimerId;
27
22
  type CancelAnimationFrame = (id: TimerId) => void;
28
23
  type CancelIdleCallback = (id: TimerId) => void;
29
24
  type ClearImmediate = (id: NodeImmediate) => void;
30
- type FakeMethod = "setTimeout" | "clearTimeout" | "setImmediate" | "clearImmediate" | "setInterval" | "clearInterval" | "Date" | "nextTick" | "hrtime" | "requestAnimationFrame" | "cancelAnimationFrame" | "requestIdleCallback" | "cancelIdleCallback" | "performance" | "queueMicrotask";
25
+ type TemporalTimelike = {
26
+ epochMilliseconds: number;
27
+ };
28
+ type FakeMethod = "setTimeout" | "clearTimeout" | "setImmediate" | "clearImmediate" | "setInterval" | "clearInterval" | "Date" | "nextTick" | "hrtime" | "requestAnimationFrame" | "cancelAnimationFrame" | "requestIdleCallback" | "cancelIdleCallback" | "performance" | "queueMicrotask" | "Intl" | "Temporal";
31
29
  type TimerId = number | NodeImmediate | Timer;
32
30
  type GlobalObject = Record<string, any> & {
33
31
  setTimeout?: SetTimeout;
@@ -45,6 +43,7 @@ type GlobalObject = Record<string, any> & {
45
43
  performance?: any;
46
44
  Performance?: any;
47
45
  Intl?: any;
46
+ Temporal?: any;
48
47
  Promise?: typeof Promise;
49
48
  Date: typeof Date & {
50
49
  isFake?: boolean;
@@ -68,8 +67,8 @@ type TimerInitialProps = {
68
67
  order?: number;
69
68
  heapIndex?: number;
70
69
  };
71
- type Config = {
72
- now?: number | Date;
70
+ type Config$1 = {
71
+ now?: number | Date | TemporalTimelike;
73
72
  toFake?: FakeMethod[];
74
73
  toNotFake?: FakeMethod[];
75
74
  loopLimit?: number;
@@ -89,6 +88,241 @@ type NodeImmediate = {
89
88
  unref: NodeImmediateUnref;
90
89
  };
91
90
 
91
+ /**
92
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
93
+ *
94
+ * This source code is licensed under the MIT license found in the
95
+ * LICENSE file in the root directory of this source tree.
96
+ */
97
+ interface Colors {
98
+ comment: {
99
+ close: string;
100
+ open: string;
101
+ };
102
+ content: {
103
+ close: string;
104
+ open: string;
105
+ };
106
+ prop: {
107
+ close: string;
108
+ open: string;
109
+ };
110
+ tag: {
111
+ close: string;
112
+ open: string;
113
+ };
114
+ value: {
115
+ close: string;
116
+ open: string;
117
+ };
118
+ }
119
+ type Indent = (arg0: string) => string;
120
+ type Refs = Array<unknown>;
121
+ type Print = (arg0: unknown) => string;
122
+ /**
123
+ * compare function used when sorting object keys, `null` can be used to skip over sorting.
124
+ */
125
+ type CompareKeys = ((a: string, b: string) => number) | null | undefined;
126
+ interface PrettyFormatOptions {
127
+ /**
128
+ * Call `toJSON` on objects before formatting them.
129
+ * Ignored after the formatter has already called `toJSON` once for a value.
130
+ * @default true
131
+ */
132
+ callToJSON?: boolean;
133
+ /**
134
+ * Whether to escape special characters in regular expressions.
135
+ * @default false
136
+ */
137
+ escapeRegex?: boolean;
138
+ /**
139
+ * Whether to escape special characters in strings.
140
+ * @default true
141
+ */
142
+ escapeString?: boolean;
143
+ /**
144
+ * Whether to highlight syntax using terminal colors.
145
+ * @default false
146
+ */
147
+ highlight?: boolean;
148
+ /**
149
+ * Number of spaces to use for each level of indentation.
150
+ * @default 2
151
+ */
152
+ indent?: number;
153
+ /**
154
+ * Maximum depth to recurse into nested values.
155
+ * @default Infinity
156
+ */
157
+ maxDepth?: number;
158
+ /**
159
+ * Maximum number of items to print in arrays, sets, maps, and similar collections.
160
+ * @default Infinity
161
+ */
162
+ maxWidth?: number;
163
+ /**
164
+ * Approximate per-depth-level budget for output length.
165
+ * When the accumulated output at any single depth level exceeds this value,
166
+ * further nesting is collapsed. This is a heuristic safety valve, not a hard
167
+ * limit — total output can reach up to roughly `maxDepth × maxOutputLength`.
168
+ * @default 1_000_000
169
+ */
170
+ maxOutputLength?: number;
171
+ /**
172
+ * Whether to minimize added whitespace, including indentation and line breaks.
173
+ *
174
+ * When `true`, pretty-format defaults `spacingInner` to `' '`, `spacingOuter` to `''`,
175
+ * and ignores indentation. It also changes the default for `printBasicPrototype`
176
+ * from `true` to `false`, although an explicit `printBasicPrototype` still wins.
177
+ * Explicit `spacingInner` / `spacingOuter` overrides still apply.
178
+ * @default false
179
+ */
180
+ min?: boolean;
181
+ /**
182
+ * Whether to print `Object` / `Array` prefixes for plain objects and arrays.
183
+ *
184
+ * Defaults to `true`, unless `min` is `true`, in which case it defaults to `false`.
185
+ * An explicit `printBasicPrototype` value always overrides the `min` default.
186
+ */
187
+ printBasicPrototype?: boolean;
188
+ /**
189
+ * Whether to include the function name when formatting functions.
190
+ * @default true
191
+ */
192
+ printFunctionName?: boolean;
193
+ /**
194
+ * Whether to include shadow-root contents when formatting DOM nodes.
195
+ * @default true
196
+ */
197
+ printShadowRoot?: boolean;
198
+ /**
199
+ * Compare function used when sorting object keys. Set to `null` to disable sorting.
200
+ */
201
+ compareKeys?: CompareKeys;
202
+ /**
203
+ * Plugins used to serialize application-specific data types.
204
+ * @default []
205
+ */
206
+ plugins?: Plugins;
207
+ /**
208
+ * Whitespace inserted after commas between items or entries.
209
+ *
210
+ * For example, in `{a: 1, b: 2}` or `[1, 2]`, this controls the gap after each comma:
211
+ * `{a: 1,${spacingInner}b: 2}`
212
+ * `[1,${spacingInner}2]`
213
+ *
214
+ * Defaults to `'\n'` in regular mode and `' '` when `min` is `true`.
215
+ * Can be overridden independently of `min`.
216
+ */
217
+ spacingInner?: string;
218
+ /**
219
+ * Whitespace inserted immediately inside collection/object delimiters.
220
+ *
221
+ * For example, this controls the space or newline right after the opening delimiter
222
+ * and right before the closing delimiter:
223
+ * `{${spacingOuter}a: 1${spacingOuter}}`
224
+ * `[${spacingOuter}1${spacingOuter}]`
225
+ *
226
+ * Defaults to `'\n'` in regular mode and `''` when `min` is `true`.
227
+ * Can be overridden independently of `min`.
228
+ */
229
+ spacingOuter?: string;
230
+ /**
231
+ * Whether to print strings using single quotes instead of double quotes.
232
+ *
233
+ * For example:
234
+ * `"hello"` when `false`
235
+ * `'hello'` when `true`
236
+ *
237
+ * @default false
238
+ */
239
+ singleQuote?: boolean;
240
+ /**
241
+ * Whether to always quote object property keys.
242
+ *
243
+ * For example:
244
+ * `{"a": 1}` when `true`
245
+ * `{a: 1}` when `false` and the key is a valid identifier
246
+ * `{"my-key": 1}` still stays quoted because it is not a valid identifier
247
+ *
248
+ * @default true
249
+ */
250
+ quoteKeys?: boolean;
251
+ }
252
+ type OptionsReceived = PrettyFormatOptions;
253
+ interface Config {
254
+ callToJSON: boolean;
255
+ compareKeys: CompareKeys;
256
+ colors: Colors;
257
+ escapeRegex: boolean;
258
+ escapeString: boolean;
259
+ indent: string;
260
+ maxDepth: number;
261
+ maxWidth: number;
262
+ min: boolean;
263
+ plugins: Plugins;
264
+ printBasicPrototype: boolean;
265
+ printFunctionName: boolean;
266
+ printShadowRoot: boolean;
267
+ spacingInner: string;
268
+ spacingOuter: string;
269
+ singleQuote: boolean;
270
+ quoteKeys: boolean;
271
+ maxOutputLength: number;
272
+ }
273
+ type Printer = (val: unknown, config: Config, indentation: string, depth: number, refs: Refs, hasCalledToJSON?: boolean) => string;
274
+ type Test$1 = (arg0: any) => boolean;
275
+ interface NewPlugin {
276
+ serialize: (val: any, config: Config, indentation: string, depth: number, refs: Refs, printer: Printer) => string;
277
+ test: Test$1;
278
+ }
279
+ interface PluginOptions {
280
+ edgeSpacing: string;
281
+ min: boolean;
282
+ spacing: string;
283
+ }
284
+ interface OldPlugin {
285
+ print: (val: unknown, print: Print, indent: Indent, options: PluginOptions, colors: Colors) => string;
286
+ test: Test$1;
287
+ }
288
+ type Plugin = NewPlugin | OldPlugin;
289
+ type Plugins = Array<Plugin>;
290
+
291
+ interface StringifyOptions extends PrettyFormatOptions {
292
+ maxLength?: number;
293
+ filterNode?: string | ((node: any) => boolean);
294
+ }
295
+ declare function stringify(object: unknown, maxDepth?: number, { maxLength, filterNode, ...options }?: StringifyOptions): string;
296
+ declare function format(args: unknown[], options?: InspectOptions): string;
297
+ interface InspectOptions extends StringifyOptions {
298
+ truncate?: number;
299
+ multiline?: boolean;
300
+ }
301
+ declare function inspect(obj: unknown, options?: InspectOptions): string;
302
+
303
+ type Awaitable<T> = T | PromiseLike<T>;
304
+ type Arrayable<T> = T | Array<T>;
305
+ interface ParsedStack {
306
+ method: string;
307
+ file: string;
308
+ line: number;
309
+ column: number;
310
+ }
311
+ interface SerializedError {
312
+ message: string;
313
+ stacks?: ParsedStack[];
314
+ stack?: string;
315
+ name?: string;
316
+ cause?: SerializedError;
317
+ [key: string]: unknown;
318
+ }
319
+ interface TestError extends SerializedError {
320
+ cause?: TestError;
321
+ diff?: string;
322
+ actual?: string;
323
+ expected?: string;
324
+ }
325
+
92
326
  interface SnapshotEnvironment {
93
327
  getVersion: () => string;
94
328
  getHeader: () => string;
@@ -302,6 +536,79 @@ interface RawSnapshotInfo {
302
536
  content?: string;
303
537
  }
304
538
 
539
+ /**
540
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
541
+ *
542
+ * This source code is licensed under the MIT license found in the
543
+ * LICENSE file in the root directory of this source tree.
544
+ */
545
+
546
+ type DiffOptionsColor = (arg: string) => string;
547
+ interface DiffOptions {
548
+ aAnnotation?: string;
549
+ aColor?: DiffOptionsColor;
550
+ aIndicator?: string;
551
+ bAnnotation?: string;
552
+ bColor?: DiffOptionsColor;
553
+ bIndicator?: string;
554
+ changeColor?: DiffOptionsColor;
555
+ changeLineTrailingSpaceColor?: DiffOptionsColor;
556
+ commonColor?: DiffOptionsColor;
557
+ commonIndicator?: string;
558
+ commonLineTrailingSpaceColor?: DiffOptionsColor;
559
+ contextLines?: number;
560
+ emptyFirstOrLastLinePlaceholder?: string;
561
+ expand?: boolean;
562
+ includeChangeCounts?: boolean;
563
+ omitAnnotationLines?: boolean;
564
+ patchColor?: DiffOptionsColor;
565
+ printBasicPrototype?: boolean;
566
+ maxDepth?: number;
567
+ compareKeys?: CompareKeys;
568
+ truncateThreshold?: number;
569
+ truncateAnnotation?: string;
570
+ truncateAnnotationColor?: DiffOptionsColor;
571
+ }
572
+ interface SerializedDiffOptions {
573
+ aAnnotation?: string;
574
+ aIndicator?: string;
575
+ bAnnotation?: string;
576
+ bIndicator?: string;
577
+ commonIndicator?: string;
578
+ contextLines?: number;
579
+ emptyFirstOrLastLinePlaceholder?: string;
580
+ expand?: boolean;
581
+ includeChangeCounts?: boolean;
582
+ omitAnnotationLines?: boolean;
583
+ printBasicPrototype?: boolean;
584
+ maxDepth?: number;
585
+ truncateThreshold?: number;
586
+ truncateAnnotation?: string;
587
+ }
588
+
589
+ /**
590
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
591
+ *
592
+ * This source code is licensed under the MIT license found in the
593
+ * LICENSE file in the root directory of this source tree.
594
+ */
595
+
596
+ interface StringifiedMemory {
597
+ expected?: string;
598
+ actual?: string;
599
+ }
600
+ interface Memorize {
601
+ (pointer: "expected" | "actual", stringifiedValue: string): string;
602
+ }
603
+ /**
604
+ * @param a Expected value
605
+ * @param b Received value
606
+ * @param options Diff options
607
+ * @returns {string | null} a string diff
608
+ */
609
+ declare function diff(a: any, b: any, options?: DiffOptions, memorize?: Memorize): string | undefined;
610
+ declare function printDiffOrStringify(received: unknown, expected: unknown, options?: DiffOptions, memory?: StringifiedMemory): string | undefined;
611
+
305
612
  interface AfterSuiteRunMeta {
306
613
  coverage?: unknown;
307
614
  testFiles: string[];
@@ -328,6 +635,7 @@ interface ResolveFunctionResult {
328
635
  file: string;
329
636
  url: string;
330
637
  }
638
+ type ModuleType = "cjs" | "esm";
331
639
  interface FetchCachedFileSystemResult {
332
640
  cached: true;
333
641
  tmp: string;
@@ -335,6 +643,7 @@ interface FetchCachedFileSystemResult {
335
643
  file: string | null;
336
644
  url: string;
337
645
  invalidate: boolean;
646
+ moduleType?: ModuleType;
338
647
  }
339
648
  type LabelColor = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
340
649
  interface AsyncLeak {
@@ -344,6 +653,484 @@ interface AsyncLeak {
344
653
  type: string;
345
654
  }
346
655
 
656
+ interface MockResultReturn<T> {
657
+ type: "return";
658
+ /**
659
+ * The value that was returned from the function. If function returned a Promise, then this will be a resolved value.
660
+ */
661
+ value: T;
662
+ }
663
+ interface MockResultIncomplete {
664
+ type: "incomplete";
665
+ value: undefined;
666
+ }
667
+ interface MockResultThrow {
668
+ type: "throw";
669
+ /**
670
+ * An error that was thrown during function execution.
671
+ */
672
+ value: any;
673
+ }
674
+ interface MockSettledResultIncomplete {
675
+ type: "incomplete";
676
+ value: undefined;
677
+ }
678
+ interface MockSettledResultFulfilled<T> {
679
+ type: "fulfilled";
680
+ value: T;
681
+ }
682
+ interface MockSettledResultRejected {
683
+ type: "rejected";
684
+ value: any;
685
+ }
686
+ type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
687
+ type MockSettledResult<T> = MockSettledResultFulfilled<T> | MockSettledResultRejected | MockSettledResultIncomplete;
688
+ type MockParameters<T extends Procedure | Constructable> = T extends Constructable ? ConstructorParameters<T> : T extends Procedure ? Parameters<T> : never;
689
+ type MockReturnType<T extends Procedure | Constructable> = T extends Constructable ? InstanceType<T> : T extends Procedure ? ReturnType<T> : never;
690
+ type MockProcedureContext<T extends Procedure | Constructable> = T extends Constructable ? InstanceType<T> : ThisParameterType<T>;
691
+ interface MockContext<T extends Procedure | Constructable = Procedure> {
692
+ /**
693
+ * This is an array containing all arguments for each call. One item of the array is the arguments of that call.
694
+ *
695
+ * @see https://vitest.dev/api/mock#mock-calls
696
+ * @example
697
+ * const fn = vi.fn()
698
+ *
699
+ * fn('arg1', 'arg2')
700
+ * fn('arg3')
701
+ *
702
+ * fn.mock.calls === [
703
+ * ['arg1', 'arg2'], // first call
704
+ * ['arg3'], // second call
705
+ * ]
706
+ */
707
+ calls: MockParameters<T>[];
708
+ /**
709
+ * This is an array containing all instances that were instantiated when mock was called with a `new` keyword. Note that this is an actual context (`this`) of the function, not a return value.
710
+ * @see https://vitest.dev/api/mock#mock-instances
711
+ */
712
+ instances: MockProcedureContext<T>[];
713
+ /**
714
+ * An array of `this` values that were used during each call to the mock function.
715
+ * @see https://vitest.dev/api/mock#mock-contexts
716
+ */
717
+ contexts: MockProcedureContext<T>[];
718
+ /**
719
+ * The order of mock's execution. This returns an array of numbers which are shared between all defined mocks.
720
+ *
721
+ * @see https://vitest.dev/api/mock#mock-invocationcallorder
722
+ * @example
723
+ * const fn1 = vi.fn()
724
+ * const fn2 = vi.fn()
725
+ *
726
+ * fn1()
727
+ * fn2()
728
+ * fn1()
729
+ *
730
+ * fn1.mock.invocationCallOrder === [1, 3]
731
+ * fn2.mock.invocationCallOrder === [2]
732
+ */
733
+ invocationCallOrder: number[];
734
+ /**
735
+ * This is an array containing all values that were `returned` from the function.
736
+ *
737
+ * The `value` property contains the returned value or thrown error. If the function returned a `Promise`, then `result` will always be `'return'` even if the promise was rejected.
738
+ *
739
+ * @see https://vitest.dev/api/mock#mock-results
740
+ * @example
741
+ * const fn = vi.fn()
742
+ * .mockReturnValueOnce('result')
743
+ * .mockImplementationOnce(() => { throw new Error('thrown error') })
744
+ *
745
+ * const result = fn()
746
+ *
747
+ * try {
748
+ * fn()
749
+ * }
750
+ * catch {}
751
+ *
752
+ * fn.mock.results === [
753
+ * {
754
+ * type: 'return',
755
+ * value: 'result',
756
+ * },
757
+ * {
758
+ * type: 'throw',
759
+ * value: Error,
760
+ * },
761
+ * ]
762
+ */
763
+ results: MockResult<MockReturnType<T>>[];
764
+ /**
765
+ * An array containing all values that were `resolved` or `rejected` from the function.
766
+ *
767
+ * This array will be empty if the function was never resolved or rejected.
768
+ *
769
+ * @see https://vitest.dev/api/mock#mock-settledresults
770
+ * @example
771
+ * const fn = vi.fn().mockResolvedValueOnce('result')
772
+ *
773
+ * const result = fn()
774
+ *
775
+ * fn.mock.settledResults === [
776
+ * {
777
+ * type: 'incomplete',
778
+ * value: undefined,
779
+ * }
780
+ * ]
781
+ * fn.mock.results === [
782
+ * {
783
+ * type: 'return',
784
+ * value: Promise<'result'>,
785
+ * },
786
+ * ]
787
+ *
788
+ * await result
789
+ *
790
+ * fn.mock.settledResults === [
791
+ * {
792
+ * type: 'fulfilled',
793
+ * value: 'result',
794
+ * },
795
+ * ]
796
+ */
797
+ settledResults: MockSettledResult<Awaited<MockReturnType<T>>>[];
798
+ /**
799
+ * This contains the arguments of the last call. If spy wasn't called, will return `undefined`.
800
+ * @see https://vitest.dev/api/mock#mock-lastcall
801
+ */
802
+ lastCall: MockParameters<T> | undefined;
803
+ }
804
+ type Procedure = (...args: any[]) => any;
805
+ type NormalizedProcedure<T extends Procedure | Constructable> = T extends Constructable ? ({
806
+ new (...args: ConstructorParameters<T>): InstanceType<T>;
807
+ }) | ({
808
+ (this: InstanceType<T>, ...args: ConstructorParameters<T>): void;
809
+ }) : T extends Procedure ? (...args: Parameters<T>) => ReturnType<T> : never;
810
+ type Methods<T> = keyof { [K in keyof T as T[K] extends Procedure ? K : never] : T[K] };
811
+ type Properties<T> = { [K in keyof T] : T[K] extends Procedure ? never : K }[keyof T] & (string | symbol);
812
+ type Classes<T> = { [K in keyof T] : T[K] extends new (...args: any[]) => any ? K : never }[keyof T] & (string | symbol);
813
+ interface MockInstance<T extends Procedure | Constructable = Procedure> extends Disposable {
814
+ /**
815
+ * Use it to return the name assigned to the mock with the `.mockName(name)` method. By default, it will return `vi.fn()`.
816
+ * @see https://vitest.dev/api/mock#getmockname
817
+ */
818
+ getMockName(): string;
819
+ /**
820
+ * Sets the internal mock name. This is useful for identifying the mock when an assertion fails.
821
+ * @see https://vitest.dev/api/mock#mockname
822
+ */
823
+ mockName(name: string): this;
824
+ /**
825
+ * Current context of the mock. It stores information about all invocation calls, instances, and results.
826
+ */
827
+ mock: MockContext<T>;
828
+ /**
829
+ * Clears all information about every call. After calling it, all properties on `.mock` will return to their initial state. This method does not reset implementations. It is useful for cleaning up mocks between different assertions.
830
+ *
831
+ * To automatically call this method before each test, enable the [`clearMocks`](https://vitest.dev/config/clearmocks) setting in the configuration.
832
+ * @see https://vitest.dev/api/mock#mockclear
833
+ */
834
+ mockClear(): this;
835
+ /**
836
+ * Does what `mockClear` does and resets inner implementation to the original function. This also resets all "once" implementations.
837
+ *
838
+ * Note that resetting a mock from `vi.fn()` will set implementation to an empty function that returns `undefined`.
839
+ * Resetting a mock from `vi.fn(impl)` will set implementation to `impl`. It is useful for completely resetting a mock to its default state.
840
+ *
841
+ * To automatically call this method before each test, enable the [`mockReset`](https://vitest.dev/config/mockreset) setting in the configuration.
842
+ * @see https://vitest.dev/api/mock#mockreset
843
+ */
844
+ mockReset(): this;
845
+ /**
846
+ * Does what `mockReset` does and restores original descriptors of spied-on objects.
847
+ * @see https://vitest.dev/api/mock#mockrestore
848
+ */
849
+ mockRestore(): void;
850
+ /**
851
+ * Returns current permanent mock implementation if there is one.
852
+ *
853
+ * If mock was created with `vi.fn`, it will consider passed down method as a mock implementation.
854
+ *
855
+ * If mock was created with `vi.spyOn`, it will return `undefined` unless a custom implementation was provided.
856
+ */
857
+ getMockImplementation(): NormalizedProcedure<T> | undefined;
858
+ /**
859
+ * Accepts a function to be used as the mock implementation. TypeScript expects the arguments and return type to match those of the original function.
860
+ * @see https://vitest.dev/api/mock#mockimplementation
861
+ * @example
862
+ * const increment = vi.fn().mockImplementation(count => count + 1);
863
+ * expect(increment(3)).toBe(4);
864
+ */
865
+ mockImplementation(fn: NormalizedProcedure<T>): this;
866
+ /**
867
+ * Accepts a function to be used as the mock implementation. TypeScript expects the arguments and return type to match those of the original function. This method can be chained to produce different results for multiple function calls.
868
+ *
869
+ * When the mocked function runs out of implementations, it will invoke the default implementation set with `vi.fn(() => defaultValue)` or `.mockImplementation(() => defaultValue)` if they were called.
870
+ * @see https://vitest.dev/api/mock#mockimplementationonce
871
+ * @example
872
+ * const fn = vi.fn(count => count).mockImplementationOnce(count => count + 1);
873
+ * expect(fn(3)).toBe(4);
874
+ * expect(fn(3)).toBe(3);
875
+ */
876
+ mockImplementationOnce(fn: NormalizedProcedure<T>): this;
877
+ /**
878
+ * Overrides the original mock implementation temporarily while the callback is being executed.
879
+ *
880
+ * Note that this method takes precedence over the [`mockImplementationOnce`](https://vitest.dev/api/mock#mockimplementationonce).
881
+ * @see https://vitest.dev/api/mock#withimplementation
882
+ * @example
883
+ * const myMockFn = vi.fn(() => 'original')
884
+ *
885
+ * myMockFn.withImplementation(() => 'temp', () => {
886
+ * myMockFn() // 'temp'
887
+ * })
888
+ *
889
+ * myMockFn() // 'original'
890
+ */
891
+ withImplementation(fn: NormalizedProcedure<T>, cb: () => Promise<unknown>): Promise<this>;
892
+ withImplementation(fn: NormalizedProcedure<T>, cb: () => unknown): this;
893
+ /**
894
+ * Use this if you need to return the `this` context from the method without invoking the actual implementation.
895
+ * @see https://vitest.dev/api/mock#mockreturnthis
896
+ */
897
+ mockReturnThis(): this;
898
+ /**
899
+ * Accepts a value that will be returned whenever the mock function is called. TypeScript will only accept values that match the return type of the original function.
900
+ * @see https://vitest.dev/api/mock#mockreturnvalue
901
+ * @example
902
+ * const mock = vi.fn()
903
+ * mock.mockReturnValue(42)
904
+ * mock() // 42
905
+ * mock.mockReturnValue(43)
906
+ * mock() // 43
907
+ */
908
+ mockReturnValue(value: MockReturnType<T>): this;
909
+ /**
910
+ * Accepts a value that will be returned whenever the mock function is called. TypeScript will only accept values that match the return type of the original function.
911
+ *
912
+ * When the mocked function runs out of implementations, it will invoke the default implementation set with `vi.fn(() => defaultValue)` or `.mockImplementation(() => defaultValue)` if they were called.
913
+ * @example
914
+ * const myMockFn = vi
915
+ * .fn()
916
+ * .mockReturnValue('default')
917
+ * .mockReturnValueOnce('first call')
918
+ * .mockReturnValueOnce('second call')
919
+ *
920
+ * // 'first call', 'second call', 'default'
921
+ * console.log(myMockFn(), myMockFn(), myMockFn())
922
+ */
923
+ mockReturnValueOnce(value: MockReturnType<T>): this;
924
+ /**
925
+ * Accepts a value that will be thrown whenever the mock function is called.
926
+ * @see https://vitest.dev/api/mock#mockthrow
927
+ * @example
928
+ * const myMockFn = vi.fn().mockThrow(new Error('error'))
929
+ * myMockFn() // throws 'error'
930
+ */
931
+ mockThrow(value: unknown): this;
932
+ /**
933
+ * Accepts a value that will be thrown during the next function call. If chained, every consecutive call will throw the specified value.
934
+ * @example
935
+ * const myMockFn = vi
936
+ * .fn()
937
+ * .mockReturnValue('default')
938
+ * .mockThrowOnce(new Error('first call error'))
939
+ * .mockThrowOnce('second call error')
940
+ *
941
+ * expect(() => myMockFn()).toThrowError('first call error')
942
+ * expect(() => myMockFn()).toThrowError('second call error')
943
+ * expect(myMockFn()).toEqual('default')
944
+ */
945
+ mockThrowOnce(value: unknown): this;
946
+ /**
947
+ * Accepts a value that will be resolved when the async function is called. TypeScript will only accept values that match the return type of the original function.
948
+ * @example
949
+ * const asyncMock = vi.fn().mockResolvedValue(42)
950
+ * asyncMock() // Promise<42>
951
+ */
952
+ mockResolvedValue(value: Awaited<MockReturnType<T>>): this;
953
+ /**
954
+ * Accepts a value that will be resolved during the next function call. TypeScript will only accept values that match the return type of the original function. If chained, each consecutive call will resolve the specified value.
955
+ * @example
956
+ * const myMockFn = vi
957
+ * .fn()
958
+ * .mockResolvedValue('default')
959
+ * .mockResolvedValueOnce('first call')
960
+ * .mockResolvedValueOnce('second call')
961
+ *
962
+ * // Promise<'first call'>, Promise<'second call'>, Promise<'default'>
963
+ * console.log(myMockFn(), myMockFn(), myMockFn())
964
+ */
965
+ mockResolvedValueOnce(value: Awaited<MockReturnType<T>>): this;
966
+ /**
967
+ * Accepts an error that will be rejected when async function is called.
968
+ * @example
969
+ * const asyncMock = vi.fn().mockRejectedValue(new Error('Async error'))
970
+ * await asyncMock() // throws Error<'Async error'>
971
+ */
972
+ mockRejectedValue(error: unknown): this;
973
+ /**
974
+ * Accepts a value that will be rejected during the next function call. If chained, each consecutive call will reject the specified value.
975
+ * @example
976
+ * const asyncMock = vi
977
+ * .fn()
978
+ * .mockResolvedValueOnce('first call')
979
+ * .mockRejectedValueOnce(new Error('Async error'))
980
+ *
981
+ * await asyncMock() // first call
982
+ * await asyncMock() // throws Error<'Async error'>
983
+ */
984
+ mockRejectedValueOnce(error: unknown): this;
985
+ }
986
+ type Mock<T extends Procedure | Constructable = Procedure> = MockInstance<T> & (T extends Constructable ? (T extends Procedure ? {
987
+ new (...args: ConstructorParameters<T>): InstanceType<T>;
988
+ (...args: Parameters<T>): ReturnType<T>;
989
+ } : {
990
+ new (...args: ConstructorParameters<T>): InstanceType<T>;
991
+ }) : {
992
+ new (...args: MockParameters<T>): MockReturnType<T>;
993
+ (...args: MockParameters<T>): MockReturnType<T>;
994
+ }) & { [P in keyof T] : T[P] };
995
+ type PartialMaybePromise<T> = T extends Promise<Awaited<T>> ? Promise<Partial<Awaited<T>>> : Partial<T>;
996
+ type PartialResultFunction<T> = T extends Constructable ? ({
997
+ new (...args: ConstructorParameters<T>): InstanceType<T>;
998
+ }) | ({
999
+ (this: InstanceType<T>, ...args: ConstructorParameters<T>): void;
1000
+ }) : T extends Procedure ? (...args: Parameters<T>) => PartialMaybePromise<ReturnType<T>> : T;
1001
+ type PartialMock<T extends Procedure | Constructable = Procedure> = Mock<PartialResultFunction<T extends Mock ? NonNullable<ReturnType<T["getMockImplementation"]>> : T>>;
1002
+ type DeepPartial<T> = T extends Procedure ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends object ? { [K in keyof T]? : DeepPartial<T[K]> } : T;
1003
+ type DeepPartialMaybePromise<T> = T extends Promise<Awaited<T>> ? Promise<DeepPartial<Awaited<T>>> : DeepPartial<T>;
1004
+ type DeepPartialResultFunction<T> = T extends Constructable ? ({
1005
+ new (...args: ConstructorParameters<T>): InstanceType<T>;
1006
+ }) | ({
1007
+ (this: InstanceType<T>, ...args: ConstructorParameters<T>): void;
1008
+ }) : T extends Procedure ? (...args: Parameters<T>) => DeepPartialMaybePromise<ReturnType<T>> : T;
1009
+ type DeepPartialMock<T extends Procedure | Constructable = Procedure> = Mock<DeepPartialResultFunction<T extends Mock ? NonNullable<ReturnType<T["getMockImplementation"]>> : T>>;
1010
+ type MaybeMockedConstructor<T> = T extends Constructable ? Mock<T> : T;
1011
+ type MockedFunction<T extends Procedure | Constructable> = Mock<T> & MockedObject<T>;
1012
+ type PartiallyMockedFunction<T extends Procedure | Constructable> = PartialMock<T> & MockedObject<T>;
1013
+ type MockedFunctionDeep<T extends Procedure | Constructable> = Mock<T> & MockedObjectDeep<T>;
1014
+ type PartiallyMockedFunctionDeep<T extends Procedure | Constructable> = DeepPartialMock<T> & MockedObjectDeep<T>;
1015
+ type MockedObject<T> = MaybeMockedConstructor<T> & { [K in Methods<T>] : T[K] extends Procedure ? MockedFunction<T[K]> : T[K] } & { [K in Properties<T>] : T[K] };
1016
+ type MockedObjectDeep<T> = MaybeMockedConstructor<T> & { [K in Methods<T>] : T[K] extends Procedure ? MockedFunctionDeep<T[K]> : T[K] } & { [K in Properties<T>] : MaybeMockedDeep<T[K]> };
1017
+ type MaybeMockedDeep<T> = T extends Procedure | Constructable ? MockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
1018
+ type MaybePartiallyMockedDeep<T> = T extends Procedure | Constructable ? PartiallyMockedFunctionDeep<T> : T extends object ? MockedObjectDeep<T> : T;
1019
+ type MaybeMocked<T> = T extends Procedure | Constructable ? MockedFunction<T> : T extends object ? MockedObject<T> : T;
1020
+ type MaybePartiallyMocked<T> = T extends Procedure | Constructable ? PartiallyMockedFunction<T> : T extends object ? MockedObject<T> : T;
1021
+ interface Constructable {
1022
+ new (...args: any[]): any;
1023
+ }
1024
+ type MockedClass<T extends Constructable> = MockInstance<T> & {
1025
+ prototype: T extends {
1026
+ prototype: any;
1027
+ } ? Mocked<T["prototype"]> : never;
1028
+ } & T;
1029
+ type Mocked<T> = { [P in keyof T] : T[P] extends Procedure ? MockInstance<T[P]> : T[P] extends Constructable ? MockedClass<T[P]> : T[P] } & T;
1030
+ interface MockConfig {
1031
+ mockImplementation: Procedure | Constructable | undefined;
1032
+ mockOriginal: Procedure | Constructable | undefined;
1033
+ mockName: string;
1034
+ onceMockImplementations: Array<Procedure | Constructable>;
1035
+ }
1036
+ interface MockInstanceOption {
1037
+ originalImplementation?: Procedure | Constructable;
1038
+ mockImplementation?: Procedure | Constructable;
1039
+ resetToMockImplementation?: boolean;
1040
+ restore?: () => void;
1041
+ prototypeMembers?: (string | symbol)[];
1042
+ keepMembersImplementation?: boolean;
1043
+ prototypeState?: MockContext;
1044
+ prototypeConfig?: MockConfig;
1045
+ resetToMockName?: boolean;
1046
+ name?: string | symbol;
1047
+ }
1048
+
1049
+ declare function isMockFunction(fn: any): fn is Mock;
1050
+ declare function createMockInstance(options?: MockInstanceOption): Mock<Procedure | Constructable>;
1051
+ declare function fn<T extends Procedure | Constructable = Procedure>(originalImplementation?: T): Mock<T>;
1052
+ type SpyOnValue<
1053
+ T extends object,
1054
+ K extends keyof any
1055
+ > = K extends keyof Required<T> ? Required<T>[K] : (T & Record<K, unknown>)[K];
1056
+ type SpyOnMethod<
1057
+ T extends object,
1058
+ K extends keyof any
1059
+ > = SpyOnValue<T, K> extends Constructable | Procedure ? SpyOnValue<T, K> : never;
1060
+ type SpyOnMethodKey<
1061
+ T extends object,
1062
+ K extends keyof any
1063
+ > = SpyOnValue<T, K> extends Constructable | Procedure ? K : never;
1064
+ declare function spyOn<
1065
+ T extends object,
1066
+ S extends Properties<Required<T>>
1067
+ >(object: T, key: S, accessor: "get"): Mock<() => T[S]>;
1068
+ declare function spyOn<
1069
+ T extends object,
1070
+ G extends Properties<Required<T>>
1071
+ >(object: T, key: G, accessor: "set"): Mock<(arg: T[G]) => void>;
1072
+ declare function spyOn<
1073
+ T extends object,
1074
+ M extends Classes<Required<T>> | Methods<Required<T>>
1075
+ >(object: T, key: M): Required<T>[M] extends Constructable | Procedure ? Mock<Required<T>[M]> : never;
1076
+ declare function spyOn<
1077
+ T extends object,
1078
+ K extends keyof any
1079
+ >(object: T, key: SpyOnMethodKey<T, K>): Mock<SpyOnMethod<T, K>>;
1080
+ declare function restoreAllMocks(): void;
1081
+ declare function clearAllMocks(): void;
1082
+ declare function resetAllMocks(): void;
1083
+
1084
+ type _vitest_spy_Constructable = Constructable;
1085
+ type _vitest_spy_MaybeMocked<T> = MaybeMocked<T>;
1086
+ type _vitest_spy_MaybeMockedConstructor<T> = MaybeMockedConstructor<T>;
1087
+ type _vitest_spy_MaybeMockedDeep<T> = MaybeMockedDeep<T>;
1088
+ type _vitest_spy_MaybePartiallyMocked<T> = MaybePartiallyMocked<T>;
1089
+ type _vitest_spy_MaybePartiallyMockedDeep<T> = MaybePartiallyMockedDeep<T>;
1090
+ type _vitest_spy_Mock<T extends Procedure | Constructable = Procedure> = Mock<T>;
1091
+ type _vitest_spy_MockContext<T extends Procedure | Constructable = Procedure> = MockContext<T>;
1092
+ type _vitest_spy_MockInstance<T extends Procedure | Constructable = Procedure> = MockInstance<T>;
1093
+ type _vitest_spy_MockInstanceOption = MockInstanceOption;
1094
+ type _vitest_spy_MockParameters<T extends Procedure | Constructable> = MockParameters<T>;
1095
+ type _vitest_spy_MockProcedureContext<T extends Procedure | Constructable> = MockProcedureContext<T>;
1096
+ type _vitest_spy_MockResult<T> = MockResult<T>;
1097
+ type _vitest_spy_MockResultIncomplete = MockResultIncomplete;
1098
+ type _vitest_spy_MockResultReturn<T> = MockResultReturn<T>;
1099
+ type _vitest_spy_MockResultThrow = MockResultThrow;
1100
+ type _vitest_spy_MockReturnType<T extends Procedure | Constructable> = MockReturnType<T>;
1101
+ type _vitest_spy_MockSettledResult<T> = MockSettledResult<T>;
1102
+ type _vitest_spy_MockSettledResultFulfilled<T> = MockSettledResultFulfilled<T>;
1103
+ type _vitest_spy_MockSettledResultIncomplete = MockSettledResultIncomplete;
1104
+ type _vitest_spy_MockSettledResultRejected = MockSettledResultRejected;
1105
+ type _vitest_spy_Mocked<T> = Mocked<T>;
1106
+ type _vitest_spy_MockedClass<T extends Constructable> = MockedClass<T>;
1107
+ type _vitest_spy_MockedFunction<T extends Procedure | Constructable> = MockedFunction<T>;
1108
+ type _vitest_spy_MockedFunctionDeep<T extends Procedure | Constructable> = MockedFunctionDeep<T>;
1109
+ type _vitest_spy_MockedObject<T> = MockedObject<T>;
1110
+ type _vitest_spy_MockedObjectDeep<T> = MockedObjectDeep<T>;
1111
+ type _vitest_spy_PartialMock<T extends Procedure | Constructable = Procedure> = PartialMock<T>;
1112
+ type _vitest_spy_PartiallyMockedFunction<T extends Procedure | Constructable> = PartiallyMockedFunction<T>;
1113
+ type _vitest_spy_PartiallyMockedFunctionDeep<T extends Procedure | Constructable> = PartiallyMockedFunctionDeep<T>;
1114
+ type _vitest_spy_Procedure = Procedure;
1115
+ declare const _vitest_spy_clearAllMocks: typeof clearAllMocks;
1116
+ declare const _vitest_spy_createMockInstance: typeof createMockInstance;
1117
+ declare const _vitest_spy_fn: typeof fn;
1118
+ declare const _vitest_spy_isMockFunction: typeof isMockFunction;
1119
+ declare const _vitest_spy_resetAllMocks: typeof resetAllMocks;
1120
+ declare const _vitest_spy_restoreAllMocks: typeof restoreAllMocks;
1121
+ declare const _vitest_spy_spyOn: typeof spyOn;
1122
+ declare namespace _vitest_spy {
1123
+ export { _vitest_spy_clearAllMocks as clearAllMocks, _vitest_spy_createMockInstance as createMockInstance, _vitest_spy_fn as fn, _vitest_spy_isMockFunction as isMockFunction, _vitest_spy_resetAllMocks as resetAllMocks, _vitest_spy_restoreAllMocks as restoreAllMocks, _vitest_spy_spyOn as spyOn };
1124
+ export type { _vitest_spy_Constructable as Constructable, _vitest_spy_MaybeMocked as MaybeMocked, _vitest_spy_MaybeMockedConstructor as MaybeMockedConstructor, _vitest_spy_MaybeMockedDeep as MaybeMockedDeep, _vitest_spy_MaybePartiallyMocked as MaybePartiallyMocked, _vitest_spy_MaybePartiallyMockedDeep as MaybePartiallyMockedDeep, _vitest_spy_Mock as Mock, _vitest_spy_MockContext as MockContext, _vitest_spy_MockInstance as MockInstance, _vitest_spy_MockInstanceOption as MockInstanceOption, _vitest_spy_MockParameters as MockParameters, _vitest_spy_MockProcedureContext as MockProcedureContext, _vitest_spy_MockResult as MockResult, _vitest_spy_MockResultIncomplete as MockResultIncomplete, _vitest_spy_MockResultReturn as MockResultReturn, _vitest_spy_MockResultThrow as MockResultThrow, _vitest_spy_MockReturnType as MockReturnType, _vitest_spy_MockSettledResult as MockSettledResult, _vitest_spy_MockSettledResultFulfilled as MockSettledResultFulfilled, _vitest_spy_MockSettledResultIncomplete as MockSettledResultIncomplete, _vitest_spy_MockSettledResultRejected as MockSettledResultRejected, _vitest_spy_Mocked as Mocked, _vitest_spy_MockedClass as MockedClass, _vitest_spy_MockedFunction as MockedFunction, _vitest_spy_MockedFunctionDeep as MockedFunctionDeep, _vitest_spy_MockedObject as MockedObject, _vitest_spy_MockedObjectDeep as MockedObjectDeep, _vitest_spy_PartialMock as PartialMock, _vitest_spy_PartiallyMockedFunction as PartiallyMockedFunction, _vitest_spy_PartiallyMockedFunctionDeep as PartiallyMockedFunctionDeep, _vitest_spy_Procedure as Procedure };
1125
+ }
1126
+
1127
+ interface Formatter {
1128
+ (input?: unknown): string;
1129
+ open: string;
1130
+ close: string;
1131
+ }
1132
+ declare function disableDefaultColors(): void;
1133
+
347
1134
  interface AsymmetricMatcherInterface {
348
1135
  asymmetricMatch: (other: unknown, customTesters?: Array<Tester>) => boolean;
349
1136
  toString: () => string;
@@ -1157,16 +1944,77 @@ declare global {
1157
1944
  }
1158
1945
 
1159
1946
  type ExtractBenchNames<T extends BenchRegistration<any>[]> = Exclude<{ [K in keyof T] : T[K] extends BenchRegistration<infer N> ? N : never }[number], never>;
1160
- type BenchResult = TaskResultCompleted & TaskResultRuntimeInfo & TaskResultTimestampProviderInfo;
1947
+ /**
1948
+ * A benchmarked function. Vitest-owned and engine-agnostic.
1949
+ */
1950
+ type BenchFn = Fn;
1951
+ /**
1952
+ * Per-benchmark initialization options passed to `bench(name, options, fn)`.
1953
+ */
1954
+ type BenchOptions = FnOptions;
1955
+ /**
1956
+ * Engine-neutral run options forwarded to a {@link BenchmarkProvider}. These
1957
+ * come from the optional trailing options argument of `bench.compare()` and
1958
+ * `registration.run()`.
1959
+ */
1960
+ type BenchRunOptions = BenchOptions$1;
1961
+ /**
1962
+ * The result of a single benchmark, produced by a {@link BenchmarkProvider}.
1963
+ * Structurally compatible with tinybench's task statistics so it flows
1964
+ * unchanged into the reporter, `bench.from()` baselines and comparison tables.
1965
+ * The `name` matches the corresponding {@link BenchRegistration}.
1966
+ */
1967
+ interface BenchResult extends TaskResultCompleted, TaskResultRuntimeInfo, TaskResultTimestampProviderInfo {
1968
+ /** The registered benchmark name this result belongs to. */
1969
+ name: string;
1970
+ }
1971
+ /**
1972
+ * A benchmark defined by `bench()` (or `bench.from()`), as seen by a
1973
+ * {@link BenchmarkProvider}. `fn`/`fnOpts` are absent for `bench.from()`
1974
+ * registrations, which are resolved from a stored baseline instead of run.
1975
+ */
1976
+ interface BenchRegistrationInput {
1977
+ name: string;
1978
+ fn: BenchFn;
1979
+ fnOpts?: BenchOptions;
1980
+ }
1981
+ /**
1982
+ * The set of benchmarks registered by a single test, handed to
1983
+ * {@link BenchmarkProvider.run}.
1984
+ */
1985
+ interface BenchmarkGroup {
1986
+ /** The test that registered these benchmarks. */
1987
+ test: Test;
1988
+ /** The resolved benchmark configuration for the current project. */
1989
+ config: SerializedConfig["benchmark"];
1990
+ /** The runnable registrations, in registration order. */
1991
+ registrations: BenchRegistrationInput[];
1992
+ /** Engine-neutral run options, when provided by the caller. */
1993
+ options?: BenchRunOptions;
1994
+ }
1995
+ /**
1996
+ * Executes the benchmarks of a single test and returns their results.
1997
+ *
1998
+ * A custom provider module must default-export an object of this shape.
1999
+ *
2000
+ * The returned array is the sole source of results: it's what `bench().run()`
2001
+ * resolves to and what the reporter serializes. Results are matched to
2002
+ * registrations by `name`; return one {@link BenchResult} per registration.
2003
+ *
2004
+ * @experimental
2005
+ */
2006
+ interface BenchmarkProvider {
2007
+ run: (group: BenchmarkGroup) => Promise<BenchResult[]>;
2008
+ }
1161
2009
  interface BenchStorage<T extends string> {
1162
2010
  get: (name: T) => BenchResult;
1163
2011
  }
1164
2012
 
1165
2013
  /**
1166
- * Options accepted by `bench(name, options, fn)`. Extends tinybench's
1167
- * `FnOptions` with Vitest-specific fields.
2014
+ * Options accepted by `bench(name, options, fn)`. Extends the per-benchmark
2015
+ * lifecycle hooks with Vitest-specific fields.
1168
2016
  */
1169
- interface BenchFnOptions extends FnOptions {
2017
+ interface BenchFnOptions extends BenchOptions {
1170
2018
  /**
1171
2019
  * Path (relative to the project root) where the benchmark result is written
1172
2020
  * after a successful run. The string `${projectName}` is substituted with
@@ -1187,21 +2035,21 @@ interface BenchRegistration<Name extends string> {
1187
2035
  /**
1188
2036
  * The benchmark function. Absent for registrations created via `bench.from()`.
1189
2037
  */
1190
- fn?: Fn;
2038
+ fn?: BenchFn;
1191
2039
  /**
1192
2040
  * Per-benchmark options (`beforeEach`, `beforeAll`, etc.). Absent for
1193
2041
  * registrations created via `bench.from()`.
1194
2042
  */
1195
- fnOpts?: FnOptions;
1196
- run: (options?: BenchOptions) => Promise<BenchResult>;
2043
+ fnOpts?: BenchOptions;
2044
+ run: (options?: BenchRunOptions) => Promise<BenchResult>;
1197
2045
  }
1198
2046
  interface BenchCompare {
1199
2047
  <Args extends BenchRegistration<any>[]>(...args: Args): Promise<BenchStorage<ExtractBenchNames<Args>>>;
1200
- <Args extends BenchRegistration<any>[]>(...args: [...Args, BenchOptions]): Promise<BenchStorage<ExtractBenchNames<Args>>>;
2048
+ <Args extends BenchRegistration<any>[]>(...args: [...Args, BenchRunOptions]): Promise<BenchStorage<ExtractBenchNames<Args>>>;
1201
2049
  }
1202
2050
  interface BenchFactory {
1203
- <Name extends string>(name: Name | Function, fn: Fn): BenchRegistration<Name>;
1204
- <Name extends string>(name: Name | Function, options: BenchFnOptions, fn: Fn): BenchRegistration<Name>;
2051
+ <Name extends string>(name: Name | Function, fn: BenchFn): BenchRegistration<Name>;
2052
+ <Name extends string>(name: Name | Function, options: BenchFnOptions, fn: BenchFn): BenchRegistration<Name>;
1205
2053
  }
1206
2054
  interface BenchFromSource {
1207
2055
  (): BaselineData | Promise<BaselineData>;
@@ -2457,7 +3305,7 @@ interface TestArtifactLocation extends FileLocation {}
2457
3305
  *
2458
3306
  * Extend this interface when creating custom test artifacts. Vitest automatically manages the `attachments` array and injects the `location` property to indicate where the artifact was created in your test code.
2459
3307
  *
2460
- * **Important**: when running with [`api.allowWrite`](https://vitest.dev/config/api#api-allowwrite) or [`browser.api.allowWrite`](https://vitest.dev/config/browser/api#api-allowwrite) disabled, Vitest empties the `attachments` array on every artifact before reporting it.
3308
+ * **Important**: when running with [`api.allowWrite`](https://vitest.dev/config/api#api-allowwrite) disabled, Vitest empties the `attachments` array on every artifact before reporting it.
2461
3309
  */
2462
3310
  interface TestArtifactBase {
2463
3311
  /** File or data attachments associated with this artifact */
@@ -2764,6 +3612,7 @@ interface SerializedConfig {
2764
3612
  strictTags: boolean;
2765
3613
  color?: LabelColor;
2766
3614
  globals: boolean;
3615
+ injectCjsGlobals: boolean;
2767
3616
  base: string | undefined;
2768
3617
  snapshotEnvironment?: string;
2769
3618
  disableConsoleIntercept: boolean | undefined;
@@ -2777,7 +3626,7 @@ interface SerializedConfig {
2777
3626
  restoreMocks: boolean;
2778
3627
  unstubGlobals: boolean;
2779
3628
  unstubEnvs: boolean;
2780
- fakeTimers: Config;
3629
+ fakeTimers: Config$1;
2781
3630
  defines: Record<string, any>;
2782
3631
  expect: {
2783
3632
  requireAssertions?: boolean;
@@ -2834,8 +3683,6 @@ interface SerializedConfig {
2834
3683
  browser: {
2835
3684
  name: string;
2836
3685
  headless: boolean;
2837
- isolate: boolean;
2838
- fileParallelism: boolean;
2839
3686
  ui: boolean;
2840
3687
  viewport: {
2841
3688
  width: number;
@@ -2866,12 +3713,13 @@ interface SerializedConfig {
2866
3713
  benchmark: {
2867
3714
  enabled: boolean;
2868
3715
  retainSamples: boolean;
3716
+ provider: string | undefined;
2869
3717
  suppressExportGetterWarnings: boolean;
2870
3718
  projectName: string;
2871
3719
  };
2872
3720
  serializedDefines: string;
3721
+ fsModuleCache: boolean;
2873
3722
  experimental: {
2874
- fsModuleCache: boolean;
2875
3723
  importDurations: {
2876
3724
  print: boolean | "on-warn";
2877
3725
  limit: number;
@@ -2896,6 +3744,8 @@ interface SerializedConfig {
2896
3744
  interface SerializedCoverageConfig {
2897
3745
  provider: "istanbul" | "v8" | "custom" | undefined;
2898
3746
  reportsDirectory: string;
3747
+ /** Directory where workers write raw coverage results, shard-aware */
3748
+ coverageFilesDirectory: string;
2899
3749
  htmlDir: string | undefined;
2900
3750
  enabled: boolean;
2901
3751
  customProviderModule: string | undefined;
@@ -2912,5 +3762,5 @@ type RuntimeConfig = Pick<SerializedConfig, "allowOnly" | "testTimeout" | "hookT
2912
3762
  type RuntimeOptions = Partial<RuntimeConfig>;
2913
3763
  type BrowserTraceViewMode = "on" | "off" | "on-first-retry" | "on-all-retries" | "retain-on-failure";
2914
3764
 
2915
- export { onTestFailed as aA, onTestFinished as aB, SnapshotState as aE, afterAll as au, afterEach as av, aroundAll as aw, aroundEach as ax, beforeAll as ay, beforeEach as az, createChainable as t };
2916
- export type { OnTestFinishedHandler as $, AsyncExpectationResult as A, BaselineData as B, Config as C, DomainSnapshotAdapter as D, ExpectStatic as E, File as F, BenchRegistration as G, BenchResult as H, ImportDuration as I, BenchStorage as J, BrowserTraceArtifact as K, LabelColor as L, ModuleGraphData as M, DeeplyAllowMatchers as N, DomainMatchResult as O, ProvidedContext as P, FailureScreenshotArtifact as Q, RuntimeOptions as R, SerializedRootConfig as S, TestAnnotation as T, UserConsoleLog as U, VitestRunner as V, JestAssertion as W, RawMatcherFn as X, Matchers as Y, MatchersObject as Z, OnTestFailedHandler as _, TestArtifact as a, RunMode as a0, TaskBase as a1, TaskResult as a2, RuntimeConfig as a3, SerializedCoverageConfig as a4, SnapshotData as a5, SnapshotMatchOptions as a6, SnapshotResult as a7, SnapshotSerializer as a8, SnapshotStateOptions as a9, SequenceHooks as aC, SequenceSetupFiles as aD, PromisifyAssertion as aF, Tester as aG, FileSpecification as aH, SnapshotEnvironment as aI, SnapshotEnvironmentOptions as aJ, SerializableRetry as aK, AsyncLeak as aL, BrowserTraceViewMode as aM, FetchCachedFileSystemResult as aN, ResolveFunctionResult as aO, SnapshotSummary as aa, SnapshotUpdateState as ab, SuiteFactory as ac, SuiteOptions as ad, TaskCustomOptions as ae, TaskMeta as af, TaskState as ag, TestAnnotationArtifact as ah, TestArtifactBase as ai, TestArtifactLocation as aj, TestArtifactRegistry as ak, TestAttachment as al, TestBenchmark as am, TestBenchmarkTask as an, TestFunction as ao, TestOptions as ap, TestTagDefinition as aq, TestTags as ar, UncheckedSnapshot as as, VisualRegressionArtifact as at, TaskResultPack as b, TaskEventPack as c, Test as d, TaskPopulated as e, MatcherState as f, SyncExpectationResult as g, ExpectationResult as h, TestAPI as i, SuiteCollector as j, SuiteAPI as k, Suite as l, SuiteHooks as m, SerializedConfig as n, VitestRunnerImportSource as o, Task as p, CancelReason as q, TestTryOptions as r, TestContext as s, AfterSuiteRunMeta as u, Assertion as v, AsymmetricMatchersContaining as w, Bench as x, BenchFnOptions as y, BenchFromSource as z };
3765
+ export { createChainable as J, afterAll as a$, afterEach as b0, aroundAll as b1, aroundEach as b2, beforeAll as b3, beforeEach as b4, onTestFailed as b5, onTestFinished as b6, disableDefaultColors as b9, SnapshotState as ba, _vitest_spy as bg, format as bi, inspect as bj, stringify as bk, fn as l, spyOn as s };
3766
+ export type { BenchRegistration as $, Awaitable as A, CancelReason as B, Config$1 as C, DomainSnapshotAdapter as D, ExpectStatic as E, File as F, TestTryOptions as G, TestContext as H, ImportDuration as I, AfterSuiteRunMeta as K, LabelColor as L, ModuleGraphData as M, Assertion as N, AsymmetricMatchersContaining as O, ProvidedContext as P, BaselineData as Q, RuntimeOptions as R, SerializedRootConfig as S, TestAnnotation as T, UserConsoleLog as U, VitestRunner as V, Bench as W, BenchFn as X, BenchFnOptions as Y, BenchFromSource as Z, BenchOptions as _, TestArtifact as a, BenchRegistrationInput as a0, BenchResult as a1, BenchRunOptions as a2, BenchStorage as a3, BenchmarkGroup as a4, BenchmarkProvider as a5, BrowserTraceArtifact as a6, DeeplyAllowMatchers as a7, DiffOptions as a8, DomainMatchResult as a9, SerializedError as aA, SnapshotData as aB, SnapshotMatchOptions as aC, SnapshotResult as aD, SnapshotSerializer as aE, SnapshotStateOptions as aF, SnapshotSummary as aG, SnapshotUpdateState as aH, SuiteFactory as aI, SuiteOptions as aJ, TaskCustomOptions as aK, TaskMeta as aL, TaskState as aM, TestAnnotationArtifact as aN, TestArtifactBase as aO, TestArtifactLocation as aP, TestArtifactRegistry as aQ, TestAttachment as aR, TestBenchmark as aS, TestBenchmarkTask as aT, TestError as aU, TestFunction as aV, TestOptions as aW, TestTagDefinition as aX, TestTags as aY, UncheckedSnapshot as aZ, VisualRegressionArtifact as a_, FailureScreenshotArtifact as aa, JestAssertion as ab, RawMatcherFn as ac, Matchers as ad, MatchersObject as ae, MockContext as af, MockResult as ag, MockResultIncomplete as ah, MockResultReturn as ai, MockResultThrow as aj, MockSettledResult as ak, MockSettledResultFulfilled as al, MockSettledResultIncomplete as am, MockSettledResultRejected as an, Mocked as ao, MockedClass as ap, MockedFunction as aq, MockedObject as ar, OnTestFailedHandler as as, OnTestFinishedHandler as at, ParsedStack as au, RunMode as av, TaskBase as aw, TaskResult as ax, RuntimeConfig as ay, SerializedCoverageConfig as az, TaskResultPack as b, SequenceHooks as b7, SequenceSetupFiles as b8, PromisifyAssertion as bb, Tester as bc, Plugin as bd, FileSpecification as be, SerializedDiffOptions as bf, StringifyOptions as bh, SnapshotEnvironment as bl, SnapshotEnvironmentOptions as bm, SerializableRetry as bn, BrowserTraceViewMode as bo, Arrayable as bp, ModuleType as bq, AsyncLeak as br, PrettyFormatOptions as bs, FetchCachedFileSystemResult as bt, ResolveFunctionResult as bu, TaskEventPack as c, Test as d, TaskPopulated as e, MatcherState as f, SyncExpectationResult as g, AsyncExpectationResult as h, ExpectationResult as i, Procedure as j, Mock as k, MaybeMockedDeep as m, MaybeMocked as n, MaybePartiallyMocked as o, MaybePartiallyMockedDeep as p, MockInstance as q, TestAPI as r, SuiteCollector as t, SuiteAPI as u, Suite as v, SuiteHooks as w, SerializedConfig as x, VitestRunnerImportSource as y, Task as z };