vitest 4.1.5 → 5.0.0-beta.2

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 (80) hide show
  1. package/LICENSE.md +7 -0
  2. package/dist/browser.d.ts +9 -9
  3. package/dist/browser.js +4 -4
  4. package/dist/chunks/{base.RR7zL1h0.js → base.Opc_YHkk.js} +10 -11
  5. package/dist/chunks/browser.d.BUhkKcDl.d.ts +899 -0
  6. package/dist/chunks/{cac.DJJmV0dT.js → cac.8N4bOkkB.js} +23 -11
  7. package/dist/chunks/{cli-api.Cjt90eJu.js → cli-api.B0RFke2g.js} +5799 -353
  8. package/dist/chunks/{config.d.A1h_Y6Jt.d.ts → config.d.D91DHYaD.d.ts} +11 -3
  9. package/dist/chunks/{console.3WNpx0tS.js → console.B3IRP8fX.js} +3 -1
  10. package/dist/chunks/{constants.CPYnjOGj.js → constants.-juJ8b_4.js} +1 -1
  11. package/dist/chunks/{coverage.d.BZtK59WP.d.ts → coverage.d.g2xbl2sP.d.ts} +4 -0
  12. package/dist/chunks/{creator.DgVhQm5q.js → creator.BqL2U_x4.js} +1 -1
  13. package/dist/chunks/{defaults.9aQKnqFk.js → defaults.szbHWQun.js} +4 -2
  14. package/dist/chunks/environment.d-DOJxxZV9.d.DOJxxZV9.d.ts +17 -0
  15. package/dist/chunks/general.d.DFAHgpC2.d.ts +247 -0
  16. package/dist/chunks/{global.d.DVsSRdQ5.d.ts → global.d.DhbKSQoV.d.ts} +4 -5
  17. package/dist/chunks/{globals.Dj1TGiMC.js → globals.EHmmu0nC.js} +15 -14
  18. package/dist/chunks/{index.DXx9Dtk7.js → index.CViWo__T.js} +5 -5
  19. package/dist/chunks/{startVitestModuleRunner.bRl2_oI_.js → index.CbgUM9E5.js} +731 -5
  20. package/dist/chunks/{test.DNmyFkvJ.js → index.D_7-4CaB.js} +2659 -14
  21. package/dist/chunks/{init-forks.UV3ZQGQH.js → init-forks.DMge3WTt.js} +1 -1
  22. package/dist/chunks/{init-threads.D3eCsY76.js → init-threads.eIoyCTon.js} +1 -1
  23. package/dist/chunks/{init.D98-gwRW.js → init.BVd7SaCA.js} +3 -5
  24. package/dist/chunks/{nativeModuleMocker.BRN2oBJd.js → nativeModuleMocker.DKpFw0pk.js} +3 -2
  25. package/dist/chunks/{index.BCY_7LL2.js → nativeModuleRunner.BOeMnHl4.js} +43 -12
  26. package/dist/chunks/node.CwFbQqI1.js +47 -0
  27. package/dist/chunks/{reporters.d.CEnv6XRv.d.ts → plugin.d.cIKZEZ16.d.ts} +306 -19
  28. package/dist/chunks/plugins.DrsmdUE2.js +37 -0
  29. package/dist/chunks/{rpc.MzXet3jl.js → rpc.DFRWVnRh.js} +16 -1
  30. package/dist/chunks/{rpc.d.B_8sPU0w.d.ts → rpc.d.7JZuxZ8u.d.ts} +19 -3
  31. package/dist/chunks/{setup-common.DYx3LtFI.js → setup-common.Hpq30zVk.js} +7 -3
  32. package/dist/chunks/{utils.BS4fH3nR.js → utils.DKODp04v.js} +3 -4
  33. package/dist/chunks/{vm.DVLYObm9.js → vm.2okbRRME.js} +6 -6
  34. package/dist/chunks/{worker.d.ZpHpO4yb.d.ts → worker.d.Bu1kXGw4.d.ts} +3 -3
  35. package/dist/cli.js +2 -2
  36. package/dist/config.cjs +4 -2
  37. package/dist/config.d.ts +21 -18
  38. package/dist/config.js +2 -2
  39. package/dist/index.d.ts +84 -22
  40. package/dist/index.js +15 -13
  41. package/dist/module-evaluator.d.ts +5 -3
  42. package/dist/module-evaluator.js +1 -1
  43. package/dist/node.d.ts +114 -19
  44. package/dist/node.js +21 -26
  45. package/dist/runtime.d.ts +40 -4
  46. package/dist/runtime.js +5 -6
  47. package/dist/{chunks/traces.DT5aQ62U.js → traces.js} +1 -1
  48. package/dist/worker.d.ts +5 -5
  49. package/dist/worker.js +21 -23
  50. package/dist/workers/forks.js +21 -23
  51. package/dist/workers/runVmTests.js +17 -16
  52. package/dist/workers/threads.js +21 -23
  53. package/dist/workers/vmForks.js +7 -9
  54. package/dist/workers/vmThreads.js +7 -9
  55. package/package.json +21 -38
  56. package/dist/chunks/benchmark.CX_oY03V.js +0 -40
  57. package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +0 -24
  58. package/dist/chunks/browser.d.BcoexmFG.d.ts +0 -62
  59. package/dist/chunks/coverage.DM_a_rWm.js +0 -1087
  60. package/dist/chunks/evaluatedModules.Dg1zASAC.js +0 -17
  61. package/dist/chunks/index.DC7d2Pf8.js +0 -729
  62. package/dist/chunks/index.DdgEv5B1.js +0 -42
  63. package/dist/chunks/index.UpGiHP7g.js +0 -4255
  64. package/dist/chunks/nativeModuleRunner.BIakptoF.js +0 -36
  65. package/dist/chunks/node.COQbm6gK.js +0 -14
  66. package/dist/chunks/plugin.d.BM2TCi12.d.ts +0 -38
  67. package/dist/chunks/suite.d.udJtyAgw.d.ts +0 -10
  68. package/dist/chunks/traces.d.D2T_R8rx.d.ts +0 -60
  69. package/dist/coverage.d.ts +0 -123
  70. package/dist/coverage.js +0 -27
  71. package/dist/environments.d.ts +0 -22
  72. package/dist/environments.js +0 -5
  73. package/dist/reporters.d.ts +0 -27
  74. package/dist/reporters.js +0 -26
  75. package/dist/runners.d.ts +0 -70
  76. package/dist/runners.js +0 -19
  77. package/dist/snapshot.d.ts +0 -9
  78. package/dist/snapshot.js +0 -6
  79. package/dist/suite.d.ts +0 -5
  80. package/dist/suite.js +0 -8
