@interfere/react 12.0.1 → 12.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{api-wpS4xoMY.d.mts → api-DEVCOKkJ.d.mts} +4 -0
- package/dist/dist-ByNfzdQp.mjs +17 -0
- package/dist/error-boundary.d.mts +1 -1
- package/dist/{index-D-HGWlgi.d.mts → index-BVwotsYa.d.mts} +1 -1
- package/dist/internal/capture-boundary.d.mts +1 -1
- package/dist/internal/capture.d.mts +1 -1
- package/dist/internal/consent.d.mts +2 -8
- package/dist/internal/consent.mjs +1 -1
- package/dist/internal/kernel-registry.d.mts +1 -1
- package/dist/internal/kernel.d.mts +1 -1
- package/dist/internal/kernel.mjs +1 -1
- package/dist/internal/otel/exporter.mjs +1 -1
- package/dist/internal/otel/index.d.mts +2 -2
- package/dist/internal/otel/provider.d.mts +1 -1
- package/dist/internal/otel/provider.mjs +1 -1
- package/dist/internal/plugin-runtime.d.mts +1 -1
- package/dist/internal/plugin-runtime.mjs +1 -1
- package/dist/internal/react-context.d.mts +1 -1
- package/dist/internal/sw-queue.mjs +1 -1
- package/dist/internal/version.mjs +1 -1
- package/dist/internal/wrapper-singleton.d.mts +3 -3
- package/dist/internal/wrapper-singleton.mjs +1 -1
- package/dist/plugins/device.d.mts +1 -1
- package/dist/plugins/errors.d.mts +1 -1
- package/dist/plugins/lib/loader.d.mts +1 -1
- package/dist/plugins/lib/types.d.mts +1 -1
- package/dist/plugins/logs.d.mts +1 -1
- package/dist/plugins/logs.mjs +1 -1
- package/dist/plugins/page-events.d.mts +1 -1
- package/dist/plugins/rage-clicks.d.mts +1 -1
- package/dist/plugins/replay/delivery.d.mts +1 -1
- package/dist/plugins/replay/index.d.mts +1 -1
- package/dist/{provider-DRuvRafW.d.mts → provider-B2L5znqI.d.mts} +24 -16
- package/dist/{provider-CF0h4Mah.d.mts → provider-Df5aXrYa.d.mts} +4 -2
- package/dist/provider.d.mts +1 -1
- package/dist/react-error-handler.d.mts +1 -1
- package/dist/tracking/api.d.mts +1 -1
- package/dist/tracking/api.mjs +1 -1
- package/dist/tracking/registration.fixture.d.mts +3112 -0
- package/dist/tracking/registration.fixture.mjs +133 -0
- package/dist/tracking/session-retry.d.mts +10 -0
- package/dist/tracking/session-retry.mjs +1 -0
- package/dist/{version-XRSM9Pwm.mjs → version-CmerIGVk.mjs} +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,3112 @@
|
|
|
1
|
+
import { t as SessionTracker } from "../api-DEVCOKkJ.mjs";
|
|
2
|
+
//#region ../../../../node_modules/.bun/vitest@5.0.1+3a20bcfa24daf8e9/node_modules/vitest/optional-runtime-types.d.ts
|
|
3
|
+
/* eslint-disable ts/ban-ts-comment */
|
|
4
|
+
interface Disposable {
|
|
5
|
+
// @ts-ignore -- Symbol.dispose might not be in user types
|
|
6
|
+
[Symbol.dispose]: () => void;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region ../../../../node_modules/.bun/tinybench@6.1.4/node_modules/tinybench/dist/index.d.ts
|
|
10
|
+
//#region src/task.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* A class that represents each benchmark task in Tinybench. It keeps track of the
|
|
13
|
+
* results, name, the task function, the number times the task function has been executed, ...
|
|
14
|
+
*/
|
|
15
|
+
declare class Task$1 extends EventTarget {
|
|
16
|
+
#private;
|
|
17
|
+
addEventListener: (<K extends TaskEvents>(type: K, listener: EventListener<K, 'task'> | EventListenerObject<K, 'task'> | null, options?: AddEventListenerOptionsArgument) => void) & EventTarget['addEventListener'];
|
|
18
|
+
removeEventListener: (<K extends TaskEvents>(type: K, listener: EventListener<K, 'task'> | EventListenerObject<K, 'task'> | null, options?: RemoveEventListenerOptionsArgument) => void) & EventTarget['removeEventListener'];
|
|
19
|
+
/**
|
|
20
|
+
* The estimated effective timer resolution observed during the last run,
|
|
21
|
+
* computed as the smallest strictly positive latency sample that repeats
|
|
22
|
+
* among the timer-measured samples, or the smallest strictly positive
|
|
23
|
+
* sample when none repeats (samples supplied via `overriddenDuration` are
|
|
24
|
+
* excluded). When `subtractTimerOverhead` is enabled the value is derived
|
|
25
|
+
* from the overhead-corrected samples rather than the raw timer grain.
|
|
26
|
+
* @returns The resolution in milliseconds, or `undefined` when no
|
|
27
|
+
* timer-measured strictly positive sample was observed (e.g. every
|
|
28
|
+
* sample was supplied via `overriddenDuration`)
|
|
29
|
+
*/
|
|
30
|
+
get detectedResolution(): number | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* The name of the task.
|
|
33
|
+
* @returns The task name as a string
|
|
34
|
+
*/
|
|
35
|
+
get name(): string;
|
|
36
|
+
/**
|
|
37
|
+
* The result of the task.
|
|
38
|
+
* @returns The task result including state, statistics, and runtime information
|
|
39
|
+
*/
|
|
40
|
+
get result(): TaskResult$1 & TaskResultRuntimeInfo & TaskResultTimestampProviderInfo;
|
|
41
|
+
/**
|
|
42
|
+
* The number of times the task function has been executed.
|
|
43
|
+
* @returns The total number of executions performed
|
|
44
|
+
*/
|
|
45
|
+
get runs(): number;
|
|
46
|
+
constructor(bench: BenchLike, name: string, fn: Fn, fnOpts?: FnOptions);
|
|
47
|
+
/**
|
|
48
|
+
* Resets the task to make the `Task.runs` a zero-value and remove the `Task.result` object property.
|
|
49
|
+
* @param emit - whether to emit the `reset` event or not
|
|
50
|
+
*/
|
|
51
|
+
reset(emit?: boolean): void;
|
|
52
|
+
/**
|
|
53
|
+
* Runs the current task and writes the results in `Task.result` object property.
|
|
54
|
+
* @returns the current task
|
|
55
|
+
*/
|
|
56
|
+
run(): Promise<Task$1>;
|
|
57
|
+
/**
|
|
58
|
+
* Runs the current task synchronously and writes the results in `Task.result` object property.
|
|
59
|
+
* @returns the current task
|
|
60
|
+
*/
|
|
61
|
+
runSync(): this;
|
|
62
|
+
/**
|
|
63
|
+
* Warms up the current task.
|
|
64
|
+
*/
|
|
65
|
+
warmup(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Warms up the current task synchronously.
|
|
68
|
+
*/
|
|
69
|
+
warmupSync(): void;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/event.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* The BenchEvent class represents events that occur during the benchmarking
|
|
75
|
+
* process.
|
|
76
|
+
*/
|
|
77
|
+
declare class BenchEvent<K extends BenchEvents = BenchEvents, M extends 'bench' | 'task' = 'bench'> extends globalThis.Event {
|
|
78
|
+
#private;
|
|
79
|
+
type: K;
|
|
80
|
+
/**
|
|
81
|
+
* The error associated with the event.
|
|
82
|
+
* @returns The error if the event type is one that includes an error; otherwise, undefined
|
|
83
|
+
*/
|
|
84
|
+
get error(): K extends BenchEventsWithError ? Error : undefined;
|
|
85
|
+
/**
|
|
86
|
+
* The reason a `'warning'` event was dispatched.
|
|
87
|
+
* @returns The {@link TimerSaturationReason} for `'warning'` events;
|
|
88
|
+
* `undefined` for every other event type and for `'warning'` events
|
|
89
|
+
* dispatched without a reason
|
|
90
|
+
*/
|
|
91
|
+
get reason(): K extends 'warning' ? TimerSaturationReason | undefined : undefined;
|
|
92
|
+
/**
|
|
93
|
+
* The task associated with the event.
|
|
94
|
+
* @returns The task if the event type is one that includes a task; otherwise, undefined
|
|
95
|
+
*/
|
|
96
|
+
get task(): M extends 'task' ? Task$1 : K extends BenchEventsWithTask ? Task$1 : undefined;
|
|
97
|
+
constructor(type: 'warning', task: Task$1, reason?: TimerSaturationReason);
|
|
98
|
+
constructor(type: BenchEventsWithError, task: Task$1, error: Error);
|
|
99
|
+
constructor(type: BenchEventsWithTask, task: Task$1);
|
|
100
|
+
constructor(type: BenchEventsOptionalTask, task?: Task$1);
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/types.d.ts
|
|
104
|
+
/**
|
|
105
|
+
* Options for adding an event listener
|
|
106
|
+
*/
|
|
107
|
+
type AddEventListenerOptionsArgument = Parameters<EventTarget['addEventListener']>[2];
|
|
108
|
+
/**
|
|
109
|
+
* Bench events
|
|
110
|
+
*/
|
|
111
|
+
type BenchEvents = 'abort' | 'add' | 'complete' | 'cycle' | 'error' | 'remove' | 'reset' | 'start' | 'warmup' | 'warning';
|
|
112
|
+
/**
|
|
113
|
+
* Bench events that may have an associated Task
|
|
114
|
+
*/
|
|
115
|
+
type BenchEventsOptionalTask = Exclude<BenchEvents, 'add' | 'cycle' | 'error' | 'remove'>;
|
|
116
|
+
/**
|
|
117
|
+
* Bench events that have an associated error
|
|
118
|
+
*/
|
|
119
|
+
type BenchEventsWithError = Extract<BenchEvents, 'error'>;
|
|
120
|
+
/**
|
|
121
|
+
* Bench events that have an associated Task
|
|
122
|
+
*/
|
|
123
|
+
type BenchEventsWithTask = Extract<BenchEvents, 'add' | 'cycle' | 'error' | 'remove' | 'warning'>;
|
|
124
|
+
/**
|
|
125
|
+
* Used to decouple Bench and Task
|
|
126
|
+
*/
|
|
127
|
+
interface BenchLike extends EventTarget {
|
|
128
|
+
/**
|
|
129
|
+
* Adds a listener for the specified event type.
|
|
130
|
+
*/
|
|
131
|
+
addEventListener: (<K extends BenchEvents>(type: K, listener: EventListener<K> | EventListenerObject<K> | null, options?: AddEventListenerOptionsArgument) => void) & EventTarget['addEventListener'];
|
|
132
|
+
/**
|
|
133
|
+
* Executes tasks concurrently based on the specified concurrency mode, if set.
|
|
134
|
+
*
|
|
135
|
+
* - When `mode` is set to `null` (default), concurrency is disabled.
|
|
136
|
+
* - When `mode` is set to 'task', each task's iterations (calls of a task function) run concurrently.
|
|
137
|
+
* - When `mode` is set to 'bench', different tasks within the bench run concurrently.
|
|
138
|
+
*/
|
|
139
|
+
concurrency: Concurrency;
|
|
140
|
+
/**
|
|
141
|
+
* The amount of executions per task.
|
|
142
|
+
*/
|
|
143
|
+
iterations: number;
|
|
144
|
+
/**
|
|
145
|
+
* A function to get a timestamp.
|
|
146
|
+
*/
|
|
147
|
+
now: NowFn;
|
|
148
|
+
/**
|
|
149
|
+
* Removes a previously registered event listener.
|
|
150
|
+
*/
|
|
151
|
+
removeEventListener: (<K extends BenchEvents>(type: K, listener: EventListener<K> | EventListenerObject<K> | null, options?: RemoveEventListenerOptionsArgument) => void) & EventTarget['removeEventListener'];
|
|
152
|
+
/**
|
|
153
|
+
* Should samples be retained for further custom processing
|
|
154
|
+
*/
|
|
155
|
+
retainSamples: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* The JavaScript runtime environment.
|
|
158
|
+
*/
|
|
159
|
+
runtime: JSRuntime;
|
|
160
|
+
/**
|
|
161
|
+
* The JavaScript runtime version.
|
|
162
|
+
*/
|
|
163
|
+
runtimeVersion: string;
|
|
164
|
+
/**
|
|
165
|
+
* A setup function that runs before each task execution.
|
|
166
|
+
*/
|
|
167
|
+
setup: (task: Task$1, mode: HookMode) => Promise<void> | void;
|
|
168
|
+
/**
|
|
169
|
+
* An AbortSignal to cancel the benchmark
|
|
170
|
+
*/
|
|
171
|
+
signal?: AbortSignal;
|
|
172
|
+
/**
|
|
173
|
+
* A teardown function that runs after each task execution.
|
|
174
|
+
*/
|
|
175
|
+
teardown: (task: Task$1, mode: HookMode) => Promise<void> | void;
|
|
176
|
+
/**
|
|
177
|
+
* The maximum number of concurrent tasks to run
|
|
178
|
+
*/
|
|
179
|
+
threshold: number;
|
|
180
|
+
/**
|
|
181
|
+
* Whether to throw an error if a task function throws
|
|
182
|
+
*/
|
|
183
|
+
throws: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* The amount of time to run each task.
|
|
186
|
+
*/
|
|
187
|
+
time: number;
|
|
188
|
+
/**
|
|
189
|
+
* The estimated cost of one timestamp provider call in milliseconds.
|
|
190
|
+
*
|
|
191
|
+
* Calibrated once at construction; `undefined` (or omitted) when timer
|
|
192
|
+
* overhead subtraction is disabled or unsupported by the implementation.
|
|
193
|
+
*/
|
|
194
|
+
readonly timerOverhead?: number;
|
|
195
|
+
/**
|
|
196
|
+
* The timestamp provider used by the benchmark.
|
|
197
|
+
*/
|
|
198
|
+
timestampProvider: TimestampProvider;
|
|
199
|
+
/**
|
|
200
|
+
* Whether to warmup the tasks before running them
|
|
201
|
+
*/
|
|
202
|
+
warmup: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* The amount of warmup iterations per task.
|
|
205
|
+
*/
|
|
206
|
+
warmupIterations: number;
|
|
207
|
+
/**
|
|
208
|
+
* The amount of time to warmup each task.
|
|
209
|
+
*/
|
|
210
|
+
warmupTime: number;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Bench options
|
|
214
|
+
*/
|
|
215
|
+
interface BenchOptions$1 {
|
|
216
|
+
/**
|
|
217
|
+
* Executes tasks concurrently based on the specified concurrency mode.
|
|
218
|
+
*
|
|
219
|
+
* - When `mode` is set to `null` (default), concurrency is disabled.
|
|
220
|
+
* - When `mode` is set to 'task', each task's iterations (calls of a task function) run concurrently.
|
|
221
|
+
* - When `mode` is set to 'bench', different tasks within the bench run concurrently.
|
|
222
|
+
*/
|
|
223
|
+
concurrency?: Concurrency;
|
|
224
|
+
/**
|
|
225
|
+
* The number of times that a task should run if even the time option is finished.
|
|
226
|
+
* @default 64
|
|
227
|
+
*/
|
|
228
|
+
iterations?: number;
|
|
229
|
+
/**
|
|
230
|
+
* Benchmark name.
|
|
231
|
+
*/
|
|
232
|
+
name?: string;
|
|
233
|
+
/**
|
|
234
|
+
* Function to get the current timestamp in milliseconds.
|
|
235
|
+
*/
|
|
236
|
+
now?: NowFn;
|
|
237
|
+
/**
|
|
238
|
+
* Keep samples for statistics calculation
|
|
239
|
+
* @default false
|
|
240
|
+
*/
|
|
241
|
+
retainSamples?: boolean;
|
|
242
|
+
/**
|
|
243
|
+
* Setup function to run before each benchmark task (cycle)
|
|
244
|
+
*/
|
|
245
|
+
setup?: Hook;
|
|
246
|
+
/**
|
|
247
|
+
* An AbortSignal for aborting the benchmark.
|
|
248
|
+
*/
|
|
249
|
+
signal?: AbortSignal;
|
|
250
|
+
/**
|
|
251
|
+
* Whether to subtract an estimated timestamp provider call overhead from
|
|
252
|
+
* each raw latency sample.
|
|
253
|
+
*
|
|
254
|
+
* Each sample is measured as `t1 - t0` around a single call to the task
|
|
255
|
+
* function, so every raw sample is inflated by approximately one
|
|
256
|
+
* timestamp provider call cost `C`. When this option is `true`, an
|
|
257
|
+
* estimate `Ĉ` is computed once at construction time via
|
|
258
|
+
* {@link calibrateTimerOverhead}, and `max(0, raw_sample - Ĉ)` is used
|
|
259
|
+
* in place of each non-overridden sample before statistics are computed.
|
|
260
|
+
*
|
|
261
|
+
* **Statistics after correction.** All fields of {@link Statistics} are
|
|
262
|
+
* derived from the clamped corrected samples, not from the raw
|
|
263
|
+
* distribution. With `M` denoting the raw-sample mean:
|
|
264
|
+
*
|
|
265
|
+
* - **Clean-shift regime (`X >> Ĉ`).** The clamp `max(0, …)` rarely
|
|
266
|
+
* triggers, so the correction acts as a translation by `Ĉ`. Location
|
|
267
|
+
* statistics (`mean`, `min`, `max`, all percentiles) decrease by `Ĉ`;
|
|
268
|
+
* absolute-unit dispersion (`vr`, `sd`, `sem`, `moe`, `mad`, `aad`)
|
|
269
|
+
* is essentially unchanged. Because `rme = moe / mean`, it inflates
|
|
270
|
+
* by the deterministic factor `M / (M − Ĉ)` whenever `Ĉ > 0`.
|
|
271
|
+
* - **Sub-overhead regime (`X ≈ Ĉ`).** A non-trivial fraction of
|
|
272
|
+
* samples clamp to `0`, biasing the corrected mean upward,
|
|
273
|
+
* contracting `vr`/`sd`/`sem`/`moe`/`aad`, and compounding the
|
|
274
|
+
* `M / (M − Ĉ)` factor in `rme`. Once the cumulative mass of raw
|
|
275
|
+
* samples at or below `Ĉ` reaches a given quantile, that percentile
|
|
276
|
+
* collapses to `0`; in particular `p50` collapses once at least half
|
|
277
|
+
* of the raw samples satisfy `raw_sample ≤ Ĉ`, which then forces
|
|
278
|
+
* `mad` and `aad` toward `0`. Prefer `overriddenDuration` for
|
|
279
|
+
* sub-overhead measurements.
|
|
280
|
+
*
|
|
281
|
+
* **Three observable consequences of the clamp.**
|
|
282
|
+
*
|
|
283
|
+
* 1. `latency.min` may be exactly `0` even when no zero-duration sample
|
|
284
|
+
* was actually observed.
|
|
285
|
+
* 2. The throughput estimator substitutes `1000 / latency.mean` (or `0`
|
|
286
|
+
* when `mean === 0`) for every clamped sample.
|
|
287
|
+
* 3. {@link detectTimerSaturation} criterion `'zero-dominated'` cannot
|
|
288
|
+
* distinguish clamped samples from genuine zero-duration timer
|
|
289
|
+
* reads, so a `'warning'` event may be dispatched in the
|
|
290
|
+
* sub-overhead regime even when the timer itself is not saturated.
|
|
291
|
+
*
|
|
292
|
+
* **Caveat — `concurrency: "task"`.** The overhead is calibrated once
|
|
293
|
+
* at construction time with sequential timer calls. Setting both
|
|
294
|
+
* options causes the constructor (and `run()`) to throw, since the
|
|
295
|
+
* sequentially-calibrated estimate would not reflect the per-iteration
|
|
296
|
+
* timer call cost under concurrent execution.
|
|
297
|
+
*
|
|
298
|
+
* **Caveat — `overriddenDuration`.** Samples returned by the task
|
|
299
|
+
* function via `overriddenDuration` are intentional user values and
|
|
300
|
+
* are never modified by the correction. They are also excluded from
|
|
301
|
+
* {@link Task.detectedResolution} and from timer-saturation detection.
|
|
302
|
+
*
|
|
303
|
+
* On runtimes with a coarse timer (resolution >= 1 ms), the
|
|
304
|
+
* calibration returns `0` and this option becomes a no-op.
|
|
305
|
+
* @default false
|
|
306
|
+
*/
|
|
307
|
+
subtractTimerOverhead?: boolean;
|
|
308
|
+
/**
|
|
309
|
+
* Teardown function to run after each benchmark task (cycle).
|
|
310
|
+
*/
|
|
311
|
+
teardown?: Hook;
|
|
312
|
+
/**
|
|
313
|
+
* The maximum number of concurrent tasks to run
|
|
314
|
+
* @default Number.POSITIVE_INFINITY
|
|
315
|
+
*/
|
|
316
|
+
threshold?: number;
|
|
317
|
+
/**
|
|
318
|
+
* Throws if a task fails.
|
|
319
|
+
* @default false
|
|
320
|
+
*/
|
|
321
|
+
throws?: boolean;
|
|
322
|
+
/**
|
|
323
|
+
* Time needed for running a benchmark task in milliseconds.
|
|
324
|
+
* @default 1000
|
|
325
|
+
*/
|
|
326
|
+
time?: number;
|
|
327
|
+
/**
|
|
328
|
+
* The timestamp provider used by the benchmark. By default 'performance.now'
|
|
329
|
+
* will be used.
|
|
330
|
+
*/
|
|
331
|
+
timestampProvider?: TimestampFns | TimestampProvider;
|
|
332
|
+
/**
|
|
333
|
+
* Warmup benchmark.
|
|
334
|
+
* @default true
|
|
335
|
+
*/
|
|
336
|
+
warmup?: boolean;
|
|
337
|
+
/**
|
|
338
|
+
* Warmup iterations.
|
|
339
|
+
* @default 16
|
|
340
|
+
*/
|
|
341
|
+
warmupIterations?: number;
|
|
342
|
+
/**
|
|
343
|
+
* Warmup time in milliseconds.
|
|
344
|
+
* @default 250
|
|
345
|
+
*/
|
|
346
|
+
warmupTime?: number;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* - When `mode` is set to `null` (default), concurrency is disabled.
|
|
350
|
+
* - When `mode` is set to 'task', each task's iterations (calls of a task function) run concurrently.
|
|
351
|
+
* - When `mode` is set to 'bench', different tasks within the bench run concurrently.
|
|
352
|
+
*/
|
|
353
|
+
type Concurrency = 'bench' | 'task' | null;
|
|
354
|
+
/**
|
|
355
|
+
* Event listener
|
|
356
|
+
*/
|
|
357
|
+
type EventListener<E extends BenchEvents, M extends 'bench' | 'task' = 'bench'> = (evt: BenchEvent<E, M>) => void;
|
|
358
|
+
/**
|
|
359
|
+
* Both the `Task` and `Bench` objects extend the `EventTarget` object.
|
|
360
|
+
* So you can attach a listeners to different types of events to each class instance
|
|
361
|
+
* using the universal `addEventListener` and `removeEventListener` methods.
|
|
362
|
+
*/
|
|
363
|
+
interface EventListenerObject<E extends BenchEvents, M extends 'bench' | 'task' = 'bench'> {
|
|
364
|
+
/**
|
|
365
|
+
* A method called when the event is dispatched.
|
|
366
|
+
*/
|
|
367
|
+
handleEvent(evt: BenchEvent<E, M>): void;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* The task function.
|
|
371
|
+
*
|
|
372
|
+
* If you need to provide a custom duration for the task (e.g.: because
|
|
373
|
+
* you want to measure a specific part of its execution), you can return an
|
|
374
|
+
* object with a `overriddenDuration` field. You should still use
|
|
375
|
+
* `bench.opts.now()` to measure that duration.
|
|
376
|
+
*/
|
|
377
|
+
type Fn = () => FnReturnedObject | Promise<FnReturnedObject | unknown> | unknown;
|
|
378
|
+
/**
|
|
379
|
+
* The task hook function signature.
|
|
380
|
+
* If warmup is enabled, the hook will be called twice, once for the warmup and once for the run.
|
|
381
|
+
* @param mode the mode where the hook is being called
|
|
382
|
+
*/
|
|
383
|
+
type FnHook = (this: Task$1, mode?: HookMode) => Promise<void> | void;
|
|
384
|
+
/**
|
|
385
|
+
* The task function options
|
|
386
|
+
*/
|
|
387
|
+
interface FnOptions {
|
|
388
|
+
/**
|
|
389
|
+
* An optional function that is run after all iterations of this task end
|
|
390
|
+
*/
|
|
391
|
+
afterAll?: FnHook;
|
|
392
|
+
/**
|
|
393
|
+
* An optional function that is run after each iteration of this task
|
|
394
|
+
*/
|
|
395
|
+
afterEach?: FnHook;
|
|
396
|
+
/**
|
|
397
|
+
* Whether the provided task function is asynchronous, otherwise it is
|
|
398
|
+
* determined automatically.
|
|
399
|
+
*
|
|
400
|
+
* Measuring an async task awaits it inside the timed window, so each sample
|
|
401
|
+
* includes one microtask-turn overhead that `subtractTimerOverhead` does not
|
|
402
|
+
* remove. For sub-resolution timings, prefer `overriddenDuration`.
|
|
403
|
+
*/
|
|
404
|
+
async?: boolean;
|
|
405
|
+
/**
|
|
406
|
+
* An optional function that is run before iterations of this task begin
|
|
407
|
+
*/
|
|
408
|
+
beforeAll?: FnHook;
|
|
409
|
+
/**
|
|
410
|
+
* An optional function that is run before each iteration of this task
|
|
411
|
+
*/
|
|
412
|
+
beforeEach?: FnHook;
|
|
413
|
+
/**
|
|
414
|
+
* Retain samples for this task, overriding the bench-level retainSamples option
|
|
415
|
+
*/
|
|
416
|
+
retainSamples?: boolean;
|
|
417
|
+
/**
|
|
418
|
+
* An AbortSignal for aborting this specific task
|
|
419
|
+
*
|
|
420
|
+
* If not provided, falls back to {@link BenchOptions.signal}
|
|
421
|
+
*/
|
|
422
|
+
signal?: AbortSignal;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* A possible object returned by task functions to override default behaviors,
|
|
426
|
+
* like the duration of the function itself.
|
|
427
|
+
*/
|
|
428
|
+
interface FnReturnedObject {
|
|
429
|
+
/**
|
|
430
|
+
* An overridden duration for the task function, to be used instead of the
|
|
431
|
+
* duration measured by tinybench when running the benchmark.
|
|
432
|
+
*
|
|
433
|
+
* This can be useful to measure parts of the execution of a function that are
|
|
434
|
+
* hard to execute independently.
|
|
435
|
+
*/
|
|
436
|
+
overriddenDuration?: number;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* The hook function signature.
|
|
440
|
+
* If warmup is enabled, the hook will be called twice, once for the warmup and once for the run.
|
|
441
|
+
* @param task the task instance
|
|
442
|
+
* @param mode the mode where the hook is being called
|
|
443
|
+
*/
|
|
444
|
+
type Hook = (task?: Task$1, mode?: HookMode) => Promise<void> | void;
|
|
445
|
+
/**
|
|
446
|
+
* The mode in which a task hook is invoked ('warmup' or 'run').
|
|
447
|
+
*/
|
|
448
|
+
type HookMode = 'run' | 'warmup';
|
|
449
|
+
/**
|
|
450
|
+
* The JavaScript runtime environment.
|
|
451
|
+
* @see https://runtime-keys.proposal.wintercg.org/
|
|
452
|
+
*/
|
|
453
|
+
type JSRuntime = 'browser' | 'bun' | 'deno' | 'edge-light' | 'fastly' | 'hermes' | 'jsc' | 'lagon' | 'moddable' | 'netlify' | 'node' | 'quickjs-ng' | 'spidermonkey' | 'unknown' | 'v8' | 'workerd';
|
|
454
|
+
/**
|
|
455
|
+
* A function that returns the current timestamp.
|
|
456
|
+
*/
|
|
457
|
+
type NowFn = () => number;
|
|
458
|
+
type RemoveEventListenerOptionsArgument = Parameters<EventTarget['removeEventListener']>[2];
|
|
459
|
+
/**
|
|
460
|
+
* A type representing a samples-array with at least one number.
|
|
461
|
+
*/
|
|
462
|
+
type Samples = [number, ...number[]];
|
|
463
|
+
/**
|
|
464
|
+
* A type representing a sorted samples-array with at least one number.
|
|
465
|
+
*/
|
|
466
|
+
type SortedSamples = Samples & {
|
|
467
|
+
/**
|
|
468
|
+
* A unique symbol to identify sorted samples
|
|
469
|
+
*/
|
|
470
|
+
readonly __sorted__: unique symbol;
|
|
471
|
+
};
|
|
472
|
+
/**
|
|
473
|
+
* The statistics object
|
|
474
|
+
*/
|
|
475
|
+
interface Statistics {
|
|
476
|
+
/**
|
|
477
|
+
* mean/average absolute deviation
|
|
478
|
+
*/
|
|
479
|
+
aad: number;
|
|
480
|
+
/**
|
|
481
|
+
* critical value
|
|
482
|
+
*/
|
|
483
|
+
critical: number;
|
|
484
|
+
/**
|
|
485
|
+
* degrees of freedom
|
|
486
|
+
*/
|
|
487
|
+
df: number;
|
|
488
|
+
/**
|
|
489
|
+
* median absolute deviation, not scaled by the 1.4826 normal-consistency factor
|
|
490
|
+
*/
|
|
491
|
+
mad: number;
|
|
492
|
+
/**
|
|
493
|
+
* the maximum value
|
|
494
|
+
*/
|
|
495
|
+
max: number;
|
|
496
|
+
/**
|
|
497
|
+
* mean/average
|
|
498
|
+
*/
|
|
499
|
+
mean: number;
|
|
500
|
+
/**
|
|
501
|
+
* the minimum value
|
|
502
|
+
*/
|
|
503
|
+
min: number;
|
|
504
|
+
/**
|
|
505
|
+
* margin of error
|
|
506
|
+
*/
|
|
507
|
+
moe: number;
|
|
508
|
+
/**
|
|
509
|
+
* p50/median percentile
|
|
510
|
+
*/
|
|
511
|
+
p50: number;
|
|
512
|
+
/**
|
|
513
|
+
* p75 percentile
|
|
514
|
+
*/
|
|
515
|
+
p75: number;
|
|
516
|
+
/**
|
|
517
|
+
* p99 percentile
|
|
518
|
+
*/
|
|
519
|
+
p99: number;
|
|
520
|
+
/**
|
|
521
|
+
* p995 percentile
|
|
522
|
+
*/
|
|
523
|
+
p995: number;
|
|
524
|
+
/**
|
|
525
|
+
* p999 percentile
|
|
526
|
+
*/
|
|
527
|
+
p999: number;
|
|
528
|
+
/**
|
|
529
|
+
* relative margin of error
|
|
530
|
+
*/
|
|
531
|
+
rme: number;
|
|
532
|
+
/**
|
|
533
|
+
* samples used to calculate the statistics
|
|
534
|
+
*/
|
|
535
|
+
samples: SortedSamples | undefined;
|
|
536
|
+
/**
|
|
537
|
+
* samples count
|
|
538
|
+
*/
|
|
539
|
+
samplesCount: number;
|
|
540
|
+
/**
|
|
541
|
+
* standard deviation
|
|
542
|
+
*/
|
|
543
|
+
sd: number;
|
|
544
|
+
/**
|
|
545
|
+
* standard error of the mean/average (a.k.a. the standard deviation of the distribution of the sample mean/average)
|
|
546
|
+
*/
|
|
547
|
+
sem: number;
|
|
548
|
+
/**
|
|
549
|
+
* variance
|
|
550
|
+
*/
|
|
551
|
+
variance: number;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Task events
|
|
555
|
+
*/
|
|
556
|
+
type TaskEvents = Extract<BenchEvents, 'abort' | 'complete' | 'cycle' | 'error' | 'reset' | 'start' | 'warmup' | 'warning'>;
|
|
557
|
+
/**
|
|
558
|
+
* The task result
|
|
559
|
+
*/
|
|
560
|
+
type TaskResult$1 = TaskResultAborted | TaskResultAbortedWithStatistics | TaskResultCompleted | TaskResultErrored | TaskResultNotStarted | TaskResultStarted;
|
|
561
|
+
/**
|
|
562
|
+
* The task result for aborted tasks.
|
|
563
|
+
*/
|
|
564
|
+
interface TaskResultAborted {
|
|
565
|
+
/**
|
|
566
|
+
* the task state
|
|
567
|
+
*/
|
|
568
|
+
state: 'aborted';
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* The task result for aborted tasks, having also statistical data.
|
|
572
|
+
*/
|
|
573
|
+
interface TaskResultAbortedWithStatistics extends TaskResultWithStatistics {
|
|
574
|
+
/**
|
|
575
|
+
* the task state
|
|
576
|
+
*/
|
|
577
|
+
state: 'aborted-with-statistics';
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* The task result for completed tasks with statistical data.
|
|
581
|
+
*/
|
|
582
|
+
interface TaskResultCompleted extends TaskResultWithStatistics {
|
|
583
|
+
/**
|
|
584
|
+
* the task state
|
|
585
|
+
*/
|
|
586
|
+
state: 'completed';
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* The task result for errored tasks
|
|
590
|
+
*/
|
|
591
|
+
interface TaskResultErrored {
|
|
592
|
+
/**
|
|
593
|
+
* the error that caused the task to fail
|
|
594
|
+
*/
|
|
595
|
+
error: Error;
|
|
596
|
+
/**
|
|
597
|
+
* the task state
|
|
598
|
+
*/
|
|
599
|
+
state: 'errored';
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* The task result for not started tasks
|
|
603
|
+
*/
|
|
604
|
+
interface TaskResultNotStarted {
|
|
605
|
+
/**
|
|
606
|
+
* the task state
|
|
607
|
+
*/
|
|
608
|
+
state: 'not-started';
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* The additional runtime information for task results
|
|
612
|
+
*/
|
|
613
|
+
interface TaskResultRuntimeInfo {
|
|
614
|
+
/**
|
|
615
|
+
* the JavaScript runtime environment
|
|
616
|
+
*/
|
|
617
|
+
runtime: JSRuntime;
|
|
618
|
+
/**
|
|
619
|
+
* the JavaScript runtime version
|
|
620
|
+
*/
|
|
621
|
+
runtimeVersion: string;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* The task result for started tasks
|
|
625
|
+
*/
|
|
626
|
+
interface TaskResultStarted {
|
|
627
|
+
/**
|
|
628
|
+
* the task state
|
|
629
|
+
*/
|
|
630
|
+
state: 'started';
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* The timestamp provider information for task results
|
|
634
|
+
*/
|
|
635
|
+
interface TaskResultTimestampProviderInfo {
|
|
636
|
+
/**
|
|
637
|
+
* the name of the timestamp provider used during the benchmark
|
|
638
|
+
*/
|
|
639
|
+
timestampProviderName: TimestampProviderName;
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* The statistical data for task results
|
|
643
|
+
*/
|
|
644
|
+
interface TaskResultWithStatistics {
|
|
645
|
+
/**
|
|
646
|
+
* the task latency statistics
|
|
647
|
+
*/
|
|
648
|
+
latency: Statistics;
|
|
649
|
+
/**
|
|
650
|
+
* how long each operation takes (ms)
|
|
651
|
+
*/
|
|
652
|
+
period: number;
|
|
653
|
+
/**
|
|
654
|
+
* the task throughput statistics
|
|
655
|
+
*/
|
|
656
|
+
throughput: Statistics;
|
|
657
|
+
/**
|
|
658
|
+
* the time to run the task benchmark cycle (ms)
|
|
659
|
+
*/
|
|
660
|
+
totalTime: number;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Reason a sample set is classified as timer-saturated.
|
|
664
|
+
*
|
|
665
|
+
* - `'zero-dominated'` — more than half of the samples are exactly zero.
|
|
666
|
+
* - `'low-distinct'` — distinct sample count is below
|
|
667
|
+
* `max(3, min(10, ⌊n / 1000⌋))`.
|
|
668
|
+
* - `'zero-mad'` — median absolute deviation is zero with more than 100
|
|
669
|
+
* samples.
|
|
670
|
+
*/
|
|
671
|
+
type TimerSaturationReason = 'low-distinct' | 'zero-dominated' | 'zero-mad';
|
|
672
|
+
/**
|
|
673
|
+
* A timestamp function that returns either a number or bigint.
|
|
674
|
+
*/
|
|
675
|
+
type TimestampFn = () => TimestampValue;
|
|
676
|
+
/**
|
|
677
|
+
* Possible timestamp provider names.
|
|
678
|
+
* 'custom' is used when a custom timestamp function is provided.
|
|
679
|
+
*/
|
|
680
|
+
type TimestampFns = 'auto' | 'bunNanoseconds' | 'custom' | 'hrtimeNow' | 'performanceNow';
|
|
681
|
+
/**
|
|
682
|
+
* A timestamp provider and its related functions.
|
|
683
|
+
*/
|
|
684
|
+
interface TimestampProvider {
|
|
685
|
+
/**
|
|
686
|
+
* The actual function of the timestamp provider.
|
|
687
|
+
* @returns the timestamp value
|
|
688
|
+
*/
|
|
689
|
+
fn: TimestampFn;
|
|
690
|
+
/**
|
|
691
|
+
* Converts milliseconds to the timestamp value.
|
|
692
|
+
* @param value - the milliseconds value
|
|
693
|
+
* @returns the timestamp value
|
|
694
|
+
*/
|
|
695
|
+
fromMs: (value: number) => TimestampValue;
|
|
696
|
+
/**
|
|
697
|
+
* The name of the timestamp provider.
|
|
698
|
+
*/
|
|
699
|
+
name: TimestampProviderName;
|
|
700
|
+
/**
|
|
701
|
+
* Converts the timestamp value to milliseconds.
|
|
702
|
+
* @param value - the timestamp value
|
|
703
|
+
* @returns the milliseconds
|
|
704
|
+
*/
|
|
705
|
+
toMs: (value: TimestampValue) => number;
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* The name of a timestamp provider: a known provider name or any custom string.
|
|
709
|
+
*/
|
|
710
|
+
type TimestampProviderName = (string & {}) | TimestampFns;
|
|
711
|
+
/**
|
|
712
|
+
* A timestamp value, either number or bigint. Internally timestamps can use
|
|
713
|
+
* either representation depending on the environment and the chosen timestamp
|
|
714
|
+
* function.
|
|
715
|
+
*/
|
|
716
|
+
type TimestampValue = bigint | number;
|
|
717
|
+
//#endregion
|
|
718
|
+
//#region ../../../../node_modules/.bun/vitest@5.0.1+3a20bcfa24daf8e9/node_modules/vitest/dist/chunks/config.d.CU_b-wJj.d.ts
|
|
719
|
+
/**
|
|
720
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
721
|
+
*
|
|
722
|
+
* This source code is licensed under the MIT license found in the
|
|
723
|
+
* LICENSE file in the root directory of this source tree.
|
|
724
|
+
*/
|
|
725
|
+
interface Colors {
|
|
726
|
+
comment: {
|
|
727
|
+
close: string;
|
|
728
|
+
open: string;
|
|
729
|
+
};
|
|
730
|
+
content: {
|
|
731
|
+
close: string;
|
|
732
|
+
open: string;
|
|
733
|
+
};
|
|
734
|
+
prop: {
|
|
735
|
+
close: string;
|
|
736
|
+
open: string;
|
|
737
|
+
};
|
|
738
|
+
tag: {
|
|
739
|
+
close: string;
|
|
740
|
+
open: string;
|
|
741
|
+
};
|
|
742
|
+
value: {
|
|
743
|
+
close: string;
|
|
744
|
+
open: string;
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
type Indent = (arg0: string) => string;
|
|
748
|
+
type Refs = Array<unknown>;
|
|
749
|
+
type Print = (arg0: unknown) => string;
|
|
750
|
+
/**
|
|
751
|
+
* compare function used when sorting object keys, `null` can be used to skip over sorting.
|
|
752
|
+
*/
|
|
753
|
+
type CompareKeys = ((a: string, b: string) => number) | null | undefined;
|
|
754
|
+
interface PrettyFormatOptions {
|
|
755
|
+
/**
|
|
756
|
+
* Call `toJSON` on objects before formatting them.
|
|
757
|
+
* Ignored after the formatter has already called `toJSON` once for a value.
|
|
758
|
+
* @default true
|
|
759
|
+
*/
|
|
760
|
+
callToJSON?: boolean;
|
|
761
|
+
/**
|
|
762
|
+
* Whether to escape special characters in regular expressions.
|
|
763
|
+
* @default false
|
|
764
|
+
*/
|
|
765
|
+
escapeRegex?: boolean;
|
|
766
|
+
/**
|
|
767
|
+
* Whether to escape special characters in strings.
|
|
768
|
+
* @default true
|
|
769
|
+
*/
|
|
770
|
+
escapeString?: boolean;
|
|
771
|
+
/**
|
|
772
|
+
* Whether to highlight syntax using terminal colors.
|
|
773
|
+
* @default false
|
|
774
|
+
*/
|
|
775
|
+
highlight?: boolean;
|
|
776
|
+
/**
|
|
777
|
+
* Number of spaces to use for each level of indentation.
|
|
778
|
+
* @default 2
|
|
779
|
+
*/
|
|
780
|
+
indent?: number;
|
|
781
|
+
/**
|
|
782
|
+
* Maximum depth to recurse into nested values.
|
|
783
|
+
* @default Infinity
|
|
784
|
+
*/
|
|
785
|
+
maxDepth?: number;
|
|
786
|
+
/**
|
|
787
|
+
* Maximum number of items to print in arrays, sets, maps, and similar collections.
|
|
788
|
+
* @default Infinity
|
|
789
|
+
*/
|
|
790
|
+
maxWidth?: number;
|
|
791
|
+
/**
|
|
792
|
+
* Approximate per-depth-level budget for output length.
|
|
793
|
+
* When the accumulated output at any single depth level exceeds this value,
|
|
794
|
+
* further nesting is collapsed. This is a heuristic safety valve, not a hard
|
|
795
|
+
* limit — total output can reach up to roughly `maxDepth × maxOutputLength`.
|
|
796
|
+
* @default 1_000_000
|
|
797
|
+
*/
|
|
798
|
+
maxOutputLength?: number;
|
|
799
|
+
/**
|
|
800
|
+
* Whether to minimize added whitespace, including indentation and line breaks.
|
|
801
|
+
*
|
|
802
|
+
* When `true`, pretty-format defaults `spacingInner` to `' '`, `spacingOuter` to `''`,
|
|
803
|
+
* and ignores indentation. It also changes the default for `printBasicPrototype`
|
|
804
|
+
* from `true` to `false`, although an explicit `printBasicPrototype` still wins.
|
|
805
|
+
* Explicit `spacingInner` / `spacingOuter` overrides still apply.
|
|
806
|
+
* @default false
|
|
807
|
+
*/
|
|
808
|
+
min?: boolean;
|
|
809
|
+
/**
|
|
810
|
+
* Whether to print `Object` / `Array` prefixes for plain objects and arrays.
|
|
811
|
+
*
|
|
812
|
+
* Defaults to `true`, unless `min` is `true`, in which case it defaults to `false`.
|
|
813
|
+
* An explicit `printBasicPrototype` value always overrides the `min` default.
|
|
814
|
+
*/
|
|
815
|
+
printBasicPrototype?: boolean;
|
|
816
|
+
/**
|
|
817
|
+
* Whether to include the function name when formatting functions.
|
|
818
|
+
* @default true
|
|
819
|
+
*/
|
|
820
|
+
printFunctionName?: boolean;
|
|
821
|
+
/**
|
|
822
|
+
* Whether to include shadow-root contents when formatting DOM nodes.
|
|
823
|
+
* @default true
|
|
824
|
+
*/
|
|
825
|
+
printShadowRoot?: boolean;
|
|
826
|
+
/**
|
|
827
|
+
* Compare function used when sorting object keys. Set to `null` to disable sorting.
|
|
828
|
+
*/
|
|
829
|
+
compareKeys?: CompareKeys;
|
|
830
|
+
/**
|
|
831
|
+
* Plugins used to serialize application-specific data types.
|
|
832
|
+
* @default []
|
|
833
|
+
*/
|
|
834
|
+
plugins?: Plugins;
|
|
835
|
+
/**
|
|
836
|
+
* Whitespace inserted after commas between items or entries.
|
|
837
|
+
*
|
|
838
|
+
* For example, in `{a: 1, b: 2}` or `[1, 2]`, this controls the gap after each comma:
|
|
839
|
+
* `{a: 1,${spacingInner}b: 2}`
|
|
840
|
+
* `[1,${spacingInner}2]`
|
|
841
|
+
*
|
|
842
|
+
* Defaults to `'\n'` in regular mode and `' '` when `min` is `true`.
|
|
843
|
+
* Can be overridden independently of `min`.
|
|
844
|
+
*/
|
|
845
|
+
spacingInner?: string;
|
|
846
|
+
/**
|
|
847
|
+
* Whitespace inserted immediately inside collection/object delimiters.
|
|
848
|
+
*
|
|
849
|
+
* For example, this controls the space or newline right after the opening delimiter
|
|
850
|
+
* and right before the closing delimiter:
|
|
851
|
+
* `{${spacingOuter}a: 1${spacingOuter}}`
|
|
852
|
+
* `[${spacingOuter}1${spacingOuter}]`
|
|
853
|
+
*
|
|
854
|
+
* Defaults to `'\n'` in regular mode and `''` when `min` is `true`.
|
|
855
|
+
* Can be overridden independently of `min`.
|
|
856
|
+
*/
|
|
857
|
+
spacingOuter?: string;
|
|
858
|
+
/**
|
|
859
|
+
* Whether to print strings using single quotes instead of double quotes.
|
|
860
|
+
*
|
|
861
|
+
* For example:
|
|
862
|
+
* `"hello"` when `false`
|
|
863
|
+
* `'hello'` when `true`
|
|
864
|
+
*
|
|
865
|
+
* @default false
|
|
866
|
+
*/
|
|
867
|
+
singleQuote?: boolean;
|
|
868
|
+
/**
|
|
869
|
+
* Whether to always quote object property keys.
|
|
870
|
+
*
|
|
871
|
+
* For example:
|
|
872
|
+
* `{"a": 1}` when `true`
|
|
873
|
+
* `{a: 1}` when `false` and the key is a valid identifier
|
|
874
|
+
* `{"my-key": 1}` still stays quoted because it is not a valid identifier
|
|
875
|
+
*
|
|
876
|
+
* @default true
|
|
877
|
+
*/
|
|
878
|
+
quoteKeys?: boolean;
|
|
879
|
+
}
|
|
880
|
+
type OptionsReceived = PrettyFormatOptions;
|
|
881
|
+
interface Config {
|
|
882
|
+
callToJSON: boolean;
|
|
883
|
+
compareKeys: CompareKeys;
|
|
884
|
+
colors: Colors;
|
|
885
|
+
escapeRegex: boolean;
|
|
886
|
+
escapeString: boolean;
|
|
887
|
+
indent: string;
|
|
888
|
+
maxDepth: number;
|
|
889
|
+
maxWidth: number;
|
|
890
|
+
min: boolean;
|
|
891
|
+
plugins: Plugins;
|
|
892
|
+
printBasicPrototype: boolean;
|
|
893
|
+
printFunctionName: boolean;
|
|
894
|
+
printShadowRoot: boolean;
|
|
895
|
+
spacingInner: string;
|
|
896
|
+
spacingOuter: string;
|
|
897
|
+
singleQuote: boolean;
|
|
898
|
+
quoteKeys: boolean;
|
|
899
|
+
maxOutputLength: number;
|
|
900
|
+
}
|
|
901
|
+
type Printer = (val: unknown, config: Config, indentation: string, depth: number, refs: Refs, hasCalledToJSON?: boolean) => string;
|
|
902
|
+
type Test$1 = (arg0: any) => boolean;
|
|
903
|
+
interface NewPlugin {
|
|
904
|
+
serialize: (val: any, config: Config, indentation: string, depth: number, refs: Refs, printer: Printer) => string;
|
|
905
|
+
test: Test$1;
|
|
906
|
+
}
|
|
907
|
+
interface PluginOptions {
|
|
908
|
+
edgeSpacing: string;
|
|
909
|
+
min: boolean;
|
|
910
|
+
spacing: string;
|
|
911
|
+
}
|
|
912
|
+
interface OldPlugin {
|
|
913
|
+
print: (val: unknown, print: Print, indent: Indent, options: PluginOptions, colors: Colors) => string;
|
|
914
|
+
test: Test$1;
|
|
915
|
+
}
|
|
916
|
+
type Plugin = NewPlugin | OldPlugin;
|
|
917
|
+
type Plugins = Array<Plugin>;
|
|
918
|
+
interface StringifyOptions extends PrettyFormatOptions {
|
|
919
|
+
maxLength?: number;
|
|
920
|
+
filterNode?: string | ((node: any) => boolean);
|
|
921
|
+
}
|
|
922
|
+
declare function stringify(object: unknown, maxDepth?: number, { maxLength, filterNode, ...options }?: StringifyOptions): string;
|
|
923
|
+
type Awaitable<T> = T | PromiseLike<T>;
|
|
924
|
+
interface ParsedStack {
|
|
925
|
+
method: string;
|
|
926
|
+
file: string;
|
|
927
|
+
line: number;
|
|
928
|
+
column: number;
|
|
929
|
+
}
|
|
930
|
+
interface SerializedError {
|
|
931
|
+
message: string;
|
|
932
|
+
stacks?: ParsedStack[];
|
|
933
|
+
stack?: string;
|
|
934
|
+
name?: string;
|
|
935
|
+
cause?: SerializedError;
|
|
936
|
+
[key: string]: unknown;
|
|
937
|
+
}
|
|
938
|
+
interface TestError extends SerializedError {
|
|
939
|
+
cause?: TestError;
|
|
940
|
+
diff?: string;
|
|
941
|
+
actual?: string;
|
|
942
|
+
expected?: string;
|
|
943
|
+
}
|
|
944
|
+
interface DomainMatchResult {
|
|
945
|
+
pass: boolean;
|
|
946
|
+
message?: string;
|
|
947
|
+
/**
|
|
948
|
+
* The captured value viewed through the template's lens.
|
|
949
|
+
*
|
|
950
|
+
* Where the template uses patterns (e.g. regexes) or omits details,
|
|
951
|
+
* the resolved string adopts those patterns. Where the template doesn't
|
|
952
|
+
* match, the resolved string uses literal captured values instead.
|
|
953
|
+
*
|
|
954
|
+
* Used for two purposes:
|
|
955
|
+
* - **Diff display** (actual side): compared against `expected`
|
|
956
|
+
* so the diff highlights only genuine mismatches, not pattern-vs-literal noise.
|
|
957
|
+
* - **Snapshot update** (`--update`): written as the new snapshot content,
|
|
958
|
+
* preserving user-edited patterns from matched regions while incorporating
|
|
959
|
+
* actual values for mismatched regions.
|
|
960
|
+
*
|
|
961
|
+
* When omitted, falls back to `render(capture(received))` (the raw rendered value).
|
|
962
|
+
*/
|
|
963
|
+
resolved?: string;
|
|
964
|
+
/**
|
|
965
|
+
* The stored template re-rendered as a string, representing what the user
|
|
966
|
+
* originally wrote or last saved.
|
|
967
|
+
*
|
|
968
|
+
* Used as the expected side in diff display.
|
|
969
|
+
*
|
|
970
|
+
* When omitted, falls back to the raw snapshot string from the snap file
|
|
971
|
+
* or inline snapshot.
|
|
972
|
+
*/
|
|
973
|
+
expected?: string;
|
|
974
|
+
}
|
|
975
|
+
interface RawSnapshotInfo {
|
|
976
|
+
file: string;
|
|
977
|
+
readonly?: boolean;
|
|
978
|
+
content?: string;
|
|
979
|
+
}
|
|
980
|
+
interface SnapshotEnvironment {
|
|
981
|
+
getVersion: () => string;
|
|
982
|
+
getHeader: () => string;
|
|
983
|
+
resolvePath: (filepath: string) => Promise<string>;
|
|
984
|
+
resolveRawPath: (testPath: string, rawPath: string) => Promise<string>;
|
|
985
|
+
saveSnapshotFile: (filepath: string, snapshot: string) => Promise<void>;
|
|
986
|
+
readSnapshotFile: (filepath: string) => Promise<string | null>;
|
|
987
|
+
readSnapshotFileData?: (filepath: string) => Promise<Record<string, string> | null>;
|
|
988
|
+
removeSnapshotFile: (filepath: string) => Promise<void>;
|
|
989
|
+
processStackTrace?: (stack: ParsedStack) => ParsedStack;
|
|
990
|
+
}
|
|
991
|
+
declare class DefaultMap<K, V> extends Map<K, V> {
|
|
992
|
+
private defaultFn;
|
|
993
|
+
constructor(defaultFn: (key: K) => V, entries?: Iterable<readonly [K, V]>);
|
|
994
|
+
override get(key: K): V;
|
|
995
|
+
}
|
|
996
|
+
declare class CounterMap<K> extends DefaultMap<K, number> {
|
|
997
|
+
constructor();
|
|
998
|
+
_total: number | undefined;
|
|
999
|
+
valueOf(): number;
|
|
1000
|
+
increment(key: K): void;
|
|
1001
|
+
total(): number;
|
|
1002
|
+
}
|
|
1003
|
+
interface SnapshotReturnOptions {
|
|
1004
|
+
actual: string;
|
|
1005
|
+
count: number;
|
|
1006
|
+
expected?: string;
|
|
1007
|
+
key: string;
|
|
1008
|
+
pass: boolean;
|
|
1009
|
+
}
|
|
1010
|
+
interface SaveStatus {
|
|
1011
|
+
deleted: boolean;
|
|
1012
|
+
saved: boolean;
|
|
1013
|
+
}
|
|
1014
|
+
interface ExpectedSnapshot {
|
|
1015
|
+
key: string;
|
|
1016
|
+
count: number;
|
|
1017
|
+
data?: string;
|
|
1018
|
+
markAsChecked: () => void;
|
|
1019
|
+
}
|
|
1020
|
+
declare class SnapshotState {
|
|
1021
|
+
testFilePath: string;
|
|
1022
|
+
snapshotPath: string;
|
|
1023
|
+
private _counters;
|
|
1024
|
+
private _dirty;
|
|
1025
|
+
private _updateSnapshot;
|
|
1026
|
+
private _snapshotData;
|
|
1027
|
+
private _initialData;
|
|
1028
|
+
private _inlineSnapshots;
|
|
1029
|
+
private _inlineSnapshotStacks;
|
|
1030
|
+
private _testIdToKeys;
|
|
1031
|
+
private _rawSnapshots;
|
|
1032
|
+
private _uncheckedKeys;
|
|
1033
|
+
private _snapshotFormat;
|
|
1034
|
+
private _environment;
|
|
1035
|
+
private _fileExists;
|
|
1036
|
+
expand: boolean;
|
|
1037
|
+
private _added;
|
|
1038
|
+
private _matched;
|
|
1039
|
+
private _unmatched;
|
|
1040
|
+
private _updated;
|
|
1041
|
+
get added(): CounterMap<string>;
|
|
1042
|
+
set added(value: number);
|
|
1043
|
+
get matched(): CounterMap<string>;
|
|
1044
|
+
set matched(value: number);
|
|
1045
|
+
get unmatched(): CounterMap<string>;
|
|
1046
|
+
set unmatched(value: number);
|
|
1047
|
+
get updated(): CounterMap<string>;
|
|
1048
|
+
set updated(value: number);
|
|
1049
|
+
private constructor();
|
|
1050
|
+
static create(testFilePath: string, options: SnapshotStateOptions): Promise<SnapshotState>;
|
|
1051
|
+
get snapshotUpdateState(): SnapshotUpdateState;
|
|
1052
|
+
get environment(): SnapshotEnvironment;
|
|
1053
|
+
markSnapshotsAsCheckedForTest(testName: string): void;
|
|
1054
|
+
clearTest(testId: string): void;
|
|
1055
|
+
protected _inferInlineSnapshotStack(stacks: ParsedStack[]): ParsedStack | null;
|
|
1056
|
+
private _addSnapshot;
|
|
1057
|
+
private _resolveKey;
|
|
1058
|
+
private _resolveInlineStack;
|
|
1059
|
+
private _reconcile;
|
|
1060
|
+
save(): Promise<SaveStatus>;
|
|
1061
|
+
getUncheckedCount(): number;
|
|
1062
|
+
getUncheckedKeys(): Array<string>;
|
|
1063
|
+
removeUncheckedKeys(): void;
|
|
1064
|
+
probeExpectedSnapshot(options: Pick<SnapshotMatchOptions, "testName" | "testId" | "isInline" | "inlineSnapshot">): ExpectedSnapshot;
|
|
1065
|
+
match({ testId, testName, received, key, inlineSnapshot, isInline, error, rawSnapshot, assertionName }: SnapshotMatchOptions): SnapshotReturnOptions;
|
|
1066
|
+
processDomainSnapshot({ testId, received, expectedSnapshot, matchResult, isInline, error, assertionName }: ProcessDomainSnapshotOptions): SnapshotReturnOptions;
|
|
1067
|
+
pack(): Promise<SnapshotResult>;
|
|
1068
|
+
}
|
|
1069
|
+
type SnapshotUpdateState = "all" | "new" | "none";
|
|
1070
|
+
interface SnapshotStateOptions {
|
|
1071
|
+
updateSnapshot: SnapshotUpdateState;
|
|
1072
|
+
snapshotEnvironment: SnapshotEnvironment;
|
|
1073
|
+
expand?: boolean;
|
|
1074
|
+
snapshotFormat?: OptionsReceived;
|
|
1075
|
+
resolveSnapshotPath?: (path: string, extension: string, context?: any) => string;
|
|
1076
|
+
}
|
|
1077
|
+
interface SnapshotMatchOptions {
|
|
1078
|
+
testId: string;
|
|
1079
|
+
testName: string;
|
|
1080
|
+
received: unknown;
|
|
1081
|
+
key?: string;
|
|
1082
|
+
inlineSnapshot?: string;
|
|
1083
|
+
isInline: boolean;
|
|
1084
|
+
error?: Error;
|
|
1085
|
+
rawSnapshot?: RawSnapshotInfo;
|
|
1086
|
+
assertionName?: string;
|
|
1087
|
+
}
|
|
1088
|
+
interface ProcessDomainSnapshotOptions {
|
|
1089
|
+
testId: string;
|
|
1090
|
+
received: string;
|
|
1091
|
+
expectedSnapshot: ExpectedSnapshot;
|
|
1092
|
+
matchResult?: DomainMatchResult;
|
|
1093
|
+
isInline?: boolean;
|
|
1094
|
+
assertionName?: string;
|
|
1095
|
+
error?: Error;
|
|
1096
|
+
}
|
|
1097
|
+
interface SnapshotResult {
|
|
1098
|
+
filepath: string;
|
|
1099
|
+
added: number;
|
|
1100
|
+
fileDeleted: boolean;
|
|
1101
|
+
matched: number;
|
|
1102
|
+
unchecked: number;
|
|
1103
|
+
uncheckedKeys: Array<string>;
|
|
1104
|
+
unmatched: number;
|
|
1105
|
+
updated: number;
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1109
|
+
*
|
|
1110
|
+
* This source code is licensed under the MIT license found in the
|
|
1111
|
+
* LICENSE file in the root directory of this source tree.
|
|
1112
|
+
*/
|
|
1113
|
+
type DiffOptionsColor = (arg: string) => string;
|
|
1114
|
+
interface DiffOptions {
|
|
1115
|
+
aAnnotation?: string;
|
|
1116
|
+
aColor?: DiffOptionsColor;
|
|
1117
|
+
aIndicator?: string;
|
|
1118
|
+
bAnnotation?: string;
|
|
1119
|
+
bColor?: DiffOptionsColor;
|
|
1120
|
+
bIndicator?: string;
|
|
1121
|
+
changeColor?: DiffOptionsColor;
|
|
1122
|
+
changeLineTrailingSpaceColor?: DiffOptionsColor;
|
|
1123
|
+
commonColor?: DiffOptionsColor;
|
|
1124
|
+
commonIndicator?: string;
|
|
1125
|
+
commonLineTrailingSpaceColor?: DiffOptionsColor;
|
|
1126
|
+
contextLines?: number;
|
|
1127
|
+
emptyFirstOrLastLinePlaceholder?: string;
|
|
1128
|
+
expand?: boolean;
|
|
1129
|
+
includeChangeCounts?: boolean;
|
|
1130
|
+
omitAnnotationLines?: boolean;
|
|
1131
|
+
patchColor?: DiffOptionsColor;
|
|
1132
|
+
printBasicPrototype?: boolean;
|
|
1133
|
+
maxDepth?: number;
|
|
1134
|
+
compareKeys?: CompareKeys;
|
|
1135
|
+
truncateThreshold?: number;
|
|
1136
|
+
truncateAnnotation?: string;
|
|
1137
|
+
truncateAnnotationColor?: DiffOptionsColor;
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1141
|
+
*
|
|
1142
|
+
* This source code is licensed under the MIT license found in the
|
|
1143
|
+
* LICENSE file in the root directory of this source tree.
|
|
1144
|
+
*/
|
|
1145
|
+
interface StringifiedMemory {
|
|
1146
|
+
expected?: string;
|
|
1147
|
+
actual?: string;
|
|
1148
|
+
}
|
|
1149
|
+
interface Memorize {
|
|
1150
|
+
(pointer: "expected" | "actual", stringifiedValue: string): string;
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* @param a Expected value
|
|
1154
|
+
* @param b Received value
|
|
1155
|
+
* @param options Diff options
|
|
1156
|
+
* @returns {string | null} a string diff
|
|
1157
|
+
*/
|
|
1158
|
+
declare function diff(a: any, b: any, options?: DiffOptions, memorize?: Memorize): string | undefined;
|
|
1159
|
+
declare function printDiffOrStringify(received: unknown, expected: unknown, options?: DiffOptions, memory?: StringifiedMemory): string | undefined;
|
|
1160
|
+
interface UserConsoleLog {
|
|
1161
|
+
content: string;
|
|
1162
|
+
origin?: string;
|
|
1163
|
+
browser?: boolean;
|
|
1164
|
+
type: "stdout" | "stderr";
|
|
1165
|
+
taskId?: string;
|
|
1166
|
+
time: number;
|
|
1167
|
+
size: number;
|
|
1168
|
+
}
|
|
1169
|
+
interface MockResultReturn<T> {
|
|
1170
|
+
type: "return";
|
|
1171
|
+
/**
|
|
1172
|
+
* The value that was returned from the function. If function returned a Promise, then this will be a resolved value.
|
|
1173
|
+
*/
|
|
1174
|
+
value: T;
|
|
1175
|
+
}
|
|
1176
|
+
interface MockResultIncomplete {
|
|
1177
|
+
type: "incomplete";
|
|
1178
|
+
value: undefined;
|
|
1179
|
+
}
|
|
1180
|
+
interface MockResultThrow {
|
|
1181
|
+
type: "throw";
|
|
1182
|
+
/**
|
|
1183
|
+
* An error that was thrown during function execution.
|
|
1184
|
+
*/
|
|
1185
|
+
value: any;
|
|
1186
|
+
}
|
|
1187
|
+
interface MockSettledResultIncomplete {
|
|
1188
|
+
type: "incomplete";
|
|
1189
|
+
value: undefined;
|
|
1190
|
+
}
|
|
1191
|
+
interface MockSettledResultFulfilled<T> {
|
|
1192
|
+
type: "fulfilled";
|
|
1193
|
+
value: T;
|
|
1194
|
+
}
|
|
1195
|
+
interface MockSettledResultRejected {
|
|
1196
|
+
type: "rejected";
|
|
1197
|
+
value: any;
|
|
1198
|
+
}
|
|
1199
|
+
type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
|
|
1200
|
+
type MockSettledResult<T> = MockSettledResultFulfilled<T> | MockSettledResultRejected | MockSettledResultIncomplete;
|
|
1201
|
+
type MockParameters<T extends Procedure | Constructable> = T extends Constructable ? ConstructorParameters<T> : T extends Procedure ? Parameters<T> : never;
|
|
1202
|
+
type MockReturnType<T extends Procedure | Constructable> = T extends Constructable ? InstanceType<T> : T extends Procedure ? ReturnType<T> : never;
|
|
1203
|
+
type MockProcedureContext<T extends Procedure | Constructable> = T extends Constructable ? InstanceType<T> : ThisParameterType<T>;
|
|
1204
|
+
interface MockContext<T extends Procedure | Constructable = Procedure> {
|
|
1205
|
+
/**
|
|
1206
|
+
* This is an array containing all arguments for each call. One item of the array is the arguments of that call.
|
|
1207
|
+
*
|
|
1208
|
+
* @see https://vitest.dev/api/mock#mock-calls
|
|
1209
|
+
* @example
|
|
1210
|
+
* const fn = vi.fn()
|
|
1211
|
+
*
|
|
1212
|
+
* fn('arg1', 'arg2')
|
|
1213
|
+
* fn('arg3')
|
|
1214
|
+
*
|
|
1215
|
+
* fn.mock.calls === [
|
|
1216
|
+
* ['arg1', 'arg2'], // first call
|
|
1217
|
+
* ['arg3'], // second call
|
|
1218
|
+
* ]
|
|
1219
|
+
*/
|
|
1220
|
+
calls: MockParameters<T>[];
|
|
1221
|
+
/**
|
|
1222
|
+
* 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.
|
|
1223
|
+
* @see https://vitest.dev/api/mock#mock-instances
|
|
1224
|
+
*/
|
|
1225
|
+
instances: MockProcedureContext<T>[];
|
|
1226
|
+
/**
|
|
1227
|
+
* An array of `this` values that were used during each call to the mock function.
|
|
1228
|
+
* @see https://vitest.dev/api/mock#mock-contexts
|
|
1229
|
+
*/
|
|
1230
|
+
contexts: MockProcedureContext<T>[];
|
|
1231
|
+
/**
|
|
1232
|
+
* The order of mock's execution. This returns an array of numbers which are shared between all defined mocks.
|
|
1233
|
+
*
|
|
1234
|
+
* @see https://vitest.dev/api/mock#mock-invocationcallorder
|
|
1235
|
+
* @example
|
|
1236
|
+
* const fn1 = vi.fn()
|
|
1237
|
+
* const fn2 = vi.fn()
|
|
1238
|
+
*
|
|
1239
|
+
* fn1()
|
|
1240
|
+
* fn2()
|
|
1241
|
+
* fn1()
|
|
1242
|
+
*
|
|
1243
|
+
* fn1.mock.invocationCallOrder === [1, 3]
|
|
1244
|
+
* fn2.mock.invocationCallOrder === [2]
|
|
1245
|
+
*/
|
|
1246
|
+
invocationCallOrder: number[];
|
|
1247
|
+
/**
|
|
1248
|
+
* This is an array containing all values that were `returned` from the function.
|
|
1249
|
+
*
|
|
1250
|
+
* 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.
|
|
1251
|
+
*
|
|
1252
|
+
* @see https://vitest.dev/api/mock#mock-results
|
|
1253
|
+
* @example
|
|
1254
|
+
* const fn = vi.fn()
|
|
1255
|
+
* .mockReturnValueOnce('result')
|
|
1256
|
+
* .mockImplementationOnce(() => { throw new Error('thrown error') })
|
|
1257
|
+
*
|
|
1258
|
+
* const result = fn()
|
|
1259
|
+
*
|
|
1260
|
+
* try {
|
|
1261
|
+
* fn()
|
|
1262
|
+
* }
|
|
1263
|
+
* catch {}
|
|
1264
|
+
*
|
|
1265
|
+
* fn.mock.results === [
|
|
1266
|
+
* {
|
|
1267
|
+
* type: 'return',
|
|
1268
|
+
* value: 'result',
|
|
1269
|
+
* },
|
|
1270
|
+
* {
|
|
1271
|
+
* type: 'throw',
|
|
1272
|
+
* value: Error,
|
|
1273
|
+
* },
|
|
1274
|
+
* ]
|
|
1275
|
+
*/
|
|
1276
|
+
results: MockResult<MockReturnType<T>>[];
|
|
1277
|
+
/**
|
|
1278
|
+
* An array containing all values that were `resolved` or `rejected` from the function.
|
|
1279
|
+
*
|
|
1280
|
+
* This array will be empty if the function was never resolved or rejected.
|
|
1281
|
+
*
|
|
1282
|
+
* @see https://vitest.dev/api/mock#mock-settledresults
|
|
1283
|
+
* @example
|
|
1284
|
+
* const fn = vi.fn().mockResolvedValueOnce('result')
|
|
1285
|
+
*
|
|
1286
|
+
* const result = fn()
|
|
1287
|
+
*
|
|
1288
|
+
* fn.mock.settledResults === [
|
|
1289
|
+
* {
|
|
1290
|
+
* type: 'incomplete',
|
|
1291
|
+
* value: undefined,
|
|
1292
|
+
* }
|
|
1293
|
+
* ]
|
|
1294
|
+
* fn.mock.results === [
|
|
1295
|
+
* {
|
|
1296
|
+
* type: 'return',
|
|
1297
|
+
* value: Promise<'result'>,
|
|
1298
|
+
* },
|
|
1299
|
+
* ]
|
|
1300
|
+
*
|
|
1301
|
+
* await result
|
|
1302
|
+
*
|
|
1303
|
+
* fn.mock.settledResults === [
|
|
1304
|
+
* {
|
|
1305
|
+
* type: 'fulfilled',
|
|
1306
|
+
* value: 'result',
|
|
1307
|
+
* },
|
|
1308
|
+
* ]
|
|
1309
|
+
*/
|
|
1310
|
+
settledResults: MockSettledResult<Awaited<MockReturnType<T>>>[];
|
|
1311
|
+
/**
|
|
1312
|
+
* This contains the arguments of the last call. If spy wasn't called, will return `undefined`.
|
|
1313
|
+
* @see https://vitest.dev/api/mock#mock-lastcall
|
|
1314
|
+
*/
|
|
1315
|
+
lastCall: MockParameters<T> | undefined;
|
|
1316
|
+
}
|
|
1317
|
+
type Procedure = (...args: any[]) => any;
|
|
1318
|
+
type NormalizedProcedure<T extends Procedure | Constructable> = T extends Constructable ? ({
|
|
1319
|
+
new (...args: ConstructorParameters<T>): InstanceType<T>;
|
|
1320
|
+
}) | ({
|
|
1321
|
+
(this: InstanceType<T>, ...args: ConstructorParameters<T>): void;
|
|
1322
|
+
}) : T extends Procedure ? (...args: Parameters<T>) => ReturnType<T> : never;
|
|
1323
|
+
interface MockInstance<T extends Procedure | Constructable = Procedure> extends Disposable {
|
|
1324
|
+
/**
|
|
1325
|
+
* Use it to return the name assigned to the mock with the `.mockName(name)` method. By default, it will return `vi.fn()`.
|
|
1326
|
+
* @see https://vitest.dev/api/mock#getmockname
|
|
1327
|
+
*/
|
|
1328
|
+
getMockName(): string;
|
|
1329
|
+
/**
|
|
1330
|
+
* Sets the internal mock name. This is useful for identifying the mock when an assertion fails.
|
|
1331
|
+
* @see https://vitest.dev/api/mock#mockname
|
|
1332
|
+
*/
|
|
1333
|
+
mockName(name: string): this;
|
|
1334
|
+
/**
|
|
1335
|
+
* Current context of the mock. It stores information about all invocation calls, instances, and results.
|
|
1336
|
+
*/
|
|
1337
|
+
mock: MockContext<T>;
|
|
1338
|
+
/**
|
|
1339
|
+
* 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.
|
|
1340
|
+
*
|
|
1341
|
+
* To automatically call this method before each test, enable the [`clearMocks`](https://vitest.dev/config/clearmocks) setting in the configuration.
|
|
1342
|
+
* @see https://vitest.dev/api/mock#mockclear
|
|
1343
|
+
*/
|
|
1344
|
+
mockClear(): this;
|
|
1345
|
+
/**
|
|
1346
|
+
* Does what `mockClear` does and resets inner implementation to the original function. This also resets all "once" implementations.
|
|
1347
|
+
*
|
|
1348
|
+
* Note that resetting a mock from `vi.fn()` will set implementation to an empty function that returns `undefined`.
|
|
1349
|
+
* Resetting a mock from `vi.fn(impl)` will set implementation to `impl`. It is useful for completely resetting a mock to its default state.
|
|
1350
|
+
*
|
|
1351
|
+
* To automatically call this method before each test, enable the [`mockReset`](https://vitest.dev/config/mockreset) setting in the configuration.
|
|
1352
|
+
* @see https://vitest.dev/api/mock#mockreset
|
|
1353
|
+
*/
|
|
1354
|
+
mockReset(): this;
|
|
1355
|
+
/**
|
|
1356
|
+
* Does what `mockReset` does and restores original descriptors of spied-on objects.
|
|
1357
|
+
* @see https://vitest.dev/api/mock#mockrestore
|
|
1358
|
+
*/
|
|
1359
|
+
mockRestore(): void;
|
|
1360
|
+
/**
|
|
1361
|
+
* Returns current permanent mock implementation if there is one.
|
|
1362
|
+
*
|
|
1363
|
+
* If mock was created with `vi.fn`, it will consider passed down method as a mock implementation.
|
|
1364
|
+
*
|
|
1365
|
+
* If mock was created with `vi.spyOn`, it will return `undefined` unless a custom implementation was provided.
|
|
1366
|
+
*/
|
|
1367
|
+
getMockImplementation(): NormalizedProcedure<T> | undefined;
|
|
1368
|
+
/**
|
|
1369
|
+
* Accepts a function to be used as the mock implementation. TypeScript expects the arguments and return type to match those of the original function.
|
|
1370
|
+
* @see https://vitest.dev/api/mock#mockimplementation
|
|
1371
|
+
* @example
|
|
1372
|
+
* const increment = vi.fn().mockImplementation(count => count + 1);
|
|
1373
|
+
* expect(increment(3)).toBe(4);
|
|
1374
|
+
*/
|
|
1375
|
+
mockImplementation(fn: NormalizedProcedure<T>): this;
|
|
1376
|
+
/**
|
|
1377
|
+
* 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.
|
|
1378
|
+
*
|
|
1379
|
+
* 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.
|
|
1380
|
+
* @see https://vitest.dev/api/mock#mockimplementationonce
|
|
1381
|
+
* @example
|
|
1382
|
+
* const fn = vi.fn(count => count).mockImplementationOnce(count => count + 1);
|
|
1383
|
+
* expect(fn(3)).toBe(4);
|
|
1384
|
+
* expect(fn(3)).toBe(3);
|
|
1385
|
+
*/
|
|
1386
|
+
mockImplementationOnce(fn: NormalizedProcedure<T>): this;
|
|
1387
|
+
/**
|
|
1388
|
+
* Overrides the original mock implementation temporarily while the callback is being executed.
|
|
1389
|
+
*
|
|
1390
|
+
* Note that this method takes precedence over the [`mockImplementationOnce`](https://vitest.dev/api/mock#mockimplementationonce).
|
|
1391
|
+
* @see https://vitest.dev/api/mock#withimplementation
|
|
1392
|
+
* @example
|
|
1393
|
+
* const myMockFn = vi.fn(() => 'original')
|
|
1394
|
+
*
|
|
1395
|
+
* myMockFn.withImplementation(() => 'temp', () => {
|
|
1396
|
+
* myMockFn() // 'temp'
|
|
1397
|
+
* })
|
|
1398
|
+
*
|
|
1399
|
+
* myMockFn() // 'original'
|
|
1400
|
+
*/
|
|
1401
|
+
withImplementation(fn: NormalizedProcedure<T>, cb: () => Promise<unknown>): Promise<this>;
|
|
1402
|
+
withImplementation(fn: NormalizedProcedure<T>, cb: () => unknown): this;
|
|
1403
|
+
/**
|
|
1404
|
+
* Use this if you need to return the `this` context from the method without invoking the actual implementation.
|
|
1405
|
+
* @see https://vitest.dev/api/mock#mockreturnthis
|
|
1406
|
+
*/
|
|
1407
|
+
mockReturnThis(): this;
|
|
1408
|
+
/**
|
|
1409
|
+
* 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.
|
|
1410
|
+
* @see https://vitest.dev/api/mock#mockreturnvalue
|
|
1411
|
+
* @example
|
|
1412
|
+
* const mock = vi.fn()
|
|
1413
|
+
* mock.mockReturnValue(42)
|
|
1414
|
+
* mock() // 42
|
|
1415
|
+
* mock.mockReturnValue(43)
|
|
1416
|
+
* mock() // 43
|
|
1417
|
+
*/
|
|
1418
|
+
mockReturnValue(value: MockReturnType<T>): this;
|
|
1419
|
+
/**
|
|
1420
|
+
* 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.
|
|
1421
|
+
*
|
|
1422
|
+
* 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.
|
|
1423
|
+
* @example
|
|
1424
|
+
* const myMockFn = vi
|
|
1425
|
+
* .fn()
|
|
1426
|
+
* .mockReturnValue('default')
|
|
1427
|
+
* .mockReturnValueOnce('first call')
|
|
1428
|
+
* .mockReturnValueOnce('second call')
|
|
1429
|
+
*
|
|
1430
|
+
* // 'first call', 'second call', 'default'
|
|
1431
|
+
* console.log(myMockFn(), myMockFn(), myMockFn())
|
|
1432
|
+
*/
|
|
1433
|
+
mockReturnValueOnce(value: MockReturnType<T>): this;
|
|
1434
|
+
/**
|
|
1435
|
+
* Accepts a value that will be thrown whenever the mock function is called.
|
|
1436
|
+
* @see https://vitest.dev/api/mock#mockthrow
|
|
1437
|
+
* @example
|
|
1438
|
+
* const myMockFn = vi.fn().mockThrow(new Error('error'))
|
|
1439
|
+
* myMockFn() // throws 'error'
|
|
1440
|
+
*/
|
|
1441
|
+
mockThrow(value: unknown): this;
|
|
1442
|
+
/**
|
|
1443
|
+
* Accepts a value that will be thrown during the next function call. If chained, every consecutive call will throw the specified value.
|
|
1444
|
+
* @example
|
|
1445
|
+
* const myMockFn = vi
|
|
1446
|
+
* .fn()
|
|
1447
|
+
* .mockReturnValue('default')
|
|
1448
|
+
* .mockThrowOnce(new Error('first call error'))
|
|
1449
|
+
* .mockThrowOnce('second call error')
|
|
1450
|
+
*
|
|
1451
|
+
* expect(() => myMockFn()).toThrowError('first call error')
|
|
1452
|
+
* expect(() => myMockFn()).toThrowError('second call error')
|
|
1453
|
+
* expect(myMockFn()).toEqual('default')
|
|
1454
|
+
*/
|
|
1455
|
+
mockThrowOnce(value: unknown): this;
|
|
1456
|
+
/**
|
|
1457
|
+
* 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.
|
|
1458
|
+
* @example
|
|
1459
|
+
* const asyncMock = vi.fn().mockResolvedValue(42)
|
|
1460
|
+
* asyncMock() // Promise<42>
|
|
1461
|
+
*/
|
|
1462
|
+
mockResolvedValue(value: Awaited<MockReturnType<T>>): this;
|
|
1463
|
+
/**
|
|
1464
|
+
* 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.
|
|
1465
|
+
* @example
|
|
1466
|
+
* const myMockFn = vi
|
|
1467
|
+
* .fn()
|
|
1468
|
+
* .mockResolvedValue('default')
|
|
1469
|
+
* .mockResolvedValueOnce('first call')
|
|
1470
|
+
* .mockResolvedValueOnce('second call')
|
|
1471
|
+
*
|
|
1472
|
+
* // Promise<'first call'>, Promise<'second call'>, Promise<'default'>
|
|
1473
|
+
* console.log(myMockFn(), myMockFn(), myMockFn())
|
|
1474
|
+
*/
|
|
1475
|
+
mockResolvedValueOnce(value: Awaited<MockReturnType<T>>): this;
|
|
1476
|
+
/**
|
|
1477
|
+
* Accepts an error that will be rejected when async function is called.
|
|
1478
|
+
* @example
|
|
1479
|
+
* const asyncMock = vi.fn().mockRejectedValue(new Error('Async error'))
|
|
1480
|
+
* await asyncMock() // throws Error<'Async error'>
|
|
1481
|
+
*/
|
|
1482
|
+
mockRejectedValue(error: unknown): this;
|
|
1483
|
+
/**
|
|
1484
|
+
* Accepts a value that will be rejected during the next function call. If chained, each consecutive call will reject the specified value.
|
|
1485
|
+
* @example
|
|
1486
|
+
* const asyncMock = vi
|
|
1487
|
+
* .fn()
|
|
1488
|
+
* .mockResolvedValueOnce('first call')
|
|
1489
|
+
* .mockRejectedValueOnce(new Error('Async error'))
|
|
1490
|
+
*
|
|
1491
|
+
* await asyncMock() // first call
|
|
1492
|
+
* await asyncMock() // throws Error<'Async error'>
|
|
1493
|
+
*/
|
|
1494
|
+
mockRejectedValueOnce(error: unknown): this;
|
|
1495
|
+
}
|
|
1496
|
+
type Mock<T extends Procedure | Constructable = Procedure> = MockInstance<T> & (T extends Constructable ? (T extends Procedure ? {
|
|
1497
|
+
new (...args: ConstructorParameters<T>): InstanceType<T>;
|
|
1498
|
+
(...args: Parameters<T>): ReturnType<T>;
|
|
1499
|
+
} : {
|
|
1500
|
+
new (...args: ConstructorParameters<T>): InstanceType<T>;
|
|
1501
|
+
}) : {
|
|
1502
|
+
new (...args: MockParameters<T>): MockReturnType<T>;
|
|
1503
|
+
(...args: MockParameters<T>): MockReturnType<T>;
|
|
1504
|
+
}) & { [P in keyof T]: T[P]; };
|
|
1505
|
+
interface Constructable {
|
|
1506
|
+
new (...args: any[]): any;
|
|
1507
|
+
}
|
|
1508
|
+
interface Formatter {
|
|
1509
|
+
(input?: unknown): string;
|
|
1510
|
+
open: string;
|
|
1511
|
+
close: string;
|
|
1512
|
+
}
|
|
1513
|
+
interface AsymmetricMatcherInterface {
|
|
1514
|
+
asymmetricMatch: (other: unknown, customTesters?: Array<Tester>) => boolean;
|
|
1515
|
+
toString: () => string;
|
|
1516
|
+
getExpectedType?: () => string;
|
|
1517
|
+
toAsymmetricMatcher?: () => string;
|
|
1518
|
+
}
|
|
1519
|
+
declare abstract class AsymmetricMatcher<T, State extends MatcherState = MatcherState> implements AsymmetricMatcherInterface {
|
|
1520
|
+
protected sample: T;
|
|
1521
|
+
protected inverse: boolean;
|
|
1522
|
+
$$typeof: symbol;
|
|
1523
|
+
constructor(sample: T, inverse?: boolean);
|
|
1524
|
+
protected getMatcherContext(expect?: Chai.ExpectStatic): State;
|
|
1525
|
+
abstract asymmetricMatch(other: unknown, customTesters?: Array<Tester>): boolean;
|
|
1526
|
+
abstract toString(): string;
|
|
1527
|
+
getExpectedType?(): string;
|
|
1528
|
+
toAsymmetricMatcher?(): string;
|
|
1529
|
+
}
|
|
1530
|
+
declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
|
|
1531
|
+
declare function printReceived(object: unknown): string;
|
|
1532
|
+
declare function printExpected(value: unknown): string;
|
|
1533
|
+
declare function getMatcherUtils(): {
|
|
1534
|
+
EXPECTED_COLOR: Formatter;
|
|
1535
|
+
RECEIVED_COLOR: Formatter;
|
|
1536
|
+
INVERTED_COLOR: Formatter;
|
|
1537
|
+
BOLD_WEIGHT: Formatter;
|
|
1538
|
+
DIM_COLOR: Formatter;
|
|
1539
|
+
diff: typeof diff;
|
|
1540
|
+
matcherHint: typeof matcherHint;
|
|
1541
|
+
printReceived: typeof printReceived;
|
|
1542
|
+
printExpected: typeof printExpected;
|
|
1543
|
+
printDiffOrStringify: typeof printDiffOrStringify;
|
|
1544
|
+
printWithType: typeof printWithType;
|
|
1545
|
+
};
|
|
1546
|
+
declare function printWithType<T>(name: string, value: T, print: (value: T) => string): string;
|
|
1547
|
+
type Tester = (this: TesterContext, a: any, b: any, customTesters: Array<Tester>) => boolean | undefined;
|
|
1548
|
+
interface TesterContext {
|
|
1549
|
+
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
1550
|
+
}
|
|
1551
|
+
interface MatcherHintOptions {
|
|
1552
|
+
comment?: string;
|
|
1553
|
+
expectedColor?: Formatter;
|
|
1554
|
+
isDirectExpectCall?: boolean;
|
|
1555
|
+
isNot?: boolean;
|
|
1556
|
+
promise?: string;
|
|
1557
|
+
receivedColor?: Formatter;
|
|
1558
|
+
secondArgument?: string;
|
|
1559
|
+
secondArgumentColor?: Formatter;
|
|
1560
|
+
}
|
|
1561
|
+
interface MatcherState {
|
|
1562
|
+
customTesters: Array<Tester>;
|
|
1563
|
+
assertionCalls: number;
|
|
1564
|
+
currentTestName?: string;
|
|
1565
|
+
/**
|
|
1566
|
+
* @deprecated exists only in types
|
|
1567
|
+
*/
|
|
1568
|
+
dontThrow?: () => void;
|
|
1569
|
+
/**
|
|
1570
|
+
* @deprecated exists only in types
|
|
1571
|
+
*/
|
|
1572
|
+
error?: Error;
|
|
1573
|
+
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
1574
|
+
/**
|
|
1575
|
+
* @deprecated exists only in types
|
|
1576
|
+
*/
|
|
1577
|
+
expand?: boolean;
|
|
1578
|
+
expectedAssertionsNumber?: number | null;
|
|
1579
|
+
expectedAssertionsNumberErrorGen?: (() => Error) | null;
|
|
1580
|
+
isExpectingAssertions?: boolean;
|
|
1581
|
+
isExpectingAssertionsError?: Error | null;
|
|
1582
|
+
isNot: boolean;
|
|
1583
|
+
promise: string;
|
|
1584
|
+
/**
|
|
1585
|
+
* @deprecated exists only in types
|
|
1586
|
+
*/
|
|
1587
|
+
suppressedErrors: Array<Error>;
|
|
1588
|
+
testPath?: string;
|
|
1589
|
+
utils: ReturnType<typeof getMatcherUtils> & {
|
|
1590
|
+
diff: typeof diff;
|
|
1591
|
+
stringify: typeof stringify;
|
|
1592
|
+
iterableEquality: Tester;
|
|
1593
|
+
subsetEquality: Tester;
|
|
1594
|
+
};
|
|
1595
|
+
soft?: boolean;
|
|
1596
|
+
poll?: boolean;
|
|
1597
|
+
/**
|
|
1598
|
+
* The same assertion instance that chai plugins receive.
|
|
1599
|
+
* @experimental
|
|
1600
|
+
* @see {@link https://www.chaijs.com/guide/plugins/} Core Plugin Concepts
|
|
1601
|
+
*/
|
|
1602
|
+
readonly assertion: Assertion$1;
|
|
1603
|
+
}
|
|
1604
|
+
interface SyncExpectationResult {
|
|
1605
|
+
pass: boolean;
|
|
1606
|
+
message: () => string;
|
|
1607
|
+
actual?: any;
|
|
1608
|
+
expected?: any;
|
|
1609
|
+
meta?: object;
|
|
1610
|
+
}
|
|
1611
|
+
type AsyncExpectationResult = Promise<SyncExpectationResult>;
|
|
1612
|
+
type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
|
|
1613
|
+
interface RawMatcherFn<T extends MatcherState = MatcherState, E extends Array<any> = Array<any>> {
|
|
1614
|
+
(this: T, received: any, ...expected: E): ExpectationResult;
|
|
1615
|
+
}
|
|
1616
|
+
interface Matchers<R extends void | Promise<void> = void | Promise<void>, T = unknown> {}
|
|
1617
|
+
type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>> & ThisType<T> & { [K in keyof Matchers]?: RawMatcherFn<T, Parameters<Matchers[K]>>; };
|
|
1618
|
+
interface ExpectStatic extends Chai.ExpectStatic, Matchers<any>, AsymmetricMatchersContaining {
|
|
1619
|
+
<T>(actual: T, message?: string): Assertion$1<void, T>;
|
|
1620
|
+
extend: (expects: MatchersObject) => void;
|
|
1621
|
+
anything: () => any;
|
|
1622
|
+
any: (constructor: unknown) => any;
|
|
1623
|
+
getState: () => MatcherState;
|
|
1624
|
+
setState: (state: Partial<MatcherState>) => void;
|
|
1625
|
+
not: AsymmetricMatchersContaining;
|
|
1626
|
+
}
|
|
1627
|
+
interface CustomMatcher<R = any> {
|
|
1628
|
+
/**
|
|
1629
|
+
* Checks that a value satisfies a custom matcher function.
|
|
1630
|
+
*
|
|
1631
|
+
* @param matcher - A function returning a boolean based on the custom condition
|
|
1632
|
+
* @param message - Optional custom error message on failure
|
|
1633
|
+
*
|
|
1634
|
+
* @example
|
|
1635
|
+
* expect(age).toSatisfy(val => val >= 18, 'Age must be at least 18');
|
|
1636
|
+
* expect(age).toEqual(expect.toSatisfy(val => val >= 18, 'Age must be at least 18'));
|
|
1637
|
+
*/
|
|
1638
|
+
toSatisfy: (matcher: (value: any) => boolean, message?: string) => R;
|
|
1639
|
+
/**
|
|
1640
|
+
* Matches if the received value is one of the values in the expected array or set.
|
|
1641
|
+
*
|
|
1642
|
+
* @example
|
|
1643
|
+
* expect(1).toBeOneOf([1, 2, 3])
|
|
1644
|
+
* expect('foo').toBeOneOf([expect.any(String)])
|
|
1645
|
+
* expect({ a: 1 }).toEqual({ a: expect.toBeOneOf(['1', '2', '3']) })
|
|
1646
|
+
*/
|
|
1647
|
+
toBeOneOf: <T>(sample: ReadonlyArray<T> | ReadonlySet<T>) => R;
|
|
1648
|
+
}
|
|
1649
|
+
interface AsymmetricMatchersContaining extends Matchers<any>, CustomMatcher {
|
|
1650
|
+
/**
|
|
1651
|
+
* Matches if the received string contains the expected substring.
|
|
1652
|
+
*
|
|
1653
|
+
* @example
|
|
1654
|
+
* expect('I have an apple').toEqual(expect.stringContaining('apple'));
|
|
1655
|
+
* expect({ a: 'test string' }).toEqual({ a: expect.stringContaining('test') });
|
|
1656
|
+
*/
|
|
1657
|
+
stringContaining: (expected: string) => any;
|
|
1658
|
+
/**
|
|
1659
|
+
* Matches if the received object contains all properties of the expected object.
|
|
1660
|
+
*
|
|
1661
|
+
* @example
|
|
1662
|
+
* expect({ a: '1', b: 2 }).toEqual(expect.objectContaining({ a: '1' }))
|
|
1663
|
+
*/
|
|
1664
|
+
objectContaining: <T = any>(expected: DeeplyAllowMatchers<T>) => any;
|
|
1665
|
+
/**
|
|
1666
|
+
* Matches if the received array contains all elements in the expected array.
|
|
1667
|
+
*
|
|
1668
|
+
* @example
|
|
1669
|
+
* expect(['a', 'b', 'c']).toEqual(expect.arrayContaining(['b', 'a']));
|
|
1670
|
+
*/
|
|
1671
|
+
arrayContaining: <T = unknown>(expected: Array<DeeplyAllowMatchers<T>>) => any;
|
|
1672
|
+
/**
|
|
1673
|
+
* Matches if the received string or regex matches the expected pattern.
|
|
1674
|
+
*
|
|
1675
|
+
* @example
|
|
1676
|
+
* expect('hello world').toEqual(expect.stringMatching(/^hello/));
|
|
1677
|
+
* expect('hello world').toEqual(expect.stringMatching('hello'));
|
|
1678
|
+
*/
|
|
1679
|
+
stringMatching: (expected: string | RegExp) => any;
|
|
1680
|
+
/**
|
|
1681
|
+
* Matches if the received number is within a certain precision of the expected number.
|
|
1682
|
+
*
|
|
1683
|
+
* @example
|
|
1684
|
+
* expect(10.45).toEqual(expect.closeTo(10.5, 1));
|
|
1685
|
+
* expect(5.11).toEqual(expect.closeTo(5.12)); // with default precision
|
|
1686
|
+
*/
|
|
1687
|
+
closeTo: (expected: number, precision?: number) => any;
|
|
1688
|
+
/**
|
|
1689
|
+
* Matches if the received value validates against a Standard Schema.
|
|
1690
|
+
*
|
|
1691
|
+
* @param schema - A Standard Schema V1 compatible schema object
|
|
1692
|
+
*
|
|
1693
|
+
* @example
|
|
1694
|
+
* expect(user).toEqual(expect.schemaMatching(z.object({ name: z.string() })))
|
|
1695
|
+
* expect(['hello', 'world']).toEqual([expect.schemaMatching(z.string()), expect.schemaMatching(z.string())])
|
|
1696
|
+
*/
|
|
1697
|
+
schemaMatching: (schema: unknown) => any;
|
|
1698
|
+
}
|
|
1699
|
+
type WithAsymmetricMatcher<T> = T | AsymmetricMatcher<unknown>;
|
|
1700
|
+
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>;
|
|
1701
|
+
interface JestAssertion<R extends void | Promise<void>, T = unknown> extends CustomMatcher<R> {
|
|
1702
|
+
/**
|
|
1703
|
+
* Used when you want to check that two objects have the same value.
|
|
1704
|
+
* This matcher recursively checks the equality of all fields, rather than checking for object identity.
|
|
1705
|
+
*
|
|
1706
|
+
* @example
|
|
1707
|
+
* expect(user).toEqual({ name: 'Alice', age: 30 });
|
|
1708
|
+
*/
|
|
1709
|
+
toEqual: <E>(expected: E) => R;
|
|
1710
|
+
/**
|
|
1711
|
+
* Use to test that objects have the same types as well as structure.
|
|
1712
|
+
*
|
|
1713
|
+
* @example
|
|
1714
|
+
* expect(user).toStrictEqual({ name: 'Alice', age: 30 });
|
|
1715
|
+
*/
|
|
1716
|
+
toStrictEqual: <E>(expected: E) => R;
|
|
1717
|
+
/**
|
|
1718
|
+
* Checks that a value is what you expect. It calls `Object.is` to compare values.
|
|
1719
|
+
* Don't use `toBe` with floating-point numbers.
|
|
1720
|
+
*
|
|
1721
|
+
* @example
|
|
1722
|
+
* expect(result).toBe(42);
|
|
1723
|
+
* expect(status).toBe(true);
|
|
1724
|
+
*/
|
|
1725
|
+
toBe: <E>(expected: E) => R;
|
|
1726
|
+
/**
|
|
1727
|
+
* Check that a string matches a regular expression.
|
|
1728
|
+
*
|
|
1729
|
+
* @example
|
|
1730
|
+
* expect(message).toMatch(/hello/);
|
|
1731
|
+
* expect(greeting).toMatch('world');
|
|
1732
|
+
*/
|
|
1733
|
+
toMatch: (expected: string | RegExp) => R;
|
|
1734
|
+
/**
|
|
1735
|
+
* Used to check that a JavaScript object matches a subset of the properties of an object
|
|
1736
|
+
*
|
|
1737
|
+
* @example
|
|
1738
|
+
* expect(user).toMatchObject({
|
|
1739
|
+
* name: 'Alice',
|
|
1740
|
+
* address: { city: 'Wonderland' }
|
|
1741
|
+
* });
|
|
1742
|
+
*/
|
|
1743
|
+
toMatchObject: <E extends object | any[]>(expected: E) => R;
|
|
1744
|
+
/**
|
|
1745
|
+
* Used when you want to check that an item is in a list.
|
|
1746
|
+
* For testing the items in the list, this uses `===`, a strict equality check.
|
|
1747
|
+
*
|
|
1748
|
+
* @example
|
|
1749
|
+
* expect(items).toContain('apple');
|
|
1750
|
+
* expect(numbers).toContain(5);
|
|
1751
|
+
*/
|
|
1752
|
+
toContain: <E>(item: E) => R;
|
|
1753
|
+
/**
|
|
1754
|
+
* Used when you want to check that an item is in a list.
|
|
1755
|
+
* For testing the items in the list, this matcher recursively checks the
|
|
1756
|
+
* equality of all fields, rather than checking for object identity.
|
|
1757
|
+
*
|
|
1758
|
+
* @example
|
|
1759
|
+
* expect(items).toContainEqual({ name: 'apple', quantity: 1 });
|
|
1760
|
+
*/
|
|
1761
|
+
toContainEqual: <E>(item: E) => R;
|
|
1762
|
+
/**
|
|
1763
|
+
* Use when you don't care what a value is, you just want to ensure a value
|
|
1764
|
+
* is true in a boolean context. In JavaScript, there are six falsy values:
|
|
1765
|
+
* `false`, `0`, `''`, `null`, `undefined`, and `NaN`. Everything else is truthy.
|
|
1766
|
+
*
|
|
1767
|
+
* @example
|
|
1768
|
+
* expect(user.isActive).toBeTruthy();
|
|
1769
|
+
*/
|
|
1770
|
+
toBeTruthy: () => R;
|
|
1771
|
+
/**
|
|
1772
|
+
* When you don't care what a value is, you just want to
|
|
1773
|
+
* ensure a value is false in a boolean context.
|
|
1774
|
+
*
|
|
1775
|
+
* @example
|
|
1776
|
+
* expect(user.isActive).toBeFalsy();
|
|
1777
|
+
*/
|
|
1778
|
+
toBeFalsy: () => R;
|
|
1779
|
+
/**
|
|
1780
|
+
* For comparing floating point numbers.
|
|
1781
|
+
*
|
|
1782
|
+
* @example
|
|
1783
|
+
* expect(score).toBeGreaterThan(10);
|
|
1784
|
+
*/
|
|
1785
|
+
toBeGreaterThan: (num: number | bigint) => R;
|
|
1786
|
+
/**
|
|
1787
|
+
* For comparing floating point numbers.
|
|
1788
|
+
*
|
|
1789
|
+
* @example
|
|
1790
|
+
* expect(score).toBeGreaterThanOrEqual(10);
|
|
1791
|
+
*/
|
|
1792
|
+
toBeGreaterThanOrEqual: (num: number | bigint) => R;
|
|
1793
|
+
/**
|
|
1794
|
+
* For comparing floating point numbers.
|
|
1795
|
+
*
|
|
1796
|
+
* @example
|
|
1797
|
+
* expect(score).toBeLessThan(10);
|
|
1798
|
+
*/
|
|
1799
|
+
toBeLessThan: (num: number | bigint) => R;
|
|
1800
|
+
/**
|
|
1801
|
+
* For comparing floating point numbers.
|
|
1802
|
+
*
|
|
1803
|
+
* @example
|
|
1804
|
+
* expect(score).toBeLessThanOrEqual(10);
|
|
1805
|
+
*/
|
|
1806
|
+
toBeLessThanOrEqual: (num: number | bigint) => R;
|
|
1807
|
+
/**
|
|
1808
|
+
* Used to check that a variable is NaN.
|
|
1809
|
+
*
|
|
1810
|
+
* @example
|
|
1811
|
+
* expect(value).toBeNaN();
|
|
1812
|
+
*/
|
|
1813
|
+
toBeNaN: () => R;
|
|
1814
|
+
/**
|
|
1815
|
+
* Used to check that a variable is undefined.
|
|
1816
|
+
*
|
|
1817
|
+
* @example
|
|
1818
|
+
* expect(value).toBeUndefined();
|
|
1819
|
+
*/
|
|
1820
|
+
toBeUndefined: () => R;
|
|
1821
|
+
/**
|
|
1822
|
+
* This is the same as `.toBe(null)` but the error messages are a bit nicer.
|
|
1823
|
+
* So use `.toBeNull()` when you want to check that something is null.
|
|
1824
|
+
*
|
|
1825
|
+
* @example
|
|
1826
|
+
* expect(value).toBeNull();
|
|
1827
|
+
*/
|
|
1828
|
+
toBeNull: () => R;
|
|
1829
|
+
/**
|
|
1830
|
+
* Used to check that a variable is nullable (null or undefined).
|
|
1831
|
+
*
|
|
1832
|
+
* @example
|
|
1833
|
+
* expect(value).toBeNullable();
|
|
1834
|
+
*/
|
|
1835
|
+
toBeNullable: () => R;
|
|
1836
|
+
/**
|
|
1837
|
+
* Ensure that a variable is not undefined.
|
|
1838
|
+
*
|
|
1839
|
+
* @example
|
|
1840
|
+
* expect(value).toBeDefined();
|
|
1841
|
+
*/
|
|
1842
|
+
toBeDefined: () => R;
|
|
1843
|
+
/**
|
|
1844
|
+
* Ensure that an object is an instance of a class.
|
|
1845
|
+
* This matcher uses `instanceof` underneath.
|
|
1846
|
+
*
|
|
1847
|
+
* @example
|
|
1848
|
+
* expect(new Date()).toBeInstanceOf(Date);
|
|
1849
|
+
*/
|
|
1850
|
+
toBeInstanceOf: <E>(expected: E) => R;
|
|
1851
|
+
/**
|
|
1852
|
+
* Used to check that an object has a `.length` property
|
|
1853
|
+
* and it is set to a certain numeric value.
|
|
1854
|
+
*
|
|
1855
|
+
* @example
|
|
1856
|
+
* expect([1, 2, 3]).toHaveLength(3);
|
|
1857
|
+
* expect('hello').toHaveLength(5);
|
|
1858
|
+
*/
|
|
1859
|
+
toHaveLength: (length: number) => R;
|
|
1860
|
+
/**
|
|
1861
|
+
* Use to check if a property at the specified path exists on an object.
|
|
1862
|
+
* For checking deeply nested properties, you may use dot notation or an array containing
|
|
1863
|
+
* the path segments for deep references.
|
|
1864
|
+
*
|
|
1865
|
+
* Optionally, you can provide a value to check if it matches the value present at the path
|
|
1866
|
+
* on the target object. This matcher uses 'deep equality' (like `toEqual()`) and recursively checks
|
|
1867
|
+
* the equality of all fields.
|
|
1868
|
+
*
|
|
1869
|
+
* @example
|
|
1870
|
+
* expect(user).toHaveProperty('address.city', 'New York');
|
|
1871
|
+
* expect(config).toHaveProperty(['settings', 'theme'], 'dark');
|
|
1872
|
+
*/
|
|
1873
|
+
toHaveProperty: <E>(property: string | (string | number)[], value?: E) => R;
|
|
1874
|
+
/**
|
|
1875
|
+
* Using exact equality with floating point numbers is a bad idea.
|
|
1876
|
+
* Rounding means that intuitive things fail.
|
|
1877
|
+
* The default for `numDigits` is 2.
|
|
1878
|
+
*
|
|
1879
|
+
* @example
|
|
1880
|
+
* expect(price).toBeCloseTo(9.99, 2);
|
|
1881
|
+
*/
|
|
1882
|
+
toBeCloseTo: (number: number, numDigits?: number) => R;
|
|
1883
|
+
/**
|
|
1884
|
+
* Ensures that a mock function is called an exact number of times.
|
|
1885
|
+
*
|
|
1886
|
+
* Also under the alias `expect.toBeCalledTimes`.
|
|
1887
|
+
*
|
|
1888
|
+
* @example
|
|
1889
|
+
* expect(mockFunc).toHaveBeenCalledTimes(2);
|
|
1890
|
+
*/
|
|
1891
|
+
toHaveBeenCalledTimes: (times: number) => R;
|
|
1892
|
+
/**
|
|
1893
|
+
* Ensures that a mock function is called an exact number of times.
|
|
1894
|
+
*
|
|
1895
|
+
* Alias for `expect.toHaveBeenCalledTimes`.
|
|
1896
|
+
*
|
|
1897
|
+
* @example
|
|
1898
|
+
* expect(mockFunc).toBeCalledTimes(2);
|
|
1899
|
+
* @deprecated Use `toHaveBeenCalledTimes` instead
|
|
1900
|
+
*/
|
|
1901
|
+
toBeCalledTimes: (times: number) => R;
|
|
1902
|
+
/**
|
|
1903
|
+
* Ensures that a mock function is called.
|
|
1904
|
+
*
|
|
1905
|
+
* Also under the alias `expect.toBeCalled`.
|
|
1906
|
+
*
|
|
1907
|
+
* @example
|
|
1908
|
+
* expect(mockFunc).toHaveBeenCalled();
|
|
1909
|
+
*/
|
|
1910
|
+
toHaveBeenCalled: () => R;
|
|
1911
|
+
/**
|
|
1912
|
+
* Ensures that a mock function is called.
|
|
1913
|
+
*
|
|
1914
|
+
* Alias for `expect.toHaveBeenCalled`.
|
|
1915
|
+
*
|
|
1916
|
+
* @example
|
|
1917
|
+
* expect(mockFunc).toBeCalled();
|
|
1918
|
+
* @deprecated Use `toHaveBeenCalled` instead
|
|
1919
|
+
*/
|
|
1920
|
+
toBeCalled: () => R;
|
|
1921
|
+
/**
|
|
1922
|
+
* Ensure that a mock function is called with specific arguments.
|
|
1923
|
+
*
|
|
1924
|
+
* Also under the alias `expect.toBeCalledWith`.
|
|
1925
|
+
*
|
|
1926
|
+
* @example
|
|
1927
|
+
* expect(mockFunc).toHaveBeenCalledWith('arg1', 42);
|
|
1928
|
+
*/
|
|
1929
|
+
toHaveBeenCalledWith: <E extends any[]>(...args: E) => R;
|
|
1930
|
+
/**
|
|
1931
|
+
* Ensure that a mock function is called with specific arguments.
|
|
1932
|
+
*
|
|
1933
|
+
* Alias for `expect.toHaveBeenCalledWith`.
|
|
1934
|
+
*
|
|
1935
|
+
* @example
|
|
1936
|
+
* expect(mockFunc).toBeCalledWith('arg1', 42);
|
|
1937
|
+
* @deprecated Use `toHaveBeenCalledWith` instead
|
|
1938
|
+
*/
|
|
1939
|
+
toBeCalledWith: <E extends any[]>(...args: E) => R;
|
|
1940
|
+
/**
|
|
1941
|
+
* Ensure that a mock function is called with specific arguments on an Nth call.
|
|
1942
|
+
*
|
|
1943
|
+
* Also under the alias `expect.nthCalledWith`.
|
|
1944
|
+
*
|
|
1945
|
+
* @example
|
|
1946
|
+
* expect(mockFunc).toHaveBeenNthCalledWith(2, 'secondArg');
|
|
1947
|
+
*/
|
|
1948
|
+
toHaveBeenNthCalledWith: <E extends any[]>(n: number, ...args: E) => R;
|
|
1949
|
+
/**
|
|
1950
|
+
* If you have a mock function, you can use `.toHaveBeenLastCalledWith`
|
|
1951
|
+
* to test what arguments it was last called with.
|
|
1952
|
+
*
|
|
1953
|
+
* Also under the alias `expect.lastCalledWith`.
|
|
1954
|
+
*
|
|
1955
|
+
* @example
|
|
1956
|
+
* expect(mockFunc).toHaveBeenLastCalledWith('lastArg');
|
|
1957
|
+
*/
|
|
1958
|
+
toHaveBeenLastCalledWith: <E extends any[]>(...args: E) => R;
|
|
1959
|
+
/**
|
|
1960
|
+
* Used to test that a function throws when it is called.
|
|
1961
|
+
*
|
|
1962
|
+
* Also under the alias `expect.toThrowError`.
|
|
1963
|
+
*
|
|
1964
|
+
* @example
|
|
1965
|
+
* expect(() => functionWithError()).toThrow('Error message');
|
|
1966
|
+
* expect(() => parseJSON('invalid')).toThrow(SyntaxError);
|
|
1967
|
+
* expect(() => { throw 42 }).toThrow(42);
|
|
1968
|
+
*/
|
|
1969
|
+
toThrow: (expected?: any) => R;
|
|
1970
|
+
/**
|
|
1971
|
+
* Used to test that a function throws when it is called.
|
|
1972
|
+
*
|
|
1973
|
+
* Alias for `expect.toThrow`.
|
|
1974
|
+
*
|
|
1975
|
+
* @example
|
|
1976
|
+
* expect(() => functionWithError()).toThrowError('Error message');
|
|
1977
|
+
* expect(() => parseJSON('invalid')).toThrowError(SyntaxError);
|
|
1978
|
+
* expect(() => { throw 42 }).toThrowError(42);
|
|
1979
|
+
* @deprecated Use `toThrow` instead
|
|
1980
|
+
*/
|
|
1981
|
+
toThrowError: (expected?: any) => R;
|
|
1982
|
+
/**
|
|
1983
|
+
* Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
|
|
1984
|
+
*
|
|
1985
|
+
* Alias for `expect.toHaveReturned`.
|
|
1986
|
+
*
|
|
1987
|
+
* @example
|
|
1988
|
+
* expect(mockFunc).toReturn();
|
|
1989
|
+
* @deprecated Use `toHaveReturned` instead
|
|
1990
|
+
*/
|
|
1991
|
+
toReturn: () => R;
|
|
1992
|
+
/**
|
|
1993
|
+
* Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
|
|
1994
|
+
*
|
|
1995
|
+
* Also under the alias `expect.toReturn`.
|
|
1996
|
+
*
|
|
1997
|
+
* @example
|
|
1998
|
+
* expect(mockFunc).toHaveReturned();
|
|
1999
|
+
*/
|
|
2000
|
+
toHaveReturned: () => R;
|
|
2001
|
+
/**
|
|
2002
|
+
* Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
|
|
2003
|
+
* Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
|
|
2004
|
+
*
|
|
2005
|
+
* Alias for `expect.toHaveReturnedTimes`.
|
|
2006
|
+
*
|
|
2007
|
+
* @example
|
|
2008
|
+
* expect(mockFunc).toReturnTimes(3);
|
|
2009
|
+
* @deprecated Use `toHaveReturnedTimes` instead
|
|
2010
|
+
*/
|
|
2011
|
+
toReturnTimes: (times: number) => R;
|
|
2012
|
+
/**
|
|
2013
|
+
* Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
|
|
2014
|
+
* Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
|
|
2015
|
+
*
|
|
2016
|
+
* Also under the alias `expect.toReturnTimes`.
|
|
2017
|
+
*
|
|
2018
|
+
* @example
|
|
2019
|
+
* expect(mockFunc).toHaveReturnedTimes(3);
|
|
2020
|
+
*/
|
|
2021
|
+
toHaveReturnedTimes: (times: number) => R;
|
|
2022
|
+
/**
|
|
2023
|
+
* Use to ensure that a mock function returned a specific value.
|
|
2024
|
+
*
|
|
2025
|
+
* Alias for `expect.toHaveReturnedWith`.
|
|
2026
|
+
*
|
|
2027
|
+
* @example
|
|
2028
|
+
* expect(mockFunc).toReturnWith('returnValue');
|
|
2029
|
+
* @deprecated Use `toHaveReturnedWith` instead
|
|
2030
|
+
*/
|
|
2031
|
+
toReturnWith: <E>(value: E) => R;
|
|
2032
|
+
/**
|
|
2033
|
+
* Use to ensure that a mock function returned a specific value.
|
|
2034
|
+
*
|
|
2035
|
+
* Also under the alias `expect.toReturnWith`.
|
|
2036
|
+
*
|
|
2037
|
+
* @example
|
|
2038
|
+
* expect(mockFunc).toHaveReturnedWith('returnValue');
|
|
2039
|
+
*/
|
|
2040
|
+
toHaveReturnedWith: <E>(value: E) => R;
|
|
2041
|
+
/**
|
|
2042
|
+
* Use to test the specific value that a mock function last returned.
|
|
2043
|
+
* If the last call to the mock function threw an error, then this matcher will fail
|
|
2044
|
+
* no matter what value you provided as the expected return value.
|
|
2045
|
+
*
|
|
2046
|
+
* Also under the alias `expect.lastReturnedWith`.
|
|
2047
|
+
*
|
|
2048
|
+
* @example
|
|
2049
|
+
* expect(mockFunc).toHaveLastReturnedWith('lastValue');
|
|
2050
|
+
*/
|
|
2051
|
+
toHaveLastReturnedWith: <E>(value: E) => R;
|
|
2052
|
+
/**
|
|
2053
|
+
* Use to test the specific value that a mock function returned for the nth call.
|
|
2054
|
+
* If the nth call to the mock function threw an error, then this matcher will fail
|
|
2055
|
+
* no matter what value you provided as the expected return value.
|
|
2056
|
+
*
|
|
2057
|
+
* Also under the alias `expect.nthReturnedWith`.
|
|
2058
|
+
*
|
|
2059
|
+
* @example
|
|
2060
|
+
* expect(mockFunc).toHaveNthReturnedWith(2, 'nthValue');
|
|
2061
|
+
*/
|
|
2062
|
+
toHaveNthReturnedWith: <E>(nthCall: number, value: E) => R;
|
|
2063
|
+
}
|
|
2064
|
+
type VitestAssertion<A, R extends void | Promise<void>, T = unknown> = { [K in keyof A]: A[K] extends Chai.Assertion ? Assertion$1<R, T> : A[K] extends ((...args: any[]) => any) ? R extends Promise<void> ? PromisifyFunction<A[K]> : A[K] : VitestAssertion<A[K], R, T>; } & ((type: string, message?: string) => Assertion$1<R, T>);
|
|
2065
|
+
type Promisify<O> = { [K in keyof O]: PromisifyFunction<O[K]>; };
|
|
2066
|
+
type PromisifyFunction<T> = T extends ((...args: infer A) => infer R) ? Promisify<T> & ((...args: A) => R extends Promise<any> ? R : Promise<R>) : T;
|
|
2067
|
+
type PromisifyAssertion<T> = Assertion$1<Promise<void>, Awaited<T>>;
|
|
2068
|
+
interface Assertion$1<R extends void | Promise<void> = void, T = unknown> extends VitestAssertion<Chai.Assertion, R, T>, JestAssertion<R, T>, ChaiMockAssertion<R, T>, Matchers<R, T> {
|
|
2069
|
+
/**
|
|
2070
|
+
* Ensures a value is of a specific type.
|
|
2071
|
+
*
|
|
2072
|
+
* @example
|
|
2073
|
+
* expect(value).toBeTypeOf('string');
|
|
2074
|
+
* expect(number).toBeTypeOf('number');
|
|
2075
|
+
*/
|
|
2076
|
+
toBeTypeOf: (expected: "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined") => R;
|
|
2077
|
+
/**
|
|
2078
|
+
* Asserts that a mock function was called exactly once.
|
|
2079
|
+
*
|
|
2080
|
+
* @example
|
|
2081
|
+
* expect(mockFunc).toHaveBeenCalledOnce();
|
|
2082
|
+
*/
|
|
2083
|
+
toHaveBeenCalledOnce: () => R;
|
|
2084
|
+
/**
|
|
2085
|
+
* Ensure that a mock function is called with specific arguments and called
|
|
2086
|
+
* exactly once.
|
|
2087
|
+
*
|
|
2088
|
+
* @example
|
|
2089
|
+
* expect(mockFunc).toHaveBeenCalledExactlyOnceWith('arg1', 42);
|
|
2090
|
+
*/
|
|
2091
|
+
toHaveBeenCalledExactlyOnceWith: <E extends any[]>(...args: E) => R;
|
|
2092
|
+
/**
|
|
2093
|
+
* This assertion checks if a `Mock` was called before another `Mock`.
|
|
2094
|
+
* @param mock - A mock function created by `vi.spyOn` or `vi.fn`
|
|
2095
|
+
* @param failIfNoFirstInvocation - Fail if the first mock was never called
|
|
2096
|
+
* @example
|
|
2097
|
+
* const mock1 = vi.fn()
|
|
2098
|
+
* const mock2 = vi.fn()
|
|
2099
|
+
*
|
|
2100
|
+
* mock1()
|
|
2101
|
+
* mock2()
|
|
2102
|
+
* mock1()
|
|
2103
|
+
*
|
|
2104
|
+
* expect(mock1).toHaveBeenCalledBefore(mock2)
|
|
2105
|
+
*/
|
|
2106
|
+
toHaveBeenCalledBefore: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => R;
|
|
2107
|
+
/**
|
|
2108
|
+
* This assertion checks if a `Mock` was called after another `Mock`.
|
|
2109
|
+
* @param mock - A mock function created by `vi.spyOn` or `vi.fn`
|
|
2110
|
+
* @param failIfNoFirstInvocation - Fail if the first mock was never called
|
|
2111
|
+
* @example
|
|
2112
|
+
* const mock1 = vi.fn()
|
|
2113
|
+
* const mock2 = vi.fn()
|
|
2114
|
+
*
|
|
2115
|
+
* mock2()
|
|
2116
|
+
* mock1()
|
|
2117
|
+
* mock2()
|
|
2118
|
+
*
|
|
2119
|
+
* expect(mock1).toHaveBeenCalledAfter(mock2)
|
|
2120
|
+
*/
|
|
2121
|
+
toHaveBeenCalledAfter: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => R;
|
|
2122
|
+
/**
|
|
2123
|
+
* Checks that at least one of the mock function's calls has resolved.
|
|
2124
|
+
*
|
|
2125
|
+
* @example
|
|
2126
|
+
* expect(mockAsyncFunc).toHaveResolved();
|
|
2127
|
+
*/
|
|
2128
|
+
toHaveResolved: () => R;
|
|
2129
|
+
/**
|
|
2130
|
+
* Checks that at least one of the mock function's calls has resolved to a specific value.
|
|
2131
|
+
*
|
|
2132
|
+
* @example
|
|
2133
|
+
* expect(mockAsyncFunc).toHaveResolvedWith('success');
|
|
2134
|
+
*/
|
|
2135
|
+
toHaveResolvedWith: <E>(value: E) => R;
|
|
2136
|
+
/**
|
|
2137
|
+
* Ensures a promise resolves a specific number of times.
|
|
2138
|
+
*
|
|
2139
|
+
* @example
|
|
2140
|
+
* expect(mockAsyncFunc).toHaveResolvedTimes(3);
|
|
2141
|
+
*/
|
|
2142
|
+
toHaveResolvedTimes: (times: number) => R;
|
|
2143
|
+
/**
|
|
2144
|
+
* Asserts that the last resolved value of a promise matches an expected value.
|
|
2145
|
+
*
|
|
2146
|
+
* @example
|
|
2147
|
+
* await expect(mockAsyncFunc).toHaveLastResolvedWith('finalResult');
|
|
2148
|
+
*/
|
|
2149
|
+
toHaveLastResolvedWith: <E>(value: E) => R;
|
|
2150
|
+
/**
|
|
2151
|
+
* Ensures a specific value was returned by a promise on the nth resolution.
|
|
2152
|
+
*
|
|
2153
|
+
* @example
|
|
2154
|
+
* await expect(mockAsyncFunc).toHaveNthResolvedWith(2, 'secondResult');
|
|
2155
|
+
*/
|
|
2156
|
+
toHaveNthResolvedWith: <E>(nthCall: number, value: E) => R;
|
|
2157
|
+
/**
|
|
2158
|
+
* Verifies that a promise resolves.
|
|
2159
|
+
*
|
|
2160
|
+
* @example
|
|
2161
|
+
* await expect(someAsyncFunc).resolves.toBe(42);
|
|
2162
|
+
*/
|
|
2163
|
+
resolves: PromisifyAssertion<T>;
|
|
2164
|
+
/**
|
|
2165
|
+
* Verifies that a promise rejects.
|
|
2166
|
+
*
|
|
2167
|
+
* @example
|
|
2168
|
+
* await expect(someAsyncFunc).rejects.toThrow('error');
|
|
2169
|
+
*/
|
|
2170
|
+
rejects: PromisifyAssertion<unknown>;
|
|
2171
|
+
}
|
|
2172
|
+
/**
|
|
2173
|
+
* Chai-style assertions for spy/mock testing.
|
|
2174
|
+
* These provide sinon-chai compatible assertion names that delegate to Jest-style implementations.
|
|
2175
|
+
*/
|
|
2176
|
+
interface ChaiMockAssertion<R extends void | Promise<void>, T = unknown> {
|
|
2177
|
+
/**
|
|
2178
|
+
* Checks that a spy was called at least once.
|
|
2179
|
+
* Chai-style equivalent of `toHaveBeenCalled`.
|
|
2180
|
+
*
|
|
2181
|
+
* @example
|
|
2182
|
+
* expect(spy).to.have.been.called
|
|
2183
|
+
*/
|
|
2184
|
+
readonly called: Assertion$1<R, T>;
|
|
2185
|
+
/**
|
|
2186
|
+
* Checks that a spy was called a specific number of times.
|
|
2187
|
+
* Chai-style equivalent of `toHaveBeenCalledTimes`.
|
|
2188
|
+
*
|
|
2189
|
+
* @example
|
|
2190
|
+
* expect(spy).to.have.callCount(3)
|
|
2191
|
+
*/
|
|
2192
|
+
callCount: (count: number) => R;
|
|
2193
|
+
/**
|
|
2194
|
+
* Checks that a spy was called with specific arguments at least once.
|
|
2195
|
+
* Chai-style equivalent of `toHaveBeenCalledWith`.
|
|
2196
|
+
*
|
|
2197
|
+
* @example
|
|
2198
|
+
* expect(spy).to.have.been.calledWith('arg1', 'arg2')
|
|
2199
|
+
*/
|
|
2200
|
+
calledWith: <E extends any[]>(...args: E) => R;
|
|
2201
|
+
/**
|
|
2202
|
+
* Checks that a spy was called exactly once.
|
|
2203
|
+
* Chai-style equivalent of `toHaveBeenCalledOnce`.
|
|
2204
|
+
*
|
|
2205
|
+
* @example
|
|
2206
|
+
* expect(spy).to.have.been.calledOnce
|
|
2207
|
+
*/
|
|
2208
|
+
readonly calledOnce: Assertion$1<R, T>;
|
|
2209
|
+
/**
|
|
2210
|
+
* Checks that a spy was called exactly once with specific arguments.
|
|
2211
|
+
* Chai-style equivalent of `toHaveBeenCalledExactlyOnceWith`.
|
|
2212
|
+
*
|
|
2213
|
+
* @example
|
|
2214
|
+
* expect(spy).to.have.been.calledOnceWith('arg1', 'arg2')
|
|
2215
|
+
*/
|
|
2216
|
+
calledOnceWith: <E extends any[]>(...args: E) => R;
|
|
2217
|
+
/**
|
|
2218
|
+
* Checks that the last call to a spy was made with specific arguments.
|
|
2219
|
+
* Chai-style equivalent of `toHaveBeenLastCalledWith`.
|
|
2220
|
+
*
|
|
2221
|
+
* @example
|
|
2222
|
+
* expect(spy).to.have.been.lastCalledWith('arg1', 'arg2')
|
|
2223
|
+
*/
|
|
2224
|
+
lastCalledWith: <E extends any[]>(...args: E) => R;
|
|
2225
|
+
/**
|
|
2226
|
+
* Checks that the nth call to a spy was made with specific arguments.
|
|
2227
|
+
* Chai-style equivalent of `toHaveBeenNthCalledWith`.
|
|
2228
|
+
*
|
|
2229
|
+
* @example
|
|
2230
|
+
* expect(spy).to.have.been.nthCalledWith(2, 'arg1', 'arg2')
|
|
2231
|
+
*/
|
|
2232
|
+
nthCalledWith: <E extends any[]>(n: number, ...args: E) => R;
|
|
2233
|
+
/**
|
|
2234
|
+
* Checks that a spy returned a specific value at least once.
|
|
2235
|
+
* Chai-style equivalent of `toHaveReturnedWith`.
|
|
2236
|
+
*
|
|
2237
|
+
* @example
|
|
2238
|
+
* expect(spy).to.have.returned('value')
|
|
2239
|
+
*/
|
|
2240
|
+
returned: <E>(value: E) => R;
|
|
2241
|
+
/**
|
|
2242
|
+
* Checks that a spy returned a specific value at least once.
|
|
2243
|
+
* Chai-style equivalent of `toHaveReturnedWith`.
|
|
2244
|
+
*
|
|
2245
|
+
* @example
|
|
2246
|
+
* expect(spy).to.have.returnedWith('value')
|
|
2247
|
+
*/
|
|
2248
|
+
returnedWith: <E>(value: E) => R;
|
|
2249
|
+
/**
|
|
2250
|
+
* Checks that a spy returned successfully a specific number of times.
|
|
2251
|
+
* Chai-style equivalent of `toHaveReturnedTimes`.
|
|
2252
|
+
*
|
|
2253
|
+
* @example
|
|
2254
|
+
* expect(spy).to.have.returnedTimes(3)
|
|
2255
|
+
*/
|
|
2256
|
+
returnedTimes: (count: number) => R;
|
|
2257
|
+
/**
|
|
2258
|
+
* Checks that the last return value of a spy matches the expected value.
|
|
2259
|
+
* Chai-style equivalent of `toHaveLastReturnedWith`.
|
|
2260
|
+
*
|
|
2261
|
+
* @example
|
|
2262
|
+
* expect(spy).to.have.lastReturnedWith('value')
|
|
2263
|
+
*/
|
|
2264
|
+
lastReturnedWith: <E>(value: E) => R;
|
|
2265
|
+
/**
|
|
2266
|
+
* Checks that the nth return value of a spy matches the expected value.
|
|
2267
|
+
* Chai-style equivalent of `toHaveNthReturnedWith`.
|
|
2268
|
+
*
|
|
2269
|
+
* @example
|
|
2270
|
+
* expect(spy).to.have.nthReturnedWith(2, 'value')
|
|
2271
|
+
*/
|
|
2272
|
+
nthReturnedWith: <E>(n: number, value: E) => R;
|
|
2273
|
+
/**
|
|
2274
|
+
* Checks that a spy was called before another spy.
|
|
2275
|
+
* Chai-style equivalent of `toHaveBeenCalledBefore`.
|
|
2276
|
+
*
|
|
2277
|
+
* @example
|
|
2278
|
+
* expect(spy1).to.have.been.calledBefore(spy2)
|
|
2279
|
+
*/
|
|
2280
|
+
calledBefore: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => R;
|
|
2281
|
+
/**
|
|
2282
|
+
* Checks that a spy was called after another spy.
|
|
2283
|
+
* Chai-style equivalent of `toHaveBeenCalledAfter`.
|
|
2284
|
+
*
|
|
2285
|
+
* @example
|
|
2286
|
+
* expect(spy1).to.have.been.calledAfter(spy2)
|
|
2287
|
+
*/
|
|
2288
|
+
calledAfter: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => R;
|
|
2289
|
+
/**
|
|
2290
|
+
* Checks that a spy was called exactly twice.
|
|
2291
|
+
* Chai-style equivalent of `toHaveBeenCalledTimes(2)`.
|
|
2292
|
+
*
|
|
2293
|
+
* @example
|
|
2294
|
+
* expect(spy).to.have.been.calledTwice
|
|
2295
|
+
*/
|
|
2296
|
+
readonly calledTwice: Assertion$1<R, T>;
|
|
2297
|
+
/**
|
|
2298
|
+
* Checks that a spy was called exactly three times.
|
|
2299
|
+
* Chai-style equivalent of `toHaveBeenCalledTimes(3)`.
|
|
2300
|
+
*
|
|
2301
|
+
* @example
|
|
2302
|
+
* expect(spy).to.have.been.calledThrice
|
|
2303
|
+
*/
|
|
2304
|
+
readonly calledThrice: Assertion$1<R, T>;
|
|
2305
|
+
}
|
|
2306
|
+
type ExtractBenchNames<T extends BenchRegistration<any>[]> = Exclude<{ [K in keyof T]: T[K] extends BenchRegistration<infer N> ? N : never; }[number], never>;
|
|
2307
|
+
/**
|
|
2308
|
+
* A benchmarked function. Vitest-owned and engine-agnostic.
|
|
2309
|
+
*/
|
|
2310
|
+
type BenchFn = Fn;
|
|
2311
|
+
/**
|
|
2312
|
+
* Per-benchmark initialization options passed to `bench(name, options, fn)`.
|
|
2313
|
+
*/
|
|
2314
|
+
type BenchOptions = FnOptions;
|
|
2315
|
+
/**
|
|
2316
|
+
* Engine-neutral run options forwarded to a {@link BenchmarkProvider}. These
|
|
2317
|
+
* come from the optional trailing options argument of `bench.compare()` and
|
|
2318
|
+
* `registration.run()`.
|
|
2319
|
+
*/
|
|
2320
|
+
type BenchRunOptions = BenchOptions$1;
|
|
2321
|
+
/**
|
|
2322
|
+
* The result of a single benchmark, produced by a {@link BenchmarkProvider}.
|
|
2323
|
+
* Structurally compatible with tinybench's task statistics so it flows
|
|
2324
|
+
* unchanged into the reporter, `bench.from()` baselines and comparison tables.
|
|
2325
|
+
* The `name` matches the corresponding {@link BenchRegistration}.
|
|
2326
|
+
*/
|
|
2327
|
+
interface BenchResult extends TaskResultCompleted, TaskResultRuntimeInfo, TaskResultTimestampProviderInfo {
|
|
2328
|
+
/** The registered benchmark name this result belongs to. */
|
|
2329
|
+
name: string;
|
|
2330
|
+
}
|
|
2331
|
+
interface BenchStorage<T extends string> {
|
|
2332
|
+
get: (name: T) => BenchResult;
|
|
2333
|
+
}
|
|
2334
|
+
/**
|
|
2335
|
+
* Options accepted by `bench(name, options, fn)`. Extends the per-benchmark
|
|
2336
|
+
* lifecycle hooks with Vitest-specific fields.
|
|
2337
|
+
*/
|
|
2338
|
+
interface BenchFnOptions extends BenchOptions {
|
|
2339
|
+
/**
|
|
2340
|
+
* Path (relative to the project root) where the benchmark result is written
|
|
2341
|
+
* after a successful run. The string `${projectName}` is substituted with
|
|
2342
|
+
* the current project name. Absolute paths are accepted as long as they
|
|
2343
|
+
* resolve inside the project root.
|
|
2344
|
+
*/
|
|
2345
|
+
writeResult?: string;
|
|
2346
|
+
/**
|
|
2347
|
+
* Mark this benchmark as a per-project entry. Per-project tasks still appear
|
|
2348
|
+
* in the inline comparison table for the current run, and Vitest additionally
|
|
2349
|
+
* collects them across projects and prints a single cross-project table at
|
|
2350
|
+
* the end of the run.
|
|
2351
|
+
*/
|
|
2352
|
+
perProject?: boolean;
|
|
2353
|
+
}
|
|
2354
|
+
interface BenchRegistration<Name extends string> {
|
|
2355
|
+
name: Name;
|
|
2356
|
+
/**
|
|
2357
|
+
* The benchmark function. Absent for registrations created via `bench.from()`.
|
|
2358
|
+
*/
|
|
2359
|
+
fn?: BenchFn;
|
|
2360
|
+
/**
|
|
2361
|
+
* Per-benchmark options (`beforeEach`, `beforeAll`, etc.). Absent for
|
|
2362
|
+
* registrations created via `bench.from()`.
|
|
2363
|
+
*/
|
|
2364
|
+
fnOpts?: BenchOptions;
|
|
2365
|
+
run: (options?: BenchRunOptions) => Promise<BenchResult>;
|
|
2366
|
+
}
|
|
2367
|
+
interface BenchCompare {
|
|
2368
|
+
<Args extends BenchRegistration<any>[]>(...args: Args): Promise<BenchStorage<ExtractBenchNames<Args>>>;
|
|
2369
|
+
<Args extends BenchRegistration<any>[]>(...args: [...Args, BenchRunOptions]): Promise<BenchStorage<ExtractBenchNames<Args>>>;
|
|
2370
|
+
}
|
|
2371
|
+
interface BenchFactory {
|
|
2372
|
+
<Name extends string>(name: Name | Function, fn: BenchFn): BenchRegistration<Name>;
|
|
2373
|
+
<Name extends string>(name: Name | Function, options: BenchFnOptions, fn: BenchFn): BenchRegistration<Name>;
|
|
2374
|
+
}
|
|
2375
|
+
interface BenchFromSource {
|
|
2376
|
+
(): BaselineData | Promise<BaselineData>;
|
|
2377
|
+
}
|
|
2378
|
+
interface BenchFrom {
|
|
2379
|
+
<Name extends string>(name: Name | Function, source: string | BenchFromSource): BenchRegistration<Name>;
|
|
2380
|
+
}
|
|
2381
|
+
interface Bench extends BenchFactory {
|
|
2382
|
+
compare: BenchCompare;
|
|
2383
|
+
from: BenchFrom;
|
|
2384
|
+
}
|
|
2385
|
+
type RunMode = "run" | "skip" | "only" | "todo" | "queued";
|
|
2386
|
+
type TaskState = RunMode | "pass" | "fail";
|
|
2387
|
+
interface TaskBase {
|
|
2388
|
+
/**
|
|
2389
|
+
* Unique task identifier. Based on the file id and the position of the task.
|
|
2390
|
+
* The id of the file task is based on the file path relative to root and project name.
|
|
2391
|
+
* It will not change between runs.
|
|
2392
|
+
* @example `1201091390`, `1201091390_0`, `1201091390_0_1`
|
|
2393
|
+
*/
|
|
2394
|
+
id: string;
|
|
2395
|
+
/**
|
|
2396
|
+
* Task name provided by the user. If no name was provided, it will be an empty string.
|
|
2397
|
+
*/
|
|
2398
|
+
name: string;
|
|
2399
|
+
/**
|
|
2400
|
+
* Full name including the file path, any parent suites, and this task's name.
|
|
2401
|
+
*
|
|
2402
|
+
* Uses ` > ` as the separator between levels.
|
|
2403
|
+
*
|
|
2404
|
+
* @example
|
|
2405
|
+
* // file
|
|
2406
|
+
* 'test/task-names.test.ts'
|
|
2407
|
+
* @example
|
|
2408
|
+
* // suite
|
|
2409
|
+
* 'test/task-names.test.ts > meal planning'
|
|
2410
|
+
* 'test/task-names.test.ts > meal planning > grocery lists'
|
|
2411
|
+
* @example
|
|
2412
|
+
* // test
|
|
2413
|
+
* 'test/task-names.test.ts > meal planning > grocery lists > calculates ingredients'
|
|
2414
|
+
*/
|
|
2415
|
+
fullName: string;
|
|
2416
|
+
/**
|
|
2417
|
+
* Full name excluding the file path, including any parent suites and this task's name. `undefined` for file tasks.
|
|
2418
|
+
*
|
|
2419
|
+
* Uses ` > ` as the separator between levels.
|
|
2420
|
+
*
|
|
2421
|
+
* @example
|
|
2422
|
+
* // file
|
|
2423
|
+
* undefined
|
|
2424
|
+
* @example
|
|
2425
|
+
* // suite
|
|
2426
|
+
* 'meal planning'
|
|
2427
|
+
* 'meal planning > grocery lists'
|
|
2428
|
+
* @example
|
|
2429
|
+
* // test
|
|
2430
|
+
* 'meal planning > grocery lists > calculates ingredients'
|
|
2431
|
+
*/
|
|
2432
|
+
fullTestName?: string;
|
|
2433
|
+
/**
|
|
2434
|
+
* Task mode.
|
|
2435
|
+
* - **skip**: task is skipped
|
|
2436
|
+
* - **only**: only this task and other tasks with `only` mode will run
|
|
2437
|
+
* - **todo**: task is marked as a todo, alias for `skip`
|
|
2438
|
+
* - **run**: task will run or already ran
|
|
2439
|
+
* - **queued**: task will start running next. It can only exist on the File
|
|
2440
|
+
*/
|
|
2441
|
+
mode: RunMode;
|
|
2442
|
+
/**
|
|
2443
|
+
* Custom metadata for the task. JSON reporter will save this data.
|
|
2444
|
+
*/
|
|
2445
|
+
meta: TaskMeta;
|
|
2446
|
+
/**
|
|
2447
|
+
* Whether the task was produced with `.each()` method.
|
|
2448
|
+
*/
|
|
2449
|
+
each?: boolean;
|
|
2450
|
+
/**
|
|
2451
|
+
* Whether the task should run concurrently with other tasks.
|
|
2452
|
+
*/
|
|
2453
|
+
concurrent?: boolean;
|
|
2454
|
+
/**
|
|
2455
|
+
* Whether the tasks of the suite run in a random order.
|
|
2456
|
+
*/
|
|
2457
|
+
shuffle?: boolean;
|
|
2458
|
+
/**
|
|
2459
|
+
* Suite that this task is part of. File task or the global suite will have no parent.
|
|
2460
|
+
*/
|
|
2461
|
+
suite?: Suite;
|
|
2462
|
+
/**
|
|
2463
|
+
* Result of the task. Suite and file tasks will only have the result if there
|
|
2464
|
+
* was an error during collection or inside `afterAll`/`beforeAll`.
|
|
2465
|
+
*/
|
|
2466
|
+
result?: TaskResult;
|
|
2467
|
+
/**
|
|
2468
|
+
* Retry configuration for the task.
|
|
2469
|
+
* - If a number, specifies how many times to retry
|
|
2470
|
+
* - If an object, allows fine-grained retry control
|
|
2471
|
+
* @default 0
|
|
2472
|
+
*/
|
|
2473
|
+
retry?: Retry;
|
|
2474
|
+
/**
|
|
2475
|
+
* The amount of times the task should be repeated after the successful run.
|
|
2476
|
+
* If the task fails, it will not be retried unless `retry` is specified.
|
|
2477
|
+
* @default 0
|
|
2478
|
+
*/
|
|
2479
|
+
repeats?: number;
|
|
2480
|
+
/**
|
|
2481
|
+
* Location of the task in the file. This field is populated only if
|
|
2482
|
+
* `includeTaskLocation` option is set. It is generated by calling `new Error`
|
|
2483
|
+
* and parsing the stack trace, so the location might differ depending on the runtime.
|
|
2484
|
+
*/
|
|
2485
|
+
location?: Location;
|
|
2486
|
+
/**
|
|
2487
|
+
* If the test was collected by parsing the file AST, and the name
|
|
2488
|
+
* is not a static string, this property will be set to `true`.
|
|
2489
|
+
* @experimental
|
|
2490
|
+
*/
|
|
2491
|
+
dynamic?: boolean;
|
|
2492
|
+
/**
|
|
2493
|
+
* Custom tags of the task. Useful for filtering tasks.
|
|
2494
|
+
*/
|
|
2495
|
+
tags?: string[];
|
|
2496
|
+
logs?: UserConsoleLog[];
|
|
2497
|
+
}
|
|
2498
|
+
interface TaskPopulated extends TaskBase {
|
|
2499
|
+
/**
|
|
2500
|
+
* File task. It's the root task of the file.
|
|
2501
|
+
*/
|
|
2502
|
+
file: File;
|
|
2503
|
+
/**
|
|
2504
|
+
* Whether the task should succeed if it fails. If the task fails, it will be marked as passed.
|
|
2505
|
+
*/
|
|
2506
|
+
fails?: boolean;
|
|
2507
|
+
/**
|
|
2508
|
+
* Store promises (from async expects) to wait for them before finishing the test
|
|
2509
|
+
*/
|
|
2510
|
+
promises?: Promise<any>[];
|
|
2511
|
+
}
|
|
2512
|
+
/**
|
|
2513
|
+
* Custom metadata that can be used in reporters.
|
|
2514
|
+
*/
|
|
2515
|
+
interface TaskMeta {
|
|
2516
|
+
typecheck?: boolean;
|
|
2517
|
+
benchmark?: boolean;
|
|
2518
|
+
__vitest_label__?: string;
|
|
2519
|
+
}
|
|
2520
|
+
/**
|
|
2521
|
+
* The result of calling a task.
|
|
2522
|
+
*/
|
|
2523
|
+
interface TaskResult {
|
|
2524
|
+
/**
|
|
2525
|
+
* State of the task. Inherits the `task.mode` during collection.
|
|
2526
|
+
* When the task has finished, it will be changed to `pass` or `fail`.
|
|
2527
|
+
* - **pass**: task ran successfully
|
|
2528
|
+
* - **fail**: task failed
|
|
2529
|
+
*/
|
|
2530
|
+
state: TaskState;
|
|
2531
|
+
/**
|
|
2532
|
+
* Errors that occurred during the task execution. It is possible to have several errors
|
|
2533
|
+
* if `expect.soft()` failed multiple times or `retry` was triggered.
|
|
2534
|
+
*/
|
|
2535
|
+
errors?: TestError[];
|
|
2536
|
+
/**
|
|
2537
|
+
* How long in milliseconds the task took to run.
|
|
2538
|
+
*/
|
|
2539
|
+
duration?: number;
|
|
2540
|
+
/**
|
|
2541
|
+
* Time in milliseconds when the task started running.
|
|
2542
|
+
*/
|
|
2543
|
+
startTime?: number;
|
|
2544
|
+
/**
|
|
2545
|
+
* Heap size in bytes after the task finished.
|
|
2546
|
+
* Only available if `logHeapUsage` option is set and `process.memoryUsage` is defined.
|
|
2547
|
+
*/
|
|
2548
|
+
heap?: number;
|
|
2549
|
+
/**
|
|
2550
|
+
* State of related to this task hooks. Useful during reporting.
|
|
2551
|
+
*/
|
|
2552
|
+
hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
|
|
2553
|
+
/**
|
|
2554
|
+
* The amount of times the task was retried. The task is retried only if it
|
|
2555
|
+
* failed and `retry` option is set.
|
|
2556
|
+
*/
|
|
2557
|
+
retryCount?: number;
|
|
2558
|
+
/**
|
|
2559
|
+
* The amount of times the task was repeated. The task is repeated only if
|
|
2560
|
+
* `repeats` option is set. This number also contains `retryCount`.
|
|
2561
|
+
*/
|
|
2562
|
+
repeatCount?: number;
|
|
2563
|
+
}
|
|
2564
|
+
/** The time spent importing & executing a non-externalized file. */
|
|
2565
|
+
interface ImportDuration {
|
|
2566
|
+
/** The time spent importing & executing the file itself, not counting all non-externalized imports that the file does. */
|
|
2567
|
+
selfTime: number;
|
|
2568
|
+
/** The time spent importing & executing the file and all its imports. */
|
|
2569
|
+
totalTime: number;
|
|
2570
|
+
/** Will be set to `true`, if the module was externalized. In this case totalTime and selfTime are identical. */
|
|
2571
|
+
external?: boolean;
|
|
2572
|
+
/** Which module imported this module first. All subsequent imports are cached. */
|
|
2573
|
+
importer?: string;
|
|
2574
|
+
}
|
|
2575
|
+
interface Suite extends TaskBase {
|
|
2576
|
+
type: "suite";
|
|
2577
|
+
/**
|
|
2578
|
+
* File task. It's the root task of the file.
|
|
2579
|
+
*/
|
|
2580
|
+
file: File;
|
|
2581
|
+
/**
|
|
2582
|
+
* An array of tasks that are part of the suite.
|
|
2583
|
+
*/
|
|
2584
|
+
tasks: Task[];
|
|
2585
|
+
}
|
|
2586
|
+
interface File extends Suite {
|
|
2587
|
+
/**
|
|
2588
|
+
* The name of the pool that the file belongs to.
|
|
2589
|
+
* @default 'forks'
|
|
2590
|
+
*/
|
|
2591
|
+
pool?: string;
|
|
2592
|
+
/**
|
|
2593
|
+
* The environment that processes the file on the server.
|
|
2594
|
+
*/
|
|
2595
|
+
viteEnvironment?: string;
|
|
2596
|
+
/**
|
|
2597
|
+
* The path to the file in UNIX format.
|
|
2598
|
+
*/
|
|
2599
|
+
filepath: string;
|
|
2600
|
+
/**
|
|
2601
|
+
* The name of the workspace project the file belongs to.
|
|
2602
|
+
*/
|
|
2603
|
+
projectName: string | undefined;
|
|
2604
|
+
/**
|
|
2605
|
+
* The time it took to collect all tests in the file.
|
|
2606
|
+
* This time also includes importing all the file dependencies.
|
|
2607
|
+
*/
|
|
2608
|
+
collectDuration?: number;
|
|
2609
|
+
/**
|
|
2610
|
+
* The portion of `collectDuration` the worker spent waiting for the server
|
|
2611
|
+
* to resolve and transform modules.
|
|
2612
|
+
*/
|
|
2613
|
+
collectFetchDuration?: number;
|
|
2614
|
+
/**
|
|
2615
|
+
* The time it took to import the setup file.
|
|
2616
|
+
*/
|
|
2617
|
+
setupDuration?: number;
|
|
2618
|
+
/**
|
|
2619
|
+
* The portion of `setupDuration` the worker spent waiting for the server
|
|
2620
|
+
* to resolve and transform modules.
|
|
2621
|
+
*/
|
|
2622
|
+
setupFetchDuration?: number;
|
|
2623
|
+
/** The time spent importing every non-externalized dependency that Vitest has processed. */
|
|
2624
|
+
importDurations?: Record<string, ImportDuration>;
|
|
2625
|
+
prepareDuration?: number;
|
|
2626
|
+
environmentLoad?: number;
|
|
2627
|
+
concurrencyId: number;
|
|
2628
|
+
workerId: number;
|
|
2629
|
+
}
|
|
2630
|
+
interface Test<ExtraContext = object> extends TaskPopulated {
|
|
2631
|
+
type: "test";
|
|
2632
|
+
/**
|
|
2633
|
+
* Test context that will be passed to the test function.
|
|
2634
|
+
*/
|
|
2635
|
+
context: TestContext & ExtraContext;
|
|
2636
|
+
/**
|
|
2637
|
+
* The test timeout in milliseconds.
|
|
2638
|
+
*/
|
|
2639
|
+
timeout: number;
|
|
2640
|
+
/**
|
|
2641
|
+
* An array of custom annotations.
|
|
2642
|
+
*/
|
|
2643
|
+
annotations: TestAnnotation[];
|
|
2644
|
+
/**
|
|
2645
|
+
* An array of artifacts produced by the test.
|
|
2646
|
+
*
|
|
2647
|
+
* @experimental
|
|
2648
|
+
*/
|
|
2649
|
+
artifacts: TestArtifact[];
|
|
2650
|
+
fullTestName: string;
|
|
2651
|
+
/**
|
|
2652
|
+
* An array of benchmark results generated by `context.bench` function.
|
|
2653
|
+
* The benchmark is added only after `bench().run` or `bench.compare` is resolved.
|
|
2654
|
+
*
|
|
2655
|
+
* @experimental
|
|
2656
|
+
*/
|
|
2657
|
+
benchmarks: TestBenchmark[];
|
|
2658
|
+
}
|
|
2659
|
+
interface TestBenchmark {
|
|
2660
|
+
name: string;
|
|
2661
|
+
tasks: TestBenchmarkTask[];
|
|
2662
|
+
}
|
|
2663
|
+
type TestBenchmarkStatistics = Statistics;
|
|
2664
|
+
interface BaselineData {
|
|
2665
|
+
latency: TestBenchmarkStatistics;
|
|
2666
|
+
throughput: TestBenchmarkStatistics;
|
|
2667
|
+
period: number;
|
|
2668
|
+
totalTime: number;
|
|
2669
|
+
}
|
|
2670
|
+
interface TestBenchmarkTask {
|
|
2671
|
+
name: string;
|
|
2672
|
+
latency: TestBenchmarkStatistics;
|
|
2673
|
+
throughput: TestBenchmarkStatistics;
|
|
2674
|
+
period: number;
|
|
2675
|
+
totalTime: number;
|
|
2676
|
+
rank: number;
|
|
2677
|
+
perProject?: boolean;
|
|
2678
|
+
/**
|
|
2679
|
+
* `true` when the task was produced by `bench.from()` rather than by
|
|
2680
|
+
* executing a function. Reporters can use this to render the row as a
|
|
2681
|
+
* static reference (no margin of error, no samples).
|
|
2682
|
+
*/
|
|
2683
|
+
fromStore?: boolean;
|
|
2684
|
+
}
|
|
2685
|
+
type Task = Test | Suite | File;
|
|
2686
|
+
/**
|
|
2687
|
+
* Retry configuration for tests.
|
|
2688
|
+
* Can be a number for simple retry count, or an object for advanced retry control.
|
|
2689
|
+
*/
|
|
2690
|
+
type Retry = number | {
|
|
2691
|
+
/**
|
|
2692
|
+
* The number of times to retry the test if it fails.
|
|
2693
|
+
* @default 0
|
|
2694
|
+
*/
|
|
2695
|
+
count?: number;
|
|
2696
|
+
/**
|
|
2697
|
+
* Delay in milliseconds between retry attempts.
|
|
2698
|
+
* @default 0
|
|
2699
|
+
*/
|
|
2700
|
+
delay?: number;
|
|
2701
|
+
/**
|
|
2702
|
+
* Condition to determine if a test should be retried based on the error.
|
|
2703
|
+
* - If a RegExp, it is tested against the error message
|
|
2704
|
+
* - If a function, called with the TestError object; return true to retry
|
|
2705
|
+
*
|
|
2706
|
+
* NOTE: Functions can only be used in test files, not in vitest.config.ts,
|
|
2707
|
+
* because the configuration is serialized when passed to worker threads.
|
|
2708
|
+
*
|
|
2709
|
+
* @default undefined (retry on all errors)
|
|
2710
|
+
*/
|
|
2711
|
+
condition?: RegExp | ((error: TestError) => boolean);
|
|
2712
|
+
};
|
|
2713
|
+
interface BeforeEachListener<ExtraContext = object> {
|
|
2714
|
+
(context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
|
|
2715
|
+
}
|
|
2716
|
+
interface AfterEachListener<ExtraContext = object> {
|
|
2717
|
+
(context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
|
|
2718
|
+
}
|
|
2719
|
+
interface AroundEachListener<ExtraContext = object> {
|
|
2720
|
+
(runTest: () => Promise<void>, context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
|
|
2721
|
+
}
|
|
2722
|
+
interface RegisteredAllListener {
|
|
2723
|
+
(suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
2724
|
+
}
|
|
2725
|
+
interface RegisteredAroundAllListener {
|
|
2726
|
+
(runSuite: () => Promise<void>, suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
2727
|
+
}
|
|
2728
|
+
interface SuiteHooks<ExtraContext = object> {
|
|
2729
|
+
beforeAll: RegisteredAllListener[];
|
|
2730
|
+
afterAll: RegisteredAllListener[];
|
|
2731
|
+
aroundAll: RegisteredAroundAllListener[];
|
|
2732
|
+
beforeEach: BeforeEachListener<ExtraContext>[];
|
|
2733
|
+
afterEach: AfterEachListener<ExtraContext>[];
|
|
2734
|
+
aroundEach: AroundEachListener<ExtraContext>[];
|
|
2735
|
+
}
|
|
2736
|
+
/**
|
|
2737
|
+
* User's custom test context.
|
|
2738
|
+
*/
|
|
2739
|
+
interface TestContext {
|
|
2740
|
+
/**
|
|
2741
|
+
* Metadata of the current test
|
|
2742
|
+
*/
|
|
2743
|
+
readonly task: Readonly<Test>;
|
|
2744
|
+
/**
|
|
2745
|
+
* An [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) that will be aborted if the test times out or
|
|
2746
|
+
* the test run was cancelled.
|
|
2747
|
+
* @see {@link https://vitest.dev/guide/test-context#signal}
|
|
2748
|
+
*/
|
|
2749
|
+
readonly signal: AbortSignal;
|
|
2750
|
+
/**
|
|
2751
|
+
* Register a callback to run when this specific test fails.
|
|
2752
|
+
* Useful when tests run concurrently.
|
|
2753
|
+
* @see {@link https://vitest.dev/guide/test-context#ontestfailed}
|
|
2754
|
+
*/
|
|
2755
|
+
readonly onTestFailed: (fn: OnTestFailedHandler, timeout?: number) => void;
|
|
2756
|
+
/**
|
|
2757
|
+
* Register a callback to run when this specific test finishes.
|
|
2758
|
+
* Useful when tests run concurrently.
|
|
2759
|
+
* @see {@link https://vitest.dev/guide/test-context#ontestfinished}
|
|
2760
|
+
*/
|
|
2761
|
+
readonly onTestFinished: (fn: OnTestFinishedHandler, timeout?: number) => void;
|
|
2762
|
+
/**
|
|
2763
|
+
* Mark tests as skipped. All execution after this call will be skipped.
|
|
2764
|
+
* This function throws an error, so make sure you are not catching it accidentally.
|
|
2765
|
+
* @see {@link https://vitest.dev/guide/test-context#skip}
|
|
2766
|
+
*/
|
|
2767
|
+
readonly skip: {
|
|
2768
|
+
(note?: string): never;
|
|
2769
|
+
(condition: boolean, note?: string): void;
|
|
2770
|
+
};
|
|
2771
|
+
/**
|
|
2772
|
+
* Add a test annotation that will be displayed by your reporter.
|
|
2773
|
+
* @see {@link https://vitest.dev/guide/test-context#annotate}
|
|
2774
|
+
*/
|
|
2775
|
+
readonly annotate: {
|
|
2776
|
+
(message: string, type?: string, attachment?: TestAttachment): Promise<TestAnnotation>;
|
|
2777
|
+
(message: string, attachment?: TestAttachment): Promise<TestAnnotation>;
|
|
2778
|
+
};
|
|
2779
|
+
/**
|
|
2780
|
+
* `expect` instance bound to the current test.
|
|
2781
|
+
*
|
|
2782
|
+
* This API is useful for running snapshot tests concurrently because global expect cannot track them.
|
|
2783
|
+
*/
|
|
2784
|
+
readonly expect: ExpectStatic;
|
|
2785
|
+
/**
|
|
2786
|
+
* Create a benchmark to run. It will be reported after the test is finished.
|
|
2787
|
+
* @see {@link https://vitest.dev/guide/benchmarking}
|
|
2788
|
+
*/
|
|
2789
|
+
readonly bench: Bench;
|
|
2790
|
+
}
|
|
2791
|
+
type OnTestFailedHandler = (context: TestContext) => Awaitable<void>;
|
|
2792
|
+
type OnTestFinishedHandler = (context: TestContext) => Awaitable<void>;
|
|
2793
|
+
/**
|
|
2794
|
+
* Represents a file or data attachment associated with a test artifact.
|
|
2795
|
+
*
|
|
2796
|
+
* Attachments can be either path-based (via `path`) or inline content (via `body`).
|
|
2797
|
+
* The `contentType` helps consumers understand how to interpret the attachment data.
|
|
2798
|
+
*/
|
|
2799
|
+
interface TestAttachment {
|
|
2800
|
+
/** MIME type of the attachment (e.g., 'image/png', 'text/plain') */
|
|
2801
|
+
contentType?: string;
|
|
2802
|
+
/** Local file path or external HTTP(S) URL to the attachment. Relative paths are resolved from the project root. */
|
|
2803
|
+
path?: string;
|
|
2804
|
+
/** Inline attachment content as a string or raw binary data */
|
|
2805
|
+
body?: string | Uint8Array | undefined;
|
|
2806
|
+
/**
|
|
2807
|
+
* @experimental
|
|
2808
|
+
* How the string `body` is encoded.
|
|
2809
|
+
* - `'base64'` (default): body is already base64-encoded
|
|
2810
|
+
* - `'utf-8'`: body is a utf8 string
|
|
2811
|
+
*
|
|
2812
|
+
* `body: Uint8Array` is always auto-encoded to string with `bodyEncoding: 'base64'`
|
|
2813
|
+
* regardless of this option.
|
|
2814
|
+
*/
|
|
2815
|
+
bodyEncoding?: "base64" | "utf-8";
|
|
2816
|
+
}
|
|
2817
|
+
interface Location {
|
|
2818
|
+
/** Line number in the source file (1-indexed) */
|
|
2819
|
+
line: number;
|
|
2820
|
+
/** Column number in the line (1-indexed) */
|
|
2821
|
+
column: number;
|
|
2822
|
+
}
|
|
2823
|
+
interface FileLocation extends Location {
|
|
2824
|
+
/** Line number in the source file (1-indexed) */
|
|
2825
|
+
line: number;
|
|
2826
|
+
/** Column number in the line (1-indexed) */
|
|
2827
|
+
column: number;
|
|
2828
|
+
/** Path to the source file */
|
|
2829
|
+
file: string;
|
|
2830
|
+
}
|
|
2831
|
+
/**
|
|
2832
|
+
* Source code location information for a test artifact.
|
|
2833
|
+
*
|
|
2834
|
+
* Indicates where in the source code the artifact originated from.
|
|
2835
|
+
*/
|
|
2836
|
+
interface TestArtifactLocation extends FileLocation {}
|
|
2837
|
+
/**
|
|
2838
|
+
* @experimental
|
|
2839
|
+
*
|
|
2840
|
+
* Base interface for all test artifacts.
|
|
2841
|
+
*
|
|
2842
|
+
* 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.
|
|
2843
|
+
*
|
|
2844
|
+
* **Important**: when running with [`api.allowWrite`](https://vitest.dev/config/api#api-allowwrite) disabled, Vitest empties the `attachments` array on every artifact before reporting it.
|
|
2845
|
+
*/
|
|
2846
|
+
interface TestArtifactBase {
|
|
2847
|
+
/** File or data attachments associated with this artifact */
|
|
2848
|
+
attachments?: TestAttachment[];
|
|
2849
|
+
/** Source location where this artifact was created */
|
|
2850
|
+
location?: TestArtifactLocation;
|
|
2851
|
+
}
|
|
2852
|
+
interface TestAnnotation {
|
|
2853
|
+
message: string;
|
|
2854
|
+
type: string;
|
|
2855
|
+
location?: TestArtifactLocation;
|
|
2856
|
+
attachment?: TestAttachment;
|
|
2857
|
+
}
|
|
2858
|
+
/**
|
|
2859
|
+
* @experimental
|
|
2860
|
+
*
|
|
2861
|
+
* Artifact type for test annotations.
|
|
2862
|
+
*/
|
|
2863
|
+
interface TestAnnotationArtifact extends TestArtifactBase {
|
|
2864
|
+
type: "internal:annotation";
|
|
2865
|
+
annotation: TestAnnotation;
|
|
2866
|
+
}
|
|
2867
|
+
interface VisualRegressionArtifactAttachment extends TestAttachment {
|
|
2868
|
+
name: "reference" | "actual" | "diff";
|
|
2869
|
+
width: number;
|
|
2870
|
+
height: number;
|
|
2871
|
+
}
|
|
2872
|
+
/**
|
|
2873
|
+
* @experimental
|
|
2874
|
+
*
|
|
2875
|
+
* Artifact type for visual regressions.
|
|
2876
|
+
*/
|
|
2877
|
+
interface VisualRegressionArtifact extends TestArtifactBase {
|
|
2878
|
+
type: "internal:toMatchScreenshot";
|
|
2879
|
+
kind: "visual-regression";
|
|
2880
|
+
message: string;
|
|
2881
|
+
attachments: VisualRegressionArtifactAttachment[];
|
|
2882
|
+
}
|
|
2883
|
+
/**
|
|
2884
|
+
* @experimental
|
|
2885
|
+
*/
|
|
2886
|
+
interface BrowserTraceArtifact extends TestArtifactBase {
|
|
2887
|
+
type: "internal:browserTrace";
|
|
2888
|
+
data: unknown;
|
|
2889
|
+
}
|
|
2890
|
+
interface FailureScreenshotArtifactAttachment extends TestAttachment {
|
|
2891
|
+
path: string;
|
|
2892
|
+
/** Original file system path to the screenshot, before attachment resolution */
|
|
2893
|
+
originalPath: string;
|
|
2894
|
+
body?: undefined;
|
|
2895
|
+
}
|
|
2896
|
+
/**
|
|
2897
|
+
* @experimental
|
|
2898
|
+
*
|
|
2899
|
+
* Artifact type for failure screenshots.
|
|
2900
|
+
*/
|
|
2901
|
+
interface FailureScreenshotArtifact extends TestArtifactBase {
|
|
2902
|
+
type: "internal:failureScreenshot";
|
|
2903
|
+
attachments: [FailureScreenshotArtifactAttachment] | [];
|
|
2904
|
+
}
|
|
2905
|
+
/**
|
|
2906
|
+
* @experimental
|
|
2907
|
+
* @advanced
|
|
2908
|
+
*
|
|
2909
|
+
* Registry for custom test artifact types.
|
|
2910
|
+
*
|
|
2911
|
+
* Augment this interface to register custom artifact types that your tests can produce.
|
|
2912
|
+
*
|
|
2913
|
+
* Each custom artifact should extend {@linkcode TestArtifactBase} and include a unique `type` discriminator property.
|
|
2914
|
+
*
|
|
2915
|
+
* @remarks
|
|
2916
|
+
* - Use a `Symbol` as the **registry key** to guarantee uniqueness
|
|
2917
|
+
* - The `type` property should follow the pattern `'package-name:artifact-name'`, `'internal:'` is a reserved prefix
|
|
2918
|
+
* - Use `attachments` to include files or data; extend {@linkcode TestAttachment} for custom metadata
|
|
2919
|
+
* - `location` property is automatically injected to indicate where the artifact was created
|
|
2920
|
+
*
|
|
2921
|
+
* @example
|
|
2922
|
+
* ```ts
|
|
2923
|
+
* // Define custom attachment type for generated PDF
|
|
2924
|
+
* interface PDFAttachment extends TestAttachment {
|
|
2925
|
+
* contentType: 'application/pdf'
|
|
2926
|
+
* body: Uint8Array
|
|
2927
|
+
* pageCount: number
|
|
2928
|
+
* fileSize: number
|
|
2929
|
+
* }
|
|
2930
|
+
*
|
|
2931
|
+
* interface PDFGenerationArtifact extends TestArtifactBase {
|
|
2932
|
+
* type: 'my-plugin:pdf-generation'
|
|
2933
|
+
* templateName: string
|
|
2934
|
+
* isValid: boolean
|
|
2935
|
+
* attachments: [PDFAttachment]
|
|
2936
|
+
* }
|
|
2937
|
+
*
|
|
2938
|
+
* // Use a symbol to guarantee key uniqueness
|
|
2939
|
+
* const pdfKey = Symbol('pdf-generation')
|
|
2940
|
+
*
|
|
2941
|
+
* declare module 'vitest' {
|
|
2942
|
+
* interface TestArtifactRegistry {
|
|
2943
|
+
* [pdfKey]: PDFGenerationArtifact
|
|
2944
|
+
* }
|
|
2945
|
+
* }
|
|
2946
|
+
*
|
|
2947
|
+
* // Custom assertion for PDF generation
|
|
2948
|
+
* async function toGenerateValidPDF(
|
|
2949
|
+
* this: MatcherState,
|
|
2950
|
+
* actual: PDFTemplate,
|
|
2951
|
+
* data: Record<string, unknown>
|
|
2952
|
+
* ): AsyncExpectationResult {
|
|
2953
|
+
* const pdfBuffer = await actual.render(data)
|
|
2954
|
+
* const validation = await validatePDF(pdfBuffer)
|
|
2955
|
+
*
|
|
2956
|
+
* await recordArtifact(this.task, {
|
|
2957
|
+
* type: 'my-plugin:pdf-generation',
|
|
2958
|
+
* templateName: actual.name,
|
|
2959
|
+
* isValid: validation.success,
|
|
2960
|
+
* attachments: [{
|
|
2961
|
+
* contentType: 'application/pdf',
|
|
2962
|
+
* body: pdfBuffer,
|
|
2963
|
+
* pageCount: validation.pageCount,
|
|
2964
|
+
* fileSize: pdfBuffer.byteLength
|
|
2965
|
+
* }]
|
|
2966
|
+
* })
|
|
2967
|
+
*
|
|
2968
|
+
* return {
|
|
2969
|
+
* pass: validation.success,
|
|
2970
|
+
* message: () => validation.success
|
|
2971
|
+
* ? `Generated valid PDF with ${validation.pageCount} pages`
|
|
2972
|
+
* : `Invalid PDF: ${validation.error}`
|
|
2973
|
+
* }
|
|
2974
|
+
* }
|
|
2975
|
+
* ```
|
|
2976
|
+
*/
|
|
2977
|
+
interface TestArtifactRegistry {}
|
|
2978
|
+
/**
|
|
2979
|
+
* @experimental
|
|
2980
|
+
*
|
|
2981
|
+
* Union type of all test artifacts, including built-in and custom registered artifacts.
|
|
2982
|
+
*
|
|
2983
|
+
* This type automatically includes all artifacts registered via {@link TestArtifactRegistry}.
|
|
2984
|
+
*/
|
|
2985
|
+
type TestArtifact = BrowserTraceArtifact | FailureScreenshotArtifact | TestAnnotationArtifact | VisualRegressionArtifact | TestArtifactRegistry[keyof TestArtifactRegistry];
|
|
2986
|
+
//#endregion
|
|
2987
|
+
//#region ../../../../node_modules/.bun/vitest@5.0.1+3a20bcfa24daf8e9/node_modules/vitest/dist/chunks/task-utils.d.BZm4GSQD.d.ts
|
|
2988
|
+
interface SnapshotMatcher<R extends void | Promise<void>, T = unknown> {
|
|
2989
|
+
<U extends { [P in keyof T]: any; }>(snapshot: Partial<U>, hint?: string): R;
|
|
2990
|
+
(hint?: string): R;
|
|
2991
|
+
}
|
|
2992
|
+
interface InlineSnapshotMatcher<R extends void | Promise<void>, T = unknown> {
|
|
2993
|
+
<U extends { [P in keyof T]: any; }>(properties: Partial<U>, snapshot?: string, hint?: string): R;
|
|
2994
|
+
(hint?: string): R;
|
|
2995
|
+
}
|
|
2996
|
+
declare module "vitest" {
|
|
2997
|
+
interface MatcherState {
|
|
2998
|
+
environment: string;
|
|
2999
|
+
snapshotState: SnapshotState;
|
|
3000
|
+
task?: Readonly<Test>;
|
|
3001
|
+
}
|
|
3002
|
+
interface ExpectPollOptions {
|
|
3003
|
+
interval?: number;
|
|
3004
|
+
timeout?: number;
|
|
3005
|
+
message?: string;
|
|
3006
|
+
}
|
|
3007
|
+
interface ExpectStatic {
|
|
3008
|
+
assert: Chai.AssertStatic;
|
|
3009
|
+
unreachable: (message?: string) => never;
|
|
3010
|
+
soft: <T>(actual: T, message?: string) => Assertion<void, T>;
|
|
3011
|
+
poll: <T>(actual: (options: {
|
|
3012
|
+
signal: AbortSignal;
|
|
3013
|
+
}) => T, options?: ExpectPollOptions) => PromisifyAssertion<Awaited<T>>;
|
|
3014
|
+
addEqualityTesters: (testers: Array<Tester>) => void;
|
|
3015
|
+
assertions: (expected: number) => void;
|
|
3016
|
+
hasAssertions: () => void;
|
|
3017
|
+
addSnapshotSerializer: (plugin: Plugin) => void;
|
|
3018
|
+
}
|
|
3019
|
+
interface Assertion<R, T> {
|
|
3020
|
+
matchSnapshot: SnapshotMatcher<R, T>;
|
|
3021
|
+
toMatchSnapshot: SnapshotMatcher<R, T>;
|
|
3022
|
+
toMatchInlineSnapshot: InlineSnapshotMatcher<R, T>;
|
|
3023
|
+
/**
|
|
3024
|
+
* Checks that an error thrown by a function matches a previously recorded snapshot.
|
|
3025
|
+
*
|
|
3026
|
+
* @param hint - Optional custom error message.
|
|
3027
|
+
*
|
|
3028
|
+
* @example
|
|
3029
|
+
* expect(functionWithError).toThrowErrorMatchingSnapshot();
|
|
3030
|
+
*/
|
|
3031
|
+
toThrowErrorMatchingSnapshot: (hint?: string) => R;
|
|
3032
|
+
/**
|
|
3033
|
+
* Checks that an error thrown by a function matches an inline snapshot within the test file.
|
|
3034
|
+
* Useful for keeping snapshots close to the test code.
|
|
3035
|
+
*
|
|
3036
|
+
* @param snapshot - Optional inline snapshot string to match.
|
|
3037
|
+
* @param hint - Optional custom error message.
|
|
3038
|
+
*
|
|
3039
|
+
* @example
|
|
3040
|
+
* const throwError = () => { throw new Error('Error occurred') };
|
|
3041
|
+
* expect(throwError).toThrowErrorMatchingInlineSnapshot(`"Error occurred"`);
|
|
3042
|
+
*/
|
|
3043
|
+
toThrowErrorMatchingInlineSnapshot: (snapshot?: string, hint?: string) => R;
|
|
3044
|
+
/**
|
|
3045
|
+
* Compares the received value to a snapshot saved in a specified file.
|
|
3046
|
+
* Useful for cases where snapshot content is large or needs to be shared across tests.
|
|
3047
|
+
*
|
|
3048
|
+
* @param filepath - Path to the snapshot file.
|
|
3049
|
+
* @param hint - Optional custom error message.
|
|
3050
|
+
*
|
|
3051
|
+
* @example
|
|
3052
|
+
* await expect(largeData).toMatchFileSnapshot('path/to/snapshot.json');
|
|
3053
|
+
*/
|
|
3054
|
+
toMatchFileSnapshot: (filepath: string, hint?: string) => Promise<void>;
|
|
3055
|
+
/**
|
|
3056
|
+
* Asserts that a benchmark result is faster than another benchmark result.
|
|
3057
|
+
* Compares mean latency — lower is faster.
|
|
3058
|
+
*
|
|
3059
|
+
* @example
|
|
3060
|
+
* const result = await bench.compare(
|
|
3061
|
+
* bench('lib1', () => { lib1() }),
|
|
3062
|
+
* bench('lib2', () => { lib2() }),
|
|
3063
|
+
* )
|
|
3064
|
+
* expect(result.get('lib1')).toBeFasterThan(result.get('lib2'))
|
|
3065
|
+
* expect(result.get('lib1')).toBeFasterThan(result.get('lib2'), { delta: 0.1 })
|
|
3066
|
+
*/
|
|
3067
|
+
toBeFasterThan: (expected: BenchResult, options?: {
|
|
3068
|
+
delta?: number;
|
|
3069
|
+
}) => R;
|
|
3070
|
+
/**
|
|
3071
|
+
* Asserts that a benchmark result is slower than another benchmark result.
|
|
3072
|
+
* Compares mean latency — higher is slower.
|
|
3073
|
+
*
|
|
3074
|
+
* @example
|
|
3075
|
+
* const result = await bench.compare(
|
|
3076
|
+
* bench('lib1', () => { lib1() }),
|
|
3077
|
+
* bench('lib2', () => { lib2() }),
|
|
3078
|
+
* )
|
|
3079
|
+
* expect(result.get('lib2')).toBeSlowerThan(result.get('lib1'))
|
|
3080
|
+
* expect(result.get('lib2')).toBeSlowerThan(result.get('lib1'), { delta: 0.2 })
|
|
3081
|
+
*/
|
|
3082
|
+
toBeSlowerThan: (expected: BenchResult, options?: {
|
|
3083
|
+
delta?: number;
|
|
3084
|
+
}) => R;
|
|
3085
|
+
/**
|
|
3086
|
+
* Ensures a `vi.when` chain has been exhausted.
|
|
3087
|
+
*
|
|
3088
|
+
* A chain is exhausted when at least one `calledWith` with an associated action (`then*`) has been registered
|
|
3089
|
+
* and every registered behavior has been fully consumed. A chain with no registered
|
|
3090
|
+
* behaviors, or with `calledWith` entries that have no associated `then*` actions, is never considered exhausted.
|
|
3091
|
+
*
|
|
3092
|
+
* @see {@link https://vitest.dev/api/expect#tohavebeenexhausted}
|
|
3093
|
+
*
|
|
3094
|
+
* @example
|
|
3095
|
+
* const w = vi.when(spy).calledWith('hello').thenReturnOnce('HELLO')
|
|
3096
|
+
*
|
|
3097
|
+
* expect(w).not.toHaveBeenExhausted()
|
|
3098
|
+
*
|
|
3099
|
+
* expect(spy('hello')).toBe('HELLO')
|
|
3100
|
+
*
|
|
3101
|
+
* expect(w).toHaveBeenExhausted()
|
|
3102
|
+
*/
|
|
3103
|
+
toHaveBeenExhausted: () => R;
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
//#endregion
|
|
3107
|
+
//#region src/tracking/registration.fixture.d.ts
|
|
3108
|
+
export declare function registration(): {
|
|
3109
|
+
fetcher: Mock<typeof fetch>;
|
|
3110
|
+
tracker: SessionTracker;
|
|
3111
|
+
};
|
|
3112
|
+
//#endregion
|