@rstest/core 0.0.1
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/LICENSE +21 -0
- package/README.md +11 -0
- package/bin/rstest.js +20 -0
- package/dist/285.js +98 -0
- package/dist/353.js +488 -0
- package/dist/355.js +96 -0
- package/dist/629.js +80 -0
- package/dist/64.js +1735 -0
- package/dist/72.js +1309 -0
- package/dist/773.js +1709 -0
- package/dist/813.js +137 -0
- package/dist/973.js +482 -0
- package/dist/992.js +485 -0
- package/dist/cli.js +3685 -0
- package/dist/node.js +0 -0
- package/dist/public.js +4 -0
- package/dist/worker.js +5727 -0
- package/dist/worker.js.LICENSE.txt +28 -0
- package/dist-types/cli.d.ts +3 -0
- package/dist-types/node.d.ts +368 -0
- package/dist-types/public.d.ts +850 -0
- package/dist-types/worker.d.ts +646 -0
- package/globals.d.ts +13 -0
- package/importMeta.d.ts +3 -0
- package/package.json +85 -0
|
@@ -0,0 +1,850 @@
|
|
|
1
|
+
import type { addSerializer } from '@vitest/snapshot';
|
|
2
|
+
import type { assert as assert_2 } from 'chai';
|
|
3
|
+
import type { Assertion as Assertion_2 } from '@vitest/expect';
|
|
4
|
+
import type { ExpectStatic as ExpectStatic_2 } from '@vitest/expect';
|
|
5
|
+
import type { MatcherState as MatcherState_2 } from '@vitest/expect';
|
|
6
|
+
import type { RsbuildConfig } from '@rsbuild/core';
|
|
7
|
+
import type { SnapshotResult } from '@vitest/snapshot';
|
|
8
|
+
import type { SnapshotState } from '@vitest/snapshot';
|
|
9
|
+
import type { SnapshotSummary } from '@vitest/snapshot';
|
|
10
|
+
import type { Tester } from '@vitest/expect';
|
|
11
|
+
|
|
12
|
+
export declare const afterAll: Rstest['afterAll'];
|
|
13
|
+
|
|
14
|
+
declare type AfterAllListener = (ctx: SuiteContext) => MaybePromise<void>;
|
|
15
|
+
|
|
16
|
+
export declare const afterEach: Rstest['afterEach'];
|
|
17
|
+
|
|
18
|
+
declare type AfterEachListener = () => MaybePromise<void>;
|
|
19
|
+
|
|
20
|
+
export declare const assert: Rstest['assert'];
|
|
21
|
+
|
|
22
|
+
export declare interface Assertion<T = any> extends Assertion_2<T> {
|
|
23
|
+
matchSnapshot: SnapshotMatcher<T>;
|
|
24
|
+
toMatchSnapshot: SnapshotMatcher<T>;
|
|
25
|
+
toMatchInlineSnapshot: InlineSnapshotMatcher<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Checks that an error thrown by a function matches a previously recorded snapshot.
|
|
28
|
+
*
|
|
29
|
+
* @param message - Optional custom error message.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* expect(functionWithError).toThrowErrorMatchingSnapshot();
|
|
33
|
+
*/
|
|
34
|
+
toThrowErrorMatchingSnapshot: (message?: string) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Checks that an error thrown by a function matches an inline snapshot within the test file.
|
|
37
|
+
* Useful for keeping snapshots close to the test code.
|
|
38
|
+
*
|
|
39
|
+
* @param snapshot - Optional inline snapshot string to match.
|
|
40
|
+
* @param message - Optional custom error message.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const throwError = () => { throw new Error('Error occurred') };
|
|
44
|
+
* expect(throwError).toThrowErrorMatchingInlineSnapshot(`"Error occurred"`);
|
|
45
|
+
*/
|
|
46
|
+
toThrowErrorMatchingInlineSnapshot: (snapshot?: string, message?: string) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Compares the received value to a snapshot saved in a specified file.
|
|
49
|
+
* Useful for cases where snapshot content is large or needs to be shared across tests.
|
|
50
|
+
*
|
|
51
|
+
* @param filepath - Path to the snapshot file.
|
|
52
|
+
* @param message - Optional custom error message.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* await expect(largeData).toMatchFileSnapshot('path/to/snapshot.json');
|
|
56
|
+
*/
|
|
57
|
+
toMatchFileSnapshot: (filepath: string, message?: string) => Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Verifies that a promise resolves.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* await expect(someAsyncFunc).resolves.toBe(42);
|
|
63
|
+
*/
|
|
64
|
+
resolves: PromisifyAssertion<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Verifies that a promise rejects.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* await expect(someAsyncFunc).rejects.toThrow('error');
|
|
70
|
+
*/
|
|
71
|
+
rejects: PromisifyAssertion<T>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export declare const beforeAll: Rstest['beforeAll'];
|
|
75
|
+
|
|
76
|
+
declare type BeforeAllListener = (ctx: SuiteContext) => MaybePromise<void | AfterAllListener>;
|
|
77
|
+
|
|
78
|
+
export declare const beforeEach: Rstest['beforeEach'];
|
|
79
|
+
|
|
80
|
+
declare type BeforeEachListener = () => MaybePromise<void | AfterEachListener>;
|
|
81
|
+
|
|
82
|
+
declare type BuiltInReporterNames = keyof typeof reportersMap;
|
|
83
|
+
|
|
84
|
+
declare type BuiltinReporterOptions = {
|
|
85
|
+
default: DefaultReporterOptions;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
declare interface DecodedSourceMap extends SourceMapV3 {
|
|
89
|
+
mappings: SourceMapSegment[][];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
declare type DecodedSourceMapXInput = DecodedSourceMap & XInput;
|
|
93
|
+
|
|
94
|
+
declare class DefaultReporter implements Reporter {
|
|
95
|
+
private rootPath;
|
|
96
|
+
private config;
|
|
97
|
+
private options;
|
|
98
|
+
private statusRenderer;
|
|
99
|
+
constructor({ rootPath, options, config, }: {
|
|
100
|
+
rootPath: string;
|
|
101
|
+
config: NormalizedConfig;
|
|
102
|
+
options: DefaultReporterOptions;
|
|
103
|
+
});
|
|
104
|
+
onTestFileStart(test: TestFileInfo): void;
|
|
105
|
+
onTestFileResult(test: TestFileResult): void;
|
|
106
|
+
onTestCaseResult(_result: TestResult): void;
|
|
107
|
+
onUserConsoleLog(log: UserConsoleLog): void;
|
|
108
|
+
onExit(): Promise<void>;
|
|
109
|
+
onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary, }: {
|
|
110
|
+
results: TestFileResult[];
|
|
111
|
+
testResults: TestResult[];
|
|
112
|
+
duration: Duration;
|
|
113
|
+
snapshotSummary: SnapshotSummary;
|
|
114
|
+
getSourcemap: GetSourcemap;
|
|
115
|
+
}): Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
declare type DefaultReporterOptions = {
|
|
119
|
+
/**
|
|
120
|
+
* prints out summary of all tests
|
|
121
|
+
* @default true
|
|
122
|
+
*/
|
|
123
|
+
summary?: boolean;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* This function helps you to autocomplete configuration types.
|
|
128
|
+
* It accepts a Rsbuild config object, or a function that returns a config.
|
|
129
|
+
*/
|
|
130
|
+
export declare function defineConfig(config: RstestConfig): RstestConfig;
|
|
131
|
+
|
|
132
|
+
export declare function defineConfig(config: RstestConfigSyncFn): RstestConfigSyncFn;
|
|
133
|
+
|
|
134
|
+
export declare function defineConfig(config: RstestConfigAsyncFn): RstestConfigAsyncFn;
|
|
135
|
+
|
|
136
|
+
export declare function defineConfig(config: RstestConfigExport): RstestConfigExport;
|
|
137
|
+
|
|
138
|
+
export declare const describe: Rstest['describe'];
|
|
139
|
+
|
|
140
|
+
declare type DescribeAPI = DescribeFn & {
|
|
141
|
+
each: DescribeEachFn;
|
|
142
|
+
for: DescribeForFn;
|
|
143
|
+
only: DescribeAPI;
|
|
144
|
+
skip: DescribeAPI;
|
|
145
|
+
runIf: (condition: boolean) => DescribeAPI;
|
|
146
|
+
skipIf: (condition: boolean) => DescribeAPI;
|
|
147
|
+
todo: DescribeAPI;
|
|
148
|
+
concurrent: DescribeAPI;
|
|
149
|
+
sequential: DescribeAPI;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
declare interface DescribeEachFn {
|
|
153
|
+
<T extends Record<string, unknown>>(cases: ReadonlyArray<T>): (description: string, fn?: (param: T) => MaybePromise<void>) => void;
|
|
154
|
+
<T extends readonly [unknown, ...Array<unknown>]>(cases: ReadonlyArray<T>): (description: string, fn: (...args: [...T]) => MaybePromise<void>) => void;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
declare type DescribeFn = (description: string, fn?: () => void) => void;
|
|
158
|
+
|
|
159
|
+
declare type DescribeForFn = <T>(cases: ReadonlyArray<T>) => (description: string, fn?: (param: T) => MaybePromise<void>) => void;
|
|
160
|
+
|
|
161
|
+
declare type Duration = {
|
|
162
|
+
totalTime: number;
|
|
163
|
+
buildTime: number;
|
|
164
|
+
testTime: number;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
declare interface EncodedSourceMap extends SourceMapV3 {
|
|
168
|
+
mappings: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
declare type EncodedSourceMapXInput = EncodedSourceMap & XInput;
|
|
172
|
+
|
|
173
|
+
export declare const expect: Rstest['expect'];
|
|
174
|
+
|
|
175
|
+
declare interface ExpectPollOptions {
|
|
176
|
+
/**
|
|
177
|
+
* @default 50
|
|
178
|
+
*/
|
|
179
|
+
interval?: number;
|
|
180
|
+
/**
|
|
181
|
+
* @default 1000
|
|
182
|
+
*/
|
|
183
|
+
timeout?: number;
|
|
184
|
+
message?: string;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
declare interface ExpectStatic extends ExpectStatic_2 {
|
|
188
|
+
<T>(actual: T, message?: string): Assertion<T>;
|
|
189
|
+
unreachable: (message?: string) => never;
|
|
190
|
+
soft: <T>(actual: T, message?: string) => Assertion<T>;
|
|
191
|
+
poll: <T>(actual: () => T, options?: ExpectPollOptions) => Omit<PromisifyAssertion<Awaited<T>>, 'rejects' | 'resolves' | 'toThrow' | 'toThrowError' | 'throw' | 'throws' | 'matchSnapshot' | 'toMatchSnapshot' | 'toMatchInlineSnapshot' | 'toThrowErrorMatchingSnapshot' | 'toThrowErrorMatchingInlineSnapshot'>;
|
|
192
|
+
addEqualityTesters: (testers: Array<Tester>) => void;
|
|
193
|
+
assertions: (expected: number) => void;
|
|
194
|
+
hasAssertions: () => void;
|
|
195
|
+
addSnapshotSerializer: typeof addSerializer;
|
|
196
|
+
getState: () => MatcherState;
|
|
197
|
+
setState: (state: Partial<MatcherState>) => void;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
declare 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);
|
|
201
|
+
|
|
202
|
+
declare type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
|
|
203
|
+
|
|
204
|
+
declare interface FixtureOptions {
|
|
205
|
+
/**
|
|
206
|
+
* Whether to automatically set up current fixture, even though it's not being used in tests.
|
|
207
|
+
*/
|
|
208
|
+
auto?: boolean;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
declare type Fixtures<T extends Record<string, any> = object, ExtraContext = object> = {
|
|
212
|
+
[K in keyof T]: Fixture<T, K, ExtraContext & TestContext> | [Fixture<T, K, ExtraContext & TestContext>, FixtureOptions?];
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
declare type FormattedError = {
|
|
216
|
+
message: string;
|
|
217
|
+
name?: string;
|
|
218
|
+
stack?: string;
|
|
219
|
+
diff?: string;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
declare type FunctionLike = (...args: any) => any;
|
|
223
|
+
|
|
224
|
+
declare type GeneratedColumn = number;
|
|
225
|
+
|
|
226
|
+
declare type GetSourcemap = (sourcePath: string) => SourceMapInput | null;
|
|
227
|
+
|
|
228
|
+
declare interface InlineSnapshotMatcher<T> {
|
|
229
|
+
<U extends {
|
|
230
|
+
[P in keyof T]: any;
|
|
231
|
+
}>(properties: Partial<U>, snapshot?: string, message?: string): void;
|
|
232
|
+
(message?: string): void;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export declare const it: Rstest['it'];
|
|
236
|
+
|
|
237
|
+
declare interface MatcherState extends MatcherState_2 {
|
|
238
|
+
environment: string;
|
|
239
|
+
snapshotState: SnapshotState;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
declare type MaybePromise<T> = T | Promise<T>;
|
|
243
|
+
|
|
244
|
+
declare interface Mock<T extends FunctionLike = FunctionLike> extends MockInstance<T> {
|
|
245
|
+
new (...args: Parameters<T>): ReturnType<T>;
|
|
246
|
+
(...args: Parameters<T>): ReturnType<T>;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
declare type MockContext<T extends FunctionLike = FunctionLike> = {
|
|
250
|
+
/**
|
|
251
|
+
* List of the call arguments of all calls that have been made to the mock.
|
|
252
|
+
*/
|
|
253
|
+
calls: Array<Parameters<T>>;
|
|
254
|
+
/**
|
|
255
|
+
* List of all the object instances that have been instantiated from the mock.
|
|
256
|
+
*/
|
|
257
|
+
instances: Array<ReturnType<T>>;
|
|
258
|
+
/**
|
|
259
|
+
* List of all the function contexts that have been applied to calls to the mock.
|
|
260
|
+
*/
|
|
261
|
+
contexts: Array<ThisParameterType<T>>;
|
|
262
|
+
/**
|
|
263
|
+
* The order of mock's execution.
|
|
264
|
+
* This returns an array of numbers which are shared between all defined mocks.
|
|
265
|
+
* The index is starting with `1`.
|
|
266
|
+
*/
|
|
267
|
+
invocationCallOrder: Array<number>;
|
|
268
|
+
/**
|
|
269
|
+
* List of the call arguments of the last call that was made to the mock.
|
|
270
|
+
* If the function was not called, it will return `undefined`.
|
|
271
|
+
*/
|
|
272
|
+
lastCall: Parameters<T> | undefined;
|
|
273
|
+
/**
|
|
274
|
+
* List of the results of all calls that have been made to the mock.
|
|
275
|
+
*/
|
|
276
|
+
results: Array<MockResult<ReturnType<T>>>;
|
|
277
|
+
/**
|
|
278
|
+
* List of the results of all values that were `resolved` or `rejected` from the function.
|
|
279
|
+
*/
|
|
280
|
+
settledResults: MockSettledResult<Awaited<ReturnType<T>>>[];
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
declare type MockFn = <T extends FunctionLike = FunctionLike>(fn?: T) => Mock<T>;
|
|
284
|
+
|
|
285
|
+
declare interface MockInstance<T extends FunctionLike = FunctionLike> {
|
|
286
|
+
_isMockFunction: true;
|
|
287
|
+
/**
|
|
288
|
+
* Returns the mock name string set by calling `.mockName()`
|
|
289
|
+
*/
|
|
290
|
+
getMockName(): string;
|
|
291
|
+
/**
|
|
292
|
+
* Sets the mock name for this mock.
|
|
293
|
+
*/
|
|
294
|
+
mockName(name: string): this;
|
|
295
|
+
mock: MockContext<T>;
|
|
296
|
+
/**
|
|
297
|
+
* Clears all information about every call.
|
|
298
|
+
*/
|
|
299
|
+
mockClear(): this;
|
|
300
|
+
/**
|
|
301
|
+
* Does what `mockClear` does and resets inner implementation to the original function.
|
|
302
|
+
*/
|
|
303
|
+
mockReset(): this;
|
|
304
|
+
/**
|
|
305
|
+
* Does what `mockReset` does and restores original descriptors of spied-on objects.
|
|
306
|
+
*/
|
|
307
|
+
mockRestore(): void;
|
|
308
|
+
/**
|
|
309
|
+
* Returns current mock implementation if there is one.
|
|
310
|
+
*/
|
|
311
|
+
getMockImplementation(): T | undefined;
|
|
312
|
+
/**
|
|
313
|
+
* Accepts a function that should be used as the implementation of the mock.
|
|
314
|
+
*/
|
|
315
|
+
mockImplementation(fn: T): this;
|
|
316
|
+
/**
|
|
317
|
+
* Accepts a function that will be used as an implementation of the mock for one call to the mocked function.
|
|
318
|
+
*/
|
|
319
|
+
mockImplementationOnce(fn: T): this;
|
|
320
|
+
/**
|
|
321
|
+
* Accepts a function which should be temporarily used as the implementation of the mock while the callback is being executed.
|
|
322
|
+
*/
|
|
323
|
+
withImplementation<T2>(fn: T, callback: () => T2): T2 extends Promise<unknown> ? Promise<void> : void;
|
|
324
|
+
/**
|
|
325
|
+
* Return the `this` context from the method without invoking the actual implementation.
|
|
326
|
+
*/
|
|
327
|
+
mockReturnThis(): this;
|
|
328
|
+
/**
|
|
329
|
+
* Accepts a value that will be returned whenever the mock function is called.
|
|
330
|
+
*/
|
|
331
|
+
mockReturnValue(value: ReturnType<T>): this;
|
|
332
|
+
/**
|
|
333
|
+
* Accepts a value that will be returned for one call to the mock function.
|
|
334
|
+
*/
|
|
335
|
+
mockReturnValueOnce(value: ReturnType<T>): this;
|
|
336
|
+
/**
|
|
337
|
+
* Accepts a value that will be resolved when the async function is called.
|
|
338
|
+
*/
|
|
339
|
+
mockResolvedValue(value: Awaited<ReturnType<T>>): this;
|
|
340
|
+
/**
|
|
341
|
+
* Accepts a value that will be resolved during the next function call.
|
|
342
|
+
*/
|
|
343
|
+
mockResolvedValueOnce(value: Awaited<ReturnType<T>>): this;
|
|
344
|
+
/**
|
|
345
|
+
* Accepts an error that will be rejected when async function is called.
|
|
346
|
+
*/
|
|
347
|
+
mockRejectedValue(error: unknown): this;
|
|
348
|
+
/**
|
|
349
|
+
* Accepts a value that will be rejected during the next function call.
|
|
350
|
+
*/
|
|
351
|
+
mockRejectedValueOnce(error: unknown): this;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
declare type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
|
|
355
|
+
|
|
356
|
+
declare interface MockResultIncomplete {
|
|
357
|
+
type: 'incomplete';
|
|
358
|
+
value: undefined;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
declare interface MockResultReturn<T> {
|
|
362
|
+
type: 'return';
|
|
363
|
+
/**
|
|
364
|
+
* The value that was returned from the function. If function returned a Promise, then this will be a resolved value.
|
|
365
|
+
*/
|
|
366
|
+
value: T;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
declare interface MockResultThrow {
|
|
370
|
+
type: 'throw';
|
|
371
|
+
/**
|
|
372
|
+
* An error that was thrown during function execution.
|
|
373
|
+
*/
|
|
374
|
+
value: any;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
declare type MockSettledResult<T> = MockSettledResultFulfilled<T> | MockSettledResultRejected;
|
|
378
|
+
|
|
379
|
+
declare interface MockSettledResultFulfilled<T> {
|
|
380
|
+
type: 'fulfilled';
|
|
381
|
+
value: T;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
declare interface MockSettledResultFulfilled<T> {
|
|
385
|
+
type: 'fulfilled';
|
|
386
|
+
value: T;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
declare interface MockSettledResultRejected {
|
|
390
|
+
type: 'rejected';
|
|
391
|
+
value: any;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
declare interface MockSettledResultRejected {
|
|
395
|
+
type: 'rejected';
|
|
396
|
+
value: any;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
declare type NamesIndex = number;
|
|
400
|
+
|
|
401
|
+
declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool'>> & {
|
|
402
|
+
[key in OptionalKeys]?: RstestConfig[key];
|
|
403
|
+
} & {
|
|
404
|
+
pool: RstestPoolOptions;
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'tools' | 'onConsoleLog';
|
|
408
|
+
|
|
409
|
+
declare type Promisify<O> = {
|
|
410
|
+
[K in keyof O]: O[K] extends (...args: infer A) => infer R ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K];
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
declare type PromisifyAssertion<T> = Promisify<Assertion<T>>;
|
|
414
|
+
|
|
415
|
+
declare interface Reporter {
|
|
416
|
+
/**
|
|
417
|
+
* Called before test file run.
|
|
418
|
+
*/
|
|
419
|
+
onTestFileStart?: (test: TestFileInfo) => void;
|
|
420
|
+
/**
|
|
421
|
+
* Called when the test file has finished running.
|
|
422
|
+
*/
|
|
423
|
+
onTestFileResult?: (test: TestFileResult) => void;
|
|
424
|
+
/**
|
|
425
|
+
* Called when the test has finished running or was just skipped.
|
|
426
|
+
*/
|
|
427
|
+
onTestCaseResult?: (result: TestResult) => void;
|
|
428
|
+
/**
|
|
429
|
+
* Called after all tests have finished running.
|
|
430
|
+
*/
|
|
431
|
+
onTestRunEnd?: ({ results, testResults, duration, getSourcemap, snapshotSummary, }: {
|
|
432
|
+
results: TestFileResult[];
|
|
433
|
+
testResults: TestResult[];
|
|
434
|
+
duration: Duration;
|
|
435
|
+
getSourcemap: GetSourcemap;
|
|
436
|
+
snapshotSummary: SnapshotSummary;
|
|
437
|
+
}) => MaybePromise<void>;
|
|
438
|
+
/**
|
|
439
|
+
* Called when console log is calling.
|
|
440
|
+
*/
|
|
441
|
+
onUserConsoleLog?: (log: UserConsoleLog) => void;
|
|
442
|
+
/**
|
|
443
|
+
* Called when rstest exit abnormally
|
|
444
|
+
*/
|
|
445
|
+
onExit?: () => void;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
declare const reportersMap: {
|
|
449
|
+
default: typeof DefaultReporter;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
declare type ReporterWithOptions<Name extends BuiltInReporterNames = BuiltInReporterNames> = Name extends keyof BuiltinReporterOptions ? [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
|
|
453
|
+
|
|
454
|
+
declare type Rstest = RunnerAPI & {
|
|
455
|
+
expect: RstestExpect;
|
|
456
|
+
assert: typeof assert_2;
|
|
457
|
+
rstest: RstestUtilities;
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
export declare const rstest: RstestUtilities;
|
|
461
|
+
|
|
462
|
+
export declare interface RstestConfig {
|
|
463
|
+
/**
|
|
464
|
+
* Project root
|
|
465
|
+
*
|
|
466
|
+
* @default process.cwd()
|
|
467
|
+
*/
|
|
468
|
+
root?: string;
|
|
469
|
+
/**
|
|
470
|
+
* Project name
|
|
471
|
+
*
|
|
472
|
+
* @default rstest
|
|
473
|
+
*/
|
|
474
|
+
name?: string;
|
|
475
|
+
/**
|
|
476
|
+
* A list of glob patterns that match your test files.
|
|
477
|
+
*
|
|
478
|
+
* @default ['**\/*.{test,spec}.?(c|m)[jt]s?(x)']
|
|
479
|
+
*/
|
|
480
|
+
include?: string[];
|
|
481
|
+
/**
|
|
482
|
+
* A list of glob patterns that should be excluded from your test files.
|
|
483
|
+
*
|
|
484
|
+
* @default ['**\/node_modules/**', '**\/dist/**']
|
|
485
|
+
*/
|
|
486
|
+
exclude?: string[];
|
|
487
|
+
/**
|
|
488
|
+
* A list of glob patterns that match your in-source test files
|
|
489
|
+
*
|
|
490
|
+
* @default []
|
|
491
|
+
*/
|
|
492
|
+
includeSource?: string[];
|
|
493
|
+
/**
|
|
494
|
+
* Path to setup files. They will be run before each test file.
|
|
495
|
+
*/
|
|
496
|
+
setupFiles?: string[] | string;
|
|
497
|
+
/**
|
|
498
|
+
* Retry the test specific number of times if it fails.
|
|
499
|
+
* @default 0
|
|
500
|
+
*/
|
|
501
|
+
retry?: number;
|
|
502
|
+
/**
|
|
503
|
+
* Allows the test suite to pass when no files are found.
|
|
504
|
+
*
|
|
505
|
+
* @default false
|
|
506
|
+
*/
|
|
507
|
+
passWithNoTests?: boolean;
|
|
508
|
+
/**
|
|
509
|
+
* Pool used to run tests in.
|
|
510
|
+
*/
|
|
511
|
+
pool?: RstestPoolType | RstestPoolOptions;
|
|
512
|
+
/**
|
|
513
|
+
* Run tests in an isolated environment
|
|
514
|
+
*
|
|
515
|
+
* @default true
|
|
516
|
+
*/
|
|
517
|
+
isolate?: boolean;
|
|
518
|
+
/**
|
|
519
|
+
* Provide global APIs
|
|
520
|
+
*
|
|
521
|
+
* @default false
|
|
522
|
+
*/
|
|
523
|
+
globals?: boolean;
|
|
524
|
+
/**
|
|
525
|
+
* The environment that will be used for testing
|
|
526
|
+
*
|
|
527
|
+
* TODO: support more test environments
|
|
528
|
+
* @default 'node'
|
|
529
|
+
*/
|
|
530
|
+
testEnvironment?: 'node';
|
|
531
|
+
/**
|
|
532
|
+
* print console traces when calling any console method.
|
|
533
|
+
*
|
|
534
|
+
* @default false
|
|
535
|
+
*/
|
|
536
|
+
printConsoleTrace?: boolean;
|
|
537
|
+
/**
|
|
538
|
+
* Disable console intercept. `onConsoleLog` & `printConsoleTrace` configuration will not take effect.
|
|
539
|
+
*
|
|
540
|
+
* @default false
|
|
541
|
+
*/
|
|
542
|
+
disableConsoleIntercept?: boolean;
|
|
543
|
+
/**
|
|
544
|
+
* Update snapshot files. Will update all changed snapshots and delete obsolete ones.
|
|
545
|
+
*
|
|
546
|
+
* @default false
|
|
547
|
+
*/
|
|
548
|
+
update?: boolean;
|
|
549
|
+
/**
|
|
550
|
+
* Custom reporter for output.
|
|
551
|
+
* @default ['default']
|
|
552
|
+
*/
|
|
553
|
+
reporters?: Reporter | BuiltInReporterNames | (Reporter | BuiltInReporterNames | [BuiltInReporterNames] | ReporterWithOptions)[];
|
|
554
|
+
/**
|
|
555
|
+
* Run only tests with a name that matches the regex.
|
|
556
|
+
*/
|
|
557
|
+
testNamePattern?: string | RegExp;
|
|
558
|
+
/**
|
|
559
|
+
* Timeout of a test in milliseconds.
|
|
560
|
+
* @default 5000
|
|
561
|
+
*/
|
|
562
|
+
testTimeout?: number;
|
|
563
|
+
/**
|
|
564
|
+
* Automatically clear mock calls, instances, contexts and results before every test.
|
|
565
|
+
* @default false
|
|
566
|
+
*/
|
|
567
|
+
clearMocks?: boolean;
|
|
568
|
+
/**
|
|
569
|
+
* Automatically reset mock state before every test.
|
|
570
|
+
* @default false
|
|
571
|
+
*/
|
|
572
|
+
resetMocks?: boolean;
|
|
573
|
+
/**
|
|
574
|
+
* Automatically restore mock state and implementation before every test.
|
|
575
|
+
* @default false
|
|
576
|
+
*/
|
|
577
|
+
restoreMocks?: boolean;
|
|
578
|
+
/**
|
|
579
|
+
* The number of milliseconds after which a test or suite is considered slow and reported as such in the results.
|
|
580
|
+
* @default 300
|
|
581
|
+
*/
|
|
582
|
+
slowTestThreshold?: number;
|
|
583
|
+
/**
|
|
584
|
+
* Restores all global variables that were changed with `rstest.stubGlobal` before every test.
|
|
585
|
+
* @default false
|
|
586
|
+
*/
|
|
587
|
+
unstubGlobals?: boolean;
|
|
588
|
+
/**
|
|
589
|
+
* Restores all `process.env` values that were changed with `rstest.stubEnv` before every test.
|
|
590
|
+
* @default false
|
|
591
|
+
*/
|
|
592
|
+
unstubEnvs?: boolean;
|
|
593
|
+
/**
|
|
594
|
+
* Maximum number of concurrent tests
|
|
595
|
+
* @default 5
|
|
596
|
+
*/
|
|
597
|
+
maxConcurrency?: number;
|
|
598
|
+
/**
|
|
599
|
+
* Custom handler for console log in tests
|
|
600
|
+
*/
|
|
601
|
+
onConsoleLog?: (content: string) => boolean | void;
|
|
602
|
+
plugins?: RsbuildConfig['plugins'];
|
|
603
|
+
source?: Pick<NonNullable<RsbuildConfig['source']>, 'define' | 'tsconfigPath' | 'decorators' | 'include' | 'exclude'>;
|
|
604
|
+
output?: Pick<NonNullable<RsbuildConfig['output']>, 'cssModules'>;
|
|
605
|
+
resolve?: RsbuildConfig['resolve'];
|
|
606
|
+
tools?: Pick<NonNullable<RsbuildConfig['tools']>, 'rspack' | 'swc' | 'bundlerChain'>;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
export declare type RstestConfigAsyncFn = () => Promise<RstestConfig>;
|
|
610
|
+
|
|
611
|
+
export declare type RstestConfigExport = RstestConfig | RstestConfigSyncFn | RstestConfigAsyncFn;
|
|
612
|
+
|
|
613
|
+
export declare type RstestConfigSyncFn = () => RstestConfig;
|
|
614
|
+
|
|
615
|
+
declare type RstestExpect = ExpectStatic;
|
|
616
|
+
|
|
617
|
+
declare type RstestPoolOptions = {
|
|
618
|
+
/** Pool used to run tests in. */
|
|
619
|
+
type: RstestPoolType;
|
|
620
|
+
/** Maximum number or percentage of workers to run tests in. */
|
|
621
|
+
maxWorkers?: number | string;
|
|
622
|
+
/** Minimum number or percentage of workers to run tests in. */
|
|
623
|
+
minWorkers?: number | string;
|
|
624
|
+
/** Pass additional arguments to node process in the child processes. */
|
|
625
|
+
execArgv?: string[];
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
declare type RstestPoolType = 'forks';
|
|
629
|
+
|
|
630
|
+
declare type RstestUtilities = {
|
|
631
|
+
/**
|
|
632
|
+
* Creates a spy on a function.
|
|
633
|
+
*/
|
|
634
|
+
fn: MockFn;
|
|
635
|
+
/**
|
|
636
|
+
* Creates a spy on a method of an object
|
|
637
|
+
*/
|
|
638
|
+
spyOn: <T extends Record<string, any>, K extends keyof T>(obj: T, methodName: K, accessType?: 'get' | 'set') => MockInstance<T[K]>;
|
|
639
|
+
/**
|
|
640
|
+
* Determines if the given function is a mocked function.
|
|
641
|
+
*/
|
|
642
|
+
isMockFunction: (fn: any) => fn is MockInstance;
|
|
643
|
+
/**
|
|
644
|
+
* Calls `.mockClear()` on all spies.
|
|
645
|
+
*/
|
|
646
|
+
clearAllMocks: () => RstestUtilities;
|
|
647
|
+
/**
|
|
648
|
+
* Calls `.mockReset()` on all spies.
|
|
649
|
+
*/
|
|
650
|
+
resetAllMocks: () => RstestUtilities;
|
|
651
|
+
/**
|
|
652
|
+
* Calls `.mockRestore()` on all spies.
|
|
653
|
+
*/
|
|
654
|
+
restoreAllMocks: () => RstestUtilities;
|
|
655
|
+
/**
|
|
656
|
+
* @todo
|
|
657
|
+
* Mock a module
|
|
658
|
+
*/
|
|
659
|
+
mock: <T = unknown>(moduleName: string, moduleFactory?: () => T) => void;
|
|
660
|
+
/**
|
|
661
|
+
* @todo
|
|
662
|
+
* Mock a module, not hoisted.
|
|
663
|
+
*/
|
|
664
|
+
doMock: <T = unknown>(moduleName: string, moduleFactory?: () => T) => void;
|
|
665
|
+
/**
|
|
666
|
+
* @todo
|
|
667
|
+
* Removes module from the mocked registry.
|
|
668
|
+
*/
|
|
669
|
+
unMock: (path: string) => void;
|
|
670
|
+
/**
|
|
671
|
+
* @todo
|
|
672
|
+
* Removes module from the mocked registry, not hoisted.
|
|
673
|
+
*/
|
|
674
|
+
doUnMock: (path: string) => void;
|
|
675
|
+
/**
|
|
676
|
+
* @todo
|
|
677
|
+
* Imports a module with all of its properties (including nested properties) mocked.
|
|
678
|
+
*/
|
|
679
|
+
importMock: <T = Record<string, unknown>>(path: string) => Promise<T>;
|
|
680
|
+
/**
|
|
681
|
+
* @todo
|
|
682
|
+
* Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not.
|
|
683
|
+
*/
|
|
684
|
+
importActual: <T = Record<string, unknown>>(path: string) => Promise<T>;
|
|
685
|
+
/**
|
|
686
|
+
* @todo
|
|
687
|
+
* Resets modules registry by clearing the cache of all modules.
|
|
688
|
+
*/
|
|
689
|
+
resetModules: () => RstestUtilities;
|
|
690
|
+
/**
|
|
691
|
+
* Changes the value of environmental variable on `process.env`.
|
|
692
|
+
*/
|
|
693
|
+
stubEnv: (name: string, value: string | undefined) => RstestUtilities;
|
|
694
|
+
/**
|
|
695
|
+
* Restores all `process.env` values that were changed with `rstest.stubEnv`.
|
|
696
|
+
*/
|
|
697
|
+
unstubAllEnvs: () => RstestUtilities;
|
|
698
|
+
/**
|
|
699
|
+
* Changes the value of global variable.
|
|
700
|
+
*/
|
|
701
|
+
stubGlobal: (name: string | number | symbol, value: unknown) => RstestUtilities;
|
|
702
|
+
/**
|
|
703
|
+
* Restores all global variables that were changed with `rstest.stubGlobal`.
|
|
704
|
+
*/
|
|
705
|
+
unstubAllGlobals: () => RstestUtilities;
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
declare type RunnerAPI = {
|
|
709
|
+
describe: DescribeAPI;
|
|
710
|
+
it: TestAPIs;
|
|
711
|
+
test: TestAPIs;
|
|
712
|
+
beforeAll: (fn: BeforeAllListener, timeout?: number) => MaybePromise<void>;
|
|
713
|
+
afterAll: (fn: AfterAllListener, timeout?: number) => MaybePromise<void>;
|
|
714
|
+
beforeEach: (fn: BeforeEachListener, timeout?: number) => MaybePromise<void>;
|
|
715
|
+
afterEach: (fn: AfterEachListener, timeout?: number) => MaybePromise<void>;
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
declare interface SnapshotMatcher<T> {
|
|
719
|
+
<U extends {
|
|
720
|
+
[P in keyof T]: any;
|
|
721
|
+
}>(snapshot: Partial<U>, message?: string): void;
|
|
722
|
+
(message?: string): void;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
declare type SourceColumn = number;
|
|
726
|
+
|
|
727
|
+
declare type SourceLine = number;
|
|
728
|
+
|
|
729
|
+
declare abstract class SourceMap {
|
|
730
|
+
version: SourceMapV3['version'];
|
|
731
|
+
file: SourceMapV3['file'];
|
|
732
|
+
names: SourceMapV3['names'];
|
|
733
|
+
sourceRoot: SourceMapV3['sourceRoot'];
|
|
734
|
+
sources: SourceMapV3['sources'];
|
|
735
|
+
sourcesContent: SourceMapV3['sourcesContent'];
|
|
736
|
+
resolvedSources: SourceMapV3['sources'];
|
|
737
|
+
ignoreList: SourceMapV3['ignoreList'];
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
declare type SourceMapInput = string | EncodedSourceMapXInput | DecodedSourceMapXInput | TraceMap;
|
|
741
|
+
|
|
742
|
+
declare type SourceMapSegment = [GeneratedColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
|
|
743
|
+
|
|
744
|
+
declare interface SourceMapV3 {
|
|
745
|
+
file?: string | null;
|
|
746
|
+
names: string[];
|
|
747
|
+
sourceRoot?: string;
|
|
748
|
+
sources: (string | null)[];
|
|
749
|
+
sourcesContent?: (string | null)[];
|
|
750
|
+
version: 3;
|
|
751
|
+
ignoreList?: number[];
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
declare type SourcesIndex = number;
|
|
755
|
+
|
|
756
|
+
declare type SuiteContext = {
|
|
757
|
+
filepath: TestPath;
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
export declare const test: Rstest['test'];
|
|
761
|
+
|
|
762
|
+
declare type TestAPI<ExtraContext = object> = TestFn<ExtraContext> & {
|
|
763
|
+
each: TestEachFn;
|
|
764
|
+
for: TestForFn<ExtraContext>;
|
|
765
|
+
fails: TestAPI<ExtraContext>;
|
|
766
|
+
concurrent: TestAPI<ExtraContext>;
|
|
767
|
+
sequential: TestAPI<ExtraContext>;
|
|
768
|
+
only: TestAPI<ExtraContext>;
|
|
769
|
+
skip: TestAPI<ExtraContext>;
|
|
770
|
+
todo: TestAPI<ExtraContext>;
|
|
771
|
+
runIf: (condition: boolean) => TestAPI<ExtraContext>;
|
|
772
|
+
skipIf: (condition: boolean) => TestAPI<ExtraContext>;
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
declare type TestAPIs<ExtraContext = object> = TestAPI<ExtraContext> & {
|
|
776
|
+
extend: <T extends Record<string, any> = object>(fixtures: Fixtures<T, ExtraContext>) => TestAPIs<{
|
|
777
|
+
[K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
|
|
778
|
+
}>;
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
declare type TestCallbackFn<ExtraContext = object> = (context: TestContext & ExtraContext) => MaybePromise<void>;
|
|
782
|
+
|
|
783
|
+
declare type TestContext = {
|
|
784
|
+
expect: RstestExpect;
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
declare interface TestEachFn {
|
|
788
|
+
<T extends Record<string, unknown>>(cases: ReadonlyArray<T>): (description: string, fn?: (param: T) => MaybePromise<void>, timeout?: number) => void;
|
|
789
|
+
<T extends readonly [unknown, ...Array<unknown>]>(cases: ReadonlyArray<T>): (description: string, fn: (...args: [...T]) => MaybePromise<void>, timeout?: number) => void;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
declare type TestFileInfo = {
|
|
793
|
+
testPath: TestPath;
|
|
794
|
+
};
|
|
795
|
+
|
|
796
|
+
declare type TestFileResult = TestResult & {
|
|
797
|
+
results: TestResult[];
|
|
798
|
+
snapshotResult?: SnapshotResult;
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
declare type TestFn<ExtraContext = object> = (description: string, fn?: TestCallbackFn<ExtraContext>, timeout?: number) => void;
|
|
802
|
+
|
|
803
|
+
declare type TestForFn<ExtraContext = object> = <T>(cases: ReadonlyArray<T>) => (description: string, fn?: (param: T, context: TestContext & ExtraContext) => MaybePromise<void>, timeout?: number) => void;
|
|
804
|
+
|
|
805
|
+
/** The test file original path */
|
|
806
|
+
declare type TestPath = string;
|
|
807
|
+
|
|
808
|
+
declare type TestResult = {
|
|
809
|
+
status: TestResultStatus;
|
|
810
|
+
name: string;
|
|
811
|
+
testPath: TestPath;
|
|
812
|
+
parentNames?: string[];
|
|
813
|
+
duration?: number;
|
|
814
|
+
errors?: FormattedError[];
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
declare type TestResultStatus = 'skip' | 'pass' | 'fail' | 'todo';
|
|
818
|
+
|
|
819
|
+
declare class TraceMap implements SourceMap {
|
|
820
|
+
version: SourceMapV3['version'];
|
|
821
|
+
file: SourceMapV3['file'];
|
|
822
|
+
names: SourceMapV3['names'];
|
|
823
|
+
sourceRoot: SourceMapV3['sourceRoot'];
|
|
824
|
+
sources: SourceMapV3['sources'];
|
|
825
|
+
sourcesContent: SourceMapV3['sourcesContent'];
|
|
826
|
+
ignoreList: SourceMapV3['ignoreList'];
|
|
827
|
+
resolvedSources: string[];
|
|
828
|
+
private _encoded;
|
|
829
|
+
private _decoded;
|
|
830
|
+
private _decodedMemo;
|
|
831
|
+
private _bySources;
|
|
832
|
+
private _bySourceMemos;
|
|
833
|
+
constructor(map: SourceMapInput, mapUrl?: string | null);
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
declare type Use<T> = (value: T) => Promise<void>;
|
|
837
|
+
|
|
838
|
+
declare interface UserConsoleLog {
|
|
839
|
+
content: string;
|
|
840
|
+
name: string;
|
|
841
|
+
trace?: string;
|
|
842
|
+
testPath: TestPath;
|
|
843
|
+
type: 'stdout' | 'stderr';
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
declare type XInput = {
|
|
847
|
+
x_google_ignoreList?: SourceMapV3['ignoreList'];
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
export { }
|