vieval 0.0.1 → 0.0.4

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 (51) hide show
  1. package/README.md +8 -5
  2. package/dist/cli/index.d.mts +1 -1
  3. package/dist/cli/index.mjs +1232 -83
  4. package/dist/cli/index.mjs.map +1 -1
  5. package/dist/{config-D2fe1SnT.mjs → config-CHN24egi.mjs} +1 -1
  6. package/dist/{config-D2fe1SnT.mjs.map → config-CHN24egi.mjs.map} +1 -1
  7. package/dist/config.d.mts +2 -3
  8. package/dist/config.mjs +2 -2
  9. package/dist/core/assertions/index.d.mts +1 -1
  10. package/dist/core/inference-executors/index.d.mts +1 -45
  11. package/dist/core/inference-executors/index.mjs +1 -38
  12. package/dist/core/inference-executors/index.mjs.map +1 -1
  13. package/dist/core/processors/results/index.d.mts +1 -1
  14. package/dist/core/runner/index.d.mts +2 -2
  15. package/dist/core/runner/index.mjs +2 -2
  16. package/dist/env-C7X81PWa.mjs +41 -0
  17. package/dist/env-C7X81PWa.mjs.map +1 -0
  18. package/dist/env-DtpjACOW.d.mts +47 -0
  19. package/dist/expect-B2vaoRVZ.d.mts +10 -0
  20. package/dist/{expect-i9WZWGrA.mjs → expect-CaXiUkwY.mjs} +3 -3
  21. package/dist/expect-CaXiUkwY.mjs.map +1 -0
  22. package/dist/expect-extensions-BOzwV5EJ.mjs +197 -0
  23. package/dist/expect-extensions-BOzwV5EJ.mjs.map +1 -0
  24. package/dist/expect.d.mts +1 -1
  25. package/dist/expect.mjs +1 -1
  26. package/dist/{index-DP7jsORl.d.mts → index-BDMEAmf2.d.mts} +246 -3
  27. package/dist/{index-oSXhM1zx.d.mts → index-C3gPFmcR.d.mts} +2 -2
  28. package/dist/index.d.mts +326 -6
  29. package/dist/index.mjs +65 -23
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/{models-D_MsBtYw.mjs → models-DIGdOUpJ.mjs} +1 -1
  32. package/dist/{models-D_MsBtYw.mjs.map → models-DIGdOUpJ.mjs.map} +1 -1
  33. package/dist/plugins/chat-models/index.d.mts +465 -6
  34. package/dist/plugins/chat-models/index.mjs +469 -6
  35. package/dist/plugins/chat-models/index.mjs.map +1 -1
  36. package/dist/{registry-ChOjjdEC.mjs → registry-CHJcTN2W.mjs} +75 -16
  37. package/dist/registry-CHJcTN2W.mjs.map +1 -0
  38. package/dist/{runner-4ZsOveoY.mjs → runner-Dpy-eivM.mjs} +177 -21
  39. package/dist/runner-Dpy-eivM.mjs.map +1 -0
  40. package/dist/testing/expect-extensions.d.mts +44 -38
  41. package/dist/testing/expect-extensions.mjs +1 -1
  42. package/package.json +11 -4
  43. package/dist/expect-0jPJ7Zio.d.mts +0 -2318
  44. package/dist/expect-extensions-CwPtgTz8.mjs +0 -13471
  45. package/dist/expect-extensions-CwPtgTz8.mjs.map +0 -1
  46. package/dist/expect-i9WZWGrA.mjs.map +0 -1
  47. package/dist/magic-string.es-CH1jwzMg.mjs +0 -1013
  48. package/dist/magic-string.es-CH1jwzMg.mjs.map +0 -1
  49. package/dist/plugin-DVaRZY2x.d.mts +0 -84
  50. package/dist/registry-ChOjjdEC.mjs.map +0 -1
  51. package/dist/runner-4ZsOveoY.mjs.map +0 -1