@@ -0,0 +1,899 @@
1
+ import { MockInstance } from '@vitest/spy';
2
+ import { Formatter } from 'tinyrainbow';
3
+ import { diff, printDiffOrStringify } from '@vitest/utils/diff';
4
+ import { stringify } from '@vitest/utils/display';
5
+ import { Test, FileSpecification } from '@vitest/runner';
6
+ import { ChainableFunction } from '@vitest/runner/utils';
7
+ import { TaskResult, Bench, Options } from 'tinybench';
8
+ import { O as OTELCarrier } from './rpc.d.7JZuxZ8u.js';
9
+ import { T as TestExecutionMethod } from './worker.d.Bu1kXGw4.js';
10
+
11
+ type SerializedTestSpecification = [project: {
12
+ name: string | undefined;
13
+ root: string;
14
+ }, file: string, options: {
15
+ pool: string;
16
+ testLines?: number[] | undefined;
17
+ testIds?: string[] | undefined;
18
+ testNamePattern?: RegExp | undefined;
19
+ testTagsFilter?: string[] | undefined;
20
+ }];
21
+
22
+ interface ModuleDefinitionLocation {
23
+ line: number;
24
+ column: number;
25
+ }
26
+ interface SourceModuleLocations {
27
+ modules: ModuleDefinitionDiagnostic[];
28
+ untracked: ModuleDefinitionDiagnostic[];
29
+ }
30
+ interface ModuleDefinitionDiagnostic {
31
+ start: ModuleDefinitionLocation;
32
+ end: ModuleDefinitionLocation;
33
+ startIndex: number;
34
+ endIndex: number;
35
+ rawUrl: string;
36
+ resolvedUrl: string;
37
+ resolvedId: string;
38
+ }
39
+ interface ModuleDefinitionDurationsDiagnostic extends ModuleDefinitionDiagnostic {
40
+ selfTime: number;
41
+ totalTime: number;
42
+ transformTime?: number;
43
+ external?: boolean;
44
+ importer?: string;
45
+ }
46
+ interface UntrackedModuleDefinitionDiagnostic {
47
+ url: string;
48
+ resolvedId: string;
49
+ resolvedUrl: string;
50
+ selfTime: number;
51
+ totalTime: number;
52
+ transformTime?: number;
53
+ external?: boolean;
54
+ importer?: string;
55
+ }
56
+ interface SourceModuleDiagnostic {
57
+ modules: ModuleDefinitionDurationsDiagnostic[];
58
+ untrackedModules: UntrackedModuleDefinitionDiagnostic[];
59
+ }
60
+
61
+ interface AsymmetricMatcherInterface {
62
+ asymmetricMatch: (other: unknown, customTesters?: Array<Tester>) => boolean;
63
+ toString: () => string;
64
+ getExpectedType?: () => string;
65
+ toAsymmetricMatcher?: () => string;
66
+ }
67
+ declare abstract class AsymmetricMatcher<
68
+ T,
69
+ State extends MatcherState = MatcherState
70
+ > implements AsymmetricMatcherInterface {
71
+ protected sample: T;
72
+ protected inverse: boolean;
73
+ $$typeof: symbol;
74
+ constructor(sample: T, inverse?: boolean);
75
+ protected getMatcherContext(expect?: Chai.ExpectStatic): State;
76
+ abstract asymmetricMatch(other: unknown, customTesters?: Array<Tester>): boolean;
77
+ abstract toString(): string;
78
+ getExpectedType?(): string;
79
+ toAsymmetricMatcher?(): string;
80
+ }
81
+
82
+ declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
83
+ declare function printReceived(object: unknown): string;
84
+ declare function printExpected(value: unknown): string;
85
+ declare function getMatcherUtils(): {
86
+ EXPECTED_COLOR: Formatter;
87
+ RECEIVED_COLOR: Formatter;
88
+ INVERTED_COLOR: Formatter;
89
+ BOLD_WEIGHT: Formatter;
90
+ DIM_COLOR: Formatter;
91
+ diff: typeof diff;
92
+ matcherHint: typeof matcherHint;
93
+ printReceived: typeof printReceived;
94
+ printExpected: typeof printExpected;
95
+ printDiffOrStringify: typeof printDiffOrStringify;
96
+ printWithType: typeof printWithType;
97
+ };
98
+ declare function printWithType<T>(name: string, value: T, print: (value: T) => string): string;
99
+ type Tester = (this: TesterContext, a: any, b: any, customTesters: Array<Tester>) => boolean | undefined;
100
+ interface TesterContext {
101
+ equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
102
+ }
103
+
104
+ interface MatcherHintOptions {
105
+ comment?: string;
106
+ expectedColor?: Formatter;
107
+ isDirectExpectCall?: boolean;
108
+ isNot?: boolean;
109
+ promise?: string;
110
+ receivedColor?: Formatter;
111
+ secondArgument?: string;
112
+ secondArgumentColor?: Formatter;
113
+ }
114
+ interface MatcherState {
115
+ customTesters: Array<Tester>;
116
+ assertionCalls: number;
117
+ currentTestName?: string;
118
+ /**
119
+ * @deprecated exists only in types
120
+ */
121
+ dontThrow?: () => void;
122
+ /**
123
+ * @deprecated exists only in types
124
+ */
125
+ error?: Error;
126
+ equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
127
+ /**
128
+ * @deprecated exists only in types
129
+ */
130
+ expand?: boolean;
131
+ expectedAssertionsNumber?: number | null;
132
+ expectedAssertionsNumberErrorGen?: (() => Error) | null;
133
+ isExpectingAssertions?: boolean;
134
+ isExpectingAssertionsError?: Error | null;
135
+ isNot: boolean;
136
+ promise: string;
137
+ /**
138
+ * @deprecated exists only in types
139
+ */
140
+ suppressedErrors: Array<Error>;
141
+ testPath?: string;
142
+ utils: ReturnType<typeof getMatcherUtils> & {
143
+ diff: typeof diff;
144
+ stringify: typeof stringify;
145
+ iterableEquality: Tester;
146
+ subsetEquality: Tester;
147
+ };
148
+ soft?: boolean;
149
+ poll?: boolean;
150
+ /**
151
+ * The same assertion instance that chai plugins receive.
152
+ * @experimental
153
+ * @see {@link https://www.chaijs.com/guide/plugins/} Core Plugin Concepts
154
+ */
155
+ readonly assertion: Assertion;
156
+ }
157
+ interface SyncExpectationResult {
158
+ pass: boolean;
159
+ message: () => string;
160
+ actual?: any;
161
+ expected?: any;
162
+ meta?: object;
163
+ }
164
+ type AsyncExpectationResult = Promise<SyncExpectationResult>;
165
+ type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
166
+ interface RawMatcherFn<
167
+ T extends MatcherState = MatcherState,
168
+ E extends Array<any> = Array<any>
169
+ > {
170
+ (this: T, received: any, ...expected: E): ExpectationResult;
171
+ }
172
+ interface Matchers<T = any> {}
173
+ type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>> & ThisType<T> & { [K in keyof Matchers<T>]? : RawMatcherFn<T, Parameters<Matchers<T>[K]>> };
174
+ interface ExpectStatic extends Chai.ExpectStatic, Matchers, AsymmetricMatchersContaining {
175
+ <T>(actual: T, message?: string): Assertion<T>;
176
+ extend: (expects: MatchersObject) => void;
177
+ anything: () => any;
178
+ any: (constructor: unknown) => any;
179
+ getState: () => MatcherState;
180
+ setState: (state: Partial<MatcherState>) => void;
181
+ not: AsymmetricMatchersContaining;
182
+ }
183
+ interface CustomMatcher {
184
+ /**
185
+ * Checks that a value satisfies a custom matcher function.
186
+ *
187
+ * @param matcher - A function returning a boolean based on the custom condition
188
+ * @param message - Optional custom error message on failure
189
+ *
190
+ * @example
191
+ * expect(age).toSatisfy(val => val >= 18, 'Age must be at least 18');
192
+ * expect(age).toEqual(expect.toSatisfy(val => val >= 18, 'Age must be at least 18'));
193
+ */
194
+ toSatisfy: (matcher: (value: any) => boolean, message?: string) => any;
195
+ /**
196
+ * Matches if the received value is one of the values in the expected array or set.
197
+ *
198
+ * @example
199
+ * expect(1).toBeOneOf([1, 2, 3])
200
+ * expect('foo').toBeOneOf([expect.any(String)])
201
+ * expect({ a: 1 }).toEqual({ a: expect.toBeOneOf(['1', '2', '3']) })
202
+ */
203
+ toBeOneOf: <T>(sample: Array<T> | Set<T>) => any;
204
+ }
205
+ interface AsymmetricMatchersContaining extends CustomMatcher {
206
+ /**
207
+ * Matches if the received string contains the expected substring.
208
+ *
209
+ * @example
210
+ * expect('I have an apple').toEqual(expect.stringContaining('apple'));
211
+ * expect({ a: 'test string' }).toEqual({ a: expect.stringContaining('test') });
212
+ */
213
+ stringContaining: (expected: string) => any;
214
+ /**
215
+ * Matches if the received object contains all properties of the expected object.
216
+ *
217
+ * @example
218
+ * expect({ a: '1', b: 2 }).toEqual(expect.objectContaining({ a: '1' }))
219
+ */
220
+ objectContaining: <T = any>(expected: DeeplyAllowMatchers<T>) => any;
221
+ /**
222
+ * Matches if the received array contains all elements in the expected array.
223
+ *
224
+ * @example
225
+ * expect(['a', 'b', 'c']).toEqual(expect.arrayContaining(['b', 'a']));
226
+ */
227
+ arrayContaining: <T = unknown>(expected: Array<DeeplyAllowMatchers<T>>) => any;
228
+ /**
229
+ * Matches if the received string or regex matches the expected pattern.
230
+ *
231
+ * @example
232
+ * expect('hello world').toEqual(expect.stringMatching(/^hello/));
233
+ * expect('hello world').toEqual(expect.stringMatching('hello'));
234
+ */
235
+ stringMatching: (expected: string | RegExp) => any;
236
+ /**
237
+ * Matches if the received number is within a certain precision of the expected number.
238
+ *
239
+ * @example
240
+ * expect(10.45).toEqual(expect.closeTo(10.5, 1));
241
+ * expect(5.11).toEqual(expect.closeTo(5.12)); // with default precision
242
+ */
243
+ closeTo: (expected: number, precision?: number) => any;
244
+ /**
245
+ * Matches if the received value validates against a Standard Schema.
246
+ *
247
+ * @param schema - A Standard Schema V1 compatible schema object
248
+ *
249
+ * @example
250
+ * expect(user).toEqual(expect.schemaMatching(z.object({ name: z.string() })))
251
+ * expect(['hello', 'world']).toEqual([expect.schemaMatching(z.string()), expect.schemaMatching(z.string())])
252
+ */
253
+ schemaMatching: (schema: unknown) => any;
254
+ }
255
+ type WithAsymmetricMatcher<T> = T | AsymmetricMatcher<unknown>;
256
+ type DeeplyAllowMatchers<T> = T extends Array<infer Element> ? WithAsymmetricMatcher<T> | DeeplyAllowMatchers<Element>[] : T extends object ? WithAsymmetricMatcher<T> | { [K in keyof T] : DeeplyAllowMatchers<T[K]> } : WithAsymmetricMatcher<T>;
257
+ interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomMatcher {
258
+ /**
259
+ * Used when you want to check that two objects have the same value.
260
+ * This matcher recursively checks the equality of all fields, rather than checking for object identity.
261
+ *
262
+ * @example
263
+ * expect(user).toEqual({ name: 'Alice', age: 30 });
264
+ */
265
+ toEqual: <E>(expected: E) => void;
266
+ /**
267
+ * Use to test that objects have the same types as well as structure.
268
+ *
269
+ * @example
270
+ * expect(user).toStrictEqual({ name: 'Alice', age: 30 });
271
+ */
272
+ toStrictEqual: <E>(expected: E) => void;
273
+ /**
274
+ * Checks that a value is what you expect. It calls `Object.is` to compare values.
275
+ * Don't use `toBe` with floating-point numbers.
276
+ *
277
+ * @example
278
+ * expect(result).toBe(42);
279
+ * expect(status).toBe(true);
280
+ */
281
+ toBe: <E>(expected: E) => void;
282
+ /**
283
+ * Check that a string matches a regular expression.
284
+ *
285
+ * @example
286
+ * expect(message).toMatch(/hello/);
287
+ * expect(greeting).toMatch('world');
288
+ */
289
+ toMatch: (expected: string | RegExp) => void;
290
+ /**
291
+ * Used to check that a JavaScript object matches a subset of the properties of an object
292
+ *
293
+ * @example
294
+ * expect(user).toMatchObject({
295
+ * name: 'Alice',
296
+ * address: { city: 'Wonderland' }
297
+ * });
298
+ */
299
+ toMatchObject: <E extends object | any[]>(expected: E) => void;
300
+ /**
301
+ * Used when you want to check that an item is in a list.
302
+ * For testing the items in the list, this uses `===`, a strict equality check.
303
+ *
304
+ * @example
305
+ * expect(items).toContain('apple');
306
+ * expect(numbers).toContain(5);
307
+ */
308
+ toContain: <E>(item: E) => void;
309
+ /**
310
+ * Used when you want to check that an item is in a list.
311
+ * For testing the items in the list, this matcher recursively checks the
312
+ * equality of all fields, rather than checking for object identity.
313
+ *
314
+ * @example
315
+ * expect(items).toContainEqual({ name: 'apple', quantity: 1 });
316
+ */
317
+ toContainEqual: <E>(item: E) => void;
318
+ /**
319
+ * Use when you don't care what a value is, you just want to ensure a value
320
+ * is true in a boolean context. In JavaScript, there are six falsy values:
321
+ * `false`, `0`, `''`, `null`, `undefined`, and `NaN`. Everything else is truthy.
322
+ *
323
+ * @example
324
+ * expect(user.isActive).toBeTruthy();
325
+ */
326
+ toBeTruthy: () => void;
327
+ /**
328
+ * When you don't care what a value is, you just want to
329
+ * ensure a value is false in a boolean context.
330
+ *
331
+ * @example
332
+ * expect(user.isActive).toBeFalsy();
333
+ */
334
+ toBeFalsy: () => void;
335
+ /**
336
+ * For comparing floating point numbers.
337
+ *
338
+ * @example
339
+ * expect(score).toBeGreaterThan(10);
340
+ */
341
+ toBeGreaterThan: (num: number | bigint) => void;
342
+ /**
343
+ * For comparing floating point numbers.
344
+ *
345
+ * @example
346
+ * expect(score).toBeGreaterThanOrEqual(10);
347
+ */
348
+ toBeGreaterThanOrEqual: (num: number | bigint) => void;
349
+ /**
350
+ * For comparing floating point numbers.
351
+ *
352
+ * @example
353
+ * expect(score).toBeLessThan(10);
354
+ */
355
+ toBeLessThan: (num: number | bigint) => void;
356
+ /**
357
+ * For comparing floating point numbers.
358
+ *
359
+ * @example
360
+ * expect(score).toBeLessThanOrEqual(10);
361
+ */
362
+ toBeLessThanOrEqual: (num: number | bigint) => void;
363
+ /**
364
+ * Used to check that a variable is NaN.
365
+ *
366
+ * @example
367
+ * expect(value).toBeNaN();
368
+ */
369
+ toBeNaN: () => void;
370
+ /**
371
+ * Used to check that a variable is undefined.
372
+ *
373
+ * @example
374
+ * expect(value).toBeUndefined();
375
+ */
376
+ toBeUndefined: () => void;
377
+ /**
378
+ * This is the same as `.toBe(null)` but the error messages are a bit nicer.
379
+ * So use `.toBeNull()` when you want to check that something is null.
380
+ *
381
+ * @example
382
+ * expect(value).toBeNull();
383
+ */
384
+ toBeNull: () => void;
385
+ /**
386
+ * Used to check that a variable is nullable (null or undefined).
387
+ *
388
+ * @example
389
+ * expect(value).toBeNullable();
390
+ */
391
+ toBeNullable: () => void;
392
+ /**
393
+ * Ensure that a variable is not undefined.
394
+ *
395
+ * @example
396
+ * expect(value).toBeDefined();
397
+ */
398
+ toBeDefined: () => void;
399
+ /**
400
+ * Ensure that an object is an instance of a class.
401
+ * This matcher uses `instanceof` underneath.
402
+ *
403
+ * @example
404
+ * expect(new Date()).toBeInstanceOf(Date);
405
+ */
406
+ toBeInstanceOf: <E>(expected: E) => void;
407
+ /**
408
+ * Used to check that an object has a `.length` property
409
+ * and it is set to a certain numeric value.
410
+ *
411
+ * @example
412
+ * expect([1, 2, 3]).toHaveLength(3);
413
+ * expect('hello').toHaveLength(5);
414
+ */
415
+ toHaveLength: (length: number) => void;
416
+ /**
417
+ * Use to check if a property at the specified path exists on an object.
418
+ * For checking deeply nested properties, you may use dot notation or an array containing
419
+ * the path segments for deep references.
420
+ *
421
+ * Optionally, you can provide a value to check if it matches the value present at the path
422
+ * on the target object. This matcher uses 'deep equality' (like `toEqual()`) and recursively checks
423
+ * the equality of all fields.
424
+ *
425
+ * @example
426
+ * expect(user).toHaveProperty('address.city', 'New York');
427
+ * expect(config).toHaveProperty(['settings', 'theme'], 'dark');
428
+ */
429
+ toHaveProperty: <E>(property: string | (string | number)[], value?: E) => void;
430
+ /**
431
+ * Using exact equality with floating point numbers is a bad idea.
432
+ * Rounding means that intuitive things fail.
433
+ * The default for `numDigits` is 2.
434
+ *
435
+ * @example
436
+ * expect(price).toBeCloseTo(9.99, 2);
437
+ */
438
+ toBeCloseTo: (number: number, numDigits?: number) => void;
439
+ /**
440
+ * Ensures that a mock function is called an exact number of times.
441
+ *
442
+ * Also under the alias `expect.toBeCalledTimes`.
443
+ *
444
+ * @example
445
+ * expect(mockFunc).toHaveBeenCalledTimes(2);
446
+ */
447
+ toHaveBeenCalledTimes: (times: number) => void;
448
+ /**
449
+ * Ensures that a mock function is called an exact number of times.
450
+ *
451
+ * Alias for `expect.toHaveBeenCalledTimes`.
452
+ *
453
+ * @example
454
+ * expect(mockFunc).toBeCalledTimes(2);
455
+ * @deprecated Use `toHaveBeenCalledTimes` instead
456
+ */
457
+ toBeCalledTimes: (times: number) => void;
458
+ /**
459
+ * Ensures that a mock function is called.
460
+ *
461
+ * Also under the alias `expect.toBeCalled`.
462
+ *
463
+ * @example
464
+ * expect(mockFunc).toHaveBeenCalled();
465
+ */
466
+ toHaveBeenCalled: () => void;
467
+ /**
468
+ * Ensures that a mock function is called.
469
+ *
470
+ * Alias for `expect.toHaveBeenCalled`.
471
+ *
472
+ * @example
473
+ * expect(mockFunc).toBeCalled();
474
+ * @deprecated Use `toHaveBeenCalled` instead
475
+ */
476
+ toBeCalled: () => void;
477
+ /**
478
+ * Ensure that a mock function is called with specific arguments.
479
+ *
480
+ * Also under the alias `expect.toBeCalledWith`.
481
+ *
482
+ * @example
483
+ * expect(mockFunc).toHaveBeenCalledWith('arg1', 42);
484
+ */
485
+ toHaveBeenCalledWith: <E extends any[]>(...args: E) => void;
486
+ /**
487
+ * Ensure that a mock function is called with specific arguments.
488
+ *
489
+ * Alias for `expect.toHaveBeenCalledWith`.
490
+ *
491
+ * @example
492
+ * expect(mockFunc).toBeCalledWith('arg1', 42);
493
+ * @deprecated Use `toHaveBeenCalledWith` instead
494
+ */
495
+ toBeCalledWith: <E extends any[]>(...args: E) => void;
496
+ /**
497
+ * Ensure that a mock function is called with specific arguments on an Nth call.
498
+ *
499
+ * Also under the alias `expect.nthCalledWith`.
500
+ *
501
+ * @example
502
+ * expect(mockFunc).toHaveBeenNthCalledWith(2, 'secondArg');
503
+ */
504
+ toHaveBeenNthCalledWith: <E extends any[]>(n: number, ...args: E) => void;
505
+ /**
506
+ * If you have a mock function, you can use `.toHaveBeenLastCalledWith`
507
+ * to test what arguments it was last called with.
508
+ *
509
+ * Also under the alias `expect.lastCalledWith`.
510
+ *
511
+ * @example
512
+ * expect(mockFunc).toHaveBeenLastCalledWith('lastArg');
513
+ */
514
+ toHaveBeenLastCalledWith: <E extends any[]>(...args: E) => void;
515
+ /**
516
+ * Used to test that a function throws when it is called.
517
+ *
518
+ * Also under the alias `expect.toThrowError`.
519
+ *
520
+ * @example
521
+ * expect(() => functionWithError()).toThrow('Error message');
522
+ * expect(() => parseJSON('invalid')).toThrow(SyntaxError);
523
+ * expect(() => { throw 42 }).toThrow(42);
524
+ */
525
+ toThrow: (expected?: any) => void;
526
+ /**
527
+ * Used to test that a function throws when it is called.
528
+ *
529
+ * Alias for `expect.toThrow`.
530
+ *
531
+ * @example
532
+ * expect(() => functionWithError()).toThrowError('Error message');
533
+ * expect(() => parseJSON('invalid')).toThrowError(SyntaxError);
534
+ * expect(() => { throw 42 }).toThrowError(42);
535
+ * @deprecated Use `toThrow` instead
536
+ */
537
+ toThrowError: (expected?: any) => void;
538
+ /**
539
+ * Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
540
+ *
541
+ * Alias for `expect.toHaveReturned`.
542
+ *
543
+ * @example
544
+ * expect(mockFunc).toReturn();
545
+ * @deprecated Use `toHaveReturned` instead
546
+ */
547
+ toReturn: () => void;
548
+ /**
549
+ * Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
550
+ *
551
+ * Also under the alias `expect.toReturn`.
552
+ *
553
+ * @example
554
+ * expect(mockFunc).toHaveReturned();
555
+ */
556
+ toHaveReturned: () => void;
557
+ /**
558
+ * Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
559
+ * Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
560
+ *
561
+ * Alias for `expect.toHaveReturnedTimes`.
562
+ *
563
+ * @example
564
+ * expect(mockFunc).toReturnTimes(3);
565
+ * @deprecated Use `toHaveReturnedTimes` instead
566
+ */
567
+ toReturnTimes: (times: number) => void;
568
+ /**
569
+ * Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
570
+ * Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
571
+ *
572
+ * Also under the alias `expect.toReturnTimes`.
573
+ *
574
+ * @example
575
+ * expect(mockFunc).toHaveReturnedTimes(3);
576
+ */
577
+ toHaveReturnedTimes: (times: number) => void;
578
+ /**
579
+ * Use to ensure that a mock function returned a specific value.
580
+ *
581
+ * Alias for `expect.toHaveReturnedWith`.
582
+ *
583
+ * @example
584
+ * expect(mockFunc).toReturnWith('returnValue');
585
+ * @deprecated Use `toHaveReturnedWith` instead
586
+ */
587
+ toReturnWith: <E>(value: E) => void;
588
+ /**
589
+ * Use to ensure that a mock function returned a specific value.
590
+ *
591
+ * Also under the alias `expect.toReturnWith`.
592
+ *
593
+ * @example
594
+ * expect(mockFunc).toHaveReturnedWith('returnValue');
595
+ */
596
+ toHaveReturnedWith: <E>(value: E) => void;
597
+ /**
598
+ * Use to test the specific value that a mock function last returned.
599
+ * If the last call to the mock function threw an error, then this matcher will fail
600
+ * no matter what value you provided as the expected return value.
601
+ *
602
+ * Also under the alias `expect.lastReturnedWith`.
603
+ *
604
+ * @example
605
+ * expect(mockFunc).toHaveLastReturnedWith('lastValue');
606
+ */
607
+ toHaveLastReturnedWith: <E>(value: E) => void;
608
+ /**
609
+ * Use to test the specific value that a mock function returned for the nth call.
610
+ * If the nth call to the mock function threw an error, then this matcher will fail
611
+ * no matter what value you provided as the expected return value.
612
+ *
613
+ * Also under the alias `expect.nthReturnedWith`.
614
+ *
615
+ * @example
616
+ * expect(mockFunc).toHaveNthReturnedWith(2, 'nthValue');
617
+ */
618
+ toHaveNthReturnedWith: <E>(nthCall: number, value: E) => void;
619
+ }
620
+ type VitestAssertion<
621
+ A,
622
+ T
623
+ > = { [K in keyof A] : A[K] extends Chai.Assertion ? Assertion<T> : A[K] extends (...args: any[]) => any ? A[K] : VitestAssertion<A[K], T> } & ((type: string, message?: string) => Assertion);
624
+ type Promisify<O> = { [K in keyof O] : O[K] extends (...args: infer A) => infer R ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K] };
625
+ type PromisifyAssertion<T> = Promisify<Assertion<T>>;
626
+ interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T>, ChaiMockAssertion, Matchers<T> {
627
+ /**
628
+ * Ensures a value is of a specific type.
629
+ *
630
+ * @example
631
+ * expect(value).toBeTypeOf('string');
632
+ * expect(number).toBeTypeOf('number');
633
+ */
634
+ toBeTypeOf: (expected: "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined") => void;
635
+ /**
636
+ * Asserts that a mock function was called exactly once.
637
+ *
638
+ * @example
639
+ * expect(mockFunc).toHaveBeenCalledOnce();
640
+ */
641
+ toHaveBeenCalledOnce: () => void;
642
+ /**
643
+ * Ensure that a mock function is called with specific arguments and called
644
+ * exactly once.
645
+ *
646
+ * @example
647
+ * expect(mockFunc).toHaveBeenCalledExactlyOnceWith('arg1', 42);
648
+ */
649
+ toHaveBeenCalledExactlyOnceWith: <E extends any[]>(...args: E) => void;
650
+ /**
651
+ * This assertion checks if a `Mock` was called before another `Mock`.
652
+ * @param mock - A mock function created by `vi.spyOn` or `vi.fn`
653
+ * @param failIfNoFirstInvocation - Fail if the first mock was never called
654
+ * @example
655
+ * const mock1 = vi.fn()
656
+ * const mock2 = vi.fn()
657
+ *
658
+ * mock1()
659
+ * mock2()
660
+ * mock1()
661
+ *
662
+ * expect(mock1).toHaveBeenCalledBefore(mock2)
663
+ */
664
+ toHaveBeenCalledBefore: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
665
+ /**
666
+ * This assertion checks if a `Mock` was called after another `Mock`.
667
+ * @param mock - A mock function created by `vi.spyOn` or `vi.fn`
668
+ * @param failIfNoFirstInvocation - Fail if the first mock was never called
669
+ * @example
670
+ * const mock1 = vi.fn()
671
+ * const mock2 = vi.fn()
672
+ *
673
+ * mock2()
674
+ * mock1()
675
+ * mock2()
676
+ *
677
+ * expect(mock1).toHaveBeenCalledAfter(mock2)
678
+ */
679
+ toHaveBeenCalledAfter: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
680
+ /**
681
+ * Checks that a promise resolves successfully at least once.
682
+ *
683
+ * @example
684
+ * await expect(promise).toHaveResolved();
685
+ */
686
+ toHaveResolved: () => void;
687
+ /**
688
+ * Checks that a promise resolves to a specific value.
689
+ *
690
+ * @example
691
+ * await expect(promise).toHaveResolvedWith('success');
692
+ */
693
+ toHaveResolvedWith: <E>(value: E) => void;
694
+ /**
695
+ * Ensures a promise resolves a specific number of times.
696
+ *
697
+ * @example
698
+ * expect(mockAsyncFunc).toHaveResolvedTimes(3);
699
+ */
700
+ toHaveResolvedTimes: (times: number) => void;
701
+ /**
702
+ * Asserts that the last resolved value of a promise matches an expected value.
703
+ *
704
+ * @example
705
+ * await expect(mockAsyncFunc).toHaveLastResolvedWith('finalResult');
706
+ */
707
+ toHaveLastResolvedWith: <E>(value: E) => void;
708
+ /**
709
+ * Ensures a specific value was returned by a promise on the nth resolution.
710
+ *
711
+ * @example
712
+ * await expect(mockAsyncFunc).toHaveNthResolvedWith(2, 'secondResult');
713
+ */
714
+ toHaveNthResolvedWith: <E>(nthCall: number, value: E) => void;
715
+ /**
716
+ * Verifies that a promise resolves.
717
+ *
718
+ * @example
719
+ * await expect(someAsyncFunc).resolves.toBe(42);
720
+ */
721
+ resolves: PromisifyAssertion<T>;
722
+ /**
723
+ * Verifies that a promise rejects.
724
+ *
725
+ * @example
726
+ * await expect(someAsyncFunc).rejects.toThrow('error');
727
+ */
728
+ rejects: PromisifyAssertion<T>;
729
+ }
730
+ /**
731
+ * Chai-style assertions for spy/mock testing.
732
+ * These provide sinon-chai compatible assertion names that delegate to Jest-style implementations.
733
+ */
734
+ interface ChaiMockAssertion {
735
+ /**
736
+ * Checks that a spy was called at least once.
737
+ * Chai-style equivalent of `toHaveBeenCalled`.
738
+ *
739
+ * @example
740
+ * expect(spy).to.have.been.called
741
+ */
742
+ readonly called: Assertion;
743
+ /**
744
+ * Checks that a spy was called a specific number of times.
745
+ * Chai-style equivalent of `toHaveBeenCalledTimes`.
746
+ *
747
+ * @example
748
+ * expect(spy).to.have.callCount(3)
749
+ */
750
+ callCount: (count: number) => void;
751
+ /**
752
+ * Checks that a spy was called with specific arguments at least once.
753
+ * Chai-style equivalent of `toHaveBeenCalledWith`.
754
+ *
755
+ * @example
756
+ * expect(spy).to.have.been.calledWith('arg1', 'arg2')
757
+ */
758
+ calledWith: <E extends any[]>(...args: E) => void;
759
+ /**
760
+ * Checks that a spy was called exactly once.
761
+ * Chai-style equivalent of `toHaveBeenCalledOnce`.
762
+ *
763
+ * @example
764
+ * expect(spy).to.have.been.calledOnce
765
+ */
766
+ readonly calledOnce: Assertion;
767
+ /**
768
+ * Checks that a spy was called exactly once with specific arguments.
769
+ * Chai-style equivalent of `toHaveBeenCalledExactlyOnceWith`.
770
+ *
771
+ * @example
772
+ * expect(spy).to.have.been.calledOnceWith('arg1', 'arg2')
773
+ */
774
+ calledOnceWith: <E extends any[]>(...args: E) => void;
775
+ /**
776
+ * Checks that the last call to a spy was made with specific arguments.
777
+ * Chai-style equivalent of `toHaveBeenLastCalledWith`.
778
+ *
779
+ * @example
780
+ * expect(spy).to.have.been.lastCalledWith('arg1', 'arg2')
781
+ */
782
+ lastCalledWith: <E extends any[]>(...args: E) => void;
783
+ /**
784
+ * Checks that the nth call to a spy was made with specific arguments.
785
+ * Chai-style equivalent of `toHaveBeenNthCalledWith`.
786
+ *
787
+ * @example
788
+ * expect(spy).to.have.been.nthCalledWith(2, 'arg1', 'arg2')
789
+ */
790
+ nthCalledWith: <E extends any[]>(n: number, ...args: E) => void;
791
+ /**
792
+ * Checks that a spy returned a specific value at least once.
793
+ * Chai-style equivalent of `toHaveReturnedWith`.
794
+ *
795
+ * @example
796
+ * expect(spy).to.have.returned('value')
797
+ */
798
+ returned: <E>(value: E) => void;
799
+ /**
800
+ * Checks that a spy returned a specific value at least once.
801
+ * Chai-style equivalent of `toHaveReturnedWith`.
802
+ *
803
+ * @example
804
+ * expect(spy).to.have.returnedWith('value')
805
+ */
806
+ returnedWith: <E>(value: E) => void;
807
+ /**
808
+ * Checks that a spy returned successfully a specific number of times.
809
+ * Chai-style equivalent of `toHaveReturnedTimes`.
810
+ *
811
+ * @example
812
+ * expect(spy).to.have.returnedTimes(3)
813
+ */
814
+ returnedTimes: (count: number) => void;
815
+ /**
816
+ * Checks that the last return value of a spy matches the expected value.
817
+ * Chai-style equivalent of `toHaveLastReturnedWith`.
818
+ *
819
+ * @example
820
+ * expect(spy).to.have.lastReturnedWith('value')
821
+ */
822
+ lastReturnedWith: <E>(value: E) => void;
823
+ /**
824
+ * Checks that the nth return value of a spy matches the expected value.
825
+ * Chai-style equivalent of `toHaveNthReturnedWith`.
826
+ *
827
+ * @example
828
+ * expect(spy).to.have.nthReturnedWith(2, 'value')
829
+ */
830
+ nthReturnedWith: <E>(n: number, value: E) => void;
831
+ /**
832
+ * Checks that a spy was called before another spy.
833
+ * Chai-style equivalent of `toHaveBeenCalledBefore`.
834
+ *
835
+ * @example
836
+ * expect(spy1).to.have.been.calledBefore(spy2)
837
+ */
838
+ calledBefore: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
839
+ /**
840
+ * Checks that a spy was called after another spy.
841
+ * Chai-style equivalent of `toHaveBeenCalledAfter`.
842
+ *
843
+ * @example
844
+ * expect(spy1).to.have.been.calledAfter(spy2)
845
+ */
846
+ calledAfter: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
847
+ /**
848
+ * Checks that a spy was called exactly twice.
849
+ * Chai-style equivalent of `toHaveBeenCalledTimes(2)`.
850
+ *
851
+ * @example
852
+ * expect(spy).to.have.been.calledTwice
853
+ */
854
+ readonly calledTwice: Assertion;
855
+ /**
856
+ * Checks that a spy was called exactly three times.
857
+ * Chai-style equivalent of `toHaveBeenCalledTimes(3)`.
858
+ *
859
+ * @example
860
+ * expect(spy).to.have.been.calledThrice
861
+ */
862
+ readonly calledThrice: Assertion;
863
+ }
864
+ declare global {
865
+ namespace jest {
866
+ interface Matchers<
867
+ R,
868
+ T = {}
869
+ > {}
870
+ }
871
+ }
872
+
873
+ interface Benchmark extends Test {
874
+ meta: {
875
+ benchmark: true;
876
+ result?: TaskResult;
877
+ };
878
+ }
879
+ interface BenchmarkResult extends TaskResult {
880
+ name: string;
881
+ rank: number;
882
+ sampleCount: number;
883
+ median: number;
884
+ }
885
+ type BenchFunction = (this: Bench) => Promise<void> | void;
886
+ type ChainableBenchmarkAPI = ChainableFunction<"skip" | "only" | "todo", (name: string | Function, fn?: BenchFunction, options?: Options) => void>;
887
+ type BenchmarkAPI = ChainableBenchmarkAPI & {
888
+ skipIf: (condition: any) => ChainableBenchmarkAPI;
889
+ runIf: (condition: any) => ChainableBenchmarkAPI;
890
+ };
891
+
892
+ interface BrowserTesterOptions {
893
+ method: TestExecutionMethod;
894
+ files: FileSpecification[];
895
+ providedContext: string;
896
+ otelCarrier?: OTELCarrier;
897
+ }
898
+
899
+ export type { AsyncExpectationResult as A, BenchFunction as B, DeeplyAllowMatchers as D, ExpectStatic as E, JestAssertion as J, ModuleDefinitionDurationsDiagnostic as M, PromisifyAssertion as P, RawMatcherFn as R, SerializedTestSpecification as S, Tester as T, UntrackedModuleDefinitionDiagnostic as U, MatcherState as a, SyncExpectationResult as b, ExpectationResult as c, BenchmarkAPI as d, ModuleDefinitionDiagnostic as e, ModuleDefinitionLocation as f, SourceModuleDiagnostic as g, SourceModuleLocations as h, Assertion as i, AsymmetricMatchersContaining as j, Benchmark as k, BenchmarkResult as l, BrowserTesterOptions as m, Matchers as n, MatchersObject as o };