@pixui-dev/inflight-test 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1679 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6924 -0
- package/dist/index.js.map +1 -0
- package/dist/run-tests-C0WM7ghw.js +10613 -0
- package/dist/run-tests-C0WM7ghw.js.map +1 -0
- package/dist/run-tests-DoriyCYM.d.ts +3247 -0
- package/dist/run-tests-DoriyCYM.d.ts.map +1 -0
- package/dist/runner.d.ts +12 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +34 -0
- package/dist/runner.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,3247 @@
|
|
|
1
|
+
//#region node_modules/@vitest/expect/node_modules/@vitest/spy/optional-types.d.ts
|
|
2
|
+
/* eslint-disable ts/ban-ts-comment */
|
|
3
|
+
interface Disposable {
|
|
4
|
+
// @ts-ignore -- Symbol.dispose might not be in user types
|
|
5
|
+
[Symbol.dispose]: () => void;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region node_modules/@vitest/expect/node_modules/@vitest/spy/dist/index.d.ts
|
|
9
|
+
interface MockResultReturn<T> {
|
|
10
|
+
type: "return";
|
|
11
|
+
/**
|
|
12
|
+
* The value that was returned from the function. If function returned a Promise, then this will be a resolved value.
|
|
13
|
+
*/
|
|
14
|
+
value: T;
|
|
15
|
+
}
|
|
16
|
+
interface MockResultIncomplete {
|
|
17
|
+
type: "incomplete";
|
|
18
|
+
value: undefined;
|
|
19
|
+
}
|
|
20
|
+
interface MockResultThrow {
|
|
21
|
+
type: "throw";
|
|
22
|
+
/**
|
|
23
|
+
* An error that was thrown during function execution.
|
|
24
|
+
*/
|
|
25
|
+
value: any;
|
|
26
|
+
}
|
|
27
|
+
interface MockSettledResultIncomplete {
|
|
28
|
+
type: "incomplete";
|
|
29
|
+
value: undefined;
|
|
30
|
+
}
|
|
31
|
+
interface MockSettledResultFulfilled<T> {
|
|
32
|
+
type: "fulfilled";
|
|
33
|
+
value: T;
|
|
34
|
+
}
|
|
35
|
+
interface MockSettledResultRejected {
|
|
36
|
+
type: "rejected";
|
|
37
|
+
value: any;
|
|
38
|
+
}
|
|
39
|
+
type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
|
|
40
|
+
type MockSettledResult<T> = MockSettledResultFulfilled<T> | MockSettledResultRejected | MockSettledResultIncomplete;
|
|
41
|
+
type MockParameters<T extends Procedure | Constructable> = T extends Constructable ? ConstructorParameters<T> : T extends Procedure ? Parameters<T> : never;
|
|
42
|
+
type MockReturnType<T extends Procedure | Constructable> = T extends Constructable ? InstanceType<T> : T extends Procedure ? ReturnType<T> : never;
|
|
43
|
+
type MockProcedureContext<T extends Procedure | Constructable> = T extends Constructable ? InstanceType<T> : ThisParameterType<T>;
|
|
44
|
+
interface MockContext<T extends Procedure | Constructable = Procedure> {
|
|
45
|
+
/**
|
|
46
|
+
* This is an array containing all arguments for each call. One item of the array is the arguments of that call.
|
|
47
|
+
*
|
|
48
|
+
* @see https://vitest.dev/api/mock#mock-calls
|
|
49
|
+
* @example
|
|
50
|
+
* const fn = vi.fn()
|
|
51
|
+
*
|
|
52
|
+
* fn('arg1', 'arg2')
|
|
53
|
+
* fn('arg3')
|
|
54
|
+
*
|
|
55
|
+
* fn.mock.calls === [
|
|
56
|
+
* ['arg1', 'arg2'], // first call
|
|
57
|
+
* ['arg3'], // second call
|
|
58
|
+
* ]
|
|
59
|
+
*/
|
|
60
|
+
calls: MockParameters<T>[];
|
|
61
|
+
/**
|
|
62
|
+
* 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.
|
|
63
|
+
* @see https://vitest.dev/api/mock#mock-instances
|
|
64
|
+
*/
|
|
65
|
+
instances: MockProcedureContext<T>[];
|
|
66
|
+
/**
|
|
67
|
+
* An array of `this` values that were used during each call to the mock function.
|
|
68
|
+
* @see https://vitest.dev/api/mock#mock-contexts
|
|
69
|
+
*/
|
|
70
|
+
contexts: MockProcedureContext<T>[];
|
|
71
|
+
/**
|
|
72
|
+
* The order of mock's execution. This returns an array of numbers which are shared between all defined mocks.
|
|
73
|
+
*
|
|
74
|
+
* @see https://vitest.dev/api/mock#mock-invocationcallorder
|
|
75
|
+
* @example
|
|
76
|
+
* const fn1 = vi.fn()
|
|
77
|
+
* const fn2 = vi.fn()
|
|
78
|
+
*
|
|
79
|
+
* fn1()
|
|
80
|
+
* fn2()
|
|
81
|
+
* fn1()
|
|
82
|
+
*
|
|
83
|
+
* fn1.mock.invocationCallOrder === [1, 3]
|
|
84
|
+
* fn2.mock.invocationCallOrder === [2]
|
|
85
|
+
*/
|
|
86
|
+
invocationCallOrder: number[];
|
|
87
|
+
/**
|
|
88
|
+
* This is an array containing all values that were `returned` from the function.
|
|
89
|
+
*
|
|
90
|
+
* 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.
|
|
91
|
+
*
|
|
92
|
+
* @see https://vitest.dev/api/mock#mock-results
|
|
93
|
+
* @example
|
|
94
|
+
* const fn = vi.fn()
|
|
95
|
+
* .mockReturnValueOnce('result')
|
|
96
|
+
* .mockImplementationOnce(() => { throw new Error('thrown error') })
|
|
97
|
+
*
|
|
98
|
+
* const result = fn()
|
|
99
|
+
*
|
|
100
|
+
* try {
|
|
101
|
+
* fn()
|
|
102
|
+
* }
|
|
103
|
+
* catch {}
|
|
104
|
+
*
|
|
105
|
+
* fn.mock.results === [
|
|
106
|
+
* {
|
|
107
|
+
* type: 'return',
|
|
108
|
+
* value: 'result',
|
|
109
|
+
* },
|
|
110
|
+
* {
|
|
111
|
+
* type: 'throw',
|
|
112
|
+
* value: Error,
|
|
113
|
+
* },
|
|
114
|
+
* ]
|
|
115
|
+
*/
|
|
116
|
+
results: MockResult<MockReturnType<T>>[];
|
|
117
|
+
/**
|
|
118
|
+
* An array containing all values that were `resolved` or `rejected` from the function.
|
|
119
|
+
*
|
|
120
|
+
* This array will be empty if the function was never resolved or rejected.
|
|
121
|
+
*
|
|
122
|
+
* @see https://vitest.dev/api/mock#mock-settledresults
|
|
123
|
+
* @example
|
|
124
|
+
* const fn = vi.fn().mockResolvedValueOnce('result')
|
|
125
|
+
*
|
|
126
|
+
* const result = fn()
|
|
127
|
+
*
|
|
128
|
+
* fn.mock.settledResults === [
|
|
129
|
+
* {
|
|
130
|
+
* type: 'incomplete',
|
|
131
|
+
* value: undefined,
|
|
132
|
+
* }
|
|
133
|
+
* ]
|
|
134
|
+
* fn.mock.results === [
|
|
135
|
+
* {
|
|
136
|
+
* type: 'return',
|
|
137
|
+
* value: Promise<'result'>,
|
|
138
|
+
* },
|
|
139
|
+
* ]
|
|
140
|
+
*
|
|
141
|
+
* await result
|
|
142
|
+
*
|
|
143
|
+
* fn.mock.settledResults === [
|
|
144
|
+
* {
|
|
145
|
+
* type: 'fulfilled',
|
|
146
|
+
* value: 'result',
|
|
147
|
+
* },
|
|
148
|
+
* ]
|
|
149
|
+
*/
|
|
150
|
+
settledResults: MockSettledResult<Awaited<MockReturnType<T>>>[];
|
|
151
|
+
/**
|
|
152
|
+
* This contains the arguments of the last call. If spy wasn't called, will return `undefined`.
|
|
153
|
+
* @see https://vitest.dev/api/mock#mock-lastcall
|
|
154
|
+
*/
|
|
155
|
+
lastCall: MockParameters<T> | undefined;
|
|
156
|
+
}
|
|
157
|
+
type Procedure = (...args: any[]) => any;
|
|
158
|
+
type NormalizedProcedure<T extends Procedure | Constructable> = T extends Constructable ? ({
|
|
159
|
+
new (...args: ConstructorParameters<T>): InstanceType<T>;
|
|
160
|
+
}) | ({
|
|
161
|
+
(this: InstanceType<T>, ...args: ConstructorParameters<T>): void;
|
|
162
|
+
}) : T extends Procedure ? (...args: Parameters<T>) => ReturnType<T> : never;
|
|
163
|
+
interface MockInstance<T extends Procedure | Constructable = Procedure> extends Disposable {
|
|
164
|
+
/**
|
|
165
|
+
* Use it to return the name assigned to the mock with the `.mockName(name)` method. By default, it will return `vi.fn()`.
|
|
166
|
+
* @see https://vitest.dev/api/mock#getmockname
|
|
167
|
+
*/
|
|
168
|
+
getMockName(): string;
|
|
169
|
+
/**
|
|
170
|
+
* Sets the internal mock name. This is useful for identifying the mock when an assertion fails.
|
|
171
|
+
* @see https://vitest.dev/api/mock#mockname
|
|
172
|
+
*/
|
|
173
|
+
mockName(name: string): this;
|
|
174
|
+
/**
|
|
175
|
+
* Current context of the mock. It stores information about all invocation calls, instances, and results.
|
|
176
|
+
*/
|
|
177
|
+
mock: MockContext<T>;
|
|
178
|
+
/**
|
|
179
|
+
* 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.
|
|
180
|
+
*
|
|
181
|
+
* To automatically call this method before each test, enable the [`clearMocks`](https://vitest.dev/config/clearmocks) setting in the configuration.
|
|
182
|
+
* @see https://vitest.dev/api/mock#mockclear
|
|
183
|
+
*/
|
|
184
|
+
mockClear(): this;
|
|
185
|
+
/**
|
|
186
|
+
* Does what `mockClear` does and resets inner implementation to the original function. This also resets all "once" implementations.
|
|
187
|
+
*
|
|
188
|
+
* Note that resetting a mock from `vi.fn()` will set implementation to an empty function that returns `undefined`.
|
|
189
|
+
* Resetting a mock from `vi.fn(impl)` will set implementation to `impl`. It is useful for completely resetting a mock to its default state.
|
|
190
|
+
*
|
|
191
|
+
* To automatically call this method before each test, enable the [`mockReset`](https://vitest.dev/config/mockreset) setting in the configuration.
|
|
192
|
+
* @see https://vitest.dev/api/mock#mockreset
|
|
193
|
+
*/
|
|
194
|
+
mockReset(): this;
|
|
195
|
+
/**
|
|
196
|
+
* Does what `mockReset` does and restores original descriptors of spied-on objects.
|
|
197
|
+
* @see https://vitest.dev/api/mock#mockrestore
|
|
198
|
+
*/
|
|
199
|
+
mockRestore(): void;
|
|
200
|
+
/**
|
|
201
|
+
* Returns current permanent mock implementation if there is one.
|
|
202
|
+
*
|
|
203
|
+
* If mock was created with `vi.fn`, it will consider passed down method as a mock implementation.
|
|
204
|
+
*
|
|
205
|
+
* If mock was created with `vi.spyOn`, it will return `undefined` unless a custom implementation was provided.
|
|
206
|
+
*/
|
|
207
|
+
getMockImplementation(): NormalizedProcedure<T> | undefined;
|
|
208
|
+
/**
|
|
209
|
+
* Accepts a function to be used as the mock implementation. TypeScript expects the arguments and return type to match those of the original function.
|
|
210
|
+
* @see https://vitest.dev/api/mock#mockimplementation
|
|
211
|
+
* @example
|
|
212
|
+
* const increment = vi.fn().mockImplementation(count => count + 1);
|
|
213
|
+
* expect(increment(3)).toBe(4);
|
|
214
|
+
*/
|
|
215
|
+
mockImplementation(fn: NormalizedProcedure<T>): this;
|
|
216
|
+
/**
|
|
217
|
+
* 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.
|
|
218
|
+
*
|
|
219
|
+
* 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.
|
|
220
|
+
* @see https://vitest.dev/api/mock#mockimplementationonce
|
|
221
|
+
* @example
|
|
222
|
+
* const fn = vi.fn(count => count).mockImplementationOnce(count => count + 1);
|
|
223
|
+
* expect(fn(3)).toBe(4);
|
|
224
|
+
* expect(fn(3)).toBe(3);
|
|
225
|
+
*/
|
|
226
|
+
mockImplementationOnce(fn: NormalizedProcedure<T>): this;
|
|
227
|
+
/**
|
|
228
|
+
* Overrides the original mock implementation temporarily while the callback is being executed.
|
|
229
|
+
*
|
|
230
|
+
* Note that this method takes precedence over the [`mockImplementationOnce`](https://vitest.dev/api/mock#mockimplementationonce).
|
|
231
|
+
* @see https://vitest.dev/api/mock#withimplementation
|
|
232
|
+
* @example
|
|
233
|
+
* const myMockFn = vi.fn(() => 'original')
|
|
234
|
+
*
|
|
235
|
+
* myMockFn.withImplementation(() => 'temp', () => {
|
|
236
|
+
* myMockFn() // 'temp'
|
|
237
|
+
* })
|
|
238
|
+
*
|
|
239
|
+
* myMockFn() // 'original'
|
|
240
|
+
*/
|
|
241
|
+
withImplementation(fn: NormalizedProcedure<T>, cb: () => Promise<unknown>): Promise<this>;
|
|
242
|
+
withImplementation(fn: NormalizedProcedure<T>, cb: () => unknown): this;
|
|
243
|
+
/**
|
|
244
|
+
* Use this if you need to return the `this` context from the method without invoking the actual implementation.
|
|
245
|
+
* @see https://vitest.dev/api/mock#mockreturnthis
|
|
246
|
+
*/
|
|
247
|
+
mockReturnThis(): this;
|
|
248
|
+
/**
|
|
249
|
+
* 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.
|
|
250
|
+
* @see https://vitest.dev/api/mock#mockreturnvalue
|
|
251
|
+
* @example
|
|
252
|
+
* const mock = vi.fn()
|
|
253
|
+
* mock.mockReturnValue(42)
|
|
254
|
+
* mock() // 42
|
|
255
|
+
* mock.mockReturnValue(43)
|
|
256
|
+
* mock() // 43
|
|
257
|
+
*/
|
|
258
|
+
mockReturnValue(value: MockReturnType<T>): this;
|
|
259
|
+
/**
|
|
260
|
+
* 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.
|
|
261
|
+
*
|
|
262
|
+
* 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.
|
|
263
|
+
* @example
|
|
264
|
+
* const myMockFn = vi
|
|
265
|
+
* .fn()
|
|
266
|
+
* .mockReturnValue('default')
|
|
267
|
+
* .mockReturnValueOnce('first call')
|
|
268
|
+
* .mockReturnValueOnce('second call')
|
|
269
|
+
*
|
|
270
|
+
* // 'first call', 'second call', 'default'
|
|
271
|
+
* console.log(myMockFn(), myMockFn(), myMockFn())
|
|
272
|
+
*/
|
|
273
|
+
mockReturnValueOnce(value: MockReturnType<T>): this;
|
|
274
|
+
/**
|
|
275
|
+
* Accepts a value that will be thrown whenever the mock function is called.
|
|
276
|
+
* @see https://vitest.dev/api/mock#mockthrow
|
|
277
|
+
* @example
|
|
278
|
+
* const myMockFn = vi.fn().mockThrow(new Error('error'))
|
|
279
|
+
* myMockFn() // throws 'error'
|
|
280
|
+
*/
|
|
281
|
+
mockThrow(value: unknown): this;
|
|
282
|
+
/**
|
|
283
|
+
* Accepts a value that will be thrown during the next function call. If chained, every consecutive call will throw the specified value.
|
|
284
|
+
* @example
|
|
285
|
+
* const myMockFn = vi
|
|
286
|
+
* .fn()
|
|
287
|
+
* .mockReturnValue('default')
|
|
288
|
+
* .mockThrowOnce(new Error('first call error'))
|
|
289
|
+
* .mockThrowOnce('second call error')
|
|
290
|
+
*
|
|
291
|
+
* expect(() => myMockFn()).toThrowError('first call error')
|
|
292
|
+
* expect(() => myMockFn()).toThrowError('second call error')
|
|
293
|
+
* expect(myMockFn()).toEqual('default')
|
|
294
|
+
*/
|
|
295
|
+
mockThrowOnce(value: unknown): this;
|
|
296
|
+
/**
|
|
297
|
+
* 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.
|
|
298
|
+
* @example
|
|
299
|
+
* const asyncMock = vi.fn().mockResolvedValue(42)
|
|
300
|
+
* asyncMock() // Promise<42>
|
|
301
|
+
*/
|
|
302
|
+
mockResolvedValue(value: Awaited<MockReturnType<T>>): this;
|
|
303
|
+
/**
|
|
304
|
+
* 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.
|
|
305
|
+
* @example
|
|
306
|
+
* const myMockFn = vi
|
|
307
|
+
* .fn()
|
|
308
|
+
* .mockResolvedValue('default')
|
|
309
|
+
* .mockResolvedValueOnce('first call')
|
|
310
|
+
* .mockResolvedValueOnce('second call')
|
|
311
|
+
*
|
|
312
|
+
* // Promise<'first call'>, Promise<'second call'>, Promise<'default'>
|
|
313
|
+
* console.log(myMockFn(), myMockFn(), myMockFn())
|
|
314
|
+
*/
|
|
315
|
+
mockResolvedValueOnce(value: Awaited<MockReturnType<T>>): this;
|
|
316
|
+
/**
|
|
317
|
+
* Accepts an error that will be rejected when async function is called.
|
|
318
|
+
* @example
|
|
319
|
+
* const asyncMock = vi.fn().mockRejectedValue(new Error('Async error'))
|
|
320
|
+
* await asyncMock() // throws Error<'Async error'>
|
|
321
|
+
*/
|
|
322
|
+
mockRejectedValue(error: unknown): this;
|
|
323
|
+
/**
|
|
324
|
+
* Accepts a value that will be rejected during the next function call. If chained, each consecutive call will reject the specified value.
|
|
325
|
+
* @example
|
|
326
|
+
* const asyncMock = vi
|
|
327
|
+
* .fn()
|
|
328
|
+
* .mockResolvedValueOnce('first call')
|
|
329
|
+
* .mockRejectedValueOnce(new Error('Async error'))
|
|
330
|
+
*
|
|
331
|
+
* await asyncMock() // first call
|
|
332
|
+
* await asyncMock() // throws Error<'Async error'>
|
|
333
|
+
*/
|
|
334
|
+
mockRejectedValueOnce(error: unknown): this;
|
|
335
|
+
}
|
|
336
|
+
interface Constructable {
|
|
337
|
+
new (...args: any[]): any;
|
|
338
|
+
}
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region node_modules/@vitest/expect/node_modules/tinyrainbow/dist/index.d.ts
|
|
341
|
+
interface Formatter {
|
|
342
|
+
(input?: unknown): string;
|
|
343
|
+
open: string;
|
|
344
|
+
close: string;
|
|
345
|
+
}
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region node_modules/@vitest/expect/node_modules/@vitest/pretty-format/dist/index.d.ts
|
|
348
|
+
/**
|
|
349
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
350
|
+
*
|
|
351
|
+
* This source code is licensed under the MIT license found in the
|
|
352
|
+
* LICENSE file in the root directory of this source tree.
|
|
353
|
+
*/
|
|
354
|
+
interface Colors {
|
|
355
|
+
comment: {
|
|
356
|
+
close: string;
|
|
357
|
+
open: string;
|
|
358
|
+
};
|
|
359
|
+
content: {
|
|
360
|
+
close: string;
|
|
361
|
+
open: string;
|
|
362
|
+
};
|
|
363
|
+
prop: {
|
|
364
|
+
close: string;
|
|
365
|
+
open: string;
|
|
366
|
+
};
|
|
367
|
+
tag: {
|
|
368
|
+
close: string;
|
|
369
|
+
open: string;
|
|
370
|
+
};
|
|
371
|
+
value: {
|
|
372
|
+
close: string;
|
|
373
|
+
open: string;
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
type Indent = (arg0: string) => string;
|
|
377
|
+
type Refs = Array<unknown>;
|
|
378
|
+
type Print = (arg0: unknown) => string;
|
|
379
|
+
/**
|
|
380
|
+
* compare function used when sorting object keys, `null` can be used to skip over sorting.
|
|
381
|
+
*/
|
|
382
|
+
type CompareKeys = ((a: string, b: string) => number) | null | undefined;
|
|
383
|
+
interface PrettyFormatOptions {
|
|
384
|
+
/**
|
|
385
|
+
* Call `toJSON` on objects before formatting them.
|
|
386
|
+
* Ignored after the formatter has already called `toJSON` once for a value.
|
|
387
|
+
* @default true
|
|
388
|
+
*/
|
|
389
|
+
callToJSON?: boolean;
|
|
390
|
+
/**
|
|
391
|
+
* Whether to escape special characters in regular expressions.
|
|
392
|
+
* @default false
|
|
393
|
+
*/
|
|
394
|
+
escapeRegex?: boolean;
|
|
395
|
+
/**
|
|
396
|
+
* Whether to escape special characters in strings.
|
|
397
|
+
* @default true
|
|
398
|
+
*/
|
|
399
|
+
escapeString?: boolean;
|
|
400
|
+
/**
|
|
401
|
+
* Whether to highlight syntax using terminal colors.
|
|
402
|
+
* @default false
|
|
403
|
+
*/
|
|
404
|
+
highlight?: boolean;
|
|
405
|
+
/**
|
|
406
|
+
* Number of spaces to use for each level of indentation.
|
|
407
|
+
* @default 2
|
|
408
|
+
*/
|
|
409
|
+
indent?: number;
|
|
410
|
+
/**
|
|
411
|
+
* Maximum depth to recurse into nested values.
|
|
412
|
+
* @default Infinity
|
|
413
|
+
*/
|
|
414
|
+
maxDepth?: number;
|
|
415
|
+
/**
|
|
416
|
+
* Maximum number of items to print in arrays, sets, maps, and similar collections.
|
|
417
|
+
* @default Infinity
|
|
418
|
+
*/
|
|
419
|
+
maxWidth?: number;
|
|
420
|
+
/**
|
|
421
|
+
* Approximate per-depth-level budget for output length.
|
|
422
|
+
* When the accumulated output at any single depth level exceeds this value,
|
|
423
|
+
* further nesting is collapsed. This is a heuristic safety valve, not a hard
|
|
424
|
+
* limit — total output can reach up to roughly `maxDepth × maxOutputLength`.
|
|
425
|
+
* @default 1_000_000
|
|
426
|
+
*/
|
|
427
|
+
maxOutputLength?: number;
|
|
428
|
+
/**
|
|
429
|
+
* Whether to minimize added whitespace, including indentation and line breaks.
|
|
430
|
+
*
|
|
431
|
+
* When `true`, pretty-format defaults `spacingInner` to `' '`, `spacingOuter` to `''`,
|
|
432
|
+
* and ignores indentation. It also changes the default for `printBasicPrototype`
|
|
433
|
+
* from `true` to `false`, although an explicit `printBasicPrototype` still wins.
|
|
434
|
+
* Explicit `spacingInner` / `spacingOuter` overrides still apply.
|
|
435
|
+
* @default false
|
|
436
|
+
*/
|
|
437
|
+
min?: boolean;
|
|
438
|
+
/**
|
|
439
|
+
* Whether to print `Object` / `Array` prefixes for plain objects and arrays.
|
|
440
|
+
*
|
|
441
|
+
* Defaults to `true`, unless `min` is `true`, in which case it defaults to `false`.
|
|
442
|
+
* An explicit `printBasicPrototype` value always overrides the `min` default.
|
|
443
|
+
*/
|
|
444
|
+
printBasicPrototype?: boolean;
|
|
445
|
+
/**
|
|
446
|
+
* Whether to include the function name when formatting functions.
|
|
447
|
+
* @default true
|
|
448
|
+
*/
|
|
449
|
+
printFunctionName?: boolean;
|
|
450
|
+
/**
|
|
451
|
+
* Whether to include shadow-root contents when formatting DOM nodes.
|
|
452
|
+
* @default true
|
|
453
|
+
*/
|
|
454
|
+
printShadowRoot?: boolean;
|
|
455
|
+
/**
|
|
456
|
+
* Compare function used when sorting object keys. Set to `null` to disable sorting.
|
|
457
|
+
*/
|
|
458
|
+
compareKeys?: CompareKeys;
|
|
459
|
+
/**
|
|
460
|
+
* Plugins used to serialize application-specific data types.
|
|
461
|
+
* @default []
|
|
462
|
+
*/
|
|
463
|
+
plugins?: Plugins;
|
|
464
|
+
/**
|
|
465
|
+
* Whitespace inserted after commas between items or entries.
|
|
466
|
+
*
|
|
467
|
+
* For example, in `{a: 1, b: 2}` or `[1, 2]`, this controls the gap after each comma:
|
|
468
|
+
* `{a: 1,${spacingInner}b: 2}`
|
|
469
|
+
* `[1,${spacingInner}2]`
|
|
470
|
+
*
|
|
471
|
+
* Defaults to `'\n'` in regular mode and `' '` when `min` is `true`.
|
|
472
|
+
* Can be overridden independently of `min`.
|
|
473
|
+
*/
|
|
474
|
+
spacingInner?: string;
|
|
475
|
+
/**
|
|
476
|
+
* Whitespace inserted immediately inside collection/object delimiters.
|
|
477
|
+
*
|
|
478
|
+
* For example, this controls the space or newline right after the opening delimiter
|
|
479
|
+
* and right before the closing delimiter:
|
|
480
|
+
* `{${spacingOuter}a: 1${spacingOuter}}`
|
|
481
|
+
* `[${spacingOuter}1${spacingOuter}]`
|
|
482
|
+
*
|
|
483
|
+
* Defaults to `'\n'` in regular mode and `''` when `min` is `true`.
|
|
484
|
+
* Can be overridden independently of `min`.
|
|
485
|
+
*/
|
|
486
|
+
spacingOuter?: string;
|
|
487
|
+
/**
|
|
488
|
+
* Whether to print strings using single quotes instead of double quotes.
|
|
489
|
+
*
|
|
490
|
+
* For example:
|
|
491
|
+
* `"hello"` when `false`
|
|
492
|
+
* `'hello'` when `true`
|
|
493
|
+
*
|
|
494
|
+
* @default false
|
|
495
|
+
*/
|
|
496
|
+
singleQuote?: boolean;
|
|
497
|
+
/**
|
|
498
|
+
* Whether to always quote object property keys.
|
|
499
|
+
*
|
|
500
|
+
* For example:
|
|
501
|
+
* `{"a": 1}` when `true`
|
|
502
|
+
* `{a: 1}` when `false` and the key is a valid identifier
|
|
503
|
+
* `{"my-key": 1}` still stays quoted because it is not a valid identifier
|
|
504
|
+
*
|
|
505
|
+
* @default true
|
|
506
|
+
*/
|
|
507
|
+
quoteKeys?: boolean;
|
|
508
|
+
}
|
|
509
|
+
interface Config {
|
|
510
|
+
callToJSON: boolean;
|
|
511
|
+
compareKeys: CompareKeys;
|
|
512
|
+
colors: Colors;
|
|
513
|
+
escapeRegex: boolean;
|
|
514
|
+
escapeString: boolean;
|
|
515
|
+
indent: string;
|
|
516
|
+
maxDepth: number;
|
|
517
|
+
maxWidth: number;
|
|
518
|
+
min: boolean;
|
|
519
|
+
plugins: Plugins;
|
|
520
|
+
printBasicPrototype: boolean;
|
|
521
|
+
printFunctionName: boolean;
|
|
522
|
+
printShadowRoot: boolean;
|
|
523
|
+
spacingInner: string;
|
|
524
|
+
spacingOuter: string;
|
|
525
|
+
singleQuote: boolean;
|
|
526
|
+
quoteKeys: boolean;
|
|
527
|
+
maxOutputLength: number;
|
|
528
|
+
}
|
|
529
|
+
type Printer = (val: unknown, config: Config, indentation: string, depth: number, refs: Refs, hasCalledToJSON?: boolean) => string;
|
|
530
|
+
type Test$1 = (arg0: any) => boolean;
|
|
531
|
+
interface NewPlugin {
|
|
532
|
+
serialize: (val: any, config: Config, indentation: string, depth: number, refs: Refs, printer: Printer) => string;
|
|
533
|
+
test: Test$1;
|
|
534
|
+
}
|
|
535
|
+
interface PluginOptions {
|
|
536
|
+
edgeSpacing: string;
|
|
537
|
+
min: boolean;
|
|
538
|
+
spacing: string;
|
|
539
|
+
}
|
|
540
|
+
interface OldPlugin {
|
|
541
|
+
print: (val: unknown, print: Print, indent: Indent, options: PluginOptions, colors: Colors) => string;
|
|
542
|
+
test: Test$1;
|
|
543
|
+
}
|
|
544
|
+
type Plugin = NewPlugin | OldPlugin;
|
|
545
|
+
type Plugins = Array<Plugin>;
|
|
546
|
+
/**
|
|
547
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
548
|
+
*
|
|
549
|
+
* This source code is licensed under the MIT license found in the
|
|
550
|
+
* LICENSE file in the root directory of this source tree.
|
|
551
|
+
*/
|
|
552
|
+
//#endregion
|
|
553
|
+
//#region node_modules/@vitest/expect/node_modules/@vitest/utils/dist/types.d-BCElaP-c.d.ts
|
|
554
|
+
/**
|
|
555
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
556
|
+
*
|
|
557
|
+
* This source code is licensed under the MIT license found in the
|
|
558
|
+
* LICENSE file in the root directory of this source tree.
|
|
559
|
+
*/
|
|
560
|
+
type DiffOptionsColor = (arg: string) => string;
|
|
561
|
+
interface DiffOptions {
|
|
562
|
+
aAnnotation?: string;
|
|
563
|
+
aColor?: DiffOptionsColor;
|
|
564
|
+
aIndicator?: string;
|
|
565
|
+
bAnnotation?: string;
|
|
566
|
+
bColor?: DiffOptionsColor;
|
|
567
|
+
bIndicator?: string;
|
|
568
|
+
changeColor?: DiffOptionsColor;
|
|
569
|
+
changeLineTrailingSpaceColor?: DiffOptionsColor;
|
|
570
|
+
commonColor?: DiffOptionsColor;
|
|
571
|
+
commonIndicator?: string;
|
|
572
|
+
commonLineTrailingSpaceColor?: DiffOptionsColor;
|
|
573
|
+
contextLines?: number;
|
|
574
|
+
emptyFirstOrLastLinePlaceholder?: string;
|
|
575
|
+
expand?: boolean;
|
|
576
|
+
includeChangeCounts?: boolean;
|
|
577
|
+
omitAnnotationLines?: boolean;
|
|
578
|
+
patchColor?: DiffOptionsColor;
|
|
579
|
+
printBasicPrototype?: boolean;
|
|
580
|
+
maxDepth?: number;
|
|
581
|
+
compareKeys?: CompareKeys;
|
|
582
|
+
truncateThreshold?: number;
|
|
583
|
+
truncateAnnotation?: string;
|
|
584
|
+
truncateAnnotationColor?: DiffOptionsColor;
|
|
585
|
+
}
|
|
586
|
+
//#endregion
|
|
587
|
+
//#region node_modules/@vitest/expect/node_modules/@vitest/utils/dist/diff.d.ts
|
|
588
|
+
/**
|
|
589
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
590
|
+
*
|
|
591
|
+
* This source code is licensed under the MIT license found in the
|
|
592
|
+
* LICENSE file in the root directory of this source tree.
|
|
593
|
+
*/
|
|
594
|
+
interface StringifiedMemory {
|
|
595
|
+
expected?: string;
|
|
596
|
+
actual?: string;
|
|
597
|
+
}
|
|
598
|
+
interface Memorize {
|
|
599
|
+
(pointer: "expected" | "actual", stringifiedValue: string): string;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* @param a Expected value
|
|
603
|
+
* @param b Received value
|
|
604
|
+
* @param options Diff options
|
|
605
|
+
* @returns {string | null} a string diff
|
|
606
|
+
*/
|
|
607
|
+
declare function diff(a: any, b: any, options?: DiffOptions, memorize?: Memorize): string | undefined;
|
|
608
|
+
declare function printDiffOrStringify(received: unknown, expected: unknown, options?: DiffOptions, memory?: StringifiedMemory): string | undefined;
|
|
609
|
+
//#endregion
|
|
610
|
+
//#region node_modules/@vitest/expect/node_modules/@vitest/utils/dist/display.d.ts
|
|
611
|
+
interface StringifyOptions extends PrettyFormatOptions {
|
|
612
|
+
maxLength?: number;
|
|
613
|
+
filterNode?: string | ((node: any) => boolean);
|
|
614
|
+
}
|
|
615
|
+
declare function stringify(object: unknown, maxDepth?: number, {
|
|
616
|
+
maxLength,
|
|
617
|
+
filterNode,
|
|
618
|
+
...options
|
|
619
|
+
}?: StringifyOptions): string;
|
|
620
|
+
//#endregion
|
|
621
|
+
//#region node_modules/@vitest/expect/dist/index.d.ts
|
|
622
|
+
interface AsymmetricMatcherInterface {
|
|
623
|
+
asymmetricMatch: (other: unknown, customTesters?: Array<Tester>) => boolean;
|
|
624
|
+
toString: () => string;
|
|
625
|
+
getExpectedType?: () => string;
|
|
626
|
+
toAsymmetricMatcher?: () => string;
|
|
627
|
+
}
|
|
628
|
+
declare abstract class AsymmetricMatcher<T, State extends MatcherState = MatcherState> implements AsymmetricMatcherInterface {
|
|
629
|
+
protected sample: T;
|
|
630
|
+
protected inverse: boolean;
|
|
631
|
+
$$typeof: symbol;
|
|
632
|
+
constructor(sample: T, inverse?: boolean);
|
|
633
|
+
protected getMatcherContext(expect?: Chai.ExpectStatic): State;
|
|
634
|
+
abstract asymmetricMatch(other: unknown, customTesters?: Array<Tester>): boolean;
|
|
635
|
+
abstract toString(): string;
|
|
636
|
+
getExpectedType?(): string;
|
|
637
|
+
toAsymmetricMatcher?(): string;
|
|
638
|
+
}
|
|
639
|
+
declare function matcherHint(matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions): string;
|
|
640
|
+
declare function printReceived(object: unknown): string;
|
|
641
|
+
declare function printExpected(value: unknown): string;
|
|
642
|
+
declare function getMatcherUtils(): {
|
|
643
|
+
EXPECTED_COLOR: Formatter;
|
|
644
|
+
RECEIVED_COLOR: Formatter;
|
|
645
|
+
INVERTED_COLOR: Formatter;
|
|
646
|
+
BOLD_WEIGHT: Formatter;
|
|
647
|
+
DIM_COLOR: Formatter;
|
|
648
|
+
diff: typeof diff;
|
|
649
|
+
matcherHint: typeof matcherHint;
|
|
650
|
+
printReceived: typeof printReceived;
|
|
651
|
+
printExpected: typeof printExpected;
|
|
652
|
+
printDiffOrStringify: typeof printDiffOrStringify;
|
|
653
|
+
printWithType: typeof printWithType;
|
|
654
|
+
};
|
|
655
|
+
declare function printWithType<T>(name: string, value: T, print: (value: T) => string): string;
|
|
656
|
+
type Tester = (this: TesterContext, a: any, b: any, customTesters: Array<Tester>) => boolean | undefined;
|
|
657
|
+
interface TesterContext {
|
|
658
|
+
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
659
|
+
}
|
|
660
|
+
interface MatcherHintOptions {
|
|
661
|
+
comment?: string;
|
|
662
|
+
expectedColor?: Formatter;
|
|
663
|
+
isDirectExpectCall?: boolean;
|
|
664
|
+
isNot?: boolean;
|
|
665
|
+
promise?: string;
|
|
666
|
+
receivedColor?: Formatter;
|
|
667
|
+
secondArgument?: string;
|
|
668
|
+
secondArgumentColor?: Formatter;
|
|
669
|
+
}
|
|
670
|
+
interface MatcherState {
|
|
671
|
+
customTesters: Array<Tester>;
|
|
672
|
+
assertionCalls: number;
|
|
673
|
+
currentTestName?: string;
|
|
674
|
+
/**
|
|
675
|
+
* @deprecated exists only in types
|
|
676
|
+
*/
|
|
677
|
+
dontThrow?: () => void;
|
|
678
|
+
/**
|
|
679
|
+
* @deprecated exists only in types
|
|
680
|
+
*/
|
|
681
|
+
error?: Error;
|
|
682
|
+
equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
|
|
683
|
+
/**
|
|
684
|
+
* @deprecated exists only in types
|
|
685
|
+
*/
|
|
686
|
+
expand?: boolean;
|
|
687
|
+
expectedAssertionsNumber?: number | null;
|
|
688
|
+
expectedAssertionsNumberErrorGen?: (() => Error) | null;
|
|
689
|
+
isExpectingAssertions?: boolean;
|
|
690
|
+
isExpectingAssertionsError?: Error | null;
|
|
691
|
+
isNot: boolean;
|
|
692
|
+
promise: string;
|
|
693
|
+
/**
|
|
694
|
+
* @deprecated exists only in types
|
|
695
|
+
*/
|
|
696
|
+
suppressedErrors: Array<Error>;
|
|
697
|
+
testPath?: string;
|
|
698
|
+
utils: ReturnType<typeof getMatcherUtils> & {
|
|
699
|
+
diff: typeof diff;
|
|
700
|
+
stringify: typeof stringify;
|
|
701
|
+
iterableEquality: Tester;
|
|
702
|
+
subsetEquality: Tester;
|
|
703
|
+
};
|
|
704
|
+
soft?: boolean;
|
|
705
|
+
poll?: boolean;
|
|
706
|
+
/**
|
|
707
|
+
* The same assertion instance that chai plugins receive.
|
|
708
|
+
* @experimental
|
|
709
|
+
* @see {@link https://www.chaijs.com/guide/plugins/} Core Plugin Concepts
|
|
710
|
+
*/
|
|
711
|
+
readonly assertion: Assertion;
|
|
712
|
+
}
|
|
713
|
+
interface SyncExpectationResult {
|
|
714
|
+
pass: boolean;
|
|
715
|
+
message: () => string;
|
|
716
|
+
actual?: any;
|
|
717
|
+
expected?: any;
|
|
718
|
+
meta?: object;
|
|
719
|
+
}
|
|
720
|
+
type AsyncExpectationResult = Promise<SyncExpectationResult>;
|
|
721
|
+
type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
|
|
722
|
+
interface RawMatcherFn<T extends MatcherState = MatcherState, E extends Array<any> = Array<any>> {
|
|
723
|
+
(this: T, received: any, ...expected: E): ExpectationResult;
|
|
724
|
+
}
|
|
725
|
+
interface Matchers<T = any> {}
|
|
726
|
+
type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>> & ThisType<T> & { [K in keyof Matchers<T>]?: RawMatcherFn<T, Parameters<Matchers<T>[K]>> };
|
|
727
|
+
interface ExpectStatic extends Chai.ExpectStatic, Matchers, AsymmetricMatchersContaining {
|
|
728
|
+
<T>(actual: T, message?: string): Assertion<T>;
|
|
729
|
+
extend: (expects: MatchersObject) => void;
|
|
730
|
+
anything: () => any;
|
|
731
|
+
any: (constructor: unknown) => any;
|
|
732
|
+
getState: () => MatcherState;
|
|
733
|
+
setState: (state: Partial<MatcherState>) => void;
|
|
734
|
+
not: AsymmetricMatchersContaining;
|
|
735
|
+
}
|
|
736
|
+
interface CustomMatcher {
|
|
737
|
+
/**
|
|
738
|
+
* Checks that a value satisfies a custom matcher function.
|
|
739
|
+
*
|
|
740
|
+
* @param matcher - A function returning a boolean based on the custom condition
|
|
741
|
+
* @param message - Optional custom error message on failure
|
|
742
|
+
*
|
|
743
|
+
* @example
|
|
744
|
+
* expect(age).toSatisfy(val => val >= 18, 'Age must be at least 18');
|
|
745
|
+
* expect(age).toEqual(expect.toSatisfy(val => val >= 18, 'Age must be at least 18'));
|
|
746
|
+
*/
|
|
747
|
+
toSatisfy: (matcher: (value: any) => boolean, message?: string) => any;
|
|
748
|
+
/**
|
|
749
|
+
* Matches if the received value is one of the values in the expected array or set.
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* expect(1).toBeOneOf([1, 2, 3])
|
|
753
|
+
* expect('foo').toBeOneOf([expect.any(String)])
|
|
754
|
+
* expect({ a: 1 }).toEqual({ a: expect.toBeOneOf(['1', '2', '3']) })
|
|
755
|
+
*/
|
|
756
|
+
toBeOneOf: <T>(sample: ReadonlyArray<T> | ReadonlySet<T>) => any;
|
|
757
|
+
}
|
|
758
|
+
interface AsymmetricMatchersContaining extends CustomMatcher {
|
|
759
|
+
/**
|
|
760
|
+
* Matches if the received string contains the expected substring.
|
|
761
|
+
*
|
|
762
|
+
* @example
|
|
763
|
+
* expect('I have an apple').toEqual(expect.stringContaining('apple'));
|
|
764
|
+
* expect({ a: 'test string' }).toEqual({ a: expect.stringContaining('test') });
|
|
765
|
+
*/
|
|
766
|
+
stringContaining: (expected: string) => any;
|
|
767
|
+
/**
|
|
768
|
+
* Matches if the received object contains all properties of the expected object.
|
|
769
|
+
*
|
|
770
|
+
* @example
|
|
771
|
+
* expect({ a: '1', b: 2 }).toEqual(expect.objectContaining({ a: '1' }))
|
|
772
|
+
*/
|
|
773
|
+
objectContaining: <T = any>(expected: DeeplyAllowMatchers<T>) => any;
|
|
774
|
+
/**
|
|
775
|
+
* Matches if the received array contains all elements in the expected array.
|
|
776
|
+
*
|
|
777
|
+
* @example
|
|
778
|
+
* expect(['a', 'b', 'c']).toEqual(expect.arrayContaining(['b', 'a']));
|
|
779
|
+
*/
|
|
780
|
+
arrayContaining: <T = unknown>(expected: Array<DeeplyAllowMatchers<T>>) => any;
|
|
781
|
+
/**
|
|
782
|
+
* Matches if the received string or regex matches the expected pattern.
|
|
783
|
+
*
|
|
784
|
+
* @example
|
|
785
|
+
* expect('hello world').toEqual(expect.stringMatching(/^hello/));
|
|
786
|
+
* expect('hello world').toEqual(expect.stringMatching('hello'));
|
|
787
|
+
*/
|
|
788
|
+
stringMatching: (expected: string | RegExp) => any;
|
|
789
|
+
/**
|
|
790
|
+
* Matches if the received number is within a certain precision of the expected number.
|
|
791
|
+
*
|
|
792
|
+
* @example
|
|
793
|
+
* expect(10.45).toEqual(expect.closeTo(10.5, 1));
|
|
794
|
+
* expect(5.11).toEqual(expect.closeTo(5.12)); // with default precision
|
|
795
|
+
*/
|
|
796
|
+
closeTo: (expected: number, precision?: number) => any;
|
|
797
|
+
/**
|
|
798
|
+
* Matches if the received value validates against a Standard Schema.
|
|
799
|
+
*
|
|
800
|
+
* @param schema - A Standard Schema V1 compatible schema object
|
|
801
|
+
*
|
|
802
|
+
* @example
|
|
803
|
+
* expect(user).toEqual(expect.schemaMatching(z.object({ name: z.string() })))
|
|
804
|
+
* expect(['hello', 'world']).toEqual([expect.schemaMatching(z.string()), expect.schemaMatching(z.string())])
|
|
805
|
+
*/
|
|
806
|
+
schemaMatching: (schema: unknown) => any;
|
|
807
|
+
}
|
|
808
|
+
type WithAsymmetricMatcher<T> = T | AsymmetricMatcher<unknown>;
|
|
809
|
+
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>;
|
|
810
|
+
interface JestAssertion<T = any> extends jest.Matchers<void, T>, CustomMatcher {
|
|
811
|
+
/**
|
|
812
|
+
* Used when you want to check that two objects have the same value.
|
|
813
|
+
* This matcher recursively checks the equality of all fields, rather than checking for object identity.
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* expect(user).toEqual({ name: 'Alice', age: 30 });
|
|
817
|
+
*/
|
|
818
|
+
toEqual: <E>(expected: E) => void;
|
|
819
|
+
/**
|
|
820
|
+
* Use to test that objects have the same types as well as structure.
|
|
821
|
+
*
|
|
822
|
+
* @example
|
|
823
|
+
* expect(user).toStrictEqual({ name: 'Alice', age: 30 });
|
|
824
|
+
*/
|
|
825
|
+
toStrictEqual: <E>(expected: E) => void;
|
|
826
|
+
/**
|
|
827
|
+
* Checks that a value is what you expect. It calls `Object.is` to compare values.
|
|
828
|
+
* Don't use `toBe` with floating-point numbers.
|
|
829
|
+
*
|
|
830
|
+
* @example
|
|
831
|
+
* expect(result).toBe(42);
|
|
832
|
+
* expect(status).toBe(true);
|
|
833
|
+
*/
|
|
834
|
+
toBe: <E>(expected: E) => void;
|
|
835
|
+
/**
|
|
836
|
+
* Check that a string matches a regular expression.
|
|
837
|
+
*
|
|
838
|
+
* @example
|
|
839
|
+
* expect(message).toMatch(/hello/);
|
|
840
|
+
* expect(greeting).toMatch('world');
|
|
841
|
+
*/
|
|
842
|
+
toMatch: (expected: string | RegExp) => void;
|
|
843
|
+
/**
|
|
844
|
+
* Used to check that a JavaScript object matches a subset of the properties of an object
|
|
845
|
+
*
|
|
846
|
+
* @example
|
|
847
|
+
* expect(user).toMatchObject({
|
|
848
|
+
* name: 'Alice',
|
|
849
|
+
* address: { city: 'Wonderland' }
|
|
850
|
+
* });
|
|
851
|
+
*/
|
|
852
|
+
toMatchObject: <E extends object | any[]>(expected: E) => void;
|
|
853
|
+
/**
|
|
854
|
+
* Used when you want to check that an item is in a list.
|
|
855
|
+
* For testing the items in the list, this uses `===`, a strict equality check.
|
|
856
|
+
*
|
|
857
|
+
* @example
|
|
858
|
+
* expect(items).toContain('apple');
|
|
859
|
+
* expect(numbers).toContain(5);
|
|
860
|
+
*/
|
|
861
|
+
toContain: <E>(item: E) => void;
|
|
862
|
+
/**
|
|
863
|
+
* Used when you want to check that an item is in a list.
|
|
864
|
+
* For testing the items in the list, this matcher recursively checks the
|
|
865
|
+
* equality of all fields, rather than checking for object identity.
|
|
866
|
+
*
|
|
867
|
+
* @example
|
|
868
|
+
* expect(items).toContainEqual({ name: 'apple', quantity: 1 });
|
|
869
|
+
*/
|
|
870
|
+
toContainEqual: <E>(item: E) => void;
|
|
871
|
+
/**
|
|
872
|
+
* Use when you don't care what a value is, you just want to ensure a value
|
|
873
|
+
* is true in a boolean context. In JavaScript, there are six falsy values:
|
|
874
|
+
* `false`, `0`, `''`, `null`, `undefined`, and `NaN`. Everything else is truthy.
|
|
875
|
+
*
|
|
876
|
+
* @example
|
|
877
|
+
* expect(user.isActive).toBeTruthy();
|
|
878
|
+
*/
|
|
879
|
+
toBeTruthy: () => void;
|
|
880
|
+
/**
|
|
881
|
+
* When you don't care what a value is, you just want to
|
|
882
|
+
* ensure a value is false in a boolean context.
|
|
883
|
+
*
|
|
884
|
+
* @example
|
|
885
|
+
* expect(user.isActive).toBeFalsy();
|
|
886
|
+
*/
|
|
887
|
+
toBeFalsy: () => void;
|
|
888
|
+
/**
|
|
889
|
+
* For comparing floating point numbers.
|
|
890
|
+
*
|
|
891
|
+
* @example
|
|
892
|
+
* expect(score).toBeGreaterThan(10);
|
|
893
|
+
*/
|
|
894
|
+
toBeGreaterThan: (num: number | bigint) => void;
|
|
895
|
+
/**
|
|
896
|
+
* For comparing floating point numbers.
|
|
897
|
+
*
|
|
898
|
+
* @example
|
|
899
|
+
* expect(score).toBeGreaterThanOrEqual(10);
|
|
900
|
+
*/
|
|
901
|
+
toBeGreaterThanOrEqual: (num: number | bigint) => void;
|
|
902
|
+
/**
|
|
903
|
+
* For comparing floating point numbers.
|
|
904
|
+
*
|
|
905
|
+
* @example
|
|
906
|
+
* expect(score).toBeLessThan(10);
|
|
907
|
+
*/
|
|
908
|
+
toBeLessThan: (num: number | bigint) => void;
|
|
909
|
+
/**
|
|
910
|
+
* For comparing floating point numbers.
|
|
911
|
+
*
|
|
912
|
+
* @example
|
|
913
|
+
* expect(score).toBeLessThanOrEqual(10);
|
|
914
|
+
*/
|
|
915
|
+
toBeLessThanOrEqual: (num: number | bigint) => void;
|
|
916
|
+
/**
|
|
917
|
+
* Used to check that a variable is NaN.
|
|
918
|
+
*
|
|
919
|
+
* @example
|
|
920
|
+
* expect(value).toBeNaN();
|
|
921
|
+
*/
|
|
922
|
+
toBeNaN: () => void;
|
|
923
|
+
/**
|
|
924
|
+
* Used to check that a variable is undefined.
|
|
925
|
+
*
|
|
926
|
+
* @example
|
|
927
|
+
* expect(value).toBeUndefined();
|
|
928
|
+
*/
|
|
929
|
+
toBeUndefined: () => void;
|
|
930
|
+
/**
|
|
931
|
+
* This is the same as `.toBe(null)` but the error messages are a bit nicer.
|
|
932
|
+
* So use `.toBeNull()` when you want to check that something is null.
|
|
933
|
+
*
|
|
934
|
+
* @example
|
|
935
|
+
* expect(value).toBeNull();
|
|
936
|
+
*/
|
|
937
|
+
toBeNull: () => void;
|
|
938
|
+
/**
|
|
939
|
+
* Used to check that a variable is nullable (null or undefined).
|
|
940
|
+
*
|
|
941
|
+
* @example
|
|
942
|
+
* expect(value).toBeNullable();
|
|
943
|
+
*/
|
|
944
|
+
toBeNullable: () => void;
|
|
945
|
+
/**
|
|
946
|
+
* Ensure that a variable is not undefined.
|
|
947
|
+
*
|
|
948
|
+
* @example
|
|
949
|
+
* expect(value).toBeDefined();
|
|
950
|
+
*/
|
|
951
|
+
toBeDefined: () => void;
|
|
952
|
+
/**
|
|
953
|
+
* Ensure that an object is an instance of a class.
|
|
954
|
+
* This matcher uses `instanceof` underneath.
|
|
955
|
+
*
|
|
956
|
+
* @example
|
|
957
|
+
* expect(new Date()).toBeInstanceOf(Date);
|
|
958
|
+
*/
|
|
959
|
+
toBeInstanceOf: <E>(expected: E) => void;
|
|
960
|
+
/**
|
|
961
|
+
* Used to check that an object has a `.length` property
|
|
962
|
+
* and it is set to a certain numeric value.
|
|
963
|
+
*
|
|
964
|
+
* @example
|
|
965
|
+
* expect([1, 2, 3]).toHaveLength(3);
|
|
966
|
+
* expect('hello').toHaveLength(5);
|
|
967
|
+
*/
|
|
968
|
+
toHaveLength: (length: number) => void;
|
|
969
|
+
/**
|
|
970
|
+
* Use to check if a property at the specified path exists on an object.
|
|
971
|
+
* For checking deeply nested properties, you may use dot notation or an array containing
|
|
972
|
+
* the path segments for deep references.
|
|
973
|
+
*
|
|
974
|
+
* Optionally, you can provide a value to check if it matches the value present at the path
|
|
975
|
+
* on the target object. This matcher uses 'deep equality' (like `toEqual()`) and recursively checks
|
|
976
|
+
* the equality of all fields.
|
|
977
|
+
*
|
|
978
|
+
* @example
|
|
979
|
+
* expect(user).toHaveProperty('address.city', 'New York');
|
|
980
|
+
* expect(config).toHaveProperty(['settings', 'theme'], 'dark');
|
|
981
|
+
*/
|
|
982
|
+
toHaveProperty: <E>(property: string | (string | number)[], value?: E) => void;
|
|
983
|
+
/**
|
|
984
|
+
* Using exact equality with floating point numbers is a bad idea.
|
|
985
|
+
* Rounding means that intuitive things fail.
|
|
986
|
+
* The default for `numDigits` is 2.
|
|
987
|
+
*
|
|
988
|
+
* @example
|
|
989
|
+
* expect(price).toBeCloseTo(9.99, 2);
|
|
990
|
+
*/
|
|
991
|
+
toBeCloseTo: (number: number, numDigits?: number) => void;
|
|
992
|
+
/**
|
|
993
|
+
* Ensures that a mock function is called an exact number of times.
|
|
994
|
+
*
|
|
995
|
+
* Also under the alias `expect.toBeCalledTimes`.
|
|
996
|
+
*
|
|
997
|
+
* @example
|
|
998
|
+
* expect(mockFunc).toHaveBeenCalledTimes(2);
|
|
999
|
+
*/
|
|
1000
|
+
toHaveBeenCalledTimes: (times: number) => void;
|
|
1001
|
+
/**
|
|
1002
|
+
* Ensures that a mock function is called an exact number of times.
|
|
1003
|
+
*
|
|
1004
|
+
* Alias for `expect.toHaveBeenCalledTimes`.
|
|
1005
|
+
*
|
|
1006
|
+
* @example
|
|
1007
|
+
* expect(mockFunc).toBeCalledTimes(2);
|
|
1008
|
+
* @deprecated Use `toHaveBeenCalledTimes` instead
|
|
1009
|
+
*/
|
|
1010
|
+
toBeCalledTimes: (times: number) => void;
|
|
1011
|
+
/**
|
|
1012
|
+
* Ensures that a mock function is called.
|
|
1013
|
+
*
|
|
1014
|
+
* Also under the alias `expect.toBeCalled`.
|
|
1015
|
+
*
|
|
1016
|
+
* @example
|
|
1017
|
+
* expect(mockFunc).toHaveBeenCalled();
|
|
1018
|
+
*/
|
|
1019
|
+
toHaveBeenCalled: () => void;
|
|
1020
|
+
/**
|
|
1021
|
+
* Ensures that a mock function is called.
|
|
1022
|
+
*
|
|
1023
|
+
* Alias for `expect.toHaveBeenCalled`.
|
|
1024
|
+
*
|
|
1025
|
+
* @example
|
|
1026
|
+
* expect(mockFunc).toBeCalled();
|
|
1027
|
+
* @deprecated Use `toHaveBeenCalled` instead
|
|
1028
|
+
*/
|
|
1029
|
+
toBeCalled: () => void;
|
|
1030
|
+
/**
|
|
1031
|
+
* Ensure that a mock function is called with specific arguments.
|
|
1032
|
+
*
|
|
1033
|
+
* Also under the alias `expect.toBeCalledWith`.
|
|
1034
|
+
*
|
|
1035
|
+
* @example
|
|
1036
|
+
* expect(mockFunc).toHaveBeenCalledWith('arg1', 42);
|
|
1037
|
+
*/
|
|
1038
|
+
toHaveBeenCalledWith: <E extends any[]>(...args: E) => void;
|
|
1039
|
+
/**
|
|
1040
|
+
* Ensure that a mock function is called with specific arguments.
|
|
1041
|
+
*
|
|
1042
|
+
* Alias for `expect.toHaveBeenCalledWith`.
|
|
1043
|
+
*
|
|
1044
|
+
* @example
|
|
1045
|
+
* expect(mockFunc).toBeCalledWith('arg1', 42);
|
|
1046
|
+
* @deprecated Use `toHaveBeenCalledWith` instead
|
|
1047
|
+
*/
|
|
1048
|
+
toBeCalledWith: <E extends any[]>(...args: E) => void;
|
|
1049
|
+
/**
|
|
1050
|
+
* Ensure that a mock function is called with specific arguments on an Nth call.
|
|
1051
|
+
*
|
|
1052
|
+
* Also under the alias `expect.nthCalledWith`.
|
|
1053
|
+
*
|
|
1054
|
+
* @example
|
|
1055
|
+
* expect(mockFunc).toHaveBeenNthCalledWith(2, 'secondArg');
|
|
1056
|
+
*/
|
|
1057
|
+
toHaveBeenNthCalledWith: <E extends any[]>(n: number, ...args: E) => void;
|
|
1058
|
+
/**
|
|
1059
|
+
* If you have a mock function, you can use `.toHaveBeenLastCalledWith`
|
|
1060
|
+
* to test what arguments it was last called with.
|
|
1061
|
+
*
|
|
1062
|
+
* Also under the alias `expect.lastCalledWith`.
|
|
1063
|
+
*
|
|
1064
|
+
* @example
|
|
1065
|
+
* expect(mockFunc).toHaveBeenLastCalledWith('lastArg');
|
|
1066
|
+
*/
|
|
1067
|
+
toHaveBeenLastCalledWith: <E extends any[]>(...args: E) => void;
|
|
1068
|
+
/**
|
|
1069
|
+
* Used to test that a function throws when it is called.
|
|
1070
|
+
*
|
|
1071
|
+
* Also under the alias `expect.toThrowError`.
|
|
1072
|
+
*
|
|
1073
|
+
* @example
|
|
1074
|
+
* expect(() => functionWithError()).toThrow('Error message');
|
|
1075
|
+
* expect(() => parseJSON('invalid')).toThrow(SyntaxError);
|
|
1076
|
+
* expect(() => { throw 42 }).toThrow(42);
|
|
1077
|
+
*/
|
|
1078
|
+
toThrow: (expected?: any) => void;
|
|
1079
|
+
/**
|
|
1080
|
+
* Used to test that a function throws when it is called.
|
|
1081
|
+
*
|
|
1082
|
+
* Alias for `expect.toThrow`.
|
|
1083
|
+
*
|
|
1084
|
+
* @example
|
|
1085
|
+
* expect(() => functionWithError()).toThrowError('Error message');
|
|
1086
|
+
* expect(() => parseJSON('invalid')).toThrowError(SyntaxError);
|
|
1087
|
+
* expect(() => { throw 42 }).toThrowError(42);
|
|
1088
|
+
* @deprecated Use `toThrow` instead
|
|
1089
|
+
*/
|
|
1090
|
+
toThrowError: (expected?: any) => void;
|
|
1091
|
+
/**
|
|
1092
|
+
* Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
|
|
1093
|
+
*
|
|
1094
|
+
* Alias for `expect.toHaveReturned`.
|
|
1095
|
+
*
|
|
1096
|
+
* @example
|
|
1097
|
+
* expect(mockFunc).toReturn();
|
|
1098
|
+
* @deprecated Use `toHaveReturned` instead
|
|
1099
|
+
*/
|
|
1100
|
+
toReturn: () => void;
|
|
1101
|
+
/**
|
|
1102
|
+
* Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
|
|
1103
|
+
*
|
|
1104
|
+
* Also under the alias `expect.toReturn`.
|
|
1105
|
+
*
|
|
1106
|
+
* @example
|
|
1107
|
+
* expect(mockFunc).toHaveReturned();
|
|
1108
|
+
*/
|
|
1109
|
+
toHaveReturned: () => void;
|
|
1110
|
+
/**
|
|
1111
|
+
* Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
|
|
1112
|
+
* Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
|
|
1113
|
+
*
|
|
1114
|
+
* Alias for `expect.toHaveReturnedTimes`.
|
|
1115
|
+
*
|
|
1116
|
+
* @example
|
|
1117
|
+
* expect(mockFunc).toReturnTimes(3);
|
|
1118
|
+
* @deprecated Use `toHaveReturnedTimes` instead
|
|
1119
|
+
*/
|
|
1120
|
+
toReturnTimes: (times: number) => void;
|
|
1121
|
+
/**
|
|
1122
|
+
* Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
|
|
1123
|
+
* Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
|
|
1124
|
+
*
|
|
1125
|
+
* Also under the alias `expect.toReturnTimes`.
|
|
1126
|
+
*
|
|
1127
|
+
* @example
|
|
1128
|
+
* expect(mockFunc).toHaveReturnedTimes(3);
|
|
1129
|
+
*/
|
|
1130
|
+
toHaveReturnedTimes: (times: number) => void;
|
|
1131
|
+
/**
|
|
1132
|
+
* Use to ensure that a mock function returned a specific value.
|
|
1133
|
+
*
|
|
1134
|
+
* Alias for `expect.toHaveReturnedWith`.
|
|
1135
|
+
*
|
|
1136
|
+
* @example
|
|
1137
|
+
* expect(mockFunc).toReturnWith('returnValue');
|
|
1138
|
+
* @deprecated Use `toHaveReturnedWith` instead
|
|
1139
|
+
*/
|
|
1140
|
+
toReturnWith: <E>(value: E) => void;
|
|
1141
|
+
/**
|
|
1142
|
+
* Use to ensure that a mock function returned a specific value.
|
|
1143
|
+
*
|
|
1144
|
+
* Also under the alias `expect.toReturnWith`.
|
|
1145
|
+
*
|
|
1146
|
+
* @example
|
|
1147
|
+
* expect(mockFunc).toHaveReturnedWith('returnValue');
|
|
1148
|
+
*/
|
|
1149
|
+
toHaveReturnedWith: <E>(value: E) => void;
|
|
1150
|
+
/**
|
|
1151
|
+
* Use to test the specific value that a mock function last returned.
|
|
1152
|
+
* If the last call to the mock function threw an error, then this matcher will fail
|
|
1153
|
+
* no matter what value you provided as the expected return value.
|
|
1154
|
+
*
|
|
1155
|
+
* Also under the alias `expect.lastReturnedWith`.
|
|
1156
|
+
*
|
|
1157
|
+
* @example
|
|
1158
|
+
* expect(mockFunc).toHaveLastReturnedWith('lastValue');
|
|
1159
|
+
*/
|
|
1160
|
+
toHaveLastReturnedWith: <E>(value: E) => void;
|
|
1161
|
+
/**
|
|
1162
|
+
* Use to test the specific value that a mock function returned for the nth call.
|
|
1163
|
+
* If the nth call to the mock function threw an error, then this matcher will fail
|
|
1164
|
+
* no matter what value you provided as the expected return value.
|
|
1165
|
+
*
|
|
1166
|
+
* Also under the alias `expect.nthReturnedWith`.
|
|
1167
|
+
*
|
|
1168
|
+
* @example
|
|
1169
|
+
* expect(mockFunc).toHaveNthReturnedWith(2, 'nthValue');
|
|
1170
|
+
*/
|
|
1171
|
+
toHaveNthReturnedWith: <E>(nthCall: number, value: E) => void;
|
|
1172
|
+
}
|
|
1173
|
+
type VitestAssertion<A, T> = { [K in keyof A]: A[K] extends Chai.Assertion ? Assertion<T> : A[K] extends ((...args: any[]) => any) ? A[K] : VitestAssertion<A[K], T> } & ((type: string, message?: string) => Assertion);
|
|
1174
|
+
type Promisify<O> = { [K in keyof O]: O[K] extends ((...args: infer A) => infer R) ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K] };
|
|
1175
|
+
type PromisifyAssertion<T> = Promisify<Assertion<T>>;
|
|
1176
|
+
interface Assertion<T = any> extends VitestAssertion<Chai.Assertion, T>, JestAssertion<T>, ChaiMockAssertion, Matchers<T> {
|
|
1177
|
+
/**
|
|
1178
|
+
* Ensures a value is of a specific type.
|
|
1179
|
+
*
|
|
1180
|
+
* @example
|
|
1181
|
+
* expect(value).toBeTypeOf('string');
|
|
1182
|
+
* expect(number).toBeTypeOf('number');
|
|
1183
|
+
*/
|
|
1184
|
+
toBeTypeOf: (expected: "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined") => void;
|
|
1185
|
+
/**
|
|
1186
|
+
* Asserts that a mock function was called exactly once.
|
|
1187
|
+
*
|
|
1188
|
+
* @example
|
|
1189
|
+
* expect(mockFunc).toHaveBeenCalledOnce();
|
|
1190
|
+
*/
|
|
1191
|
+
toHaveBeenCalledOnce: () => void;
|
|
1192
|
+
/**
|
|
1193
|
+
* Ensure that a mock function is called with specific arguments and called
|
|
1194
|
+
* exactly once.
|
|
1195
|
+
*
|
|
1196
|
+
* @example
|
|
1197
|
+
* expect(mockFunc).toHaveBeenCalledExactlyOnceWith('arg1', 42);
|
|
1198
|
+
*/
|
|
1199
|
+
toHaveBeenCalledExactlyOnceWith: <E extends any[]>(...args: E) => void;
|
|
1200
|
+
/**
|
|
1201
|
+
* This assertion checks if a `Mock` was called before another `Mock`.
|
|
1202
|
+
* @param mock - A mock function created by `vi.spyOn` or `vi.fn`
|
|
1203
|
+
* @param failIfNoFirstInvocation - Fail if the first mock was never called
|
|
1204
|
+
* @example
|
|
1205
|
+
* const mock1 = vi.fn()
|
|
1206
|
+
* const mock2 = vi.fn()
|
|
1207
|
+
*
|
|
1208
|
+
* mock1()
|
|
1209
|
+
* mock2()
|
|
1210
|
+
* mock1()
|
|
1211
|
+
*
|
|
1212
|
+
* expect(mock1).toHaveBeenCalledBefore(mock2)
|
|
1213
|
+
*/
|
|
1214
|
+
toHaveBeenCalledBefore: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
|
|
1215
|
+
/**
|
|
1216
|
+
* This assertion checks if a `Mock` was called after another `Mock`.
|
|
1217
|
+
* @param mock - A mock function created by `vi.spyOn` or `vi.fn`
|
|
1218
|
+
* @param failIfNoFirstInvocation - Fail if the first mock was never called
|
|
1219
|
+
* @example
|
|
1220
|
+
* const mock1 = vi.fn()
|
|
1221
|
+
* const mock2 = vi.fn()
|
|
1222
|
+
*
|
|
1223
|
+
* mock2()
|
|
1224
|
+
* mock1()
|
|
1225
|
+
* mock2()
|
|
1226
|
+
*
|
|
1227
|
+
* expect(mock1).toHaveBeenCalledAfter(mock2)
|
|
1228
|
+
*/
|
|
1229
|
+
toHaveBeenCalledAfter: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
|
|
1230
|
+
/**
|
|
1231
|
+
* Checks that a promise resolves successfully at least once.
|
|
1232
|
+
*
|
|
1233
|
+
* @example
|
|
1234
|
+
* await expect(promise).toHaveResolved();
|
|
1235
|
+
*/
|
|
1236
|
+
toHaveResolved: () => void;
|
|
1237
|
+
/**
|
|
1238
|
+
* Checks that a promise resolves to a specific value.
|
|
1239
|
+
*
|
|
1240
|
+
* @example
|
|
1241
|
+
* await expect(promise).toHaveResolvedWith('success');
|
|
1242
|
+
*/
|
|
1243
|
+
toHaveResolvedWith: <E>(value: E) => void;
|
|
1244
|
+
/**
|
|
1245
|
+
* Ensures a promise resolves a specific number of times.
|
|
1246
|
+
*
|
|
1247
|
+
* @example
|
|
1248
|
+
* expect(mockAsyncFunc).toHaveResolvedTimes(3);
|
|
1249
|
+
*/
|
|
1250
|
+
toHaveResolvedTimes: (times: number) => void;
|
|
1251
|
+
/**
|
|
1252
|
+
* Asserts that the last resolved value of a promise matches an expected value.
|
|
1253
|
+
*
|
|
1254
|
+
* @example
|
|
1255
|
+
* await expect(mockAsyncFunc).toHaveLastResolvedWith('finalResult');
|
|
1256
|
+
*/
|
|
1257
|
+
toHaveLastResolvedWith: <E>(value: E) => void;
|
|
1258
|
+
/**
|
|
1259
|
+
* Ensures a specific value was returned by a promise on the nth resolution.
|
|
1260
|
+
*
|
|
1261
|
+
* @example
|
|
1262
|
+
* await expect(mockAsyncFunc).toHaveNthResolvedWith(2, 'secondResult');
|
|
1263
|
+
*/
|
|
1264
|
+
toHaveNthResolvedWith: <E>(nthCall: number, value: E) => void;
|
|
1265
|
+
/**
|
|
1266
|
+
* Verifies that a promise resolves.
|
|
1267
|
+
*
|
|
1268
|
+
* @example
|
|
1269
|
+
* await expect(someAsyncFunc).resolves.toBe(42);
|
|
1270
|
+
*/
|
|
1271
|
+
resolves: PromisifyAssertion<T>;
|
|
1272
|
+
/**
|
|
1273
|
+
* Verifies that a promise rejects.
|
|
1274
|
+
*
|
|
1275
|
+
* @example
|
|
1276
|
+
* await expect(someAsyncFunc).rejects.toThrow('error');
|
|
1277
|
+
*/
|
|
1278
|
+
rejects: PromisifyAssertion<T>;
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* Chai-style assertions for spy/mock testing.
|
|
1282
|
+
* These provide sinon-chai compatible assertion names that delegate to Jest-style implementations.
|
|
1283
|
+
*/
|
|
1284
|
+
interface ChaiMockAssertion {
|
|
1285
|
+
/**
|
|
1286
|
+
* Checks that a spy was called at least once.
|
|
1287
|
+
* Chai-style equivalent of `toHaveBeenCalled`.
|
|
1288
|
+
*
|
|
1289
|
+
* @example
|
|
1290
|
+
* expect(spy).to.have.been.called
|
|
1291
|
+
*/
|
|
1292
|
+
readonly called: Assertion;
|
|
1293
|
+
/**
|
|
1294
|
+
* Checks that a spy was called a specific number of times.
|
|
1295
|
+
* Chai-style equivalent of `toHaveBeenCalledTimes`.
|
|
1296
|
+
*
|
|
1297
|
+
* @example
|
|
1298
|
+
* expect(spy).to.have.callCount(3)
|
|
1299
|
+
*/
|
|
1300
|
+
callCount: (count: number) => void;
|
|
1301
|
+
/**
|
|
1302
|
+
* Checks that a spy was called with specific arguments at least once.
|
|
1303
|
+
* Chai-style equivalent of `toHaveBeenCalledWith`.
|
|
1304
|
+
*
|
|
1305
|
+
* @example
|
|
1306
|
+
* expect(spy).to.have.been.calledWith('arg1', 'arg2')
|
|
1307
|
+
*/
|
|
1308
|
+
calledWith: <E extends any[]>(...args: E) => void;
|
|
1309
|
+
/**
|
|
1310
|
+
* Checks that a spy was called exactly once.
|
|
1311
|
+
* Chai-style equivalent of `toHaveBeenCalledOnce`.
|
|
1312
|
+
*
|
|
1313
|
+
* @example
|
|
1314
|
+
* expect(spy).to.have.been.calledOnce
|
|
1315
|
+
*/
|
|
1316
|
+
readonly calledOnce: Assertion;
|
|
1317
|
+
/**
|
|
1318
|
+
* Checks that a spy was called exactly once with specific arguments.
|
|
1319
|
+
* Chai-style equivalent of `toHaveBeenCalledExactlyOnceWith`.
|
|
1320
|
+
*
|
|
1321
|
+
* @example
|
|
1322
|
+
* expect(spy).to.have.been.calledOnceWith('arg1', 'arg2')
|
|
1323
|
+
*/
|
|
1324
|
+
calledOnceWith: <E extends any[]>(...args: E) => void;
|
|
1325
|
+
/**
|
|
1326
|
+
* Checks that the last call to a spy was made with specific arguments.
|
|
1327
|
+
* Chai-style equivalent of `toHaveBeenLastCalledWith`.
|
|
1328
|
+
*
|
|
1329
|
+
* @example
|
|
1330
|
+
* expect(spy).to.have.been.lastCalledWith('arg1', 'arg2')
|
|
1331
|
+
*/
|
|
1332
|
+
lastCalledWith: <E extends any[]>(...args: E) => void;
|
|
1333
|
+
/**
|
|
1334
|
+
* Checks that the nth call to a spy was made with specific arguments.
|
|
1335
|
+
* Chai-style equivalent of `toHaveBeenNthCalledWith`.
|
|
1336
|
+
*
|
|
1337
|
+
* @example
|
|
1338
|
+
* expect(spy).to.have.been.nthCalledWith(2, 'arg1', 'arg2')
|
|
1339
|
+
*/
|
|
1340
|
+
nthCalledWith: <E extends any[]>(n: number, ...args: E) => void;
|
|
1341
|
+
/**
|
|
1342
|
+
* Checks that a spy returned a specific value at least once.
|
|
1343
|
+
* Chai-style equivalent of `toHaveReturnedWith`.
|
|
1344
|
+
*
|
|
1345
|
+
* @example
|
|
1346
|
+
* expect(spy).to.have.returned('value')
|
|
1347
|
+
*/
|
|
1348
|
+
returned: <E>(value: E) => void;
|
|
1349
|
+
/**
|
|
1350
|
+
* Checks that a spy returned a specific value at least once.
|
|
1351
|
+
* Chai-style equivalent of `toHaveReturnedWith`.
|
|
1352
|
+
*
|
|
1353
|
+
* @example
|
|
1354
|
+
* expect(spy).to.have.returnedWith('value')
|
|
1355
|
+
*/
|
|
1356
|
+
returnedWith: <E>(value: E) => void;
|
|
1357
|
+
/**
|
|
1358
|
+
* Checks that a spy returned successfully a specific number of times.
|
|
1359
|
+
* Chai-style equivalent of `toHaveReturnedTimes`.
|
|
1360
|
+
*
|
|
1361
|
+
* @example
|
|
1362
|
+
* expect(spy).to.have.returnedTimes(3)
|
|
1363
|
+
*/
|
|
1364
|
+
returnedTimes: (count: number) => void;
|
|
1365
|
+
/**
|
|
1366
|
+
* Checks that the last return value of a spy matches the expected value.
|
|
1367
|
+
* Chai-style equivalent of `toHaveLastReturnedWith`.
|
|
1368
|
+
*
|
|
1369
|
+
* @example
|
|
1370
|
+
* expect(spy).to.have.lastReturnedWith('value')
|
|
1371
|
+
*/
|
|
1372
|
+
lastReturnedWith: <E>(value: E) => void;
|
|
1373
|
+
/**
|
|
1374
|
+
* Checks that the nth return value of a spy matches the expected value.
|
|
1375
|
+
* Chai-style equivalent of `toHaveNthReturnedWith`.
|
|
1376
|
+
*
|
|
1377
|
+
* @example
|
|
1378
|
+
* expect(spy).to.have.nthReturnedWith(2, 'value')
|
|
1379
|
+
*/
|
|
1380
|
+
nthReturnedWith: <E>(n: number, value: E) => void;
|
|
1381
|
+
/**
|
|
1382
|
+
* Checks that a spy was called before another spy.
|
|
1383
|
+
* Chai-style equivalent of `toHaveBeenCalledBefore`.
|
|
1384
|
+
*
|
|
1385
|
+
* @example
|
|
1386
|
+
* expect(spy1).to.have.been.calledBefore(spy2)
|
|
1387
|
+
*/
|
|
1388
|
+
calledBefore: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
|
|
1389
|
+
/**
|
|
1390
|
+
* Checks that a spy was called after another spy.
|
|
1391
|
+
* Chai-style equivalent of `toHaveBeenCalledAfter`.
|
|
1392
|
+
*
|
|
1393
|
+
* @example
|
|
1394
|
+
* expect(spy1).to.have.been.calledAfter(spy2)
|
|
1395
|
+
*/
|
|
1396
|
+
calledAfter: (mock: MockInstance, failIfNoFirstInvocation?: boolean) => void;
|
|
1397
|
+
/**
|
|
1398
|
+
* Checks that a spy was called exactly twice.
|
|
1399
|
+
* Chai-style equivalent of `toHaveBeenCalledTimes(2)`.
|
|
1400
|
+
*
|
|
1401
|
+
* @example
|
|
1402
|
+
* expect(spy).to.have.been.calledTwice
|
|
1403
|
+
*/
|
|
1404
|
+
readonly calledTwice: Assertion;
|
|
1405
|
+
/**
|
|
1406
|
+
* Checks that a spy was called exactly three times.
|
|
1407
|
+
* Chai-style equivalent of `toHaveBeenCalledTimes(3)`.
|
|
1408
|
+
*
|
|
1409
|
+
* @example
|
|
1410
|
+
* expect(spy).to.have.been.calledThrice
|
|
1411
|
+
*/
|
|
1412
|
+
readonly calledThrice: Assertion;
|
|
1413
|
+
}
|
|
1414
|
+
declare global {
|
|
1415
|
+
namespace jest {
|
|
1416
|
+
interface Matchers<R, T = {}> {}
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
//#endregion
|
|
1420
|
+
//#region node_modules/@vitest/utils/dist/types.d.ts
|
|
1421
|
+
type Awaitable<T> = T | PromiseLike<T>;
|
|
1422
|
+
interface ParsedStack {
|
|
1423
|
+
method: string;
|
|
1424
|
+
file: string;
|
|
1425
|
+
line: number;
|
|
1426
|
+
column: number;
|
|
1427
|
+
}
|
|
1428
|
+
interface SerializedError {
|
|
1429
|
+
message: string;
|
|
1430
|
+
stacks?: ParsedStack[];
|
|
1431
|
+
stack?: string;
|
|
1432
|
+
name?: string;
|
|
1433
|
+
cause?: SerializedError;
|
|
1434
|
+
[key: string]: unknown;
|
|
1435
|
+
}
|
|
1436
|
+
interface TestError extends SerializedError {
|
|
1437
|
+
cause?: TestError;
|
|
1438
|
+
diff?: string;
|
|
1439
|
+
actual?: string;
|
|
1440
|
+
expected?: string;
|
|
1441
|
+
}
|
|
1442
|
+
//#endregion
|
|
1443
|
+
//#region src/vendored/runtime/runner/fixture.d.ts
|
|
1444
|
+
interface TestFixtureItem extends FixtureOptions {
|
|
1445
|
+
name: string;
|
|
1446
|
+
value: unknown;
|
|
1447
|
+
scope: 'test' | 'file' | 'worker';
|
|
1448
|
+
deps: Set<string>;
|
|
1449
|
+
parent?: TestFixtureItem;
|
|
1450
|
+
}
|
|
1451
|
+
type UserFixtures = Record<string, unknown>;
|
|
1452
|
+
type FixtureRegistrations = Map<string, TestFixtureItem>;
|
|
1453
|
+
declare class TestFixtures {
|
|
1454
|
+
private _suiteContexts;
|
|
1455
|
+
private _overrides;
|
|
1456
|
+
private _registrations;
|
|
1457
|
+
private static _definitions;
|
|
1458
|
+
private static _builtinFixtures;
|
|
1459
|
+
private static _fixtureOptionKeys;
|
|
1460
|
+
private static _fixtureScopes;
|
|
1461
|
+
private static _workerContextSuite;
|
|
1462
|
+
static clearDefinitions(): void;
|
|
1463
|
+
static getWorkerContexts(): Record<string, any>[];
|
|
1464
|
+
static getFileContexts(file: File): Record<string, any>[];
|
|
1465
|
+
static isFixtureOptions(obj: unknown): boolean;
|
|
1466
|
+
constructor(registrations?: FixtureRegistrations);
|
|
1467
|
+
extend(runner: VitestRunner, userFixtures: UserFixtures): TestFixtures;
|
|
1468
|
+
get(suite: Suite): FixtureRegistrations;
|
|
1469
|
+
override(runner: VitestRunner, userFixtures: UserFixtures): void;
|
|
1470
|
+
getFileContext(file: File): Record<string, any>;
|
|
1471
|
+
getWorkerContext(): Record<string, any>;
|
|
1472
|
+
private parseUserFixtures;
|
|
1473
|
+
}
|
|
1474
|
+
//#endregion
|
|
1475
|
+
//#region src/vendored/runtime/runner/hooks.d.ts
|
|
1476
|
+
/**
|
|
1477
|
+
* Registers a callback function to be executed once before all tests within the current suite.
|
|
1478
|
+
* This hook is useful for scenarios where you need to perform setup operations that are common to all tests in a suite, such as initializing a database connection or setting up a test environment.
|
|
1479
|
+
*
|
|
1480
|
+
* **Note:** The `beforeAll` hooks are executed in the order they are defined one after another. You can configure this by changing the `sequence.hooks` option in the config file.
|
|
1481
|
+
*
|
|
1482
|
+
* @param {Function} fn - The callback function to be executed before all tests.
|
|
1483
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
|
1484
|
+
* @returns {void}
|
|
1485
|
+
* @example
|
|
1486
|
+
* ```ts
|
|
1487
|
+
* // Example of using beforeAll to set up a database connection
|
|
1488
|
+
* beforeAll(async () => {
|
|
1489
|
+
* await database.connect();
|
|
1490
|
+
* });
|
|
1491
|
+
* ```
|
|
1492
|
+
*/
|
|
1493
|
+
declare function beforeAll<ExtraContext = object>(this: unknown, fn: BeforeAllListener<ExtraContext>, timeout?: number): void;
|
|
1494
|
+
/**
|
|
1495
|
+
* Registers a callback function to be executed once after all tests within the current suite have completed.
|
|
1496
|
+
* This hook is useful for scenarios where you need to perform cleanup operations after all tests in a suite have run, such as closing database connections or cleaning up temporary files.
|
|
1497
|
+
*
|
|
1498
|
+
* **Note:** The `afterAll` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
|
|
1499
|
+
*
|
|
1500
|
+
* @param {Function} fn - The callback function to be executed after all tests.
|
|
1501
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
|
1502
|
+
* @returns {void}
|
|
1503
|
+
* @example
|
|
1504
|
+
* ```ts
|
|
1505
|
+
* // Example of using afterAll to close a database connection
|
|
1506
|
+
* afterAll(async () => {
|
|
1507
|
+
* await database.disconnect();
|
|
1508
|
+
* });
|
|
1509
|
+
* ```
|
|
1510
|
+
*/
|
|
1511
|
+
declare function afterAll<ExtraContext = object>(this: unknown, fn: AfterAllListener<ExtraContext>, timeout?: number): void;
|
|
1512
|
+
/**
|
|
1513
|
+
* Registers a callback function to be executed before each test within the current suite.
|
|
1514
|
+
* This hook is useful for scenarios where you need to reset or reinitialize the test environment before each test runs, such as resetting database states, clearing caches, or reinitializing variables.
|
|
1515
|
+
*
|
|
1516
|
+
* **Note:** The `beforeEach` hooks are executed in the order they are defined one after another. You can configure this by changing the `sequence.hooks` option in the config file.
|
|
1517
|
+
*
|
|
1518
|
+
* @param {Function} fn - The callback function to be executed before each test. This function receives an `TestContext` parameter if additional test context is needed.
|
|
1519
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
|
1520
|
+
* @returns {void}
|
|
1521
|
+
* @example
|
|
1522
|
+
* ```ts
|
|
1523
|
+
* // Example of using beforeEach to reset a database state
|
|
1524
|
+
* beforeEach(async () => {
|
|
1525
|
+
* await database.reset();
|
|
1526
|
+
* });
|
|
1527
|
+
* ```
|
|
1528
|
+
*/
|
|
1529
|
+
declare function beforeEach<ExtraContext = object>(fn: BeforeEachListener<ExtraContext>, timeout?: number): void;
|
|
1530
|
+
/**
|
|
1531
|
+
* Registers a callback function to be executed after each test within the current suite has completed.
|
|
1532
|
+
* This hook is useful for scenarios where you need to clean up or reset the test environment after each test runs, such as deleting temporary files, clearing test-specific database entries, or resetting mocked functions.
|
|
1533
|
+
*
|
|
1534
|
+
* **Note:** The `afterEach` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
|
|
1535
|
+
*
|
|
1536
|
+
* @param {Function} fn - The callback function to be executed after each test. This function receives an `TestContext` parameter if additional test context is needed.
|
|
1537
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
|
1538
|
+
* @returns {void}
|
|
1539
|
+
* @example
|
|
1540
|
+
* ```ts
|
|
1541
|
+
* // Example of using afterEach to delete temporary files created during a test
|
|
1542
|
+
* afterEach(async () => {
|
|
1543
|
+
* await fileSystem.deleteTempFiles();
|
|
1544
|
+
* });
|
|
1545
|
+
* ```
|
|
1546
|
+
*/
|
|
1547
|
+
declare function afterEach<ExtraContext = object>(fn: AfterEachListener<ExtraContext>, timeout?: number): void;
|
|
1548
|
+
/**
|
|
1549
|
+
* Registers a callback function to be executed when a test fails within the current suite.
|
|
1550
|
+
* This function allows for custom actions to be performed in response to test failures, such as logging, cleanup, or additional diagnostics.
|
|
1551
|
+
*
|
|
1552
|
+
* **Note:** The `onTestFailed` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
|
|
1553
|
+
*
|
|
1554
|
+
* @param {Function} fn - The callback function to be executed upon a test failure. The function receives the test result (including errors).
|
|
1555
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
|
1556
|
+
* @throws {Error} Throws an error if the function is not called within a test.
|
|
1557
|
+
* @returns {void}
|
|
1558
|
+
* @example
|
|
1559
|
+
* ```ts
|
|
1560
|
+
* // Example of using onTestFailed to log failure details
|
|
1561
|
+
* onTestFailed(({ errors }) => {
|
|
1562
|
+
* console.log(`Test failed: ${test.name}`, errors);
|
|
1563
|
+
* });
|
|
1564
|
+
* ```
|
|
1565
|
+
*/
|
|
1566
|
+
declare const onTestFailed: TaskHook<OnTestFailedHandler>;
|
|
1567
|
+
/**
|
|
1568
|
+
* Registers a callback function to be executed when the current test finishes, regardless of the outcome (pass or fail).
|
|
1569
|
+
* This function is ideal for performing actions that should occur after every test execution, such as cleanup, logging, or resetting shared resources.
|
|
1570
|
+
*
|
|
1571
|
+
* This hook is useful if you have access to a resource in the test itself and you want to clean it up after the test finishes. It is a more compact way to clean up resources than using the combination of `beforeEach` and `afterEach`.
|
|
1572
|
+
*
|
|
1573
|
+
* **Note:** The `onTestFinished` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
|
|
1574
|
+
*
|
|
1575
|
+
* **Note:** The `onTestFinished` hook is not called if the test is canceled with a dynamic `ctx.skip()` call.
|
|
1576
|
+
*
|
|
1577
|
+
* @param {Function} fn - The callback function to be executed after a test finishes. The function can receive parameters providing details about the completed test, including its success or failure status.
|
|
1578
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
|
1579
|
+
* @throws {Error} Throws an error if the function is not called within a test.
|
|
1580
|
+
* @returns {void}
|
|
1581
|
+
* @example
|
|
1582
|
+
* ```ts
|
|
1583
|
+
* // Example of using onTestFinished for cleanup
|
|
1584
|
+
* const db = await connectToDatabase();
|
|
1585
|
+
* onTestFinished(async () => {
|
|
1586
|
+
* await db.disconnect();
|
|
1587
|
+
* });
|
|
1588
|
+
* ```
|
|
1589
|
+
*/
|
|
1590
|
+
declare const onTestFinished: TaskHook<OnTestFinishedHandler>;
|
|
1591
|
+
/**
|
|
1592
|
+
* Registers a callback function that wraps around all tests within the current suite.
|
|
1593
|
+
* The callback receives a `runSuite` function that must be called to run the suite's tests.
|
|
1594
|
+
* This hook is useful for scenarios where you need to wrap an entire suite in a context
|
|
1595
|
+
* (e.g., starting a server, opening a database connection that all tests share).
|
|
1596
|
+
*
|
|
1597
|
+
* **Note:** When multiple `aroundAll` hooks are registered, they are nested inside each other.
|
|
1598
|
+
* The first registered hook is the outermost wrapper.
|
|
1599
|
+
*
|
|
1600
|
+
* @param {Function} fn - The callback function that wraps the suite. Must call `runSuite()` to run the tests.
|
|
1601
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
|
1602
|
+
* @returns {void}
|
|
1603
|
+
* @example
|
|
1604
|
+
* ```ts
|
|
1605
|
+
* // Example of using aroundAll to wrap suite in a tracing span
|
|
1606
|
+
* aroundAll(async (runSuite) => {
|
|
1607
|
+
* await tracer.trace('test-suite', runSuite);
|
|
1608
|
+
* });
|
|
1609
|
+
* ```
|
|
1610
|
+
* @example
|
|
1611
|
+
* ```ts
|
|
1612
|
+
* // Example of using aroundAll with fixtures
|
|
1613
|
+
* aroundAll(async (runSuite, { db }) => {
|
|
1614
|
+
* await db.transaction(() => runSuite());
|
|
1615
|
+
* });
|
|
1616
|
+
* ```
|
|
1617
|
+
*/
|
|
1618
|
+
declare function aroundAll<ExtraContext = object>(this: unknown, fn: AroundAllListener<ExtraContext>, timeout?: number): void;
|
|
1619
|
+
/**
|
|
1620
|
+
* Registers a callback function that wraps around each test within the current suite.
|
|
1621
|
+
* The callback receives a `runTest` function that must be called to run the test.
|
|
1622
|
+
* This hook is useful for scenarios where you need to wrap tests in a context (e.g., database transactions).
|
|
1623
|
+
*
|
|
1624
|
+
* **Note:** When multiple `aroundEach` hooks are registered, they are nested inside each other.
|
|
1625
|
+
* The first registered hook is the outermost wrapper.
|
|
1626
|
+
*
|
|
1627
|
+
* @param {Function} fn - The callback function that wraps the test. Must call `runTest()` to run the test.
|
|
1628
|
+
* @param {number} [timeout] - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.
|
|
1629
|
+
* @returns {void}
|
|
1630
|
+
* @example
|
|
1631
|
+
* ```ts
|
|
1632
|
+
* // Example of using aroundEach to wrap tests in a database transaction
|
|
1633
|
+
* aroundEach(async (runTest) => {
|
|
1634
|
+
* await database.transaction(() => runTest());
|
|
1635
|
+
* });
|
|
1636
|
+
* ```
|
|
1637
|
+
* @example
|
|
1638
|
+
* ```ts
|
|
1639
|
+
* // Example of using aroundEach with fixtures
|
|
1640
|
+
* aroundEach(async (runTest, { db }) => {
|
|
1641
|
+
* await db.transaction(() => runTest());
|
|
1642
|
+
* });
|
|
1643
|
+
* ```
|
|
1644
|
+
*/
|
|
1645
|
+
declare function aroundEach<ExtraContext = object>(fn: AroundEachListener<ExtraContext>, timeout?: number): void;
|
|
1646
|
+
//#endregion
|
|
1647
|
+
//#region src/vendored/runtime/runner/utils/chain.d.ts
|
|
1648
|
+
type TypedChainableFunction<T, F extends (...args: any) => any, C = object> = F & { [x in keyof T]: TypedChainableFunction<T, F, C> } & {
|
|
1649
|
+
fn: (this: Record<keyof T, any>, ...args: Parameters<F>) => ReturnType<F>;
|
|
1650
|
+
} & C;
|
|
1651
|
+
declare const kChainableContext: unique symbol;
|
|
1652
|
+
//#endregion
|
|
1653
|
+
//#region src/vendored/runtime/runner/types.d.ts
|
|
1654
|
+
interface Statistics {
|
|
1655
|
+
samples: number[];
|
|
1656
|
+
min: number;
|
|
1657
|
+
max: number;
|
|
1658
|
+
hz: number;
|
|
1659
|
+
period: number;
|
|
1660
|
+
mean: number;
|
|
1661
|
+
variance: number;
|
|
1662
|
+
sd: number;
|
|
1663
|
+
sem: number;
|
|
1664
|
+
df: number;
|
|
1665
|
+
critical: number;
|
|
1666
|
+
moe: number;
|
|
1667
|
+
rme: number;
|
|
1668
|
+
p50?: number;
|
|
1669
|
+
p75: number;
|
|
1670
|
+
p99: number;
|
|
1671
|
+
p995: number;
|
|
1672
|
+
p999: number;
|
|
1673
|
+
}
|
|
1674
|
+
type UserConsoleLog = any;
|
|
1675
|
+
type Bench = any;
|
|
1676
|
+
type SerializedConfig = any;
|
|
1677
|
+
type RunMode = 'run' | 'skip' | 'only' | 'todo' | 'queued';
|
|
1678
|
+
type TaskState = RunMode | 'pass' | 'fail';
|
|
1679
|
+
interface TaskBase {
|
|
1680
|
+
/**
|
|
1681
|
+
* Unique task identifier. Based on the file id and the position of the task.
|
|
1682
|
+
* The id of the file task is based on the file path relative to root and project name.
|
|
1683
|
+
* It will not change between runs.
|
|
1684
|
+
* @example `1201091390`, `1201091390_0`, `1201091390_0_1`
|
|
1685
|
+
*/
|
|
1686
|
+
id: string;
|
|
1687
|
+
/**
|
|
1688
|
+
* Task name provided by the user. If no name was provided, it will be an empty string.
|
|
1689
|
+
*/
|
|
1690
|
+
name: string;
|
|
1691
|
+
/**
|
|
1692
|
+
* Full name including the file path, any parent suites, and this task's name.
|
|
1693
|
+
*
|
|
1694
|
+
* Uses ` > ` as the separator between levels.
|
|
1695
|
+
*
|
|
1696
|
+
* @example
|
|
1697
|
+
* // file
|
|
1698
|
+
* 'test/task-names.test.ts'
|
|
1699
|
+
* @example
|
|
1700
|
+
* // suite
|
|
1701
|
+
* 'test/task-names.test.ts > meal planning'
|
|
1702
|
+
* 'test/task-names.test.ts > meal planning > grocery lists'
|
|
1703
|
+
* @example
|
|
1704
|
+
* // test
|
|
1705
|
+
* 'test/task-names.test.ts > meal planning > grocery lists > calculates ingredients'
|
|
1706
|
+
*/
|
|
1707
|
+
fullName: string;
|
|
1708
|
+
/**
|
|
1709
|
+
* Full name excluding the file path, including any parent suites and this task's name. `undefined` for file tasks.
|
|
1710
|
+
*
|
|
1711
|
+
* Uses ` > ` as the separator between levels.
|
|
1712
|
+
*
|
|
1713
|
+
* @example
|
|
1714
|
+
* // file
|
|
1715
|
+
* undefined
|
|
1716
|
+
* @example
|
|
1717
|
+
* // suite
|
|
1718
|
+
* 'meal planning'
|
|
1719
|
+
* 'meal planning > grocery lists'
|
|
1720
|
+
* @example
|
|
1721
|
+
* // test
|
|
1722
|
+
* 'meal planning > grocery lists > calculates ingredients'
|
|
1723
|
+
*/
|
|
1724
|
+
fullTestName?: string;
|
|
1725
|
+
/**
|
|
1726
|
+
* Task mode.
|
|
1727
|
+
* - **skip**: task is skipped
|
|
1728
|
+
* - **only**: only this task and other tasks with `only` mode will run
|
|
1729
|
+
* - **todo**: task is marked as a todo, alias for `skip`
|
|
1730
|
+
* - **run**: task will run or already ran
|
|
1731
|
+
* - **queued**: task will start running next. It can only exist on the File
|
|
1732
|
+
*/
|
|
1733
|
+
mode: RunMode;
|
|
1734
|
+
/**
|
|
1735
|
+
* Custom metadata for the task. JSON reporter will save this data.
|
|
1736
|
+
*/
|
|
1737
|
+
meta: TaskMeta;
|
|
1738
|
+
/**
|
|
1739
|
+
* Whether the task was produced with `.each()` method.
|
|
1740
|
+
*/
|
|
1741
|
+
each?: boolean;
|
|
1742
|
+
/**
|
|
1743
|
+
* Whether the task should run concurrently with other tasks.
|
|
1744
|
+
*/
|
|
1745
|
+
concurrent?: boolean;
|
|
1746
|
+
/**
|
|
1747
|
+
* Whether the tasks of the suite run in a random order.
|
|
1748
|
+
*/
|
|
1749
|
+
shuffle?: boolean;
|
|
1750
|
+
/**
|
|
1751
|
+
* Suite that this task is part of. File task or the global suite will have no parent.
|
|
1752
|
+
*/
|
|
1753
|
+
suite?: Suite;
|
|
1754
|
+
/**
|
|
1755
|
+
* Result of the task. Suite and file tasks will only have the result if there
|
|
1756
|
+
* was an error during collection or inside `afterAll`/`beforeAll`.
|
|
1757
|
+
*/
|
|
1758
|
+
result?: TaskResult;
|
|
1759
|
+
/**
|
|
1760
|
+
* Retry configuration for the task.
|
|
1761
|
+
* - If a number, specifies how many times to retry
|
|
1762
|
+
* - If an object, allows fine-grained retry control
|
|
1763
|
+
* @default 0
|
|
1764
|
+
*/
|
|
1765
|
+
retry?: Retry;
|
|
1766
|
+
/**
|
|
1767
|
+
* The amount of times the task should be repeated after the successful run.
|
|
1768
|
+
* If the task fails, it will not be retried unless `retry` is specified.
|
|
1769
|
+
* @default 0
|
|
1770
|
+
*/
|
|
1771
|
+
repeats?: number;
|
|
1772
|
+
/**
|
|
1773
|
+
* Location of the task in the file. This field is populated only if
|
|
1774
|
+
* `includeTaskLocation` option is set. It is generated by calling `new Error`
|
|
1775
|
+
* and parsing the stack trace, so the location might differ depending on the runtime.
|
|
1776
|
+
*/
|
|
1777
|
+
location?: Location;
|
|
1778
|
+
/**
|
|
1779
|
+
* If the test was collected by parsing the file AST, and the name
|
|
1780
|
+
* is not a static string, this property will be set to `true`.
|
|
1781
|
+
* @experimental
|
|
1782
|
+
*/
|
|
1783
|
+
dynamic?: boolean;
|
|
1784
|
+
/**
|
|
1785
|
+
* Custom tags of the task. Useful for filtering tasks.
|
|
1786
|
+
*/
|
|
1787
|
+
tags?: string[];
|
|
1788
|
+
logs?: UserConsoleLog[];
|
|
1789
|
+
}
|
|
1790
|
+
interface TaskPopulated extends TaskBase {
|
|
1791
|
+
/**
|
|
1792
|
+
* File task. It's the root task of the file.
|
|
1793
|
+
*/
|
|
1794
|
+
file: File;
|
|
1795
|
+
/**
|
|
1796
|
+
* Whether the task should succeed if it fails. If the task fails, it will be marked as passed.
|
|
1797
|
+
*/
|
|
1798
|
+
fails?: boolean;
|
|
1799
|
+
/**
|
|
1800
|
+
* Hooks that will run if the task fails. The order depends on the `sequence.hooks` option.
|
|
1801
|
+
* @internal
|
|
1802
|
+
*/
|
|
1803
|
+
onFailed?: OnTestFailedHandler[];
|
|
1804
|
+
/**
|
|
1805
|
+
* Hooks that will run after the task finishes. The order depends on the `sequence.hooks` option.
|
|
1806
|
+
* @internal
|
|
1807
|
+
*/
|
|
1808
|
+
onFinished?: OnTestFinishedHandler[];
|
|
1809
|
+
/**
|
|
1810
|
+
* Store promises (from async expects) to wait for them before finishing the test
|
|
1811
|
+
*/
|
|
1812
|
+
promises?: Promise<any>[];
|
|
1813
|
+
}
|
|
1814
|
+
/**
|
|
1815
|
+
* Custom metadata that can be used in reporters.
|
|
1816
|
+
*/
|
|
1817
|
+
interface TaskMeta {
|
|
1818
|
+
typecheck?: boolean;
|
|
1819
|
+
benchmark?: boolean;
|
|
1820
|
+
__vitest_label__?: string;
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* The result of calling a task.
|
|
1824
|
+
*/
|
|
1825
|
+
interface TaskResult {
|
|
1826
|
+
/**
|
|
1827
|
+
* State of the task. Inherits the `task.mode` during collection.
|
|
1828
|
+
* When the task has finished, it will be changed to `pass` or `fail`.
|
|
1829
|
+
* - **pass**: task ran successfully
|
|
1830
|
+
* - **fail**: task failed
|
|
1831
|
+
*/
|
|
1832
|
+
state: TaskState;
|
|
1833
|
+
/**
|
|
1834
|
+
* Errors that occurred during the task execution. It is possible to have several errors
|
|
1835
|
+
* if `expect.soft()` failed multiple times or `retry` was triggered.
|
|
1836
|
+
*/
|
|
1837
|
+
errors?: TestError[];
|
|
1838
|
+
/**
|
|
1839
|
+
* How long in milliseconds the task took to run.
|
|
1840
|
+
*/
|
|
1841
|
+
duration?: number;
|
|
1842
|
+
/**
|
|
1843
|
+
* Time in milliseconds when the task started running.
|
|
1844
|
+
*/
|
|
1845
|
+
startTime?: number;
|
|
1846
|
+
/**
|
|
1847
|
+
* Heap size in bytes after the task finished.
|
|
1848
|
+
* Only available if `logHeapUsage` option is set and `process.memoryUsage` is defined.
|
|
1849
|
+
*/
|
|
1850
|
+
heap?: number;
|
|
1851
|
+
/**
|
|
1852
|
+
* State of related to this task hooks. Useful during reporting.
|
|
1853
|
+
*/
|
|
1854
|
+
hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
|
|
1855
|
+
/**
|
|
1856
|
+
* The amount of times the task was retried. The task is retried only if it
|
|
1857
|
+
* failed and `retry` option is set.
|
|
1858
|
+
*/
|
|
1859
|
+
retryCount?: number;
|
|
1860
|
+
/**
|
|
1861
|
+
* The amount of times the task was repeated. The task is repeated only if
|
|
1862
|
+
* `repeats` option is set. This number also contains `retryCount`.
|
|
1863
|
+
*/
|
|
1864
|
+
repeatCount?: number;
|
|
1865
|
+
/** @internal */
|
|
1866
|
+
note?: string;
|
|
1867
|
+
/**
|
|
1868
|
+
* Whether the task was skipped by calling `context.skip()`.
|
|
1869
|
+
* @internal
|
|
1870
|
+
*/
|
|
1871
|
+
pending?: boolean;
|
|
1872
|
+
}
|
|
1873
|
+
/** The time spent importing & executing a non-externalized file. */
|
|
1874
|
+
interface ImportDuration {
|
|
1875
|
+
/** The time spent importing & executing the file itself, not counting all non-externalized imports that the file does. */
|
|
1876
|
+
selfTime: number;
|
|
1877
|
+
/** The time spent importing & executing the file and all its imports. */
|
|
1878
|
+
totalTime: number;
|
|
1879
|
+
/** Will be set to `true`, if the module was externalized. In this case totalTime and selfTime are identical. */
|
|
1880
|
+
external?: boolean;
|
|
1881
|
+
/** Which module imported this module first. All subsequent imports are cached. */
|
|
1882
|
+
importer?: string;
|
|
1883
|
+
}
|
|
1884
|
+
/**
|
|
1885
|
+
* The tuple representing a single task update.
|
|
1886
|
+
* Usually reported after the task finishes.
|
|
1887
|
+
*/
|
|
1888
|
+
type TaskResultPack = [
|
|
1889
|
+
/**
|
|
1890
|
+
* Unique task identifier from `task.id`.
|
|
1891
|
+
*/
|
|
1892
|
+
id: string,
|
|
1893
|
+
/**
|
|
1894
|
+
* The result of running the task from `task.result`.
|
|
1895
|
+
*/
|
|
1896
|
+
result: TaskResult | undefined,
|
|
1897
|
+
/**
|
|
1898
|
+
* Custom metadata from `task.meta`.
|
|
1899
|
+
*/
|
|
1900
|
+
meta: TaskMeta];
|
|
1901
|
+
interface TaskEventData {
|
|
1902
|
+
annotation?: TestAnnotation | undefined;
|
|
1903
|
+
artifact?: TestArtifact | undefined;
|
|
1904
|
+
}
|
|
1905
|
+
type TaskEventPack = [
|
|
1906
|
+
/**
|
|
1907
|
+
* Unique task identifier from `task.id`.
|
|
1908
|
+
*/
|
|
1909
|
+
id: string,
|
|
1910
|
+
/**
|
|
1911
|
+
* The name of the event that triggered the update.
|
|
1912
|
+
*/
|
|
1913
|
+
event: TaskUpdateEvent,
|
|
1914
|
+
/**
|
|
1915
|
+
* Data associated with the event
|
|
1916
|
+
*/
|
|
1917
|
+
data: TaskEventData | undefined];
|
|
1918
|
+
type TaskUpdateEvent = 'test-failed-early' | 'suite-failed-early' | 'test-prepare' | 'test-finished' | 'test-retried' | 'test-cancel' | 'suite-prepare' | 'suite-finished' | 'before-hook-start' | 'before-hook-end' | 'after-hook-start' | 'after-hook-end' | 'test-annotation' | 'test-artifact';
|
|
1919
|
+
interface Suite extends TaskBase {
|
|
1920
|
+
type: 'suite';
|
|
1921
|
+
/**
|
|
1922
|
+
* File task. It's the root task of the file.
|
|
1923
|
+
*/
|
|
1924
|
+
file: File;
|
|
1925
|
+
/**
|
|
1926
|
+
* An array of tasks that are part of the suite.
|
|
1927
|
+
*/
|
|
1928
|
+
tasks: Task[];
|
|
1929
|
+
}
|
|
1930
|
+
interface File extends Suite {
|
|
1931
|
+
/**
|
|
1932
|
+
* The name of the pool that the file belongs to.
|
|
1933
|
+
* @default 'forks'
|
|
1934
|
+
*/
|
|
1935
|
+
pool?: string;
|
|
1936
|
+
/**
|
|
1937
|
+
* The environment that processes the file on the server.
|
|
1938
|
+
*/
|
|
1939
|
+
viteEnvironment?: string;
|
|
1940
|
+
/**
|
|
1941
|
+
* The path to the file in UNIX format.
|
|
1942
|
+
*/
|
|
1943
|
+
filepath: string;
|
|
1944
|
+
/**
|
|
1945
|
+
* The name of the workspace project the file belongs to.
|
|
1946
|
+
*/
|
|
1947
|
+
projectName: string | undefined;
|
|
1948
|
+
/**
|
|
1949
|
+
* The time it took to collect all tests in the file.
|
|
1950
|
+
* This time also includes importing all the file dependencies.
|
|
1951
|
+
*/
|
|
1952
|
+
collectDuration?: number;
|
|
1953
|
+
/**
|
|
1954
|
+
* The time it took to import the setup file.
|
|
1955
|
+
*/
|
|
1956
|
+
setupDuration?: number;
|
|
1957
|
+
/**
|
|
1958
|
+
* Whether the file is initiated without running any tests.
|
|
1959
|
+
* This is done to populate state on the server side by Vitest.
|
|
1960
|
+
* @internal
|
|
1961
|
+
*/
|
|
1962
|
+
local?: boolean;
|
|
1963
|
+
/** The time spent importing every non-externalized dependency that Vitest has processed. */
|
|
1964
|
+
importDurations?: Record<string, ImportDuration>;
|
|
1965
|
+
prepareDuration?: number;
|
|
1966
|
+
environmentLoad?: number;
|
|
1967
|
+
concurrencyId: number;
|
|
1968
|
+
workerId: number;
|
|
1969
|
+
}
|
|
1970
|
+
interface Test<ExtraContext = object> extends TaskPopulated {
|
|
1971
|
+
type: 'test';
|
|
1972
|
+
/**
|
|
1973
|
+
* Test context that will be passed to the test function.
|
|
1974
|
+
*/
|
|
1975
|
+
context: TestContext & ExtraContext;
|
|
1976
|
+
/**
|
|
1977
|
+
* The test timeout in milliseconds.
|
|
1978
|
+
*/
|
|
1979
|
+
timeout: number;
|
|
1980
|
+
/**
|
|
1981
|
+
* An array of custom annotations.
|
|
1982
|
+
*/
|
|
1983
|
+
annotations: TestAnnotation[];
|
|
1984
|
+
/**
|
|
1985
|
+
* An array of artifacts produced by the test.
|
|
1986
|
+
*
|
|
1987
|
+
* @experimental
|
|
1988
|
+
*/
|
|
1989
|
+
artifacts: TestArtifact[];
|
|
1990
|
+
fullTestName: string;
|
|
1991
|
+
/**
|
|
1992
|
+
* An array of benchmark results generated by `context.bench` function.
|
|
1993
|
+
* The benchmark is added only after `bench().run` or `bench.compare` is resolved.
|
|
1994
|
+
*
|
|
1995
|
+
* @experimental
|
|
1996
|
+
*/
|
|
1997
|
+
benchmarks: TestBenchmark[];
|
|
1998
|
+
}
|
|
1999
|
+
interface TestBenchmark {
|
|
2000
|
+
name: string;
|
|
2001
|
+
tasks: TestBenchmarkTask[];
|
|
2002
|
+
}
|
|
2003
|
+
type TestBenchmarkStatistics = Statistics;
|
|
2004
|
+
interface TestBenchmarkTask {
|
|
2005
|
+
name: string;
|
|
2006
|
+
latency: TestBenchmarkStatistics;
|
|
2007
|
+
throughput: TestBenchmarkStatistics;
|
|
2008
|
+
period: number;
|
|
2009
|
+
totalTime: number;
|
|
2010
|
+
rank: number;
|
|
2011
|
+
perProject?: boolean;
|
|
2012
|
+
/**
|
|
2013
|
+
* `true` when the task was produced by `bench.from()` rather than by
|
|
2014
|
+
* executing a function. Reporters can use this to render the row as a
|
|
2015
|
+
* static reference (no margin of error, no samples).
|
|
2016
|
+
*/
|
|
2017
|
+
fromStore?: boolean;
|
|
2018
|
+
}
|
|
2019
|
+
type Task = Test | Suite | File;
|
|
2020
|
+
type TestFunction<ExtraContext = object> = (context: TestContext & ExtraContext) => Awaitable<any> | void;
|
|
2021
|
+
type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
|
|
2022
|
+
1: [T[0]];
|
|
2023
|
+
2: [T[0], T[1]];
|
|
2024
|
+
3: [T[0], T[1], T[2]];
|
|
2025
|
+
4: [T[0], T[1], T[2], T[3]];
|
|
2026
|
+
5: [T[0], T[1], T[2], T[3], T[4]];
|
|
2027
|
+
6: [T[0], T[1], T[2], T[3], T[4], T[5]];
|
|
2028
|
+
7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6]];
|
|
2029
|
+
8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7]];
|
|
2030
|
+
9: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8]];
|
|
2031
|
+
10: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8], T[9]];
|
|
2032
|
+
fallback: Array<T extends ReadonlyArray<infer U> ? U : any>;
|
|
2033
|
+
}[T extends Readonly<[any]> ? 1 : T extends Readonly<[any, any]> ? 2 : T extends Readonly<[any, any, any]> ? 3 : T extends Readonly<[any, any, any, any]> ? 4 : T extends Readonly<[any, any, any, any, any]> ? 5 : T extends Readonly<[any, any, any, any, any, any]> ? 6 : T extends Readonly<[any, any, any, any, any, any, any]> ? 7 : T extends Readonly<[any, any, any, any, any, any, any, any]> ? 8 : T extends Readonly<[any, any, any, any, any, any, any, any, any]> ? 9 : T extends Readonly<[any, any, any, any, any, any, any, any, any, any]> ? 10 : 'fallback'];
|
|
2034
|
+
interface EachFunctionReturn<T extends any[]> {
|
|
2035
|
+
(name: string | Function, fn: (...args: T) => Awaitable<void>, options?: number): void;
|
|
2036
|
+
(name: string | Function, options: TestCollectorOptions, fn: (...args: T) => Awaitable<void>): void;
|
|
2037
|
+
}
|
|
2038
|
+
interface TestEachFunction {
|
|
2039
|
+
<T extends any[] | [any]>(cases: ReadonlyArray<T>): EachFunctionReturn<T>;
|
|
2040
|
+
<T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): EachFunctionReturn<ExtractEachCallbackArgs<T>>;
|
|
2041
|
+
<T>(cases: ReadonlyArray<T>): EachFunctionReturn<T[]>;
|
|
2042
|
+
(...args: [TemplateStringsArray, ...any]): EachFunctionReturn<any[]>;
|
|
2043
|
+
}
|
|
2044
|
+
interface TestForFunctionReturn<Arg, Context> {
|
|
2045
|
+
(name: string | Function, fn: (arg: Arg, context: Context) => Awaitable<void>): void;
|
|
2046
|
+
(name: string | Function, options: TestCollectorOptions, fn: (args: Arg, context: Context) => Awaitable<void>): void;
|
|
2047
|
+
}
|
|
2048
|
+
interface TestForFunction<ExtraContext> {
|
|
2049
|
+
<T>(cases: ReadonlyArray<T>): TestForFunctionReturn<T, TestContext & ExtraContext>;
|
|
2050
|
+
(strings: TemplateStringsArray, ...values: any[]): TestForFunctionReturn<any, TestContext & ExtraContext>;
|
|
2051
|
+
}
|
|
2052
|
+
interface SuiteForFunction {
|
|
2053
|
+
<T>(cases: ReadonlyArray<T>): EachFunctionReturn<[T]>;
|
|
2054
|
+
(...args: [TemplateStringsArray, ...any]): EachFunctionReturn<any[]>;
|
|
2055
|
+
}
|
|
2056
|
+
interface TestCollectorCallable<C = object> {
|
|
2057
|
+
<ExtraContext extends C>(name: string | Function, fn?: TestFunction<ExtraContext>, options?: number): void;
|
|
2058
|
+
<ExtraContext extends C>(name: string | Function, options?: TestCollectorOptions, fn?: TestFunction<ExtraContext>): void;
|
|
2059
|
+
}
|
|
2060
|
+
interface InternalChainableContext<API = TestAPI> {
|
|
2061
|
+
/** @internal */
|
|
2062
|
+
mergeContext: (ctx: Partial<InternalTestContext>) => void;
|
|
2063
|
+
/** @internal */
|
|
2064
|
+
setContext: (key: keyof InternalTestContext, value: any) => void;
|
|
2065
|
+
/** @internal */
|
|
2066
|
+
withContext: () => API;
|
|
2067
|
+
/** @internal */
|
|
2068
|
+
getFixtures: () => TestFixtures;
|
|
2069
|
+
}
|
|
2070
|
+
type ChainableTestContextMap = Pick<Required<TestOptions>, 'concurrent' | 'only' | 'skip' | 'todo' | 'fails'>;
|
|
2071
|
+
type ChainableTestAPI<ExtraContext = object> = TypedChainableFunction<ChainableTestContextMap, TestCollectorCallable<ExtraContext>, {
|
|
2072
|
+
each: TestEachFunction;
|
|
2073
|
+
for: TestForFunction<ExtraContext>;
|
|
2074
|
+
}>;
|
|
2075
|
+
type TestCollectorOptions = Omit<TestOptions, 'shuffle'>;
|
|
2076
|
+
/**
|
|
2077
|
+
* Retry configuration for tests.
|
|
2078
|
+
* Can be a number for simple retry count, or an object for advanced retry control.
|
|
2079
|
+
*/
|
|
2080
|
+
type Retry = number | {
|
|
2081
|
+
/**
|
|
2082
|
+
* The number of times to retry the test if it fails.
|
|
2083
|
+
* @default 0
|
|
2084
|
+
*/
|
|
2085
|
+
count?: number;
|
|
2086
|
+
/**
|
|
2087
|
+
* Delay in milliseconds between retry attempts.
|
|
2088
|
+
* @default 0
|
|
2089
|
+
*/
|
|
2090
|
+
delay?: number;
|
|
2091
|
+
/**
|
|
2092
|
+
* Condition to determine if a test should be retried based on the error.
|
|
2093
|
+
* - If a RegExp, it is tested against the error message
|
|
2094
|
+
* - If a function, called with the TestError object; return true to retry
|
|
2095
|
+
*
|
|
2096
|
+
* NOTE: Functions can only be used in test files, not in vitest.config.ts,
|
|
2097
|
+
* because the configuration is serialized when passed to worker threads.
|
|
2098
|
+
*
|
|
2099
|
+
* @default undefined (retry on all errors)
|
|
2100
|
+
*/
|
|
2101
|
+
condition?: RegExp | ((error: TestError) => boolean);
|
|
2102
|
+
};
|
|
2103
|
+
interface TestOptions {
|
|
2104
|
+
/**
|
|
2105
|
+
* Test timeout.
|
|
2106
|
+
*/
|
|
2107
|
+
timeout?: number;
|
|
2108
|
+
/**
|
|
2109
|
+
* Retry configuration for the test.
|
|
2110
|
+
* - If a number, specifies how many times to retry
|
|
2111
|
+
* - If an object, allows fine-grained retry control
|
|
2112
|
+
* @default 0
|
|
2113
|
+
*/
|
|
2114
|
+
retry?: Retry;
|
|
2115
|
+
/**
|
|
2116
|
+
* How many times the test will run again.
|
|
2117
|
+
* Only inner tests will repeat if set on `describe()`, nested `describe()` will inherit parent's repeat by default.
|
|
2118
|
+
*
|
|
2119
|
+
* @default 0
|
|
2120
|
+
*/
|
|
2121
|
+
repeats?: number;
|
|
2122
|
+
/**
|
|
2123
|
+
* Whether suites and tests run concurrently.
|
|
2124
|
+
* Tests inherit `concurrent` from `describe()` and nested `describe()` will inherit from parent's `concurrent`.
|
|
2125
|
+
*/
|
|
2126
|
+
concurrent?: boolean;
|
|
2127
|
+
/**
|
|
2128
|
+
* Whether the test should be skipped.
|
|
2129
|
+
*/
|
|
2130
|
+
skip?: boolean;
|
|
2131
|
+
/**
|
|
2132
|
+
* Should this test be the only one running in a suite.
|
|
2133
|
+
*/
|
|
2134
|
+
only?: boolean;
|
|
2135
|
+
/**
|
|
2136
|
+
* Whether the test should be skipped and marked as a todo.
|
|
2137
|
+
*/
|
|
2138
|
+
todo?: boolean;
|
|
2139
|
+
/**
|
|
2140
|
+
* Whether the test is expected to fail. If it does, the test will pass, otherwise it will fail.
|
|
2141
|
+
*/
|
|
2142
|
+
fails?: boolean;
|
|
2143
|
+
/**
|
|
2144
|
+
* Custom tags of the test. Useful for filtering tests.
|
|
2145
|
+
*/
|
|
2146
|
+
tags?: keyof TestTags extends never ? string[] | string : TestTags[keyof TestTags] | TestTags[keyof TestTags][];
|
|
2147
|
+
/**
|
|
2148
|
+
* Custom test metadata available to reporters.
|
|
2149
|
+
*/
|
|
2150
|
+
meta?: Partial<TaskMeta>;
|
|
2151
|
+
}
|
|
2152
|
+
interface TestTags {}
|
|
2153
|
+
interface SuiteOptions extends TestOptions {
|
|
2154
|
+
/**
|
|
2155
|
+
* Whether the tasks of the suite run in a random order.
|
|
2156
|
+
*/
|
|
2157
|
+
shuffle?: boolean;
|
|
2158
|
+
}
|
|
2159
|
+
interface ExtendedAPI<ExtraContext> {
|
|
2160
|
+
skipIf: (condition: any) => ChainableTestAPI<ExtraContext>;
|
|
2161
|
+
runIf: (condition: any) => ChainableTestAPI<ExtraContext>;
|
|
2162
|
+
}
|
|
2163
|
+
interface Hooks<ExtraContext> {
|
|
2164
|
+
/**
|
|
2165
|
+
* Suite-level hooks only receive file/worker scoped fixtures.
|
|
2166
|
+
* Test-scoped fixtures are NOT available in beforeAll/afterAll/aroundAll.
|
|
2167
|
+
*/
|
|
2168
|
+
beforeAll: typeof beforeAll<ExtractSuiteContext<ExtraContext>>;
|
|
2169
|
+
afterAll: typeof afterAll<ExtractSuiteContext<ExtraContext>>;
|
|
2170
|
+
aroundAll: typeof aroundAll<ExtractSuiteContext<ExtraContext>>;
|
|
2171
|
+
/**
|
|
2172
|
+
* Test-level hooks receive all fixtures including test-scoped ones.
|
|
2173
|
+
*/
|
|
2174
|
+
beforeEach: typeof beforeEach<ExtraContext>;
|
|
2175
|
+
afterEach: typeof afterEach<ExtraContext>;
|
|
2176
|
+
aroundEach: typeof aroundEach<ExtraContext>;
|
|
2177
|
+
}
|
|
2178
|
+
type TestAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & Hooks<ExtraContext> & {
|
|
2179
|
+
/** @internal */[kChainableContext]: InternalChainableContext<TestAPI>;
|
|
2180
|
+
/**
|
|
2181
|
+
* Extend the test API with custom fixtures.
|
|
2182
|
+
*
|
|
2183
|
+
* @example
|
|
2184
|
+
* ```ts
|
|
2185
|
+
* // Simple test fixtures (backward compatible)
|
|
2186
|
+
* const myTest = test.extend<{ foo: string }>({
|
|
2187
|
+
* foo: 'value',
|
|
2188
|
+
* })
|
|
2189
|
+
*
|
|
2190
|
+
* // With scoped fixtures - use $test/$file/$worker structure
|
|
2191
|
+
* const myTest = test.extend<{
|
|
2192
|
+
* $test: { testData: string }
|
|
2193
|
+
* $file: { fileDb: Database }
|
|
2194
|
+
* $worker: { workerConfig: Config }
|
|
2195
|
+
* }>({
|
|
2196
|
+
* testData: async ({ fileDb }, use) => {
|
|
2197
|
+
* await use(await fileDb.getData())
|
|
2198
|
+
* },
|
|
2199
|
+
* fileDb: [async ({ workerConfig }, use) => {
|
|
2200
|
+
* // File fixture can only access workerConfig, NOT testData
|
|
2201
|
+
* const db = new Database(workerConfig)
|
|
2202
|
+
* await use(db)
|
|
2203
|
+
* await db.close()
|
|
2204
|
+
* }, { scope: 'file' }],
|
|
2205
|
+
* workerConfig: [async ({}, use) => {
|
|
2206
|
+
* // Worker fixture can only access other worker fixtures
|
|
2207
|
+
* await use(loadConfig())
|
|
2208
|
+
* }, { scope: 'worker' }],
|
|
2209
|
+
* })
|
|
2210
|
+
*
|
|
2211
|
+
* // Builder pattern with automatic type inference
|
|
2212
|
+
* const myTest = test
|
|
2213
|
+
* .extend('config', { scope: 'worker' }, async ({}) => {
|
|
2214
|
+
* return { port: 3000 } // Type inferred as { port: number }
|
|
2215
|
+
* })
|
|
2216
|
+
* .extend('db', { scope: 'file' }, async ({ config }, { onCleanup }) => {
|
|
2217
|
+
* // TypeScript knows config is { port: number }
|
|
2218
|
+
* const db = new Database(config.port)
|
|
2219
|
+
* onCleanup(() => db.close()) // Register cleanup
|
|
2220
|
+
* return db // Type inferred as Database
|
|
2221
|
+
* })
|
|
2222
|
+
* .extend('data', async ({ db }) => {
|
|
2223
|
+
* // TypeScript knows db is Database
|
|
2224
|
+
* return await db.getData() // Type inferred from return
|
|
2225
|
+
* })
|
|
2226
|
+
* ```
|
|
2227
|
+
*/
|
|
2228
|
+
extend: {
|
|
2229
|
+
<K extends string, T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)>(name: K, options: WorkerScopeFixtureOptions, fn: BuilderFixtureFn<T, WorkerScopeContext<ExtraContext>>): TestAPI<AddBuilderWorker<ExtraContext, K, T>>;
|
|
2230
|
+
<K extends string, T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)>(name: K, options: FileScopeFixtureOptions, fn: BuilderFixtureFn<T, FileScopeContext<ExtraContext>>): TestAPI<AddBuilderFile<ExtraContext, K, T>>;
|
|
2231
|
+
<K extends string, T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)>(name: K, options: TestScopeFixtureOptions, fn: BuilderFixtureFn<T, TestScopeContext<ExtraContext>>): TestAPI<AddBuilderTest<ExtraContext, K, T>>;
|
|
2232
|
+
<K extends string, T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)>(name: K, fn: BuilderFixtureFn<T, TestScopeContext<ExtraContext>>): TestAPI<AddBuilderTest<ExtraContext, K, T>>;
|
|
2233
|
+
<K extends string, T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)>(name: K, options: WorkerScopeFixtureOptions, value: T extends ((...args: any[]) => any) ? never : T): TestAPI<AddBuilderWorker<ExtraContext, K, T>>;
|
|
2234
|
+
<K extends string, T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)>(name: K, options: FileScopeFixtureOptions, value: T extends ((...args: any[]) => any) ? never : T): TestAPI<AddBuilderFile<ExtraContext, K, T>>;
|
|
2235
|
+
<K extends string, T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)>(name: K, options: TestScopeFixtureOptions, value: T extends ((...args: any[]) => any) ? never : T): TestAPI<AddBuilderTest<ExtraContext, K, T>>;
|
|
2236
|
+
<K extends string, T extends (K extends keyof ExtraContext ? ExtraContext[K] : unknown)>(name: K, value: T extends ((...args: any[]) => any) ? never : T): TestAPI<AddBuilderTest<ExtraContext, K, T>>;
|
|
2237
|
+
<T extends ScopedFixturesDef>(fixtures: ScopedFixturesObject<T, ExtraContext>): TestAPI<ExtractScopedFixtures<T> & ExtraContext>;
|
|
2238
|
+
<T extends Record<string, any> = object>(fixtures: Fixtures<T, ExtraContext>): TestAPI<{ [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never }>;
|
|
2239
|
+
};
|
|
2240
|
+
/**
|
|
2241
|
+
* Overwrite fixture values for the current suite scope.
|
|
2242
|
+
* Supports both object syntax and builder pattern.
|
|
2243
|
+
*
|
|
2244
|
+
* @example
|
|
2245
|
+
* ```ts
|
|
2246
|
+
* describe('with custom config', () => {
|
|
2247
|
+
* // Object syntax
|
|
2248
|
+
* test.override({ config: { port: 4000 } })
|
|
2249
|
+
*
|
|
2250
|
+
* // Builder pattern - value
|
|
2251
|
+
* test.override('config', { port: 4000 })
|
|
2252
|
+
*
|
|
2253
|
+
* // Builder pattern - function
|
|
2254
|
+
* test.override('config', () => ({ port: 4000 }))
|
|
2255
|
+
*
|
|
2256
|
+
* // Builder pattern - function with cleanup
|
|
2257
|
+
* test.override('db', async ({ config }, { onCleanup }) => {
|
|
2258
|
+
* const db = await createDb(config)
|
|
2259
|
+
* onCleanup(() => db.close())
|
|
2260
|
+
* return db
|
|
2261
|
+
* })
|
|
2262
|
+
* })
|
|
2263
|
+
* ```
|
|
2264
|
+
*/
|
|
2265
|
+
override: {
|
|
2266
|
+
<K extends keyof ExtraContext>(name: K, options: FixtureOptions, fn: BuilderFixtureFn<ExtraContext[K], ExtraContext & TestContext>): TestAPI<ExtraContext>;
|
|
2267
|
+
<K extends keyof ExtraContext>(name: K, fn: BuilderFixtureFn<ExtraContext[K], ExtraContext & TestContext>): TestAPI<ExtraContext>;
|
|
2268
|
+
<K extends keyof ExtraContext>(name: K, options: FixtureOptions, value: ExtraContext[K] extends ((...args: any[]) => any) ? never : ExtraContext[K]): TestAPI<ExtraContext>;
|
|
2269
|
+
<K extends keyof ExtraContext>(name: K, value: ExtraContext[K] extends ((...args: any[]) => any) ? never : ExtraContext[K]): TestAPI<ExtraContext>;
|
|
2270
|
+
(fixtures: Partial<Fixtures<ExtraContext>>): TestAPI<ExtraContext>;
|
|
2271
|
+
};
|
|
2272
|
+
/**
|
|
2273
|
+
* @deprecated Use `test.override()` instead
|
|
2274
|
+
*/
|
|
2275
|
+
scoped: (fixtures: Partial<Fixtures<ExtraContext>>) => TestAPI<ExtraContext>;
|
|
2276
|
+
describe: SuiteAPI<ExtraContext>;
|
|
2277
|
+
suite: SuiteAPI<ExtraContext>;
|
|
2278
|
+
};
|
|
2279
|
+
type InternalTestChainableContext = { [K in keyof ChainableTestContextMap]: boolean | undefined };
|
|
2280
|
+
interface InternalTestContext extends InternalTestChainableContext {
|
|
2281
|
+
each: boolean | undefined;
|
|
2282
|
+
fixtures: TestFixtures;
|
|
2283
|
+
}
|
|
2284
|
+
interface FixtureOptions {
|
|
2285
|
+
/**
|
|
2286
|
+
* Whether to automatically set up current fixture, even though it's not being used.
|
|
2287
|
+
* Test-scoped auto fixtures are not initialized in suite-level hooks (`beforeAll`/`afterAll`/`aroundAll`).
|
|
2288
|
+
* @default false
|
|
2289
|
+
*/
|
|
2290
|
+
auto?: boolean;
|
|
2291
|
+
/**
|
|
2292
|
+
* Indicated if the injected value from the config should be preferred over the fixture value
|
|
2293
|
+
*/
|
|
2294
|
+
injected?: boolean;
|
|
2295
|
+
/**
|
|
2296
|
+
* When should the fixture be set up.
|
|
2297
|
+
* - **test**: fixture will be set up before every test
|
|
2298
|
+
* - **worker**: fixture will be set up once per worker
|
|
2299
|
+
* - **file**: fixture will be set up once per file
|
|
2300
|
+
*
|
|
2301
|
+
* **Warning:** The `vmThreads` and `vmForks` pools initiate worker fixtures once per test file.
|
|
2302
|
+
* @default 'test'
|
|
2303
|
+
*/
|
|
2304
|
+
scope?: 'test' | 'worker' | 'file';
|
|
2305
|
+
}
|
|
2306
|
+
/**
|
|
2307
|
+
* Options for test-scoped fixtures.
|
|
2308
|
+
* Test fixtures are set up before each test and have access to all fixtures.
|
|
2309
|
+
*/
|
|
2310
|
+
interface TestScopeFixtureOptions extends Omit<FixtureOptions, 'scope'> {
|
|
2311
|
+
/**
|
|
2312
|
+
* @default 'test'
|
|
2313
|
+
*/
|
|
2314
|
+
scope?: 'test';
|
|
2315
|
+
}
|
|
2316
|
+
/**
|
|
2317
|
+
* Options for file-scoped fixtures.
|
|
2318
|
+
* File fixtures are set up once per file and can only access other file fixtures and worker fixtures.
|
|
2319
|
+
*/
|
|
2320
|
+
interface FileScopeFixtureOptions extends Omit<FixtureOptions, 'scope'> {
|
|
2321
|
+
/**
|
|
2322
|
+
* Must be 'file' for file-scoped fixtures.
|
|
2323
|
+
*/
|
|
2324
|
+
scope: 'file';
|
|
2325
|
+
}
|
|
2326
|
+
/**
|
|
2327
|
+
* Options for worker-scoped fixtures.
|
|
2328
|
+
* Worker fixtures are set up once per worker and can only access other worker fixtures.
|
|
2329
|
+
*/
|
|
2330
|
+
interface WorkerScopeFixtureOptions extends Omit<FixtureOptions, 'scope'> {
|
|
2331
|
+
/**
|
|
2332
|
+
* Must be 'worker' for worker-scoped fixtures.
|
|
2333
|
+
*/
|
|
2334
|
+
scope: 'worker';
|
|
2335
|
+
}
|
|
2336
|
+
type Use<T> = (value: T) => Promise<void>;
|
|
2337
|
+
/**
|
|
2338
|
+
* Cleanup registration function for builder pattern fixtures.
|
|
2339
|
+
* Call this to register a cleanup function that runs after the test/file/worker completes.
|
|
2340
|
+
*
|
|
2341
|
+
* **Note:** This function can only be called once per fixture. If you need multiple
|
|
2342
|
+
* cleanup operations, either combine them into a single cleanup function or split
|
|
2343
|
+
* your fixture into multiple smaller fixtures.
|
|
2344
|
+
*/
|
|
2345
|
+
type OnCleanup = (cleanup: () => Awaitable<void>) => void;
|
|
2346
|
+
/**
|
|
2347
|
+
* Builder pattern fixture function with automatic type inference.
|
|
2348
|
+
* Returns the fixture value directly (type is inferred from return).
|
|
2349
|
+
* Use onCleanup to register teardown logic.
|
|
2350
|
+
*
|
|
2351
|
+
* Parameters can be omitted if not needed:
|
|
2352
|
+
* - `async () => value` - no dependencies, no cleanup
|
|
2353
|
+
* - `async ({ dep }) => value` - with dependencies, no cleanup
|
|
2354
|
+
* - `async ({ dep }, { onCleanup }) => value` - with dependencies and cleanup
|
|
2355
|
+
*/
|
|
2356
|
+
type BuilderFixtureFn<T, Context> = (context: Context, fixture: {
|
|
2357
|
+
onCleanup: OnCleanup;
|
|
2358
|
+
}) => T | Promise<T>;
|
|
2359
|
+
type ExtractSuiteContext<C> = C extends {
|
|
2360
|
+
$__worker?: any;
|
|
2361
|
+
} | {
|
|
2362
|
+
$__file?: any;
|
|
2363
|
+
} | {
|
|
2364
|
+
$__test?: any;
|
|
2365
|
+
} ? ExtractBuilderWorker<C> & ExtractBuilderFile<C> : C;
|
|
2366
|
+
/**
|
|
2367
|
+
* Extracts worker-scoped fixtures from a context that includes scope info.
|
|
2368
|
+
*/
|
|
2369
|
+
type ExtractBuilderWorker<C> = C extends {
|
|
2370
|
+
$__worker?: infer W;
|
|
2371
|
+
} ? W extends Record<string, any> ? W : object : object;
|
|
2372
|
+
/**
|
|
2373
|
+
* Extracts file-scoped fixtures from a context that includes scope info.
|
|
2374
|
+
*/
|
|
2375
|
+
type ExtractBuilderFile<C> = C extends {
|
|
2376
|
+
$__file?: infer F;
|
|
2377
|
+
} ? F extends Record<string, any> ? F : object : object;
|
|
2378
|
+
/**
|
|
2379
|
+
* Extracts test-scoped fixtures from a context that includes scope info.
|
|
2380
|
+
*/
|
|
2381
|
+
type ExtractBuilderTest<C> = C extends {
|
|
2382
|
+
$__test?: infer T;
|
|
2383
|
+
} ? T extends Record<string, any> ? T : object : object;
|
|
2384
|
+
/**
|
|
2385
|
+
* Adds a worker fixture to the context with proper scope tracking.
|
|
2386
|
+
*/
|
|
2387
|
+
type AddBuilderWorker<C, K extends string, V> = Omit<C, '$__worker'> & Record<K, V> & {
|
|
2388
|
+
readonly $__worker?: ExtractBuilderWorker<C> & Record<K, V>;
|
|
2389
|
+
readonly $__file?: ExtractBuilderFile<C>;
|
|
2390
|
+
readonly $__test?: ExtractBuilderTest<C>;
|
|
2391
|
+
};
|
|
2392
|
+
/**
|
|
2393
|
+
* Adds a file fixture to the context with proper scope tracking.
|
|
2394
|
+
*/
|
|
2395
|
+
type AddBuilderFile<C, K extends string, V> = Omit<C, '$__file'> & Record<K, V> & {
|
|
2396
|
+
readonly $__worker?: ExtractBuilderWorker<C>;
|
|
2397
|
+
readonly $__file?: ExtractBuilderFile<C> & Record<K, V>;
|
|
2398
|
+
readonly $__test?: ExtractBuilderTest<C>;
|
|
2399
|
+
};
|
|
2400
|
+
/**
|
|
2401
|
+
* Adds a test fixture to the context with proper scope tracking.
|
|
2402
|
+
*/
|
|
2403
|
+
type AddBuilderTest<C, K extends string, V> = Omit<C, '$__test'> & Record<K, V> & {
|
|
2404
|
+
readonly $__worker?: ExtractBuilderWorker<C>;
|
|
2405
|
+
readonly $__file?: ExtractBuilderFile<C>;
|
|
2406
|
+
readonly $__test?: ExtractBuilderTest<C> & Record<K, V>;
|
|
2407
|
+
};
|
|
2408
|
+
/**
|
|
2409
|
+
* Context available to worker-scoped fixtures.
|
|
2410
|
+
* Worker fixtures can only access other worker fixtures.
|
|
2411
|
+
* They do NOT have access to test context (task, expect, onTestFailed, etc.)
|
|
2412
|
+
* since they run once per worker, outside of any specific test.
|
|
2413
|
+
*/
|
|
2414
|
+
type WorkerScopeContext<C> = ExtractBuilderWorker<C>;
|
|
2415
|
+
/**
|
|
2416
|
+
* Context available to file-scoped fixtures.
|
|
2417
|
+
* File fixtures can access worker and other file fixtures.
|
|
2418
|
+
* They do NOT have access to test context (task, expect, onTestFailed, etc.)
|
|
2419
|
+
* since they run once per file, outside of any specific test.
|
|
2420
|
+
*/
|
|
2421
|
+
type FileScopeContext<C> = ExtractBuilderWorker<C> & ExtractBuilderFile<C>;
|
|
2422
|
+
/**
|
|
2423
|
+
* Context available to test-scoped fixtures (all fixtures + test context).
|
|
2424
|
+
*/
|
|
2425
|
+
type TestScopeContext<C> = C & TestContext;
|
|
2426
|
+
type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
|
|
2427
|
+
type Fixture<T, K extends keyof T, ExtraContext = object> = ((...args: any) => any) extends T[K] ? T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never : T[K] | (T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never);
|
|
2428
|
+
/**
|
|
2429
|
+
* Fixture function with explicit context type for scoped fixtures.
|
|
2430
|
+
*/
|
|
2431
|
+
type ScopedFixtureFn<Value, Context> = (context: Context, use: Use<Value>) => Promise<void>;
|
|
2432
|
+
/**
|
|
2433
|
+
* Fixtures definition for backward compatibility.
|
|
2434
|
+
* All fixtures are in T and any scope is allowed.
|
|
2435
|
+
*/
|
|
2436
|
+
type Fixtures<T, ExtraContext = object> = { [K in keyof T]: Fixture<T, K, ExtraContext & TestContext> | [Fixture<T, K, ExtraContext & TestContext>, FixtureOptions?] };
|
|
2437
|
+
/**
|
|
2438
|
+
* Scoped fixtures definition using a single generic with optional scope keys.
|
|
2439
|
+
* This provides better ergonomics than multiple generics.
|
|
2440
|
+
* Uses $ prefix to avoid conflicts with fixture names.
|
|
2441
|
+
*
|
|
2442
|
+
* @example
|
|
2443
|
+
* ```ts
|
|
2444
|
+
* test.extend<{
|
|
2445
|
+
* $worker?: { config: Config }
|
|
2446
|
+
* $file?: { db: Database }
|
|
2447
|
+
* $test?: { data: string }
|
|
2448
|
+
* }>({ ... })
|
|
2449
|
+
* ```
|
|
2450
|
+
*/
|
|
2451
|
+
interface ScopedFixturesDef {
|
|
2452
|
+
$test?: Record<string, any>;
|
|
2453
|
+
$file?: Record<string, any>;
|
|
2454
|
+
$worker?: Record<string, any>;
|
|
2455
|
+
}
|
|
2456
|
+
/**
|
|
2457
|
+
* Extracts fixture types from a ScopedFixturesDef.
|
|
2458
|
+
* Handles optional properties by using Exclude to remove undefined.
|
|
2459
|
+
*/
|
|
2460
|
+
type ExtractScopedFixtures<T extends ScopedFixturesDef> = ([Exclude<T['$test'], undefined>] extends [never] ? object : Exclude<T['$test'], undefined>) & ([Exclude<T['$file'], undefined>] extends [never] ? object : Exclude<T['$file'], undefined>) & ([Exclude<T['$worker'], undefined>] extends [never] ? object : Exclude<T['$worker'], undefined>);
|
|
2461
|
+
/**
|
|
2462
|
+
* Creates the fixtures object type for ScopedFixturesDef with proper scope validation.
|
|
2463
|
+
* - Test fixtures: can be defined as value, function, or tuple with optional scope
|
|
2464
|
+
* - File fixtures: MUST have { scope: 'file' }
|
|
2465
|
+
* - Worker fixtures: MUST have { scope: 'worker' }
|
|
2466
|
+
*/
|
|
2467
|
+
type ScopedFixturesObject<T extends ScopedFixturesDef, ExtraContext = object> = { [K in keyof NonNullable<T['$test']>]: NonNullable<T['$test']>[K] | ScopedFixtureFn<NonNullable<T['$test']>[K], ExtractScopedFixtures<T> & ExtraContext & TestContext> | [ScopedFixtureFn<NonNullable<T['$test']>[K], ExtractScopedFixtures<T> & ExtraContext & TestContext>, TestScopeFixtureOptions?] } & { [K in keyof NonNullable<T['$file']>]: [ScopedFixtureFn<NonNullable<T['$file']>[K], (NonNullable<T['$file']> & NonNullable<T['$worker']>) & ExtraContext>, FileScopeFixtureOptions] } & { [K in keyof NonNullable<T['$worker']>]: [ScopedFixtureFn<NonNullable<T['$worker']>[K], NonNullable<T['$worker']> & ExtraContext>, WorkerScopeFixtureOptions] };
|
|
2468
|
+
interface SuiteCollectorCallable<ExtraContext = object> {
|
|
2469
|
+
<OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, fn?: SuiteFactory<OverrideExtraContext>, options?: number): SuiteCollector<OverrideExtraContext>;
|
|
2470
|
+
<OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, options: SuiteOptions, fn?: SuiteFactory<OverrideExtraContext>): SuiteCollector<OverrideExtraContext>;
|
|
2471
|
+
}
|
|
2472
|
+
type ChainableSuiteContextMap = Pick<Required<SuiteOptions>, 'concurrent' | 'only' | 'skip' | 'todo' | 'shuffle'>;
|
|
2473
|
+
type ChainableSuiteAPI<ExtraContext = object> = TypedChainableFunction<ChainableSuiteContextMap, SuiteCollectorCallable<ExtraContext>, {
|
|
2474
|
+
each: TestEachFunction;
|
|
2475
|
+
for: SuiteForFunction;
|
|
2476
|
+
}>;
|
|
2477
|
+
type SuiteAPI<ExtraContext = object> = ChainableSuiteAPI<ExtraContext> & {
|
|
2478
|
+
/** @internal */[kChainableContext]: InternalChainableContext<TestAPI>;
|
|
2479
|
+
skipIf: (condition: any) => ChainableSuiteAPI<ExtraContext>;
|
|
2480
|
+
runIf: (condition: any) => ChainableSuiteAPI<ExtraContext>;
|
|
2481
|
+
};
|
|
2482
|
+
interface BeforeAllListener<ExtraContext = object> {
|
|
2483
|
+
(context: ExtraContext, suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
2484
|
+
}
|
|
2485
|
+
interface AfterAllListener<ExtraContext = object> {
|
|
2486
|
+
(context: ExtraContext, suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
2487
|
+
}
|
|
2488
|
+
interface BeforeEachListener<ExtraContext = object> {
|
|
2489
|
+
(context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
|
|
2490
|
+
}
|
|
2491
|
+
interface AfterEachListener<ExtraContext = object> {
|
|
2492
|
+
(context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
|
|
2493
|
+
}
|
|
2494
|
+
interface AroundEachListener<ExtraContext = object> {
|
|
2495
|
+
(runTest: () => Promise<void>, context: TestContext & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
|
|
2496
|
+
}
|
|
2497
|
+
interface AroundAllListener<ExtraContext = object> {
|
|
2498
|
+
(runSuite: () => Promise<void>, context: ExtraContext, suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
2499
|
+
}
|
|
2500
|
+
interface RegisteredAllListener {
|
|
2501
|
+
(suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
2502
|
+
}
|
|
2503
|
+
interface RegisteredAroundAllListener {
|
|
2504
|
+
(runSuite: () => Promise<void>, suite: Readonly<Suite | File>): Awaitable<unknown>;
|
|
2505
|
+
}
|
|
2506
|
+
interface SuiteHooks<ExtraContext = object> {
|
|
2507
|
+
beforeAll: RegisteredAllListener[];
|
|
2508
|
+
afterAll: RegisteredAllListener[];
|
|
2509
|
+
aroundAll: RegisteredAroundAllListener[];
|
|
2510
|
+
beforeEach: BeforeEachListener<ExtraContext>[];
|
|
2511
|
+
afterEach: AfterEachListener<ExtraContext>[];
|
|
2512
|
+
aroundEach: AroundEachListener<ExtraContext>[];
|
|
2513
|
+
}
|
|
2514
|
+
interface TaskCustomOptions extends TestOptions {
|
|
2515
|
+
/**
|
|
2516
|
+
* Whether the task was produced with `.each()` method.
|
|
2517
|
+
*/
|
|
2518
|
+
each?: boolean;
|
|
2519
|
+
/**
|
|
2520
|
+
* Task fixtures.
|
|
2521
|
+
*/
|
|
2522
|
+
fixtures?: TestFixtures;
|
|
2523
|
+
/**
|
|
2524
|
+
* Function that will be called when the task is executed.
|
|
2525
|
+
* If nothing is provided, the runner will try to get the function using `getFn(task)`.
|
|
2526
|
+
* If the runner cannot find the function, the task will be marked as failed.
|
|
2527
|
+
*/
|
|
2528
|
+
handler?: (context: TestContext) => Awaitable<void>;
|
|
2529
|
+
}
|
|
2530
|
+
interface SuiteCollector<ExtraContext = object> {
|
|
2531
|
+
readonly name: string;
|
|
2532
|
+
readonly mode: RunMode;
|
|
2533
|
+
options?: SuiteOptions;
|
|
2534
|
+
type: 'collector';
|
|
2535
|
+
test: TestAPI<ExtraContext>;
|
|
2536
|
+
tasks: (Suite | Test<ExtraContext> | SuiteCollector<ExtraContext>)[];
|
|
2537
|
+
file: File;
|
|
2538
|
+
suite?: Suite;
|
|
2539
|
+
task: (name: string, options?: TaskCustomOptions) => Test<ExtraContext>;
|
|
2540
|
+
collect: (file: File) => Promise<Suite>;
|
|
2541
|
+
clear: () => void;
|
|
2542
|
+
on: <T extends keyof SuiteHooks<ExtraContext>>(name: T, ...fn: SuiteHooks<ExtraContext>[T]) => void;
|
|
2543
|
+
}
|
|
2544
|
+
type SuiteFactory<ExtraContext = object> = (test: TestAPI<ExtraContext>) => Awaitable<void>;
|
|
2545
|
+
/**
|
|
2546
|
+
* User's custom test context.
|
|
2547
|
+
*/
|
|
2548
|
+
interface TestContext {
|
|
2549
|
+
/**
|
|
2550
|
+
* Metadata of the current test
|
|
2551
|
+
*/
|
|
2552
|
+
readonly task: Readonly<Test>;
|
|
2553
|
+
/**
|
|
2554
|
+
* An [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) that will be aborted if the test times out or
|
|
2555
|
+
* the test run was cancelled.
|
|
2556
|
+
* @see {@link https://vitest.dev/guide/test-context#signal}
|
|
2557
|
+
*/
|
|
2558
|
+
readonly signal: AbortSignal;
|
|
2559
|
+
/**
|
|
2560
|
+
* Register a callback to run when this specific test fails.
|
|
2561
|
+
* Useful when tests run concurrently.
|
|
2562
|
+
* @see {@link https://vitest.dev/guide/test-context#ontestfailed}
|
|
2563
|
+
*/
|
|
2564
|
+
readonly onTestFailed: (fn: OnTestFailedHandler, timeout?: number) => void;
|
|
2565
|
+
/**
|
|
2566
|
+
* Register a callback to run when this specific test finishes.
|
|
2567
|
+
* Useful when tests run concurrently.
|
|
2568
|
+
* @see {@link https://vitest.dev/guide/test-context#ontestfinished}
|
|
2569
|
+
*/
|
|
2570
|
+
readonly onTestFinished: (fn: OnTestFinishedHandler, timeout?: number) => void;
|
|
2571
|
+
/**
|
|
2572
|
+
* Mark tests as skipped. All execution after this call will be skipped.
|
|
2573
|
+
* This function throws an error, so make sure you are not catching it accidentally.
|
|
2574
|
+
* @see {@link https://vitest.dev/guide/test-context#skip}
|
|
2575
|
+
*/
|
|
2576
|
+
readonly skip: {
|
|
2577
|
+
(note?: string): never;
|
|
2578
|
+
(condition: boolean, note?: string): void;
|
|
2579
|
+
};
|
|
2580
|
+
/**
|
|
2581
|
+
* Add a test annotation that will be displayed by your reporter.
|
|
2582
|
+
* @see {@link https://vitest.dev/guide/test-context#annotate}
|
|
2583
|
+
*/
|
|
2584
|
+
readonly annotate: {
|
|
2585
|
+
(message: string, type?: string, attachment?: TestAttachment): Promise<TestAnnotation>;
|
|
2586
|
+
(message: string, attachment?: TestAttachment): Promise<TestAnnotation>;
|
|
2587
|
+
};
|
|
2588
|
+
/**
|
|
2589
|
+
* `expect` instance bound to the current test.
|
|
2590
|
+
*
|
|
2591
|
+
* This API is useful for running snapshot tests concurrently because global expect cannot track them.
|
|
2592
|
+
*/
|
|
2593
|
+
readonly expect: ExpectStatic;
|
|
2594
|
+
/**
|
|
2595
|
+
* Create a benchmark to run. It will be reported after the test is finished.
|
|
2596
|
+
* @see {@link https://vitest.dev/guide/benchmarking}
|
|
2597
|
+
*/
|
|
2598
|
+
readonly bench: Bench;
|
|
2599
|
+
/** @internal */
|
|
2600
|
+
_local: boolean;
|
|
2601
|
+
}
|
|
2602
|
+
type OnTestFailedHandler = (context: TestContext) => Awaitable<void>;
|
|
2603
|
+
type OnTestFinishedHandler = (context: TestContext) => Awaitable<void>;
|
|
2604
|
+
interface TaskHook<HookListener> {
|
|
2605
|
+
(fn: HookListener, timeout?: number): void;
|
|
2606
|
+
}
|
|
2607
|
+
/**
|
|
2608
|
+
* Represents a file or data attachment associated with a test artifact.
|
|
2609
|
+
*
|
|
2610
|
+
* Attachments can be either path-based (via `path`) or inline content (via `body`).
|
|
2611
|
+
* The `contentType` helps consumers understand how to interpret the attachment data.
|
|
2612
|
+
*/
|
|
2613
|
+
interface TestAttachment {
|
|
2614
|
+
/** MIME type of the attachment (e.g., 'image/png', 'text/plain') */
|
|
2615
|
+
contentType?: string;
|
|
2616
|
+
/** Local file path or external HTTP(S) URL to the attachment. Relative paths are resolved from the project root. */
|
|
2617
|
+
path?: string;
|
|
2618
|
+
/** Inline attachment content as a string or raw binary data */
|
|
2619
|
+
body?: string | Uint8Array | undefined;
|
|
2620
|
+
/**
|
|
2621
|
+
* @experimental
|
|
2622
|
+
* How the string `body` is encoded.
|
|
2623
|
+
* - `'base64'` (default): body is already base64-encoded
|
|
2624
|
+
* - `'utf-8'`: body is a utf8 string
|
|
2625
|
+
*
|
|
2626
|
+
* `body: Uint8Array` is always auto-encoded to string with `bodyEncoding: 'base64'`
|
|
2627
|
+
* regardless of this option.
|
|
2628
|
+
*/
|
|
2629
|
+
bodyEncoding?: 'base64' | 'utf-8';
|
|
2630
|
+
}
|
|
2631
|
+
interface Location {
|
|
2632
|
+
/** Line number in the source file (1-indexed) */
|
|
2633
|
+
line: number;
|
|
2634
|
+
/** Column number in the line (1-indexed) */
|
|
2635
|
+
column: number;
|
|
2636
|
+
}
|
|
2637
|
+
interface FileLocation extends Location {
|
|
2638
|
+
/** Line number in the source file (1-indexed) */
|
|
2639
|
+
line: number;
|
|
2640
|
+
/** Column number in the line (1-indexed) */
|
|
2641
|
+
column: number;
|
|
2642
|
+
/** Path to the source file */
|
|
2643
|
+
file: string;
|
|
2644
|
+
}
|
|
2645
|
+
/**
|
|
2646
|
+
* Source code location information for a test artifact.
|
|
2647
|
+
*
|
|
2648
|
+
* Indicates where in the source code the artifact originated from.
|
|
2649
|
+
*/
|
|
2650
|
+
interface TestArtifactLocation extends FileLocation {}
|
|
2651
|
+
/**
|
|
2652
|
+
* @experimental
|
|
2653
|
+
*
|
|
2654
|
+
* Base interface for all test artifacts.
|
|
2655
|
+
*
|
|
2656
|
+
* 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.
|
|
2657
|
+
*
|
|
2658
|
+
* **Important**: when running with [`api.allowWrite`](https://vitest.dev/config/api#api-allowwrite) or [`browser.api.allowWrite`](https://vitest.dev/config/browser/api#api-allowwrite) disabled, Vitest empties the `attachments` array on every artifact before reporting it.
|
|
2659
|
+
*/
|
|
2660
|
+
interface TestArtifactBase {
|
|
2661
|
+
/** File or data attachments associated with this artifact */
|
|
2662
|
+
attachments?: TestAttachment[];
|
|
2663
|
+
/** Source location where this artifact was created */
|
|
2664
|
+
location?: TestArtifactLocation;
|
|
2665
|
+
}
|
|
2666
|
+
interface TestAnnotation {
|
|
2667
|
+
message: string;
|
|
2668
|
+
type: string;
|
|
2669
|
+
location?: TestArtifactLocation;
|
|
2670
|
+
attachment?: TestAttachment;
|
|
2671
|
+
}
|
|
2672
|
+
/**
|
|
2673
|
+
* @experimental
|
|
2674
|
+
*
|
|
2675
|
+
* Artifact type for test annotations.
|
|
2676
|
+
*/
|
|
2677
|
+
interface TestAnnotationArtifact extends TestArtifactBase {
|
|
2678
|
+
type: 'internal:annotation';
|
|
2679
|
+
annotation: TestAnnotation;
|
|
2680
|
+
}
|
|
2681
|
+
interface VisualRegressionArtifactAttachment extends TestAttachment {
|
|
2682
|
+
name: 'reference' | 'actual' | 'diff';
|
|
2683
|
+
width: number;
|
|
2684
|
+
height: number;
|
|
2685
|
+
}
|
|
2686
|
+
/**
|
|
2687
|
+
* @experimental
|
|
2688
|
+
*
|
|
2689
|
+
* Artifact type for visual regressions.
|
|
2690
|
+
*/
|
|
2691
|
+
interface VisualRegressionArtifact extends TestArtifactBase {
|
|
2692
|
+
type: 'internal:toMatchScreenshot';
|
|
2693
|
+
kind: 'visual-regression';
|
|
2694
|
+
message: string;
|
|
2695
|
+
attachments: VisualRegressionArtifactAttachment[];
|
|
2696
|
+
}
|
|
2697
|
+
/**
|
|
2698
|
+
* @experimental
|
|
2699
|
+
*/
|
|
2700
|
+
interface BrowserTraceArtifact extends TestArtifactBase {
|
|
2701
|
+
type: 'internal:browserTrace';
|
|
2702
|
+
data: unknown;
|
|
2703
|
+
}
|
|
2704
|
+
interface FailureScreenshotArtifactAttachment extends TestAttachment {
|
|
2705
|
+
path: string;
|
|
2706
|
+
/** Original file system path to the screenshot, before attachment resolution */
|
|
2707
|
+
originalPath: string;
|
|
2708
|
+
body?: undefined;
|
|
2709
|
+
}
|
|
2710
|
+
/**
|
|
2711
|
+
* @experimental
|
|
2712
|
+
*
|
|
2713
|
+
* Artifact type for failure screenshots.
|
|
2714
|
+
*/
|
|
2715
|
+
interface FailureScreenshotArtifact extends TestArtifactBase {
|
|
2716
|
+
type: 'internal:failureScreenshot';
|
|
2717
|
+
attachments: [FailureScreenshotArtifactAttachment] | [];
|
|
2718
|
+
}
|
|
2719
|
+
/**
|
|
2720
|
+
* @experimental
|
|
2721
|
+
* @advanced
|
|
2722
|
+
*
|
|
2723
|
+
* Registry for custom test artifact types.
|
|
2724
|
+
*
|
|
2725
|
+
* Augment this interface to register custom artifact types that your tests can produce.
|
|
2726
|
+
*
|
|
2727
|
+
* Each custom artifact should extend {@linkcode TestArtifactBase} and include a unique `type` discriminator property.
|
|
2728
|
+
*
|
|
2729
|
+
* @remarks
|
|
2730
|
+
* - Use a `Symbol` as the **registry key** to guarantee uniqueness
|
|
2731
|
+
* - The `type` property should follow the pattern `'package-name:artifact-name'`, `'internal:'` is a reserved prefix
|
|
2732
|
+
* - Use `attachments` to include files or data; extend {@linkcode TestAttachment} for custom metadata
|
|
2733
|
+
* - `location` property is automatically injected to indicate where the artifact was created
|
|
2734
|
+
*
|
|
2735
|
+
* @example
|
|
2736
|
+
* ```ts
|
|
2737
|
+
* // Define custom attachment type for generated PDF
|
|
2738
|
+
* interface PDFAttachment extends TestAttachment {
|
|
2739
|
+
* contentType: 'application/pdf'
|
|
2740
|
+
* body: Uint8Array
|
|
2741
|
+
* pageCount: number
|
|
2742
|
+
* fileSize: number
|
|
2743
|
+
* }
|
|
2744
|
+
*
|
|
2745
|
+
* interface PDFGenerationArtifact extends TestArtifactBase {
|
|
2746
|
+
* type: 'my-plugin:pdf-generation'
|
|
2747
|
+
* templateName: string
|
|
2748
|
+
* isValid: boolean
|
|
2749
|
+
* attachments: [PDFAttachment]
|
|
2750
|
+
* }
|
|
2751
|
+
*
|
|
2752
|
+
* // Use a symbol to guarantee key uniqueness
|
|
2753
|
+
* const pdfKey = Symbol('pdf-generation')
|
|
2754
|
+
*
|
|
2755
|
+
* declare module 'vitest' {
|
|
2756
|
+
* interface TestArtifactRegistry {
|
|
2757
|
+
* [pdfKey]: PDFGenerationArtifact
|
|
2758
|
+
* }
|
|
2759
|
+
* }
|
|
2760
|
+
*
|
|
2761
|
+
* // Custom assertion for PDF generation
|
|
2762
|
+
* async function toGenerateValidPDF(
|
|
2763
|
+
* this: MatcherState,
|
|
2764
|
+
* actual: PDFTemplate,
|
|
2765
|
+
* data: Record<string, unknown>
|
|
2766
|
+
* ): AsyncExpectationResult {
|
|
2767
|
+
* const pdfBuffer = await actual.render(data)
|
|
2768
|
+
* const validation = await validatePDF(pdfBuffer)
|
|
2769
|
+
*
|
|
2770
|
+
* await recordArtifact(this.task, {
|
|
2771
|
+
* type: 'my-plugin:pdf-generation',
|
|
2772
|
+
* templateName: actual.name,
|
|
2773
|
+
* isValid: validation.success,
|
|
2774
|
+
* attachments: [{
|
|
2775
|
+
* contentType: 'application/pdf',
|
|
2776
|
+
* body: pdfBuffer,
|
|
2777
|
+
* pageCount: validation.pageCount,
|
|
2778
|
+
* fileSize: pdfBuffer.byteLength
|
|
2779
|
+
* }]
|
|
2780
|
+
* })
|
|
2781
|
+
*
|
|
2782
|
+
* return {
|
|
2783
|
+
* pass: validation.success,
|
|
2784
|
+
* message: () => validation.success
|
|
2785
|
+
* ? `Generated valid PDF with ${validation.pageCount} pages`
|
|
2786
|
+
* : `Invalid PDF: ${validation.error}`
|
|
2787
|
+
* }
|
|
2788
|
+
* }
|
|
2789
|
+
* ```
|
|
2790
|
+
*/
|
|
2791
|
+
interface TestArtifactRegistry {}
|
|
2792
|
+
/**
|
|
2793
|
+
* @experimental
|
|
2794
|
+
*
|
|
2795
|
+
* Union type of all test artifacts, including built-in and custom registered artifacts.
|
|
2796
|
+
*
|
|
2797
|
+
* This type automatically includes all artifacts registered via {@link TestArtifactRegistry}.
|
|
2798
|
+
*/
|
|
2799
|
+
type TestArtifact = BrowserTraceArtifact | FailureScreenshotArtifact | TestAnnotationArtifact | VisualRegressionArtifact | TestArtifactRegistry[keyof TestArtifactRegistry];
|
|
2800
|
+
/**
|
|
2801
|
+
* Possible options to run a single file in a test.
|
|
2802
|
+
*/
|
|
2803
|
+
interface FileSpecification {
|
|
2804
|
+
filepath: string;
|
|
2805
|
+
fileTags?: string[];
|
|
2806
|
+
testLocations?: number[] | undefined;
|
|
2807
|
+
testNamePattern?: RegExp | undefined;
|
|
2808
|
+
testTagsFilter?: string[] | undefined;
|
|
2809
|
+
testIds?: string[] | undefined;
|
|
2810
|
+
}
|
|
2811
|
+
type VitestRunnerImportSource = 'collect' | 'setup';
|
|
2812
|
+
type CancelReason = 'keyboard-input' | 'test-failure' | (string & Record<string, never>);
|
|
2813
|
+
interface TestTryOptions {
|
|
2814
|
+
retry: number;
|
|
2815
|
+
repeats: number;
|
|
2816
|
+
}
|
|
2817
|
+
interface VitestRunner {
|
|
2818
|
+
/**
|
|
2819
|
+
* First thing that's getting called before actually collecting and running tests.
|
|
2820
|
+
*/
|
|
2821
|
+
onBeforeCollect?: (paths: string[]) => unknown;
|
|
2822
|
+
/**
|
|
2823
|
+
* Called after the file task was created but not collected yet.
|
|
2824
|
+
*/
|
|
2825
|
+
onCollectStart?: (file: File) => unknown;
|
|
2826
|
+
/**
|
|
2827
|
+
* Called after collecting tests and before "onBeforeRun".
|
|
2828
|
+
*/
|
|
2829
|
+
onCollected?: (files: File[]) => unknown;
|
|
2830
|
+
/**
|
|
2831
|
+
* Called when test runner should cancel next test runs.
|
|
2832
|
+
* Runner should listen for this method and mark tests and suites as skipped in
|
|
2833
|
+
* "onBeforeRunSuite" and "onBeforeRunTask" when called.
|
|
2834
|
+
*/
|
|
2835
|
+
cancel?: (reason: CancelReason) => unknown;
|
|
2836
|
+
/**
|
|
2837
|
+
* Called before running a single test. Doesn't have "result" yet.
|
|
2838
|
+
*/
|
|
2839
|
+
onBeforeRunTask?: (test: Test) => unknown;
|
|
2840
|
+
/**
|
|
2841
|
+
* Called before actually running the test function. Already has "result" with "state" and "startTime".
|
|
2842
|
+
*/
|
|
2843
|
+
onBeforeTryTask?: (test: Test, options: TestTryOptions) => unknown;
|
|
2844
|
+
/**
|
|
2845
|
+
* When the task has finished running, but before cleanup hooks are called
|
|
2846
|
+
*/
|
|
2847
|
+
onTaskFinished?: (test: Test) => unknown;
|
|
2848
|
+
/**
|
|
2849
|
+
* Called after result and state are set.
|
|
2850
|
+
*/
|
|
2851
|
+
onAfterRunTask?: (test: Test) => unknown;
|
|
2852
|
+
/**
|
|
2853
|
+
* Called right after running the test function. Doesn't have new state yet. Will not be called, if the test function throws.
|
|
2854
|
+
*/
|
|
2855
|
+
onAfterTryTask?: (test: Test, options: TestTryOptions) => unknown;
|
|
2856
|
+
/**
|
|
2857
|
+
* Called after the retry resolution happened. Unlike `onAfterTryTask`, the test now has a new state.
|
|
2858
|
+
* All `after` hooks were also called by this point.
|
|
2859
|
+
*/
|
|
2860
|
+
onAfterRetryTask?: (test: Test, options: TestTryOptions) => unknown;
|
|
2861
|
+
/**
|
|
2862
|
+
* Called before running a single suite. Doesn't have "result" yet.
|
|
2863
|
+
*/
|
|
2864
|
+
onBeforeRunSuite?: (suite: Suite) => unknown;
|
|
2865
|
+
/**
|
|
2866
|
+
* Called after running a single suite. Has state and result.
|
|
2867
|
+
*/
|
|
2868
|
+
onAfterRunSuite?: (suite: Suite) => unknown;
|
|
2869
|
+
/**
|
|
2870
|
+
* If defined, will be called instead of usual Vitest suite partition and handling.
|
|
2871
|
+
* "before" and "after" hooks will not be ignored.
|
|
2872
|
+
*/
|
|
2873
|
+
runSuite?: (suite: Suite) => Promise<void>;
|
|
2874
|
+
/**
|
|
2875
|
+
* If defined, will be called instead of usual Vitest handling. Useful, if you have your custom test function.
|
|
2876
|
+
* "before" and "after" hooks will not be ignored.
|
|
2877
|
+
*/
|
|
2878
|
+
runTask?: (test: Test) => Promise<void>;
|
|
2879
|
+
/**
|
|
2880
|
+
* Called, when a task is updated. The same as "onTaskUpdate" in a reporter, but this is running in the same thread as tests.
|
|
2881
|
+
*/
|
|
2882
|
+
onTaskUpdate?: (task: TaskResultPack[], events: TaskEventPack[]) => Promise<void>;
|
|
2883
|
+
/**
|
|
2884
|
+
* Called when annotation is added via the `context.annotate` method.
|
|
2885
|
+
*/
|
|
2886
|
+
onTestAnnotate?: (test: Test, annotation: TestAnnotation) => Promise<TestAnnotation>;
|
|
2887
|
+
/**
|
|
2888
|
+
* @experimental
|
|
2889
|
+
*
|
|
2890
|
+
* Called when artifacts are recorded on tests via the `recordArtifact` utility.
|
|
2891
|
+
*/
|
|
2892
|
+
onTestArtifactRecord?: <Artifact extends TestArtifact>(test: Test, artifact: Artifact) => Promise<Artifact>;
|
|
2893
|
+
/**
|
|
2894
|
+
* Called before running all tests in collected paths.
|
|
2895
|
+
*/
|
|
2896
|
+
onBeforeRunFiles?: (files: File[]) => unknown;
|
|
2897
|
+
/**
|
|
2898
|
+
* Called right after running all tests in collected paths.
|
|
2899
|
+
*/
|
|
2900
|
+
onAfterRunFiles?: (files: File[]) => unknown;
|
|
2901
|
+
/**
|
|
2902
|
+
* Called when new context for a test is defined. Useful if you want to add custom properties to the context.
|
|
2903
|
+
* If you only want to define custom context, consider using "beforeAll" in "setupFiles" instead.
|
|
2904
|
+
*
|
|
2905
|
+
* @see https://vitest.dev/advanced/runner#your-task-function
|
|
2906
|
+
*/
|
|
2907
|
+
extendTaskContext?: (context: TestContext) => TestContext;
|
|
2908
|
+
/**
|
|
2909
|
+
* Called when test and setup files are imported. Can be called in two situations: when collecting tests and when importing setup files.
|
|
2910
|
+
*/
|
|
2911
|
+
importFile: (filepath: string, source: VitestRunnerImportSource) => unknown;
|
|
2912
|
+
/**
|
|
2913
|
+
* Function that is called when the runner attempts to get the value when `test.extend` is used with `{ injected: true }`
|
|
2914
|
+
*/
|
|
2915
|
+
injectValue?: (key: string) => unknown;
|
|
2916
|
+
/**
|
|
2917
|
+
* Gets the time spent importing each individual non-externalized file that Vitest collected.
|
|
2918
|
+
*/
|
|
2919
|
+
getImportDurations?: () => Record<string, ImportDuration>;
|
|
2920
|
+
/**
|
|
2921
|
+
* Publicly available configuration.
|
|
2922
|
+
*/
|
|
2923
|
+
config: SerializedConfig;
|
|
2924
|
+
/**
|
|
2925
|
+
* The name of the current pool. Can affect how stack trace is inferred on the server side.
|
|
2926
|
+
*/
|
|
2927
|
+
pool?: string;
|
|
2928
|
+
/**
|
|
2929
|
+
* The current Vite environment that processes the files on the server.
|
|
2930
|
+
*/
|
|
2931
|
+
viteEnvironment?: string;
|
|
2932
|
+
onCleanupWorkerContext?: (cleanup: () => unknown) => void;
|
|
2933
|
+
trace?<T>(name: string, cb: () => T): T;
|
|
2934
|
+
trace?<T>(name: string, attributes: Record<string, any>, cb: () => T): T;
|
|
2935
|
+
/** @internal */
|
|
2936
|
+
_currentSpecification?: FileSpecification | undefined;
|
|
2937
|
+
/** @internal */
|
|
2938
|
+
_currentTaskStartTime?: number;
|
|
2939
|
+
/** @internal */
|
|
2940
|
+
_currentTaskTimeout?: number;
|
|
2941
|
+
}
|
|
2942
|
+
//#endregion
|
|
2943
|
+
//#region src/reporter/report-io.d.ts
|
|
2944
|
+
/**
|
|
2945
|
+
* Report filesystem IO — abstracted so the blob serialization stays pure and
|
|
2946
|
+
* testable, while the actual writes go through the PixUI QuickJS `os` module.
|
|
2947
|
+
*
|
|
2948
|
+
* inflight-test never uses Node `fs`/`pathe` (req 1.6). The default
|
|
2949
|
+
* implementation here drives the QuickJS `os` builtin; the host integration
|
|
2950
|
+
* injects the concrete `os` object so this package stays decoupled from how a
|
|
2951
|
+
* given PixUI build exposes it.
|
|
2952
|
+
*/
|
|
2953
|
+
/** Minimal subset of the QuickJS `os` module we rely on. */
|
|
2954
|
+
interface QuickjsOs {
|
|
2955
|
+
open(path: string, flags: number, mode?: number): number;
|
|
2956
|
+
write(fd: number, buffer: ArrayBufferLike, byteOffset: number, byteLength: number): number;
|
|
2957
|
+
read(fd: number, buffer: ArrayBufferLike, byteOffset: number, byteLength: number): number;
|
|
2958
|
+
close(fd: number): number;
|
|
2959
|
+
mkdir(path: string, mode?: number): number;
|
|
2960
|
+
/** Returns `[stat, errno]`; `stat.size` is the file size in bytes. */
|
|
2961
|
+
stat(path: string): [{
|
|
2962
|
+
size: number;
|
|
2963
|
+
}, number];
|
|
2964
|
+
readonly O_WRONLY: number;
|
|
2965
|
+
readonly O_RDONLY: number;
|
|
2966
|
+
readonly O_CREAT: number;
|
|
2967
|
+
readonly O_TRUNC: number;
|
|
2968
|
+
}
|
|
2969
|
+
/** Runtime-agnostic report writer used by the BlobReporter + screenshot path. */
|
|
2970
|
+
interface ReportIo {
|
|
2971
|
+
/** Recursively create `dir` (no error if it already exists). */
|
|
2972
|
+
mkdirp(dir: string): void;
|
|
2973
|
+
/** Write UTF-8 text, creating/truncating the file. */
|
|
2974
|
+
writeText(path: string, text: string): void;
|
|
2975
|
+
/** Write raw bytes, creating/truncating the file. */
|
|
2976
|
+
writeBytes(path: string, bytes: Uint8Array): void;
|
|
2977
|
+
/** Read an entire file as bytes. */
|
|
2978
|
+
readBytes(path: string): Uint8Array;
|
|
2979
|
+
}
|
|
2980
|
+
/** Join path segments with `/` (report paths are POSIX-style, host-agnostic). */
|
|
2981
|
+
declare function joinPath(...parts: string[]): string;
|
|
2982
|
+
/**
|
|
2983
|
+
* {@link ReportIo} backed by the PixUI QuickJS `os` builtin.
|
|
2984
|
+
*
|
|
2985
|
+
* The `os` object is injected rather than imported so this module never hard
|
|
2986
|
+
* references an environment-specific global.
|
|
2987
|
+
*/
|
|
2988
|
+
declare class QuickjsReportIo implements ReportIo {
|
|
2989
|
+
private readonly _os;
|
|
2990
|
+
constructor(os: QuickjsOs);
|
|
2991
|
+
mkdirp(dir: string): void;
|
|
2992
|
+
writeText(path: string, text: string): void;
|
|
2993
|
+
writeBytes(path: string, bytes: Uint8Array): void;
|
|
2994
|
+
readBytes(path: string): Uint8Array;
|
|
2995
|
+
}
|
|
2996
|
+
/**
|
|
2997
|
+
* In-memory {@link ReportIo}. Useful for tests (simulated screenshot backend)
|
|
2998
|
+
* and for dry runs where nothing should touch disk. Paths are normalized to
|
|
2999
|
+
* POSIX form so writers/readers agree regardless of separator.
|
|
3000
|
+
*/
|
|
3001
|
+
declare class MemoryReportIo implements ReportIo {
|
|
3002
|
+
readonly files: Map<string, Uint8Array<ArrayBufferLike>>;
|
|
3003
|
+
readonly dirs: Set<string>;
|
|
3004
|
+
private static norm;
|
|
3005
|
+
mkdirp(dir: string): void;
|
|
3006
|
+
writeText(path: string, text: string): void;
|
|
3007
|
+
writeBytes(path: string, bytes: Uint8Array): void;
|
|
3008
|
+
readBytes(path: string): Uint8Array;
|
|
3009
|
+
}
|
|
3010
|
+
/**
|
|
3011
|
+
* Build a filesystem-safe run id from the local time, e.g.
|
|
3012
|
+
* `2026-06-04_19-30-40`. Contains no characters that are illegal in path
|
|
3013
|
+
* segments (req 5.4).
|
|
3014
|
+
*/
|
|
3015
|
+
declare function createRunId(date?: Date): string;
|
|
3016
|
+
//#endregion
|
|
3017
|
+
//#region src/ui/progress-surface.d.ts
|
|
3018
|
+
interface ProgressSurface {
|
|
3019
|
+
/** Called for every progress event while the run is in flight. */
|
|
3020
|
+
render(event: RunProgressEvent): void;
|
|
3021
|
+
/** Called once when the run finishes, with the final summary. */
|
|
3022
|
+
renderResult(result: InflightRunResult): void;
|
|
3023
|
+
/** Optional teardown (remove the overlay element, etc.). */
|
|
3024
|
+
dispose?(): void;
|
|
3025
|
+
}
|
|
3026
|
+
/** Default surface: structured console output. Runtime-agnostic. */
|
|
3027
|
+
declare class ConsoleProgressSurface implements ProgressSurface {
|
|
3028
|
+
private readonly _log;
|
|
3029
|
+
constructor(log?: (msg: string) => void);
|
|
3030
|
+
render(event: RunProgressEvent): void;
|
|
3031
|
+
renderResult(result: InflightRunResult): void;
|
|
3032
|
+
}
|
|
3033
|
+
/** Test/inspection surface: records every update. */
|
|
3034
|
+
declare class CollectingProgressSurface implements ProgressSurface {
|
|
3035
|
+
readonly events: RunProgressEvent[];
|
|
3036
|
+
result?: InflightRunResult;
|
|
3037
|
+
render(event: RunProgressEvent): void;
|
|
3038
|
+
renderResult(result: InflightRunResult): void;
|
|
3039
|
+
}
|
|
3040
|
+
//#endregion
|
|
3041
|
+
//#region src/page/activity-bridge.d.ts
|
|
3042
|
+
/**
|
|
3043
|
+
* ActivityBridge — the in-process PixUI activity SDK surface inflight-test
|
|
3044
|
+
* needs. In a real activity this is backed by the gamelet JS SDK
|
|
3045
|
+
* (`callGame` / `addOnGameCommandListener`); for tests it is backed by a
|
|
3046
|
+
* simulated implementation (see `simulated-bridge.ts`) so the runtime can be
|
|
3047
|
+
* exercised under the emulator's own vitest without a device or a real gamelet
|
|
3048
|
+
* package.
|
|
3049
|
+
*
|
|
3050
|
+
* inflight-test deliberately depends only on this tiny seam rather than on a
|
|
3051
|
+
* concrete SDK, mirroring how emulator-test depends on `BridgeClient` /
|
|
3052
|
+
* `InputBackend`.
|
|
3053
|
+
*
|
|
3054
|
+
* ── Screenshot protocol ──────────────────────────────────────────────────────
|
|
3055
|
+
* Request (Pandora → Game), protocol `pandoraCaptureScreen`:
|
|
3056
|
+
* { type: 'pandoraCaptureScreen', content: '', appId, appName,
|
|
3057
|
+
* leftTopX, leftTopY, captureWidth, captureHeight }
|
|
3058
|
+
* Callback (Game → Pandora), protocol `captureScreenCallback`:
|
|
3059
|
+
* { type: 'captureScreenCallback', content: '', appId, appName, savePath }
|
|
3060
|
+
* — `savePath` is the local PNG path the backend wrote; EMPTY means failure.
|
|
3061
|
+
*
|
|
3062
|
+
* The common envelope (`type` / `content` / `appId` / `appName`) is filled by
|
|
3063
|
+
* the SDK-aware bridge; inflight only supplies the capture geometry and reads
|
|
3064
|
+
* back `savePath`. There is no request id / correlation field: captures are
|
|
3065
|
+
* strictly serial (one in flight), so the next callback is always ours.
|
|
3066
|
+
*/
|
|
3067
|
+
/** Protocol name for requesting a host screenshot (Pandora → Game). */
|
|
3068
|
+
declare const PROTOCOL_CAPTURE_SCREEN = "pandoraCaptureScreen";
|
|
3069
|
+
/** Protocol name the host replies on with the screenshot result (Game → Pandora). */
|
|
3070
|
+
declare const PROTOCOL_CAPTURE_SCREEN_CALLBACK = "captureScreenCallback";
|
|
3071
|
+
/** A rectangular capture region, in screen pixels. */
|
|
3072
|
+
interface CaptureRect {
|
|
3073
|
+
x: number;
|
|
3074
|
+
y: number;
|
|
3075
|
+
width: number;
|
|
3076
|
+
height: number;
|
|
3077
|
+
}
|
|
3078
|
+
/**
|
|
3079
|
+
* The screenshot geometry inflight supplies for `pandoraCaptureScreen`. Full
|
|
3080
|
+
* screen is `window.screen` size at origin (0, 0); a clip maps to these fields.
|
|
3081
|
+
* The SDK-aware bridge wraps this with the `type`/`content`/`appId`/`appName`
|
|
3082
|
+
* envelope before sending.
|
|
3083
|
+
*/
|
|
3084
|
+
interface CaptureScreenRequest {
|
|
3085
|
+
/** Left-top X in screen coordinates. */
|
|
3086
|
+
leftTopX: number;
|
|
3087
|
+
/** Left-top Y in screen coordinates. */
|
|
3088
|
+
leftTopY: number;
|
|
3089
|
+
/** Capture width in pixels. */
|
|
3090
|
+
captureWidth: number;
|
|
3091
|
+
/** Capture height in pixels. */
|
|
3092
|
+
captureHeight: number;
|
|
3093
|
+
}
|
|
3094
|
+
/**
|
|
3095
|
+
* The `captureScreenCallback` payload. `savePath` is the local path of the PNG
|
|
3096
|
+
* the backend saved; an EMPTY string means the capture failed.
|
|
3097
|
+
*/
|
|
3098
|
+
interface CaptureScreenResult {
|
|
3099
|
+
savePath: string;
|
|
3100
|
+
}
|
|
3101
|
+
/**
|
|
3102
|
+
* The activity ⇄ host message bridge. A minimal subset of the gamelet SDK:
|
|
3103
|
+
* - `callGame(protocol, payload)` — fire a request to the host. The concrete
|
|
3104
|
+
* SDK bridge adds the `type`/`content`/`appId`/`appName` envelope.
|
|
3105
|
+
* - `onSDKMessage(protocol, handler)` — subscribe to host messages (matched by
|
|
3106
|
+
* protocol/`type`); returns an unsubscribe function.
|
|
3107
|
+
*/
|
|
3108
|
+
interface ActivityBridge {
|
|
3109
|
+
callGame(protocol: string, payload: unknown): void;
|
|
3110
|
+
onSDKMessage(protocol: string, handler: (payload: unknown) => void): () => void;
|
|
3111
|
+
}
|
|
3112
|
+
//#endregion
|
|
3113
|
+
//#region src/runner/run-tests.d.ts
|
|
3114
|
+
/** A discovered test file: an id plus a loader that triggers its registration. */
|
|
3115
|
+
interface TestFileSpec {
|
|
3116
|
+
/** Stable identifier (relative path), used as the task-tree file id. */
|
|
3117
|
+
id: string;
|
|
3118
|
+
/** Imports the (already bundled) test module, registering its describe/test. */
|
|
3119
|
+
load: () => unknown | Promise<unknown>;
|
|
3120
|
+
}
|
|
3121
|
+
interface RunProgressEvent {
|
|
3122
|
+
type: 'fileStart' | 'testStart' | 'testEnd' | 'done';
|
|
3123
|
+
name?: string | undefined;
|
|
3124
|
+
passed: number;
|
|
3125
|
+
failed: number;
|
|
3126
|
+
}
|
|
3127
|
+
interface InflightRunOptions {
|
|
3128
|
+
/** The test files to run, typically sourced from the webpack manifest. */
|
|
3129
|
+
specs: TestFileSpec[];
|
|
3130
|
+
/**
|
|
3131
|
+
* Absolute report directory root. When provided (together with `io`), the
|
|
3132
|
+
* BlobReporter writes `<reportDir>/<run-id>/report.blob` (+ screenshots).
|
|
3133
|
+
* Resolved by the caller from `external.writeablePath` on the PixUI host.
|
|
3134
|
+
*/
|
|
3135
|
+
reportDir?: string;
|
|
3136
|
+
/**
|
|
3137
|
+
* Filesystem writer (QuickJS `os`-backed). Required for report output;
|
|
3138
|
+
* omit it to run without writing a report (e.g. quick smoke runs).
|
|
3139
|
+
*/
|
|
3140
|
+
io?: ReportIo;
|
|
3141
|
+
/**
|
|
3142
|
+
* Activity ⇄ host bridge. When provided (with `io` + `reportDir`), the shared
|
|
3143
|
+
* {@link page} singleton can take screenshots from test code. Omit it for
|
|
3144
|
+
* runs that don't screenshot.
|
|
3145
|
+
*/
|
|
3146
|
+
activityBridge?: ActivityBridge;
|
|
3147
|
+
/** Test-id attribute for `page.getByTestId`. Default `data-testid`. */
|
|
3148
|
+
testIdAttribute?: string;
|
|
3149
|
+
/** On-screen progress surface (toast/overlay). */
|
|
3150
|
+
surface?: ProgressSurface;
|
|
3151
|
+
/** Low-level progress callback (fires for every event). */
|
|
3152
|
+
onProgress?: (event: RunProgressEvent) => void;
|
|
3153
|
+
}
|
|
3154
|
+
interface InflightRunResult {
|
|
3155
|
+
passed: number;
|
|
3156
|
+
failed: number;
|
|
3157
|
+
total: number;
|
|
3158
|
+
/**
|
|
3159
|
+
* File/suite-level failures that are NOT individual test failures — e.g. a
|
|
3160
|
+
* file that threw during collection (import error, top-level throw) or a
|
|
3161
|
+
* suite whose `beforeAll` failed. These would otherwise be invisible in the
|
|
3162
|
+
* pass/fail tally (a file that fails to collect contributes 0 tests), so we
|
|
3163
|
+
* surface them explicitly. Empty on a clean run.
|
|
3164
|
+
*/
|
|
3165
|
+
errors: string[];
|
|
3166
|
+
/** Absolute path of the written report directory, if any. */
|
|
3167
|
+
reportDir?: string;
|
|
3168
|
+
}
|
|
3169
|
+
interface ProgressEmitter {
|
|
3170
|
+
emit(event: RunProgressEvent): void;
|
|
3171
|
+
}
|
|
3172
|
+
/**
|
|
3173
|
+
* Minimal VitestRunner for the in-process (QuickJS) environment.
|
|
3174
|
+
*
|
|
3175
|
+
* The vendored runner drives collection and execution; this class only has to
|
|
3176
|
+
* resolve `importFile` to the corresponding bundled test module, surface a
|
|
3177
|
+
* config object, and translate the per-task lifecycle hooks into progress
|
|
3178
|
+
* events + pass/fail tallies. Everything else (suite/test scheduling, hook
|
|
3179
|
+
* ordering, artifact recording) is reused verbatim from the vendored source.
|
|
3180
|
+
*/
|
|
3181
|
+
declare class InflightVitestRunner implements VitestRunner {
|
|
3182
|
+
config: VitestRunner['config'];
|
|
3183
|
+
passed: number;
|
|
3184
|
+
failed: number;
|
|
3185
|
+
private readonly _byId;
|
|
3186
|
+
private readonly _emitter;
|
|
3187
|
+
constructor(specs: TestFileSpec[], emitter?: ProgressEmitter);
|
|
3188
|
+
/** Resolve a spec id to its bundled module and execute it (registers tests). */
|
|
3189
|
+
importFile(filepath: string): Promise<unknown>;
|
|
3190
|
+
onBeforeRunTask(test: {
|
|
3191
|
+
type?: string;
|
|
3192
|
+
name?: string;
|
|
3193
|
+
}): void;
|
|
3194
|
+
onAfterRunTask(test: {
|
|
3195
|
+
type?: string;
|
|
3196
|
+
name?: string;
|
|
3197
|
+
result?: {
|
|
3198
|
+
state?: string;
|
|
3199
|
+
};
|
|
3200
|
+
}): void;
|
|
3201
|
+
}
|
|
3202
|
+
/**
|
|
3203
|
+
* Run all provided test files serially inside the current runtime.
|
|
3204
|
+
*
|
|
3205
|
+
* One-shot: collects, executes, tallies pass/fail, optionally writes the blob
|
|
3206
|
+
* report + drives the progress surface, and resolves with a summary. Never
|
|
3207
|
+
* throws on test failures — failing tests are reflected in the counts
|
|
3208
|
+
* (req 4.4).
|
|
3209
|
+
*/
|
|
3210
|
+
declare function run(options: InflightRunOptions): Promise<InflightRunResult>;
|
|
3211
|
+
/** Options for {@link start}. */
|
|
3212
|
+
interface StartOptions {
|
|
3213
|
+
/**
|
|
3214
|
+
* Write a Vitest blob report. Default `true` — running and producing a report
|
|
3215
|
+
* is the norm. Set `false` for a quick smoke run with no disk output.
|
|
3216
|
+
*/
|
|
3217
|
+
report?: boolean;
|
|
3218
|
+
/** Activity ⇄ host bridge (enables `page.screenshot`). */
|
|
3219
|
+
activityBridge?: ActivityBridge;
|
|
3220
|
+
/** On-screen progress surface. */
|
|
3221
|
+
surface?: ProgressSurface;
|
|
3222
|
+
/** Low-level progress callback. */
|
|
3223
|
+
onProgress?: (event: RunProgressEvent) => void;
|
|
3224
|
+
/** Test-id attribute for `page.getByTestId`. */
|
|
3225
|
+
testIdAttribute?: string;
|
|
3226
|
+
/** Override the report root (defaults to `<external.writeablePath>/inflight-test-report`). */
|
|
3227
|
+
reportDir?: string;
|
|
3228
|
+
/** Override the report writer (defaults to a QuickJS-`os`-backed writer). */
|
|
3229
|
+
io?: ReportIo;
|
|
3230
|
+
}
|
|
3231
|
+
/**
|
|
3232
|
+
* Ergonomic entry: run `specs` with report output wired up by default.
|
|
3233
|
+
*
|
|
3234
|
+
* Unless `report: false`, the report writer + directory are auto-resolved from
|
|
3235
|
+
* the PixUI QuickJS host globals when not supplied — `io` from the `os` builtin
|
|
3236
|
+
* and `reportDir` from `<external.writeablePath>/inflight-test-report` — so an
|
|
3237
|
+
* activity can just call it. Hosts lacking those globals simply run without
|
|
3238
|
+
* writing a report.
|
|
3239
|
+
*
|
|
3240
|
+
* Most activities don't call this directly; the webpack plugin generates
|
|
3241
|
+
* `@pixui-dev/inflight-test/runner` which binds the discovered `specs` and
|
|
3242
|
+
* re-exports `start(options)` / `startWithoutReport(options)`.
|
|
3243
|
+
*/
|
|
3244
|
+
declare function start(specs: TestFileSpec[], options?: StartOptions): Promise<InflightRunResult>;
|
|
3245
|
+
//#endregion
|
|
3246
|
+
export { TestArtifact as A, joinPath as C, type SuiteCollector as D, SuiteAPI as E, beforeEach as F, onTestFailed as I, onTestFinished as L, afterAll as M, afterEach as N, Test as O, beforeAll as P, type createRunId as S, FileSpecification as T, ProgressSurface as _, type StartOptions as a, QuickjsReportIo as b, start as c, CaptureScreenRequest as d, CaptureScreenResult as f, ConsoleProgressSurface as g, CollectingProgressSurface as h, RunProgressEvent as i, VitestRunner as j, TestAPI as k, ActivityBridge as l, PROTOCOL_CAPTURE_SCREEN_CALLBACK as m, InflightRunResult as n, TestFileSpec as o, PROTOCOL_CAPTURE_SCREEN as p, InflightVitestRunner as r, run as s, InflightRunOptions as t, CaptureRect as u, MemoryReportIo as v, File as w, ReportIo as x, QuickjsOs as y };
|
|
3247
|
+
//# sourceMappingURL=run-tests-DoriyCYM.d.ts.map
|