@@ -1,2318 +0,0 @@
1
- import { Formatter } from "tinyrainbow";
2
- //#region ../../node_modules/.pnpm/@vitest+pretty-format@4.1.4/node_modules/@vitest/pretty-format/dist/index.d.ts
3
- /**
4
- * Copyright (c) Meta Platforms, Inc. and affiliates.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE file in the root directory of this source tree.
8
- */
9
- interface Colors {
10
- comment: {
11
- close: string;
12
- open: string;
13
- };
14
- content: {
15
- close: string;
16
- open: string;
17
- };
18
- prop: {
19
- close: string;
20
- open: string;
21
- };
22
- tag: {
23
- close: string;
24
- open: string;
25
- };
26
- value: {
27
- close: string;
28
- open: string;
29
- };
30
- }
31
- type Indent = (arg0: string) => string;
32
- type Refs = Array<unknown>;
33
- type Print = (arg0: unknown) => string;
34
- /**
35
- * compare function used when sorting object keys, `null` can be used to skip over sorting.
36
- */
37
- type CompareKeys = ((a: string, b: string) => number) | null | undefined;
38
- interface PrettyFormatOptions {
39
- /**
40
- * Call `toJSON` on objects before formatting them.
41
- * Ignored after the formatter has already called `toJSON` once for a value.
42
- * @default true
43
- */
44
- callToJSON?: boolean;
45
- /**
46
- * Whether to escape special characters in regular expressions.
47
- * @default false
48
- */
49
- escapeRegex?: boolean;
50
- /**
51
- * Whether to escape special characters in strings.
52
- * @default true
53
- */
54
- escapeString?: boolean;
55
- /**
56
- * Whether to highlight syntax using terminal colors.
57
- * @default false
58
- */
59
- highlight?: boolean;
60
- /**
61
- * Number of spaces to use for each level of indentation.
62
- * @default 2
63
- */
64
- indent?: number;
65
- /**
66
- * Maximum depth to recurse into nested values.
67
- * @default Infinity
68
- */
69
- maxDepth?: number;
70
- /**
71
- * Maximum number of items to print in arrays, sets, maps, and similar collections.
72
- * @default Infinity
73
- */
74
- maxWidth?: number;
75
- /**
76
- * Approximate per-depth-level budget for output length.
77
- * When the accumulated output at any single depth level exceeds this value,
78
- * further nesting is collapsed. This is a heuristic safety valve, not a hard
79
- * limit — total output can reach up to roughly `maxDepth × maxOutputLength`.
80
- * @default 1_000_000
81
- */
82
- maxOutputLength?: number;
83
- /**
84
- * Whether to minimize added whitespace, including indentation and line breaks.
85
- * @default false
86
- */
87
- min?: boolean;
88
- /**
89
- * Whether to print `Object` / `Array` prefixes for plain objects and arrays.
90
- * @default true
91
- */
92
- printBasicPrototype?: boolean;
93
- /**
94
- * Whether to include the function name when formatting functions.
95
- * @default true
96
- */
97
- printFunctionName?: boolean;
98
- /**
99
- * Whether to include shadow-root contents when formatting DOM nodes.
100
- * @default true
101
- */
102
- printShadowRoot?: boolean;
103
- /**
104
- * Compare function used when sorting object keys. Set to `null` to disable sorting.
105
- */
106
- compareKeys?: CompareKeys;
107
- /**
108
- * Plugins used to serialize application-specific data types.
109
- * @default []
110
- */
111
- plugins?: Plugins;
112
- }
113
- type OptionsReceived = PrettyFormatOptions;
114
- interface Config {
115
- callToJSON: boolean;
116
- compareKeys: CompareKeys;
117
- colors: Colors;
118
- escapeRegex: boolean;
119
- escapeString: boolean;
120
- indent: string;
121
- maxDepth: number;
122
- maxWidth: number;
123
- min: boolean;
124
- plugins: Plugins;
125
- printBasicPrototype: boolean;
126
- printFunctionName: boolean;
127
- printShadowRoot: boolean;
128
- spacingInner: string;
129
- spacingOuter: string;
130
- maxOutputLength: number;
131
- }
132
- type Printer = (val: unknown, config: Config, indentation: string, depth: number, refs: Refs, hasCalledToJSON?: boolean) => string;
133
- type Test$1 = (arg0: any) => boolean;
134
- interface NewPlugin {
135
- serialize: (val: any, config: Config, indentation: string, depth: number, refs: Refs, printer: Printer) => string;
136
- test: Test$1;
137
- }
138
- interface PluginOptions {
139
- edgeSpacing: string;
140
- min: boolean;
141
- spacing: string;
142
- }
143
- interface OldPlugin {
144
- print: (val: unknown, print: Print, indent: Indent, options: PluginOptions, colors: Colors) => string;
145
- test: Test$1;
146
- }
147
- type Plugin = NewPlugin | OldPlugin;
148
- type Plugins = Array<Plugin>;
149
- /**
150
- * Copyright (c) Meta Platforms, Inc. and affiliates.
151
- *
152
- * This source code is licensed under the MIT license found in the
153
- * LICENSE file in the root directory of this source tree.
154
- */
155
- //#endregion
156
- //#region ../../node_modules/.pnpm/@vitest+utils@4.1.4/node_modules/@vitest/utils/dist/display.d.ts
157
- interface StringifyOptions extends PrettyFormatOptions {
158
- maxLength?: number;
159
- filterNode?: string | ((node: any) => boolean);
160
- }
161
- declare function stringify(object: unknown, maxDepth?: number, {
162
- maxLength,
163
- filterNode,
164
- ...options
165
- }?: StringifyOptions): string;
166
- //#endregion
167
- //#region ../../node_modules/.pnpm/@vitest+utils@4.1.4/node_modules/@vitest/utils/dist/types.d.ts
168
- type Awaitable<T> = T | PromiseLike<T>;
169
- interface ParsedStack {
170
- method: string;
171
- file: string;
172
- line: number;
173
- column: number;
174
- }
175
- interface SerializedError {
176
- message: string;
177
- stacks?: ParsedStack[];
178
- stack?: string;
179
- name?: string;
180
- cause?: SerializedError;
181
- [key: string]: unknown;
182
- }
183
- interface TestError extends SerializedError {
184
- cause?: TestError;
185
- diff?: string;
186
- actual?: string;
187
- expected?: string;
188
- }
189
- //#endregion
190
- //#region ../../node_modules/.pnpm/@vitest+utils@4.1.4/node_modules/@vitest/utils/dist/types.d-BCElaP-c.d.ts
191
- /**
192
- * Copyright (c) Meta Platforms, Inc. and affiliates.
193
- *
194
- * This source code is licensed under the MIT license found in the
195
- * LICENSE file in the root directory of this source tree.
196
- */
197
- type DiffOptionsColor = (arg: string) => string;
198
- interface DiffOptions {
199
- aAnnotation?: string;
200
- aColor?: DiffOptionsColor;
201
- aIndicator?: string;
202
- bAnnotation?: string;
203
- bColor?: DiffOptionsColor;
204
- bIndicator?: string;
205
- changeColor?: DiffOptionsColor;
206
- changeLineTrailingSpaceColor?: DiffOptionsColor;
207
- commonColor?: DiffOptionsColor;
208
- commonIndicator?: string;
209
- commonLineTrailingSpaceColor?: DiffOptionsColor;
210
- contextLines?: number;
211
- emptyFirstOrLastLinePlaceholder?: string;
212
- expand?: boolean;
213
- includeChangeCounts?: boolean;
214
- omitAnnotationLines?: boolean;
215
- patchColor?: DiffOptionsColor;
216
- printBasicPrototype?: boolean;
217
- maxDepth?: number;
218
- compareKeys?: CompareKeys;
219
- truncateThreshold?: number;
220
- truncateAnnotation?: string;
221
- truncateAnnotationColor?: DiffOptionsColor;
222
- }
223
- //#endregion
224
- //#region ../../node_modules/.pnpm/@vitest+utils@4.1.4/node_modules/@vitest/utils/dist/diff.d.ts
225
- /**
226
- * @param a Expected value
227
- * @param b Received value
228
- * @param options Diff options
229
- * @returns {string | null} a string diff
230
- */
231
- declare function diff(a: any, b: any, options?: DiffOptions): string | undefined;
232
- declare function printDiffOrStringify(received: unknown, expected: unknown, options?: DiffOptions): string | undefined;
233
- //#endregion
234
- //#region ../../node_modules/.pnpm/@vitest+runner@4.1.4/node_modules/@vitest/runner/dist/tasks.d-Bh0IjN67.d.ts
235
- type RunMode = "run" | "skip" | "only" | "todo" | "queued";
236
- type TaskState = RunMode | "pass" | "fail";
237
- interface TaskBase {
238
- /**
239
- * Unique task identifier. Based on the file id and the position of the task.
240
- * The id of the file task is based on the file path relative to root and project name.
241
- * It will not change between runs.
242
- * @example `1201091390`, `1201091390_0`, `1201091390_0_1`
243
- */
244
- id: string;
245
- /**
246
- * Task name provided by the user. If no name was provided, it will be an empty string.
247
- */
248
- name: string;
249
- /**
250
- * Full name including the file path, any parent suites, and this task's name.
251
- *
252
- * Uses ` > ` as the separator between levels.
253
- *
254
- * @example
255
- * // file
256
- * 'test/task-names.test.ts'
257
- * @example
258
- * // suite
259
- * 'test/task-names.test.ts > meal planning'
260
- * 'test/task-names.test.ts > meal planning > grocery lists'
261
- * @example
262
- * // test
263
- * 'test/task-names.test.ts > meal planning > grocery lists > calculates ingredients'
264
- */
265
- fullName: string;
266
- /**
267
- * Full name excluding the file path, including any parent suites and this task's name. `undefined` for file tasks.
268
- *
269
- * Uses ` > ` as the separator between levels.
270
- *
271
- * @example
272
- * // file
273
- * undefined
274
- * @example
275
- * // suite
276
- * 'meal planning'
277
- * 'meal planning > grocery lists'
278
- * @example
279
- * // test
280
- * 'meal planning > grocery lists > calculates ingredients'
281
- */
282
- fullTestName?: string;
283
- /**
284
- * Task mode.
285
- * - **skip**: task is skipped
286
- * - **only**: only this task and other tasks with `only` mode will run
287
- * - **todo**: task is marked as a todo, alias for `skip`
288
- * - **run**: task will run or already ran
289
- * - **queued**: task will start running next. It can only exist on the File
290
- */
291
- mode: RunMode;
292
- /**
293
- * Custom metadata for the task. JSON reporter will save this data.
294
- */
295
- meta: TaskMeta;
296
- /**
297
- * Whether the task was produced with `.each()` method.
298
- */
299
- each?: boolean;
300
- /**
301
- * Whether the task should run concurrently with other tasks.
302
- */
303
- concurrent?: boolean;
304
- /**
305
- * Whether the tasks of the suite run in a random order.
306
- */
307
- shuffle?: boolean;
308
- /**
309
- * Suite that this task is part of. File task or the global suite will have no parent.
310
- */
311
- suite?: Suite;
312
- /**
313
- * Result of the task. Suite and file tasks will only have the result if there
314
- * was an error during collection or inside `afterAll`/`beforeAll`.
315
- */
316
- result?: TaskResult$1;
317
- /**
318
- * Retry configuration for the task.
319
- * - If a number, specifies how many times to retry
320
- * - If an object, allows fine-grained retry control
321
- * @default 0
322
- */
323
- retry?: Retry;
324
- /**
325
- * The amount of times the task should be repeated after the successful run.
326
- * If the task fails, it will not be retried unless `retry` is specified.
327
- * @default 0
328
- */
329
- repeats?: number;
330
- /**
331
- * Location of the task in the file. This field is populated only if
332
- * `includeTaskLocation` option is set. It is generated by calling `new Error`
333
- * and parsing the stack trace, so the location might differ depending on the runtime.
334
- */
335
- location?: Location;
336
- /**
337
- * If the test was collected by parsing the file AST, and the name
338
- * is not a static string, this property will be set to `true`.
339
- * @experimental
340
- */
341
- dynamic?: boolean;
342
- /**
343
- * Custom tags of the task. Useful for filtering tasks.
344
- */
345
- tags?: string[];
346
- }
347
- interface TaskPopulated extends TaskBase {
348
- /**
349
- * File task. It's the root task of the file.
350
- */
351
- file: File;
352
- /**
353
- * Whether the task should succeed if it fails. If the task fails, it will be marked as passed.
354
- */
355
- fails?: boolean;
356
- /**
357
- * Store promises (from async expects) to wait for them before finishing the test
358
- */
359
- promises?: Promise<any>[];
360
- }
361
- /**
362
- * Custom metadata that can be used in reporters.
363
- */
364
- interface TaskMeta {}
365
- /**
366
- * The result of calling a task.
367
- */
368
- interface TaskResult$1 {
369
- /**
370
- * State of the task. Inherits the `task.mode` during collection.
371
- * When the task has finished, it will be changed to `pass` or `fail`.
372
- * - **pass**: task ran successfully
373
- * - **fail**: task failed
374
- */
375
- state: TaskState;
376
- /**
377
- * Errors that occurred during the task execution. It is possible to have several errors
378
- * if `expect.soft()` failed multiple times or `retry` was triggered.
379
- */
380
- errors?: TestError[];
381
- /**
382
- * How long in milliseconds the task took to run.
383
- */
384
- duration?: number;
385
- /**
386
- * Time in milliseconds when the task started running.
387
- */
388
- startTime?: number;
389
- /**
390
- * Heap size in bytes after the task finished.
391
- * Only available if `logHeapUsage` option is set and `process.memoryUsage` is defined.
392
- */
393
- heap?: number;
394
- /**
395
- * State of related to this task hooks. Useful during reporting.
396
- */
397
- hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
398
- /**
399
- * The amount of times the task was retried. The task is retried only if it
400
- * failed and `retry` option is set.
401
- */
402
- retryCount?: number;
403
- /**
404
- * The amount of times the task was repeated. The task is repeated only if
405
- * `repeats` option is set. This number also contains `retryCount`.
406
- */
407
- repeatCount?: number;
408
- }
409
- /** The time spent importing & executing a non-externalized file. */
410
- interface ImportDuration {
411
- /** The time spent importing & executing the file itself, not counting all non-externalized imports that the file does. */
412
- selfTime: number;
413
- /** The time spent importing & executing the file and all its imports. */
414
- totalTime: number;
415
- /** Will be set to `true`, if the module was externalized. In this case totalTime and selfTime are identical. */
416
- external?: boolean;
417
- /** Which module imported this module first. All subsequent imports are cached. */
418
- importer?: string;
419
- }
420
- /**
421
- * The tuple representing a single task update.
422
- * Usually reported after the task finishes.
423
- */
424
- interface Suite extends TaskBase {
425
- type: "suite";
426
- /**
427
- * File task. It's the root task of the file.
428
- */
429
- file: File;
430
- /**
431
- * An array of tasks that are part of the suite.
432
- */
433
- tasks: Task[];
434
- }
435
- interface File extends Suite {
436
- /**
437
- * The name of the pool that the file belongs to.
438
- * @default 'forks'
439
- */
440
- pool?: string;
441
- /**
442
- * The environment that processes the file on the server.
443
- */
444
- viteEnvironment?: string;
445
- /**
446
- * The path to the file in UNIX format.
447
- */
448
- filepath: string;
449
- /**
450
- * The name of the workspace project the file belongs to.
451
- */
452
- projectName: string | undefined;
453
- /**
454
- * The time it took to collect all tests in the file.
455
- * This time also includes importing all the file dependencies.
456
- */
457
- collectDuration?: number;
458
- /**
459
- * The time it took to import the setup file.
460
- */
461
- setupDuration?: number;
462
- /** The time spent importing every non-externalized dependency that Vitest has processed. */
463
- importDurations?: Record<string, ImportDuration>;
464
- }
465
- interface Test<ExtraContext = object> extends TaskPopulated {
466
- type: "test";
467
- /**
468
- * Test context that will be passed to the test function.
469
- */
470
- context: TestContext & ExtraContext;
471
- /**
472
- * The test timeout in milliseconds.
473
- */
474
- timeout: number;
475
- /**
476
- * An array of custom annotations.
477
- */
478
- annotations: TestAnnotation[];
479
- /**
480
- * An array of artifacts produced by the test.
481
- *
482
- * @experimental
483
- */
484
- artifacts: TestArtifact[];
485
- fullTestName: string;
486
- }
487
- type Task = Test | Suite | File;
488
- /**
489
- * Retry configuration for tests.
490
- * Can be a number for simple retry count, or an object for advanced retry control.
491
- */
492
- type Retry = number | {
493
- /**
494
- * The number of times to retry the test if it fails.
495
- * @default 0
496
- */
497
- count?: number;
498
- /**
499
- * Delay in milliseconds between retry attempts.
500
- * @default 0
501
- */
502
- delay?: number;
503
- /**
504
- * Condition to determine if a test should be retried based on the error.
505
- * - If a RegExp, it is tested against the error message
506
- * - If a function, called with the TestError object; return true to retry
507
- *
508
- * NOTE: Functions can only be used in test files, not in vitest.config.ts,
509
- * because the configuration is serialized when passed to worker threads.
510
- *
511
- * @default undefined (retry on all errors)
512
- */
513
- condition?: RegExp | ((error: TestError) => boolean);
514
- };
515
- /**
516
- * Serializable retry configuration (used in config files).
517
- * Functions cannot be serialized, so only string conditions are allowed.
518
- */
519
- interface BeforeEachListener<ExtraContext = object> {
520
- (context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
521
- }
522
- interface AfterEachListener<ExtraContext = object> {
523
- (context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
524
- }
525
- interface AroundEachListener<ExtraContext = object> {
526
- (runTest: () => Promise<void>, context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
527
- }
528
- interface RegisteredAllListener {
529
- (suite: Readonly<Suite | File>): Awaitable<unknown>;
530
- }
531
- interface RegisteredAroundAllListener {
532
- (runSuite: () => Promise<void>, suite: Readonly<Suite | File>): Awaitable<unknown>;
533
- }
534
- interface SuiteHooks<ExtraContext = object> {
535
- beforeAll: RegisteredAllListener[];
536
- afterAll: RegisteredAllListener[];
537
- aroundAll: RegisteredAroundAllListener[];
538
- beforeEach: BeforeEachListener<ExtraContext>[];
539
- afterEach: AfterEachListener<ExtraContext>[];
540
- aroundEach: AroundEachListener<ExtraContext>[];
541
- }
542
- /**
543
- * User's custom test context.
544
- */
545
- interface TestContext {
546
- /**
547
- * Metadata of the current test
548
- */
549
- readonly task: Readonly<Test>;
550
- /**
551
- * An [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) that will be aborted if the test times out or
552
- * the test run was cancelled.
553
- * @see {@link https://vitest.dev/guide/test-context#signal}
554
- */
555
- readonly signal: AbortSignal;
556
- /**
557
- * Register a callback to run when this specific test fails.
558
- * Useful when tests run concurrently.
559
- * @see {@link https://vitest.dev/guide/test-context#ontestfailed}
560
- */
561
- readonly onTestFailed: (fn: OnTestFailedHandler, timeout?: number) => void;
562
- /**
563
- * Register a callback to run when this specific test finishes.
564
- * Useful when tests run concurrently.
565
- * @see {@link https://vitest.dev/guide/test-context#ontestfinished}
566
- */
567
- readonly onTestFinished: (fn: OnTestFinishedHandler, timeout?: number) => void;
568
- /**
569
- * Mark tests as skipped. All execution after this call will be skipped.
570
- * This function throws an error, so make sure you are not catching it accidentally.
571
- * @see {@link https://vitest.dev/guide/test-context#skip}
572
- */
573
- readonly skip: {
574
- (note?: string): never;
575
- (condition: boolean, note?: string): void;
576
- };
577
- /**
578
- * Add a test annotation that will be displayed by your reporter.
579
- * @see {@link https://vitest.dev/guide/test-context#annotate}
580
- */
581
- readonly annotate: {
582
- (message: string, type?: string, attachment?: TestAttachment): Promise<TestAnnotation>;
583
- (message: string, attachment?: TestAttachment): Promise<TestAnnotation>;
584
- };
585
- }
586
- type OnTestFailedHandler = (context: TestContext) => Awaitable<void>;
587
- type OnTestFinishedHandler = (context: TestContext) => Awaitable<void>;
588
- /**
589
- * Represents a file or data attachment associated with a test artifact.
590
- *
591
- * Attachments can be either file-based (via `path`) or inline content (via `body`).
592
- * The `contentType` helps consumers understand how to interpret the attachment data.
593
- */
594
- interface TestAttachment {
595
- /** MIME type of the attachment (e.g., 'image/png', 'text/plain') */
596
- contentType?: string;
597
- /** File system path to the attachment */
598
- path?: string;
599
- /** Inline attachment content as a string or raw binary data */
600
- body?: string | Uint8Array | undefined;
601
- /**
602
- * @experimental
603
- * How the string `body` is encoded.
604
- * - `'base64'` (default): body is already base64-encoded
605
- * - `'utf-8'`: body is a utf8 string
606
- *
607
- * `body: Uint8Array` is always auto-encoded to string with `bodyEncoding: 'base64'`
608
- * regardless of this option.
609
- */
610
- bodyEncoding?: "base64" | "utf-8";
611
- }
612
- interface Location {
613
- /** Line number in the source file (1-indexed) */
614
- line: number;
615
- /** Column number in the line (1-indexed) */
616
- column: number;
617
- }
618
- interface FileLocation extends Location {
619
- /** Line number in the source file (1-indexed) */
620
- line: number;
621
- /** Column number in the line (1-indexed) */
622
- column: number;
623
- /** Path to the source file */
624
- file: string;
625
- }
626
- /**
627
- * Source code location information for a test artifact.
628
- *
629
- * Indicates where in the source code the artifact originated from.
630
- */
631
- interface TestArtifactLocation extends FileLocation {}
632
- /**
633
- * @experimental
634
- *
635
- * Base interface for all test artifacts.
636
- *
637
- * 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.
638
- *
639
- * **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.
640
- */
641
- interface TestArtifactBase {
642
- /** File or data attachments associated with this artifact */
643
- attachments?: TestAttachment[];
644
- /** Source location where this artifact was created */
645
- location?: TestArtifactLocation;
646
- }
647
- /**
648
- * @deprecated Use {@linkcode TestArtifactLocation} instead.
649
- *
650
- * Kept for backwards compatibility.
651
- */
652
- interface TestAnnotation {
653
- message: string;
654
- type: string;
655
- location?: TestArtifactLocation;
656
- attachment?: TestAttachment;
657
- }
658
- /**
659
- * @experimental
660
- *
661
- * Artifact type for test annotations.
662
- */
663
- interface TestAnnotationArtifact extends TestArtifactBase {
664
- type: "internal:annotation";
665
- annotation: TestAnnotation;
666
- }
667
- interface VisualRegressionArtifactAttachment extends TestAttachment {
668
- name: "reference" | "actual" | "diff";
669
- width: number;
670
- height: number;
671
- }
672
- /**
673
- * @experimental
674
- *
675
- * Artifact type for visual regressions.
676
- */
677
- interface VisualRegressionArtifact extends TestArtifactBase {
678
- type: "internal:toMatchScreenshot";
679
- kind: "visual-regression";
680
- message: string;
681
- attachments: VisualRegressionArtifactAttachment[];
682
- }
683
- interface FailureScreenshotArtifactAttachment extends TestAttachment {
684
- path: string;
685
- /** Original file system path to the screenshot, before attachment resolution */
686
- originalPath: string;
687
- body?: undefined;
688
- }
689
- /**
690
- * @experimental
691
- *
692
- * Artifact type for failure screenshots.
693
- */
694
- interface FailureScreenshotArtifact extends TestArtifactBase {
695
- type: "internal:failureScreenshot";
696
- attachments: [FailureScreenshotArtifactAttachment] | [];
697
- }
698
- /**
699
- * @experimental
700
- * @advanced
701
- *
702
- * Registry for custom test artifact types.
703
- *
704
- * Augment this interface to register custom artifact types that your tests can produce.
705
- *
706
- * Each custom artifact should extend {@linkcode TestArtifactBase} and include a unique `type` discriminator property.
707
- *
708
- * @remarks
709
- * - Use a `Symbol` as the **registry key** to guarantee uniqueness
710
- * - The `type` property should follow the pattern `'package-name:artifact-name'`, `'internal:'` is a reserved prefix
711
- * - Use `attachments` to include files or data; extend {@linkcode TestAttachment} for custom metadata
712
- * - `location` property is automatically injected to indicate where the artifact was created
713
- *
714
- * @example
715
- * ```ts
716
- * // Define custom attachment type for generated PDF
717
- * interface PDFAttachment extends TestAttachment {
718
- * contentType: 'application/pdf'
719
- * body: Uint8Array
720
- * pageCount: number
721
- * fileSize: number
722
- * }
723
- *
724
- * interface PDFGenerationArtifact extends TestArtifactBase {
725
- * type: 'my-plugin:pdf-generation'
726
- * templateName: string
727
- * isValid: boolean
728
- * attachments: [PDFAttachment]
729
- * }
730
- *
731
- * // Use a symbol to guarantee key uniqueness
732
- * const pdfKey = Symbol('pdf-generation')
733
- *
734
- * declare module 'vitest' {
735
- * interface TestArtifactRegistry {
736
- * [pdfKey]: PDFGenerationArtifact
737
- * }
738
- * }
739
- *
740
- * // Custom assertion for PDF generation
741
- * async function toGenerateValidPDF(
742
- * this: MatcherState,
743
- * actual: PDFTemplate,
744
- * data: Record<string, unknown>
745
- * ): AsyncExpectationResult {
746
- * const pdfBuffer = await actual.render(data)
747
- * const validation = await validatePDF(pdfBuffer)
748
- *
749
- * await recordArtifact(this.task, {
750
- * type: 'my-plugin:pdf-generation',
751
- * templateName: actual.name,
752
- * isValid: validation.success,
753
- * attachments: [{
754
- * contentType: 'application/pdf',
755
- * body: pdfBuffer,
756
- * pageCount: validation.pageCount,
757
- * fileSize: pdfBuffer.byteLength
758
- * }]
759
- * })
760
- *
761
- * return {
762
- * pass: validation.success,
763
- * message: () => validation.success
764
- * ? `Generated valid PDF with ${validation.pageCount} pages`
765
- * : `Invalid PDF: ${validation.error}`
766
- * }
767
- * }
768
- * ```
769
- */
770
- interface TestArtifactRegistry {}
771
- /**
772
- * @experimental
773
- *
774
- * Union type of all test artifacts, including built-in and custom registered artifacts.
775
- *
776
- * This type automatically includes all artifacts registered via {@link TestArtifactRegistry}.
777
- */
778
- type TestArtifact = FailureScreenshotArtifact | TestAnnotationArtifact | VisualRegressionArtifact | TestArtifactRegistry[keyof TestArtifactRegistry];
779
- //#endregion
780
- //#region ../../node_modules/.pnpm/@vitest+snapshot@4.1.4/node_modules/@vitest/snapshot/dist/environment.d-DOJxxZV9.d.ts
781
- interface SnapshotEnvironment {
782
- getVersion: () => string;
783
- getHeader: () => string;
784
- resolvePath: (filepath: string) => Promise<string>;
785
- resolveRawPath: (testPath: string, rawPath: string) => Promise<string>;
786
- saveSnapshotFile: (filepath: string, snapshot: string) => Promise<void>;
787
- readSnapshotFile: (filepath: string) => Promise<string | null>;
788
- removeSnapshotFile: (filepath: string) => Promise<void>;
789
- processStackTrace?: (stack: ParsedStack) => ParsedStack;
790
- }
791
- //#endregion
792
- //#region ../../node_modules/.pnpm/@vitest+snapshot@4.1.4/node_modules/@vitest/snapshot/dist/rawSnapshot.d-D_X3-62x.d.ts
793
- interface DomainMatchResult {
794
- pass: boolean;
795
- message?: string;
796
- /**
797
- * The captured value viewed through the template's lens.
798
- *
799
- * Where the template uses patterns (e.g. regexes) or omits details,
800
- * the resolved string adopts those patterns. Where the template doesn't
801
- * match, the resolved string uses literal captured values instead.
802
- *
803
- * Used for two purposes:
804
- * - **Diff display** (actual side): compared against `expected`
805
- * so the diff highlights only genuine mismatches, not pattern-vs-literal noise.
806
- * - **Snapshot update** (`--update`): written as the new snapshot content,
807
- * preserving user-edited patterns from matched regions while incorporating
808
- * actual values for mismatched regions.
809
- *
810
- * When omitted, falls back to `render(capture(received))` (the raw rendered value).
811
- */
812
- resolved?: string;
813
- /**
814
- * The stored template re-rendered as a string, representing what the user
815
- * originally wrote or last saved.
816
- *
817
- * Used as the expected side in diff display.
818
- *
819
- * When omitted, falls back to the raw snapshot string from the snap file
820
- * or inline snapshot.
821
- */
822
- expected?: string;
823
- }
824
- /**
825
- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
826
- *
827
- * This source code is licensed under the MIT license found in the
828
- * LICENSE file in the root directory of this source tree.
829
- */
830
- declare class DefaultMap<K, V> extends Map<K, V> {
831
- private defaultFn;
832
- constructor(defaultFn: (key: K) => V, entries?: Iterable<readonly [K, V]>);
833
- get(key: K): V;
834
- }
835
- declare class CounterMap<K> extends DefaultMap<K, number> {
836
- constructor();
837
- _total: number | undefined;
838
- valueOf(): number;
839
- increment(key: K): void;
840
- total(): number;
841
- }
842
- interface SnapshotReturnOptions {
843
- actual: string;
844
- count: number;
845
- expected?: string;
846
- key: string;
847
- pass: boolean;
848
- }
849
- interface SaveStatus {
850
- deleted: boolean;
851
- saved: boolean;
852
- }
853
- interface ExpectedSnapshot {
854
- key: string;
855
- count: number;
856
- data?: string;
857
- markAsChecked: () => void;
858
- }
859
- declare class SnapshotState {
860
- testFilePath: string;
861
- snapshotPath: string;
862
- private _counters;
863
- private _dirty;
864
- private _updateSnapshot;
865
- private _snapshotData;
866
- private _initialData;
867
- private _inlineSnapshots;
868
- private _inlineSnapshotStacks;
869
- private _testIdToKeys;
870
- private _rawSnapshots;
871
- private _uncheckedKeys;
872
- private _snapshotFormat;
873
- private _environment;
874
- private _fileExists;
875
- expand: boolean;
876
- private _added;
877
- private _matched;
878
- private _unmatched;
879
- private _updated;
880
- get added(): CounterMap<string>;
881
- set added(value: number);
882
- get matched(): CounterMap<string>;
883
- set matched(value: number);
884
- get unmatched(): CounterMap<string>;
885
- set unmatched(value: number);
886
- get updated(): CounterMap<string>;
887
- set updated(value: number);
888
- private constructor();
889
- static create(testFilePath: string, options: SnapshotStateOptions): Promise<SnapshotState>;
890
- get snapshotUpdateState(): SnapshotUpdateState;
891
- get environment(): SnapshotEnvironment;
892
- markSnapshotsAsCheckedForTest(testName: string): void;
893
- clearTest(testId: string): void;
894
- protected _inferInlineSnapshotStack(stacks: ParsedStack[]): ParsedStack | null;
895
- private _addSnapshot;
896
- private _resolveKey;
897
- private _resolveInlineStack;
898
- private _reconcile;
899
- save(): Promise<SaveStatus>;
900
- getUncheckedCount(): number;
901
- getUncheckedKeys(): Array<string>;
902
- removeUncheckedKeys(): void;
903
- probeExpectedSnapshot(options: Pick<SnapshotMatchOptions, "testName" | "testId" | "isInline" | "inlineSnapshot">): ExpectedSnapshot;
904
- match({
905
- testId,
906
- testName,
907
- received,
908
- key,
909
- inlineSnapshot,
910
- isInline,
911
- error,
912
- rawSnapshot,
913
- assertionName
914
- }: SnapshotMatchOptions): SnapshotReturnOptions;
915
- processDomainSnapshot({
916
- testId,
917
- received,
918
- expectedSnapshot,
919
- matchResult,
920
- isInline,
921
- error,
922
- assertionName
923
- }: ProcessDomainSnapshotOptions): SnapshotReturnOptions;
924
- pack(): Promise<SnapshotResult>;
925
- }
926
- type SnapshotUpdateState = "all" | "new" | "none";
927
- interface SnapshotStateOptions {
928
- updateSnapshot: SnapshotUpdateState;
929
- snapshotEnvironment: SnapshotEnvironment;
930
- expand?: boolean;
931
- snapshotFormat?: OptionsReceived;
932
- resolveSnapshotPath?: (path: string, extension: string, context?: any) => string;
933
- }
934
- interface SnapshotMatchOptions {
935
- testId: string;
936
- testName: string;
937
- received: unknown;
938
- key?: string;
939
- inlineSnapshot?: string;
940
- isInline: boolean;
941
- error?: Error;
942
- rawSnapshot?: RawSnapshotInfo;
943
- assertionName?: string;
944
- }
945
- interface ProcessDomainSnapshotOptions {
946
- testId: string;
947
- received: string;
948
- expectedSnapshot: ExpectedSnapshot;
949
- matchResult?: DomainMatchResult;
950
- isInline?: boolean;
951
- assertionName?: string;
952
- error?: Error;
953
- }
954
- interface SnapshotResult {
955
- filepath: string;
956
- added: number;
957
- fileDeleted: boolean;
958
- matched: number;
959
- unchecked: number;
960
- uncheckedKeys: Array<string>;
961
- unmatched: number;
962
- updated: number;
963
- }
964
- interface RawSnapshotInfo {
965
- file: string;
966
- readonly?: boolean;
967
- content?: string;
968
- }
969
- //#endregion
970
- //#region ../../node_modules/.pnpm/vitest@4.1.4_@types+node@25.6.0_@vitest+coverage-v8@4.1.4_vite@8.0.8_@types+node@25.6.0_f62b45bc4bcc1123dfacc813508205a7/node_modules/vitest/dist/chunks/rpc.d.BFMWpdph.d.ts
971
- interface UserConsoleLog {
972
- content: string;
973
- origin?: string;
974
- browser?: boolean;
975
- type: "stdout" | "stderr";
976
- taskId?: string;
977
- time: number;
978
- size: number;
979
- }
980
- //#endregion
981
- //#region ../../node_modules/.pnpm/@vitest+spy@4.1.4/node_modules/@vitest/spy/optional-types.d.ts
982
- /* eslint-disable ts/ban-ts-comment */
983
- interface Disposable {
984
- // @ts-ignore -- Symbol.dispose might not be in user types
985
- [Symbol.dispose]: () => void;
986
- }
987
- //#endregion
988
- //#region ../../node_modules/.pnpm/@vitest+spy@4.1.4/node_modules/@vitest/spy/dist/index.d.ts
989
- interface MockResultReturn<T> {
990
- type: "return";
991
- /**
992
- * The value that was returned from the function. If function returned a Promise, then this will be a resolved value.
993
- */
994
- value: T;
995
- }
996
- interface MockResultIncomplete {
997
- type: "incomplete";
998
- value: undefined;
999
- }
1000
- interface MockResultThrow {
1001
- type: "throw";
1002
- /**
1003
- * An error that was thrown during function execution.
1004
- */
1005
- value: any;
1006
- }
1007
- interface MockSettledResultIncomplete {
1008
- type: "incomplete";
1009
- value: undefined;
1010
- }
1011
- interface MockSettledResultFulfilled<T> {
1012
- type: "fulfilled";
1013
- value: T;
1014
- }
1015
- interface MockSettledResultRejected {
1016
- type: "rejected";
1017
- value: any;
1018
- }
1019
- type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
1020
- type MockSettledResult<T> = MockSettledResultFulfilled<T> | MockSettledResultRejected | MockSettledResultIncomplete;
1021
- type MockParameters<T extends Procedure | Constructable> = T extends Constructable ? ConstructorParameters<T> : T extends Procedure ? Parameters<T> : never;
1022
- type MockReturnType<T extends Procedure | Constructable> = T extends Constructable ? InstanceType<T> : T extends Procedure ? ReturnType<T> : never;
1023
- type MockProcedureContext<T extends Procedure | Constructable> = T extends Constructable ? InstanceType<T> : ThisParameterType<T>;
1024
- interface MockContext<T extends Procedure | Constructable = Procedure> {
1025
- /**
1026
- * This is an array containing all arguments for each call. One item of the array is the arguments of that call.
1027
- *
1028
- * @see https://vitest.dev/api/mock#mock-calls
1029
- * @example
1030
- * const fn = vi.fn()
1031
- *
1032
- * fn('arg1', 'arg2')
1033
- * fn('arg3')
1034
- *
1035
- * fn.mock.calls === [
1036
- * ['arg1', 'arg2'], // first call
1037
- * ['arg3'], // second call
1038
- * ]
1039
- */
1040
- calls: MockParameters<T>[];
1041
- /**
1042
- * 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.
1043
- * @see https://vitest.dev/api/mock#mock-instances
1044
- */
1045
- instances: MockProcedureContext<T>[];
1046
- /**
1047
- * An array of `this` values that were used during each call to the mock function.
1048
- * @see https://vitest.dev/api/mock#mock-contexts
1049
- */
1050
- contexts: MockProcedureContext<T>[];
1051
- /**
1052
- * The order of mock's execution. This returns an array of numbers which are shared between all defined mocks.
1053
- *
1054
- * @see https://vitest.dev/api/mock#mock-invocationcallorder
1055
- * @example
1056
- * const fn1 = vi.fn()
1057
- * const fn2 = vi.fn()
1058
- *
1059
- * fn1()
1060
- * fn2()
1061
- * fn1()
1062
- *
1063
- * fn1.mock.invocationCallOrder === [1, 3]
1064
- * fn2.mock.invocationCallOrder === [2]
1065
- */
1066
- invocationCallOrder: number[];
1067
- /**
1068
- * This is an array containing all values that were `returned` from the function.
1069
- *
1070
- * 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.
1071
- *
1072
- * @see https://vitest.dev/api/mock#mock-results
1073
- * @example
1074
- * const fn = vi.fn()
1075
- * .mockReturnValueOnce('result')
1076
- * .mockImplementationOnce(() => { throw new Error('thrown error') })
1077
- *
1078
- * const result = fn()
1079
- *
1080
- * try {
1081
- * fn()
1082
- * }
1083
- * catch {}
1084
- *
1085
- * fn.mock.results === [
1086
- * {
1087
- * type: 'return',
1088
- * value: 'result',
1089
- * },
1090
- * {
1091
- * type: 'throw',
1092
- * value: Error,
1093
- * },
1094
- * ]
1095
- */
1096
- results: MockResult<MockReturnType<T>>[];
1097
- /**
1098
- * An array containing all values that were `resolved` or `rejected` from the function.
1099
- *
1100
- * This array will be empty if the function was never resolved or rejected.
1101
- *
1102
- * @see https://vitest.dev/api/mock#mock-settledresults
1103
- * @example
1104
- * const fn = vi.fn().mockResolvedValueOnce('result')
1105
- *
1106
- * const result = fn()
1107
- *
1108
- * fn.mock.settledResults === [
1109
- * {
1110
- * type: 'incomplete',
1111
- * value: undefined,
1112
- * }
1113
- * ]
1114
- * fn.mock.results === [
1115
- * {
1116
- * type: 'return',
1117
- * value: Promise<'result'>,
1118
- * },
1119
- * ]
1120
- *
1121
- * await result
1122
- *
1123
- * fn.mock.settledResults === [
1124
- * {
1125
- * type: 'fulfilled',
1126
- * value: 'result',
1127
- * },
1128
- * ]
1129
- */
1130
- settledResults: MockSettledResult<Awaited<MockReturnType<T>>>[];
1131
- /**
1132
- * This contains the arguments of the last call. If spy wasn't called, will return `undefined`.
1133
- * @see https://vitest.dev/api/mock#mock-lastcall
1134
- */
1135
- lastCall: MockParameters<T> | undefined;
1136
- }
1137
- type Procedure = (...args: any[]) => any;
1138
- type NormalizedProcedure<T extends Procedure | Constructable> = T extends Constructable ? ({
1139
- new (...args: ConstructorParameters<T>): InstanceType<T>;
1140
- }) | ({
1141
- (this: InstanceType<T>, ...args: ConstructorParameters<T>): void;
1142
- }) : T extends Procedure ? (...args: Parameters<T>) => ReturnType<T> : never;
1143
- interface MockInstance<T extends Procedure | Constructable = Procedure> extends Disposable {
1144
- /**
1145
- * Use it to return the name assigned to the mock with the `.mockName(name)` method. By default, it will return `vi.fn()`.
1146
- * @see https://vitest.dev/api/mock#getmockname
1147
- */
1148
- getMockName(): string;
1149
- /**
1150
- * Sets the internal mock name. This is useful for identifying the mock when an assertion fails.
1151
- * @see https://vitest.dev/api/mock#mockname
1152
- */
1153
- mockName(name: string): this;
1154
- /**
1155
- * Current context of the mock. It stores information about all invocation calls, instances, and results.
1156
- */
1157
- mock: MockContext<T>;
1158
- /**
1159
- * 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.
1160
- *
1161
- * To automatically call this method before each test, enable the [`clearMocks`](https://vitest.dev/config/clearmocks) setting in the configuration.
1162
- * @see https://vitest.dev/api/mock#mockclear
1163
- */
1164
- mockClear(): this;
1165
- /**
1166
- * Does what `mockClear` does and resets inner implementation to the original function. This also resets all "once" implementations.
1167
- *
1168
- * Note that resetting a mock from `vi.fn()` will set implementation to an empty function that returns `undefined`.
1169
- * Resetting a mock from `vi.fn(impl)` will set implementation to `impl`. It is useful for completely resetting a mock to its default state.
1170
- *
1171
- * To automatically call this method before each test, enable the [`mockReset`](https://vitest.dev/config/mockreset) setting in the configuration.
1172
- * @see https://vitest.dev/api/mock#mockreset
1173
- */
1174
- mockReset(): this;
1175
- /**
1176
- * Does what `mockReset` does and restores original descriptors of spied-on objects.
1177
- * @see https://vitest.dev/api/mock#mockrestore
1178
- */
1179
- mockRestore(): void;
1180
- /**
1181
- * Returns current permanent mock implementation if there is one.
1182
- *
1183
- * If mock was created with `vi.fn`, it will consider passed down method as a mock implementation.
1184
- *
1185
- * If mock was created with `vi.spyOn`, it will return `undefined` unless a custom implementation was provided.
1186
- */
1187
- getMockImplementation(): NormalizedProcedure<T> | undefined;
1188
- /**
1189
- * Accepts a function to be used as the mock implementation. TypeScript expects the arguments and return type to match those of the original function.
1190
- * @see https://vitest.dev/api/mock#mockimplementation
1191
- * @example
1192
- * const increment = vi.fn().mockImplementation(count => count + 1);
1193
- * expect(increment(3)).toBe(4);
1194
- */
1195
- mockImplementation(fn: NormalizedProcedure<T>): this;
1196
- /**
1197
- * 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.
1198
- *
1199
- * 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.
1200
- * @see https://vitest.dev/api/mock#mockimplementationonce
1201
- * @example
1202
- * const fn = vi.fn(count => count).mockImplementationOnce(count => count + 1);
1203
- * expect(fn(3)).toBe(4);
1204
- * expect(fn(3)).toBe(3);
1205
- */
1206
- mockImplementationOnce(fn: NormalizedProcedure<T>): this;
1207
- /**
1208
- * Overrides the original mock implementation temporarily while the callback is being executed.
1209
- *
1210
- * Note that this method takes precedence over the [`mockImplementationOnce`](https://vitest.dev/api/mock#mockimplementationonce).
1211
- * @see https://vitest.dev/api/mock#withimplementation
1212
- * @example
1213
- * const myMockFn = vi.fn(() => 'original')
1214
- *
1215
- * myMockFn.withImplementation(() => 'temp', () => {
1216
- * myMockFn() // 'temp'
1217
- * })
1218
- *
1219
- * myMockFn() // 'original'
1220
- */
1221
- withImplementation(fn: NormalizedProcedure<T>, cb: () => Promise<unknown>): Promise<this>;
1222
- withImplementation(fn: NormalizedProcedure<T>, cb: () => unknown): this;
1223
- /**
1224
- * Use this if you need to return the `this` context from the method without invoking the actual implementation.
1225
- * @see https://vitest.dev/api/mock#mockreturnthis
1226
- */
1227
- mockReturnThis(): this;
1228
- /**
1229
- * 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.
1230
- * @see https://vitest.dev/api/mock#mockreturnvalue
1231
- * @example
1232
- * const mock = vi.fn()
1233
- * mock.mockReturnValue(42)
1234
- * mock() // 42
1235
- * mock.mockReturnValue(43)
1236
- * mock() // 43
1237
- */
1238
- mockReturnValue(value: MockReturnType<T>): this;
1239
- /**
1240
- * 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.
1241
- *
1242
- * 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.
1243
- * @example
1244
- * const myMockFn = vi
1245
- * .fn()
1246
- * .mockReturnValue('default')
1247
- * .mockReturnValueOnce('first call')
1248
- * .mockReturnValueOnce('second call')
1249
- *
1250
- * // 'first call', 'second call', 'default'
1251
- * console.log(myMockFn(), myMockFn(), myMockFn())
1252
- */
1253
- mockReturnValueOnce(value: MockReturnType<T>): this;
1254
- /**
1255
- * Accepts a value that will be thrown whenever the mock function is called.
1256
- * @see https://vitest.dev/api/mock#mockthrow
1257
- * @example
1258
- * const myMockFn = vi.fn().mockThrow(new Error('error'))
1259
- * myMockFn() // throws 'error'
1260
- */
1261
- mockThrow(value: unknown): this;
1262
- /**
1263
- * Accepts a value that will be thrown during the next function call. If chained, every consecutive call will throw the specified value.
1264
- * @example
1265
- * const myMockFn = vi
1266
- * .fn()
1267
- * .mockReturnValue('default')
1268
- * .mockThrowOnce(new Error('first call error'))
1269
- * .mockThrowOnce('second call error')
1270
- *
1271
- * expect(() => myMockFn()).toThrowError('first call error')
1272
- * expect(() => myMockFn()).toThrowError('second call error')
1273
- * expect(myMockFn()).toEqual('default')
1274
- */
1275
- mockThrowOnce(value: unknown): this;
1276
- /**
1277
- * 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.
1278
- * @example
1279
- * const asyncMock = vi.fn().mockResolvedValue(42)
1280
- * asyncMock() // Promise<42>
1281
- */
1282
- mockResolvedValue(value: Awaited<MockReturnType<T>>): this;
1283
- /**
1284
- * 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.
1285
- * @example
1286
- * const myMockFn = vi
1287
- * .fn()
1288
- * .mockResolvedValue('default')
1289
- * .mockResolvedValueOnce('first call')
1290
- * .mockResolvedValueOnce('second call')
1291
- *
1292
- * // Promise<'first call'>, Promise<'second call'>, Promise<'default'>
1293
- * console.log(myMockFn(), myMockFn(), myMockFn())
1294
- */
1295
- mockResolvedValueOnce(value: Awaited<MockReturnType<T>>): this;
1296
- /**
1297
- * Accepts an error that will be rejected when async function is called.
1298
- * @example
1299
- * const asyncMock = vi.fn().mockRejectedValue(new Error('Async error'))
1300
- * await asyncMock() // throws Error<'Async error'>
1301
- */
1302
- mockRejectedValue(error: unknown): this;
1303
- /**
1304
- * Accepts a value that will be rejected during the next function call. If chained, each consecutive call will reject the specified value.
1305
- * @example
1306
- * const asyncMock = vi
1307
- * .fn()
1308
- * .mockResolvedValueOnce('first call')
1309
- * .mockRejectedValueOnce(new Error('Async error'))
1310
- *
1311
- * await asyncMock() // first call
1312
- * await asyncMock() // throws Error<'Async error'>
1313
- */
1314
- mockRejectedValueOnce(error: unknown): this;
1315
- }
1316
- interface Constructable {
1317
- new (...args: any[]): any;
1318
- }
1319
- //#endregion
1320
- //#region ../../node_modules/.pnpm/@vitest+expect@4.1.4/node_modules/@vitest/expect/dist/index.d.ts
1321
- interface AsymmetricMatcherInterface {
1322
- asymmetricMatch: (other: unknown, customTesters?: Array<Tester>) => boolean;
1323
- toString: () => string;
1324
- getExpectedType?: () => string;
1325
- toAsymmetricMatcher?: () => string;
1326
- }
1327
- declare abstract class AsymmetricMatcher<T, State extends MatcherState = MatcherState> implements AsymmetricMatcherInterface {
1328
- protected sample: T;
1329
- protected inverse: boolean;
1330
- $$typeof: symbol;
1331
- constructor(sample: T, inverse?: boolean);
1332
- protected getMatcherContext(expect?: Chai.ExpectStatic): State;
1333
- abstract asymmetricMatch(other: unknown, customTesters?: Array<Tester>): boolean;
1334
- abstract toString(): string;
1335
- getExpectedType?(): string;
1336
- toAsymmetricMatcher?(): string;
1337
- }
1338
- declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
1339
- declare function printReceived(object: unknown): string;
1340
- declare function printExpected(value: unknown): string;
1341
- declare function getMatcherUtils(): {
1342
- EXPECTED_COLOR: Formatter;
1343
- RECEIVED_COLOR: Formatter;
1344
- INVERTED_COLOR: Formatter;
1345
- BOLD_WEIGHT: Formatter;
1346
- DIM_COLOR: Formatter;
1347
- diff: typeof diff;
1348
- matcherHint: typeof matcherHint;
1349
- printReceived: typeof printReceived;
1350
- printExpected: typeof printExpected;
1351
- printDiffOrStringify: typeof printDiffOrStringify;
1352
- printWithType: typeof printWithType;
1353
- };
1354
- declare function printWithType<T>(name: string, value: T, print: (value: T) => string): string;
1355
- type Tester = (this: TesterContext, a: any, b: any, customTesters: Array<Tester>) => boolean | undefined;
1356
- interface TesterContext {
1357
- equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
1358
- }
1359
- interface MatcherHintOptions {
1360
- comment?: string;
1361
- expectedColor?: Formatter;
1362
- isDirectExpectCall?: boolean;
1363
- isNot?: boolean;
1364
- promise?: string;
1365
- receivedColor?: Formatter;
1366
- secondArgument?: string;
1367
- secondArgumentColor?: Formatter;
1368
- }
1369
- interface MatcherState {
1370
- customTesters: Array<Tester>;
1371
- assertionCalls: number;
1372
- currentTestName?: string;
1373
- /**
1374
- * @deprecated exists only in types
1375
- */
1376
- dontThrow?: () => void;
1377
- /**
1378
- * @deprecated exists only in types
1379
- */
1380
- error?: Error;
1381
- equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
1382
- /**
1383
- * @deprecated exists only in types
1384
- */
1385
- expand?: boolean;
1386
- expectedAssertionsNumber?: number | null;
1387
- expectedAssertionsNumberErrorGen?: (() => Error) | null;
1388
- isExpectingAssertions?: boolean;
1389
- isExpectingAssertionsError?: Error | null;
1390
- isNot: boolean;
1391
- promise: string;
1392
- /**
1393
- * @deprecated exists only in types
1394
- */
1395
- suppressedErrors: Array<Error>;
1396
- testPath?: string;
1397
- utils: ReturnType<typeof getMatcherUtils> & {
1398
- diff: typeof diff;
1399
- stringify: typeof stringify;
1400
- iterableEquality: Tester;
1401
- subsetEquality: Tester;
1402
- };
1403
- soft?: boolean;
1404
- poll?: boolean;
1405
- /**
1406
- * The same assertion instance that chai plugins receive.
1407
- * @experimental
1408
- * @see {@link https://www.chaijs.com/guide/plugins/} Core Plugin Concepts
1409
- */
1410
- readonly assertion: Assertion$1;
1411
- }
1412
- interface SyncExpectationResult {
1413
- pass: boolean;
1414
- message: () => string;
1415
- actual?: any;
1416
- expected?: any;
1417
- meta?: object;
1418
- }
1419
- type AsyncExpectationResult = Promise<SyncExpectationResult>;
1420
- type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
1421
- interface RawMatcherFn<T extends MatcherState = MatcherState, E extends Array<any> = Array<any>> {
1422
- (this: T, received: any, ...expected: E): ExpectationResult;
1423
- }
1424
- interface Matchers<T = any> {}
1425
- type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>> & ThisType<T> & { [K in keyof Matchers<T>]?: RawMatcherFn<T, Parameters<Matchers<T>[K]>> };
1426
- interface ExpectStatic extends Chai.ExpectStatic, Matchers, AsymmetricMatchersContaining {
1427
- <T>(actual: T, message?: string): Assertion$1<T>;
1428
- extend: (expects: MatchersObject) => void;
1429
- anything: () => any;
1430
- any: (constructor: unknown) => any;
1431
- getState: () => MatcherState;
1432
- setState: (state: Partial<MatcherState>) => void;
1433
- not: AsymmetricMatchersContaining;
1434
- }
1435
- interface CustomMatcher {
1436
- /**
1437
- * Checks that a value satisfies a custom matcher function.
1438
- *
1439
- * @param matcher - A function returning a boolean based on the custom condition
1440
- * @param message - Optional custom error message on failure
1441
- *
1442
- * @example
1443
- * expect(age).toSatisfy(val => val >= 18, 'Age must be at least 18');
1444
- * expect(age).toEqual(expect.toSatisfy(val => val >= 18, 'Age must be at least 18'));
1445
- */
1446
- toSatisfy: (matcher: (value: any) => boolean, message?: string) => any;
1447
- /**
1448
- * Matches if the received value is one of the values in the expected array or set.
1449
- *
1450
- * @example
1451
- * expect(1).toBeOneOf([1, 2, 3])
1452
- * expect('foo').toBeOneOf([expect.any(String)])
1453
- * expect({ a: 1 }).toEqual({ a: expect.toBeOneOf(['1', '2', '3']) })
1454
- */
1455
- toBeOneOf: <T>(sample: Array<T> | Set<T>) => any;
1456
- }
1457
- interface AsymmetricMatchersContaining extends CustomMatcher {
1458
- /**
1459
- * Matches if the received string contains the expected substring.
1460
- *
1461
- * @example
1462
- * expect('I have an apple').toEqual(expect.stringContaining('apple'));
1463
- * expect({ a: 'test string' }).toEqual({ a: expect.stringContaining('test') });
1464
- */
1465
- stringContaining: (expected: string) => any;
1466
- /**
1467
- * Matches if the received object contains all properties of the expected object.
1468
- *
1469
- * @example
1470
- * expect({ a: '1', b: 2 }).toEqual(expect.objectContaining({ a: '1' }))
1471
- */
1472
- objectContaining: <T = any>(expected: DeeplyAllowMatchers<T>) => any;
1473
- /**
1474
- * Matches if the received array contains all elements in the expected array.
1475
- *
1476
- * @example
1477
- * expect(['a', 'b', 'c']).toEqual(expect.arrayContaining(['b', 'a']));
1478
- */
1479
- arrayContaining: <T = unknown>(expected: Array<DeeplyAllowMatchers<T>>) => any;
1480
- /**
1481
- * Matches if the received string or regex matches the expected pattern.
1482
- *
1483
- * @example
1484
- * expect('hello world').toEqual(expect.stringMatching(/^hello/));
1485
- * expect('hello world').toEqual(expect.stringMatching('hello'));
1486
- */
1487
- stringMatching: (expected: string | RegExp) => any;
1488
- /**
1489
- * Matches if the received number is within a certain precision of the expected number.
1490
- *
1491
- * @example
1492
- * expect(10.45).toEqual(expect.closeTo(10.5, 1));
1493
- * expect(5.11).toEqual(expect.closeTo(5.12)); // with default precision
1494
- */
1495
- closeTo: (expected: number, precision?: number) => any;
1496
- /**
1497
- * Matches if the received value validates against a Standard Schema.
1498
- *
1499
- * @param schema - A Standard Schema V1 compatible schema object
1500
- *
1501
- * @example
1502
- * expect(user).toEqual(expect.schemaMatching(z.object({ name: z.string() })))
1503
- * expect(['hello', 'world']).toEqual([expect.schemaMatching(z.string()), expect.schemaMatching(z.string())])
1504
- */
1505
- schemaMatching: (schema: unknown) => any;
1506
- }
1507
- type WithAsymmetricMatcher<T> = T | AsymmetricMatcher<unknown>;
1508
- 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>;
1509
- interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomMatcher {
1510
- /**
1511
- * Used when you want to check that two objects have the same value.
1512
- * This matcher recursively checks the equality of all fields, rather than checking for object identity.
1513
- *
1514
- * @example
1515
- * expect(user).toEqual({ name: 'Alice', age: 30 });
1516
- */
1517
- toEqual: <E>(expected: E) => void;
1518
- /**
1519
- * Use to test that objects have the same types as well as structure.
1520
- *
1521
- * @example
1522
- * expect(user).toStrictEqual({ name: 'Alice', age: 30 });
1523
- */
1524
- toStrictEqual: <E>(expected: E) => void;
1525
- /**
1526
- * Checks that a value is what you expect. It calls `Object.is` to compare values.
1527
- * Don't use `toBe` with floating-point numbers.
1528
- *
1529
- * @example
1530
- * expect(result).toBe(42);
1531
- * expect(status).toBe(true);
1532
- */
1533
- toBe: <E>(expected: E) => void;
1534
- /**
1535
- * Check that a string matches a regular expression.
1536
- *
1537
- * @example
1538
- * expect(message).toMatch(/hello/);
1539
- * expect(greeting).toMatch('world');
1540
- */
1541
- toMatch: (expected: string | RegExp) => void;
1542
- /**
1543
- * Used to check that a JavaScript object matches a subset of the properties of an object
1544
- *
1545
- * @example
1546
- * expect(user).toMatchObject({
1547
- * name: 'Alice',
1548
- * address: { city: 'Wonderland' }
1549
- * });
1550
- */
1551
- toMatchObject: <E extends object | any[]>(expected: E) => void;
1552
- /**
1553
- * Used when you want to check that an item is in a list.
1554
- * For testing the items in the list, this uses `===`, a strict equality check.
1555
- *
1556
- * @example
1557
- * expect(items).toContain('apple');
1558
- * expect(numbers).toContain(5);
1559
- */
1560
- toContain: <E>(item: E) => void;
1561
- /**
1562
- * Used when you want to check that an item is in a list.
1563
- * For testing the items in the list, this matcher recursively checks the
1564
- * equality of all fields, rather than checking for object identity.
1565
- *
1566
- * @example
1567
- * expect(items).toContainEqual({ name: 'apple', quantity: 1 });
1568
- */
1569
- toContainEqual: <E>(item: E) => void;
1570
- /**
1571
- * Use when you don't care what a value is, you just want to ensure a value
1572
- * is true in a boolean context. In JavaScript, there are six falsy values:
1573
- * `false`, `0`, `''`, `null`, `undefined`, and `NaN`. Everything else is truthy.
1574
- *
1575
- * @example
1576
- * expect(user.isActive).toBeTruthy();
1577
- */
1578
- toBeTruthy: () => void;
1579
- /**
1580
- * When you don't care what a value is, you just want to
1581
- * ensure a value is false in a boolean context.
1582
- *
1583
- * @example
1584
- * expect(user.isActive).toBeFalsy();
1585
- */
1586
- toBeFalsy: () => void;
1587
- /**
1588
- * For comparing floating point numbers.
1589
- *
1590
- * @example
1591
- * expect(score).toBeGreaterThan(10);
1592
- */
1593
- toBeGreaterThan: (num: number | bigint) => void;
1594
- /**
1595
- * For comparing floating point numbers.
1596
- *
1597
- * @example
1598
- * expect(score).toBeGreaterThanOrEqual(10);
1599
- */
1600
- toBeGreaterThanOrEqual: (num: number | bigint) => void;
1601
- /**
1602
- * For comparing floating point numbers.
1603
- *
1604
- * @example
1605
- * expect(score).toBeLessThan(10);
1606
- */
1607
- toBeLessThan: (num: number | bigint) => void;
1608
- /**
1609
- * For comparing floating point numbers.
1610
- *
1611
- * @example
1612
- * expect(score).toBeLessThanOrEqual(10);
1613
- */
1614
- toBeLessThanOrEqual: (num: number | bigint) => void;
1615
- /**
1616
- * Used to check that a variable is NaN.
1617
- *
1618
- * @example
1619
- * expect(value).toBeNaN();
1620
- */
1621
- toBeNaN: () => void;
1622
- /**
1623
- * Used to check that a variable is undefined.
1624
- *
1625
- * @example
1626
- * expect(value).toBeUndefined();
1627
- */
1628
- toBeUndefined: () => void;
1629
- /**
1630
- * This is the same as `.toBe(null)` but the error messages are a bit nicer.
1631
- * So use `.toBeNull()` when you want to check that something is null.
1632
- *
1633
- * @example
1634
- * expect(value).toBeNull();
1635
- */
1636
- toBeNull: () => void;
1637
- /**
1638
- * Used to check that a variable is nullable (null or undefined).
1639
- *
1640
- * @example
1641
- * expect(value).toBeNullable();
1642
- */
1643
- toBeNullable: () => void;
1644
- /**
1645
- * Ensure that a variable is not undefined.
1646
- *
1647
- * @example
1648
- * expect(value).toBeDefined();
1649
- */
1650
- toBeDefined: () => void;
1651
- /**
1652
- * Ensure that an object is an instance of a class.
1653
- * This matcher uses `instanceof` underneath.
1654
- *
1655
- * @example
1656
- * expect(new Date()).toBeInstanceOf(Date);
1657
- */
1658
- toBeInstanceOf: <E>(expected: E) => void;
1659
- /**
1660
- * Used to check that an object has a `.length` property
1661
- * and it is set to a certain numeric value.
1662
- *
1663
- * @example
1664
- * expect([1, 2, 3]).toHaveLength(3);
1665
- * expect('hello').toHaveLength(5);
1666
- */
1667
- toHaveLength: (length: number) => void;
1668
- /**
1669
- * Use to check if a property at the specified path exists on an object.
1670
- * For checking deeply nested properties, you may use dot notation or an array containing
1671
- * the path segments for deep references.
1672
- *
1673
- * Optionally, you can provide a value to check if it matches the value present at the path
1674
- * on the target object. This matcher uses 'deep equality' (like `toEqual()`) and recursively checks
1675
- * the equality of all fields.
1676
- *
1677
- * @example
1678
- * expect(user).toHaveProperty('address.city', 'New York');
1679
- * expect(config).toHaveProperty(['settings', 'theme'], 'dark');
1680
- */
1681
- toHaveProperty: <E>(property: string | (string | number)[], value?: E) => void;
1682
- /**
1683
- * Using exact equality with floating point numbers is a bad idea.
1684
- * Rounding means that intuitive things fail.
1685
- * The default for `numDigits` is 2.
1686
- *
1687
- * @example
1688
- * expect(price).toBeCloseTo(9.99, 2);
1689
- */
1690
- toBeCloseTo: (number: number, numDigits?: number) => void;
1691
- /**
1692
- * Ensures that a mock function is called an exact number of times.
1693
- *
1694
- * Also under the alias `expect.toBeCalledTimes`.
1695
- *
1696
- * @example
1697
- * expect(mockFunc).toHaveBeenCalledTimes(2);
1698
- */
1699
- toHaveBeenCalledTimes: (times: number) => void;
1700
- /**
1701
- * Ensures that a mock function is called an exact number of times.
1702
- *
1703
- * Alias for `expect.toHaveBeenCalledTimes`.
1704
- *
1705
- * @example
1706
- * expect(mockFunc).toBeCalledTimes(2);
1707
- * @deprecated Use `toHaveBeenCalledTimes` instead
1708
- */
1709
- toBeCalledTimes: (times: number) => void;
1710
- /**
1711
- * Ensures that a mock function is called.
1712
- *
1713
- * Also under the alias `expect.toBeCalled`.
1714
- *
1715
- * @example
1716
- * expect(mockFunc).toHaveBeenCalled();
1717
- */
1718
- toHaveBeenCalled: () => void;
1719
- /**
1720
- * Ensures that a mock function is called.
1721
- *
1722
- * Alias for `expect.toHaveBeenCalled`.
1723
- *
1724
- * @example
1725
- * expect(mockFunc).toBeCalled();
1726
- * @deprecated Use `toHaveBeenCalled` instead
1727
- */
1728
- toBeCalled: () => void;
1729
- /**
1730
- * Ensure that a mock function is called with specific arguments.
1731
- *
1732
- * Also under the alias `expect.toBeCalledWith`.
1733
- *
1734
- * @example
1735
- * expect(mockFunc).toHaveBeenCalledWith('arg1', 42);
1736
- */
1737
- toHaveBeenCalledWith: <E extends any[]>(...args: E) => void;
1738
- /**
1739
- * Ensure that a mock function is called with specific arguments.
1740
- *
1741
- * Alias for `expect.toHaveBeenCalledWith`.
1742
- *
1743
- * @example
1744
- * expect(mockFunc).toBeCalledWith('arg1', 42);
1745
- * @deprecated Use `toHaveBeenCalledWith` instead
1746
- */
1747
- toBeCalledWith: <E extends any[]>(...args: E) => void;
1748
- /**
1749
- * Ensure that a mock function is called with specific arguments on an Nth call.
1750
- *
1751
- * Also under the alias `expect.nthCalledWith`.
1752
- *
1753
- * @example
1754
- * expect(mockFunc).toHaveBeenNthCalledWith(2, 'secondArg');
1755
- */
1756
- toHaveBeenNthCalledWith: <E extends any[]>(n: number, ...args: E) => void;
1757
- /**
1758
- * If you have a mock function, you can use `.toHaveBeenLastCalledWith`
1759
- * to test what arguments it was last called with.
1760
- *
1761
- * Also under the alias `expect.lastCalledWith`.
1762
- *
1763
- * @example
1764
- * expect(mockFunc).toHaveBeenLastCalledWith('lastArg');
1765
- */
1766
- toHaveBeenLastCalledWith: <E extends any[]>(...args: E) => void;
1767
- /**
1768
- * Used to test that a function throws when it is called.
1769
- *
1770
- * Also under the alias `expect.toThrowError`.
1771
- *
1772
- * @example
1773
- * expect(() => functionWithError()).toThrow('Error message');
1774
- * expect(() => parseJSON('invalid')).toThrow(SyntaxError);
1775
- * expect(() => { throw 42 }).toThrow(42);
1776
- */
1777
- toThrow: (expected?: any) => void;
1778
- /**
1779
- * Used to test that a function throws when it is called.
1780
- *
1781
- * Alias for `expect.toThrow`.
1782
- *
1783
- * @example
1784
- * expect(() => functionWithError()).toThrowError('Error message');
1785
- * expect(() => parseJSON('invalid')).toThrowError(SyntaxError);
1786
- * expect(() => { throw 42 }).toThrowError(42);
1787
- * @deprecated Use `toThrow` instead
1788
- */
1789
- toThrowError: (expected?: any) => void;
1790
- /**
1791
- * Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
1792
- *
1793
- * Alias for `expect.toHaveReturned`.
1794
- *
1795
- * @example
1796
- * expect(mockFunc).toReturn();
1797
- * @deprecated Use `toHaveReturned` instead
1798
- */
1799
- toReturn: () => void;
1800
- /**
1801
- * Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
1802
- *
1803
- * Also under the alias `expect.toReturn`.
1804
- *
1805
- * @example
1806
- * expect(mockFunc).toHaveReturned();
1807
- */
1808
- toHaveReturned: () => void;
1809
- /**
1810
- * Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
1811
- * Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
1812
- *
1813
- * Alias for `expect.toHaveReturnedTimes`.
1814
- *
1815
- * @example
1816
- * expect(mockFunc).toReturnTimes(3);
1817
- * @deprecated Use `toHaveReturnedTimes` instead
1818
- */
1819
- toReturnTimes: (times: number) => void;
1820
- /**
1821
- * Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
1822
- * Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
1823
- *
1824
- * Also under the alias `expect.toReturnTimes`.
1825
- *
1826
- * @example
1827
- * expect(mockFunc).toHaveReturnedTimes(3);
1828
- */
1829
- toHaveReturnedTimes: (times: number) => void;
1830
- /**
1831
- * Use to ensure that a mock function returned a specific value.
1832
- *
1833
- * Alias for `expect.toHaveReturnedWith`.
1834
- *
1835
- * @example
1836
- * expect(mockFunc).toReturnWith('returnValue');
1837
- * @deprecated Use `toHaveReturnedWith` instead
1838
- */
1839
- toReturnWith: <E>(value: E) => void;
1840
- /**
1841
- * Use to ensure that a mock function returned a specific value.
1842
- *
1843
- * Also under the alias `expect.toReturnWith`.
1844
- *
1845
- * @example
1846
- * expect(mockFunc).toHaveReturnedWith('returnValue');
1847
- */
1848
- toHaveReturnedWith: <E>(value: E) => void;
1849
- /**
1850
- * Use to test the specific value that a mock function last returned.
1851
- * If the last call to the mock function threw an error, then this matcher will fail
1852
- * no matter what value you provided as the expected return value.
1853
- *
1854
- * Also under the alias `expect.lastReturnedWith`.
1855
- *
1856
- * @example
1857
- * expect(mockFunc).toHaveLastReturnedWith('lastValue');
1858
- */
1859
- toHaveLastReturnedWith: <E>(value: E) => void;
1860
- /**
1861
- * Use to test the specific value that a mock function returned for the nth call.
1862
- * If the nth call to the mock function threw an error, then this matcher will fail
1863
- * no matter what value you provided as the expected return value.
1864
- *
1865
- * Also under the alias `expect.nthReturnedWith`.
1866
- *
1867
- * @example
1868
- * expect(mockFunc).toHaveNthReturnedWith(2, 'nthValue');
1869
- */
1870
- toHaveNthReturnedWith: <E>(nthCall: number, value: E) => void;
1871
- }
1872
- type VitestAssertion<A, T> = { [K in keyof A]: A[K] extends Chai.Assertion ? Assertion$1<T> : A[K] extends ((...args: any[]) => any) ? A[K] : VitestAssertion<A[K], T> } & ((type: string, message?: string) => Assertion$1);
1873
- type Promisify<O> = { [K in keyof O]: O[K] extends ((...args: infer A) => infer R) ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K] };
1874
- type PromisifyAssertion<T> = Promisify<Assertion$1<T>>;
1875
- interface Assertion$1<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T>, ChaiMockAssertion, Matchers<T> {
1876
- /**
1877
- * Ensures a value is of a specific type.
1878
- *
1879
- * @example
1880
- * expect(value).toBeTypeOf('string');
1881
- * expect(number).toBeTypeOf('number');
1882
- */
1883
- toBeTypeOf: (expected: "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined") => void;
1884
- /**
1885
- * Asserts that a mock function was called exactly once.
1886
- *
1887
- * @example
1888
- * expect(mockFunc).toHaveBeenCalledOnce();
1889
- */
1890
- toHaveBeenCalledOnce: () => void;
1891
- /**
1892
- * Ensure that a mock function is called with specific arguments and called
1893
- * exactly once.
1894
- *
1895
- * @example
1896
- * expect(mockFunc).toHaveBeenCalledExactlyOnceWith('arg1', 42);
1897
- */
1898
- toHaveBeenCalledExactlyOnceWith: <E extends any[]>(...args: E) => void;
1899
- /**
1900
- * This assertion checks if a `Mock` was called before another `Mock`.
1901
- * @param mock - A mock function created by `vi.spyOn` or `vi.fn`
1902
- * @param failIfNoFirstInvocation - Fail if the first mock was never called
1903
- * @example
1904
- * const mock1 = vi.fn()
1905
- * const mock2 = vi.fn()
1906
- *
1907
- * mock1()
1908
- * mock2()
1909
- * mock1()
1910
- *
1911
- * expect(mock1).toHaveBeenCalledBefore(mock2)
1912
- */
1913
- toHaveBeenCalledBefore: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
1914
- /**
1915
- * This assertion checks if a `Mock` was called after another `Mock`.
1916
- * @param mock - A mock function created by `vi.spyOn` or `vi.fn`
1917
- * @param failIfNoFirstInvocation - Fail if the first mock was never called
1918
- * @example
1919
- * const mock1 = vi.fn()
1920
- * const mock2 = vi.fn()
1921
- *
1922
- * mock2()
1923
- * mock1()
1924
- * mock2()
1925
- *
1926
- * expect(mock1).toHaveBeenCalledAfter(mock2)
1927
- */
1928
- toHaveBeenCalledAfter: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
1929
- /**
1930
- * Checks that a promise resolves successfully at least once.
1931
- *
1932
- * @example
1933
- * await expect(promise).toHaveResolved();
1934
- */
1935
- toHaveResolved: () => void;
1936
- /**
1937
- * Checks that a promise resolves to a specific value.
1938
- *
1939
- * @example
1940
- * await expect(promise).toHaveResolvedWith('success');
1941
- */
1942
- toHaveResolvedWith: <E>(value: E) => void;
1943
- /**
1944
- * Ensures a promise resolves a specific number of times.
1945
- *
1946
- * @example
1947
- * expect(mockAsyncFunc).toHaveResolvedTimes(3);
1948
- */
1949
- toHaveResolvedTimes: (times: number) => void;
1950
- /**
1951
- * Asserts that the last resolved value of a promise matches an expected value.
1952
- *
1953
- * @example
1954
- * await expect(mockAsyncFunc).toHaveLastResolvedWith('finalResult');
1955
- */
1956
- toHaveLastResolvedWith: <E>(value: E) => void;
1957
- /**
1958
- * Ensures a specific value was returned by a promise on the nth resolution.
1959
- *
1960
- * @example
1961
- * await expect(mockAsyncFunc).toHaveNthResolvedWith(2, 'secondResult');
1962
- */
1963
- toHaveNthResolvedWith: <E>(nthCall: number, value: E) => void;
1964
- /**
1965
- * Verifies that a promise resolves.
1966
- *
1967
- * @example
1968
- * await expect(someAsyncFunc).resolves.toBe(42);
1969
- */
1970
- resolves: PromisifyAssertion<T>;
1971
- /**
1972
- * Verifies that a promise rejects.
1973
- *
1974
- * @example
1975
- * await expect(someAsyncFunc).rejects.toThrow('error');
1976
- */
1977
- rejects: PromisifyAssertion<T>;
1978
- }
1979
- /**
1980
- * Chai-style assertions for spy/mock testing.
1981
- * These provide sinon-chai compatible assertion names that delegate to Jest-style implementations.
1982
- */
1983
- interface ChaiMockAssertion {
1984
- /**
1985
- * Checks that a spy was called at least once.
1986
- * Chai-style equivalent of `toHaveBeenCalled`.
1987
- *
1988
- * @example
1989
- * expect(spy).to.have.been.called
1990
- */
1991
- readonly called: Assertion$1;
1992
- /**
1993
- * Checks that a spy was called a specific number of times.
1994
- * Chai-style equivalent of `toHaveBeenCalledTimes`.
1995
- *
1996
- * @example
1997
- * expect(spy).to.have.callCount(3)
1998
- */
1999
- callCount: (count: number) => void;
2000
- /**
2001
- * Checks that a spy was called with specific arguments at least once.
2002
- * Chai-style equivalent of `toHaveBeenCalledWith`.
2003
- *
2004
- * @example
2005
- * expect(spy).to.have.been.calledWith('arg1', 'arg2')
2006
- */
2007
- calledWith: <E extends any[]>(...args: E) => void;
2008
- /**
2009
- * Checks that a spy was called exactly once.
2010
- * Chai-style equivalent of `toHaveBeenCalledOnce`.
2011
- *
2012
- * @example
2013
- * expect(spy).to.have.been.calledOnce
2014
- */
2015
- readonly calledOnce: Assertion$1;
2016
- /**
2017
- * Checks that a spy was called exactly once with specific arguments.
2018
- * Chai-style equivalent of `toHaveBeenCalledExactlyOnceWith`.
2019
- *
2020
- * @example
2021
- * expect(spy).to.have.been.calledOnceWith('arg1', 'arg2')
2022
- */
2023
- calledOnceWith: <E extends any[]>(...args: E) => void;
2024
- /**
2025
- * Checks that the last call to a spy was made with specific arguments.
2026
- * Chai-style equivalent of `toHaveBeenLastCalledWith`.
2027
- *
2028
- * @example
2029
- * expect(spy).to.have.been.lastCalledWith('arg1', 'arg2')
2030
- */
2031
- lastCalledWith: <E extends any[]>(...args: E) => void;
2032
- /**
2033
- * Checks that the nth call to a spy was made with specific arguments.
2034
- * Chai-style equivalent of `toHaveBeenNthCalledWith`.
2035
- *
2036
- * @example
2037
- * expect(spy).to.have.been.nthCalledWith(2, 'arg1', 'arg2')
2038
- */
2039
- nthCalledWith: <E extends any[]>(n: number, ...args: E) => void;
2040
- /**
2041
- * Checks that a spy returned a specific value at least once.
2042
- * Chai-style equivalent of `toHaveReturnedWith`.
2043
- *
2044
- * @example
2045
- * expect(spy).to.have.returned('value')
2046
- */
2047
- returned: <E>(value: E) => void;
2048
- /**
2049
- * Checks that a spy returned a specific value at least once.
2050
- * Chai-style equivalent of `toHaveReturnedWith`.
2051
- *
2052
- * @example
2053
- * expect(spy).to.have.returnedWith('value')
2054
- */
2055
- returnedWith: <E>(value: E) => void;
2056
- /**
2057
- * Checks that a spy returned successfully a specific number of times.
2058
- * Chai-style equivalent of `toHaveReturnedTimes`.
2059
- *
2060
- * @example
2061
- * expect(spy).to.have.returnedTimes(3)
2062
- */
2063
- returnedTimes: (count: number) => void;
2064
- /**
2065
- * Checks that the last return value of a spy matches the expected value.
2066
- * Chai-style equivalent of `toHaveLastReturnedWith`.
2067
- *
2068
- * @example
2069
- * expect(spy).to.have.lastReturnedWith('value')
2070
- */
2071
- lastReturnedWith: <E>(value: E) => void;
2072
- /**
2073
- * Checks that the nth return value of a spy matches the expected value.
2074
- * Chai-style equivalent of `toHaveNthReturnedWith`.
2075
- *
2076
- * @example
2077
- * expect(spy).to.have.nthReturnedWith(2, 'value')
2078
- */
2079
- nthReturnedWith: <E>(n: number, value: E) => void;
2080
- /**
2081
- * Checks that a spy was called before another spy.
2082
- * Chai-style equivalent of `toHaveBeenCalledBefore`.
2083
- *
2084
- * @example
2085
- * expect(spy1).to.have.been.calledBefore(spy2)
2086
- */
2087
- calledBefore: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
2088
- /**
2089
- * Checks that a spy was called after another spy.
2090
- * Chai-style equivalent of `toHaveBeenCalledAfter`.
2091
- *
2092
- * @example
2093
- * expect(spy1).to.have.been.calledAfter(spy2)
2094
- */
2095
- calledAfter: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
2096
- /**
2097
- * Checks that a spy was called exactly twice.
2098
- * Chai-style equivalent of `toHaveBeenCalledTimes(2)`.
2099
- *
2100
- * @example
2101
- * expect(spy).to.have.been.calledTwice
2102
- */
2103
- readonly calledTwice: Assertion$1;
2104
- /**
2105
- * Checks that a spy was called exactly three times.
2106
- * Chai-style equivalent of `toHaveBeenCalledTimes(3)`.
2107
- *
2108
- * @example
2109
- * expect(spy).to.have.been.calledThrice
2110
- */
2111
- readonly calledThrice: Assertion$1;
2112
- }
2113
- declare global {
2114
- namespace jest {
2115
- interface Matchers<R, T = {}> {}
2116
- }
2117
- }
2118
- //#endregion
2119
- //#region ../../node_modules/.pnpm/tinybench@2.9.0/node_modules/tinybench/dist/index.d.cts
2120
- /**
2121
- * the benchmark task result object
2122
- */
2123
- type TaskResult = {
2124
- error?: unknown;
2125
- /**
2126
- * The amount of time in milliseconds to run the benchmark task (cycle).
2127
- */
2128
- totalTime: number;
2129
- /**
2130
- * the minimum value in the samples
2131
- */
2132
- min: number;
2133
- /**
2134
- * the maximum value in the samples
2135
- */
2136
- max: number;
2137
- /**
2138
- * the number of operations per second
2139
- */
2140
- hz: number;
2141
- /**
2142
- * how long each operation takes (ms)
2143
- */
2144
- period: number;
2145
- /**
2146
- * task samples of each task iteration time (ms)
2147
- */
2148
- samples: number[];
2149
- /**
2150
- * samples mean/average (estimate of the population mean)
2151
- */
2152
- mean: number;
2153
- /**
2154
- * samples variance (estimate of the population variance)
2155
- */
2156
- variance: number;
2157
- /**
2158
- * samples standard deviation (estimate of the population standard deviation)
2159
- */
2160
- sd: number;
2161
- /**
2162
- * standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean)
2163
- */
2164
- sem: number;
2165
- /**
2166
- * degrees of freedom
2167
- */
2168
- df: number;
2169
- /**
2170
- * critical value of the samples
2171
- */
2172
- critical: number;
2173
- /**
2174
- * margin of error
2175
- */
2176
- moe: number;
2177
- /**
2178
- * relative margin of error
2179
- */
2180
- rme: number;
2181
- /**
2182
- * p75 percentile
2183
- */
2184
- p75: number;
2185
- /**
2186
- * p99 percentile
2187
- */
2188
- p99: number;
2189
- /**
2190
- * p995 percentile
2191
- */
2192
- p995: number;
2193
- /**
2194
- * p999 percentile
2195
- */
2196
- p999: number;
2197
- };
2198
- /**
2199
- * Both the `Task` and `Bench` objects extend the `EventTarget` object,
2200
- * so you can attach a listeners to different types of events
2201
- * to each class instance using the universal `addEventListener` and
2202
- * `removeEventListener`
2203
- */
2204
- /**
2205
- * Bench events
2206
- */
2207
- //#endregion
2208
- //#region ../../node_modules/.pnpm/vitest@4.1.4_@types+node@25.6.0_@vitest+coverage-v8@4.1.4_vite@8.0.8_@types+node@25.6.0_f62b45bc4bcc1123dfacc813508205a7/node_modules/vitest/dist/chunks/benchmark.d.DAaHLpsq.d.ts
2209
- interface BenchmarkResult extends TaskResult {
2210
- name: string;
2211
- rank: number;
2212
- sampleCount: number;
2213
- median: number;
2214
- }
2215
- //#endregion
2216
- //#region ../../node_modules/.pnpm/vitest@4.1.4_@types+node@25.6.0_@vitest+coverage-v8@4.1.4_vite@8.0.8_@types+node@25.6.0_f62b45bc4bcc1123dfacc813508205a7/node_modules/vitest/dist/chunks/global.d.D74z04P1.d.ts
2217
- interface SnapshotMatcher<T> {
2218
- <U extends { [P in keyof T]: any }>(snapshot: Partial<U>, hint?: string): void;
2219
- (hint?: string): void;
2220
- }
2221
- interface InlineSnapshotMatcher<T> {
2222
- <U extends { [P in keyof T]: any }>(properties: Partial<U>, snapshot?: string, hint?: string): void;
2223
- (hint?: string): void;
2224
- }
2225
- declare module "@vitest/expect" {
2226
- interface MatcherState {
2227
- environment: string;
2228
- snapshotState: SnapshotState;
2229
- task?: Readonly<Test>;
2230
- }
2231
- interface ExpectPollOptions {
2232
- interval?: number;
2233
- timeout?: number;
2234
- message?: string;
2235
- }
2236
- interface ExpectStatic {
2237
- assert: Chai.AssertStatic;
2238
- unreachable: (message?: string) => never;
2239
- soft: <T>(actual: T, message?: string) => Assertion<T>;
2240
- poll: <T>(actual: () => T, options?: ExpectPollOptions) => PromisifyAssertion<Awaited<T>>;
2241
- addEqualityTesters: (testers: Array<Tester>) => void;
2242
- assertions: (expected: number) => void;
2243
- hasAssertions: () => void;
2244
- addSnapshotSerializer: (plugin: Plugin) => void;
2245
- }
2246
- interface Assertion<T> {
2247
- matchSnapshot: SnapshotMatcher<T>;
2248
- toMatchSnapshot: SnapshotMatcher<T>;
2249
- toMatchInlineSnapshot: InlineSnapshotMatcher<T>;
2250
- /**
2251
- * Checks that an error thrown by a function matches a previously recorded snapshot.
2252
- *
2253
- * @param hint - Optional custom error message.
2254
- *
2255
- * @example
2256
- * expect(functionWithError).toThrowErrorMatchingSnapshot();
2257
- */
2258
- toThrowErrorMatchingSnapshot: (hint?: string) => void;
2259
- /**
2260
- * Checks that an error thrown by a function matches an inline snapshot within the test file.
2261
- * Useful for keeping snapshots close to the test code.
2262
- *
2263
- * @param snapshot - Optional inline snapshot string to match.
2264
- * @param hint - Optional custom error message.
2265
- *
2266
- * @example
2267
- * const throwError = () => { throw new Error('Error occurred') };
2268
- * expect(throwError).toThrowErrorMatchingInlineSnapshot(`"Error occurred"`);
2269
- */
2270
- toThrowErrorMatchingInlineSnapshot: (snapshot?: string, hint?: string) => void;
2271
- /**
2272
- * Compares the received value to a snapshot saved in a specified file.
2273
- * Useful for cases where snapshot content is large or needs to be shared across tests.
2274
- *
2275
- * @param filepath - Path to the snapshot file.
2276
- * @param hint - Optional custom error message.
2277
- *
2278
- * @example
2279
- * await expect(largeData).toMatchFileSnapshot('path/to/snapshot.json');
2280
- */
2281
- toMatchFileSnapshot: (filepath: string, hint?: string) => Promise<void>;
2282
- }
2283
- }
2284
- declare module "@vitest/runner" {
2285
- interface TestContext {
2286
- /**
2287
- * `expect` instance bound to the current test.
2288
- *
2289
- * This API is useful for running snapshot tests concurrently because global expect cannot track them.
2290
- */
2291
- readonly expect: ExpectStatic;
2292
- /** @internal */
2293
- _local: boolean;
2294
- }
2295
- interface TaskMeta {
2296
- typecheck?: boolean;
2297
- benchmark?: boolean;
2298
- }
2299
- interface File {
2300
- prepareDuration?: number;
2301
- environmentLoad?: number;
2302
- }
2303
- interface TaskBase {
2304
- logs?: UserConsoleLog[];
2305
- }
2306
- interface TaskResult {
2307
- benchmark?: BenchmarkResult;
2308
- }
2309
- }
2310
- //#endregion
2311
- //#region src/expect.d.ts
2312
- /**
2313
- * Re-exported expect with vieval custom matchers pre-installed.
2314
- */
2315
- declare const expect: ExpectStatic;
2316
- //#endregion
2317
- export { type expect as t };
2318
- //# sourceMappingURL=expect-0jPJ7Zio.d.mts.map