@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,646 @@
|
|
|
1
|
+
import type { addSerializer } from '@vitest/snapshot';
|
|
2
|
+
import type { Assertion as Assertion_2 } from '@vitest/expect';
|
|
3
|
+
import type { ExpectStatic as ExpectStatic_2 } from '@vitest/expect';
|
|
4
|
+
import type { MatcherState as MatcherState_2 } from '@vitest/expect';
|
|
5
|
+
import type { RsbuildConfig } from '@rsbuild/core';
|
|
6
|
+
import type { SnapshotManager } from '@vitest/snapshot/manager';
|
|
7
|
+
import type { SnapshotResult } from '@vitest/snapshot';
|
|
8
|
+
import type { SnapshotState } from '@vitest/snapshot';
|
|
9
|
+
import type { SnapshotSummary } from '@vitest/snapshot';
|
|
10
|
+
import type { SnapshotUpdateState } from '@vitest/snapshot';
|
|
11
|
+
import type { Tester } from '@vitest/expect';
|
|
12
|
+
|
|
13
|
+
declare type AfterAllListener = (ctx: SuiteContext) => MaybePromise<void>;
|
|
14
|
+
|
|
15
|
+
declare type AfterEachListener = () => MaybePromise<void>;
|
|
16
|
+
|
|
17
|
+
declare interface Assertion<T = any> extends Assertion_2<T> {
|
|
18
|
+
matchSnapshot: SnapshotMatcher<T>;
|
|
19
|
+
toMatchSnapshot: SnapshotMatcher<T>;
|
|
20
|
+
toMatchInlineSnapshot: InlineSnapshotMatcher<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Checks that an error thrown by a function matches a previously recorded snapshot.
|
|
23
|
+
*
|
|
24
|
+
* @param message - Optional custom error message.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* expect(functionWithError).toThrowErrorMatchingSnapshot();
|
|
28
|
+
*/
|
|
29
|
+
toThrowErrorMatchingSnapshot: (message?: string) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Checks that an error thrown by a function matches an inline snapshot within the test file.
|
|
32
|
+
* Useful for keeping snapshots close to the test code.
|
|
33
|
+
*
|
|
34
|
+
* @param snapshot - Optional inline snapshot string to match.
|
|
35
|
+
* @param message - Optional custom error message.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const throwError = () => { throw new Error('Error occurred') };
|
|
39
|
+
* expect(throwError).toThrowErrorMatchingInlineSnapshot(`"Error occurred"`);
|
|
40
|
+
*/
|
|
41
|
+
toThrowErrorMatchingInlineSnapshot: (snapshot?: string, message?: string) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Compares the received value to a snapshot saved in a specified file.
|
|
44
|
+
* Useful for cases where snapshot content is large or needs to be shared across tests.
|
|
45
|
+
*
|
|
46
|
+
* @param filepath - Path to the snapshot file.
|
|
47
|
+
* @param message - Optional custom error message.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* await expect(largeData).toMatchFileSnapshot('path/to/snapshot.json');
|
|
51
|
+
*/
|
|
52
|
+
toMatchFileSnapshot: (filepath: string, message?: string) => Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Verifies that a promise resolves.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* await expect(someAsyncFunc).resolves.toBe(42);
|
|
58
|
+
*/
|
|
59
|
+
resolves: PromisifyAssertion<T>;
|
|
60
|
+
/**
|
|
61
|
+
* Verifies that a promise rejects.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* await expect(someAsyncFunc).rejects.toThrow('error');
|
|
65
|
+
*/
|
|
66
|
+
rejects: PromisifyAssertion<T>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare type BeforeAllListener = (ctx: SuiteContext) => MaybePromise<void | AfterAllListener>;
|
|
70
|
+
|
|
71
|
+
declare type BeforeEachListener = () => MaybePromise<void | AfterEachListener>;
|
|
72
|
+
|
|
73
|
+
declare type BuiltInReporterNames = keyof typeof reportersMap;
|
|
74
|
+
|
|
75
|
+
declare type BuiltinReporterOptions = {
|
|
76
|
+
default: DefaultReporterOptions;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
declare interface DecodedSourceMap extends SourceMapV3 {
|
|
80
|
+
mappings: SourceMapSegment[][];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
declare type DecodedSourceMapXInput = DecodedSourceMap & XInput;
|
|
84
|
+
|
|
85
|
+
declare class DefaultReporter implements Reporter {
|
|
86
|
+
private rootPath;
|
|
87
|
+
private config;
|
|
88
|
+
private options;
|
|
89
|
+
private statusRenderer;
|
|
90
|
+
constructor({ rootPath, options, config, }: {
|
|
91
|
+
rootPath: string;
|
|
92
|
+
config: NormalizedConfig;
|
|
93
|
+
options: DefaultReporterOptions;
|
|
94
|
+
});
|
|
95
|
+
onTestFileStart(test: TestFileInfo): void;
|
|
96
|
+
onTestFileResult(test: TestFileResult): void;
|
|
97
|
+
onTestCaseResult(_result: TestResult): void;
|
|
98
|
+
onUserConsoleLog(log: UserConsoleLog): void;
|
|
99
|
+
onExit(): Promise<void>;
|
|
100
|
+
onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary, }: {
|
|
101
|
+
results: TestFileResult[];
|
|
102
|
+
testResults: TestResult[];
|
|
103
|
+
duration: Duration;
|
|
104
|
+
snapshotSummary: SnapshotSummary;
|
|
105
|
+
getSourcemap: GetSourcemap;
|
|
106
|
+
}): Promise<void>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
declare type DefaultReporterOptions = {
|
|
110
|
+
/**
|
|
111
|
+
* prints out summary of all tests
|
|
112
|
+
* @default true
|
|
113
|
+
*/
|
|
114
|
+
summary?: boolean;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** The test file output path */
|
|
118
|
+
declare type DistPath = string;
|
|
119
|
+
|
|
120
|
+
declare type Duration = {
|
|
121
|
+
totalTime: number;
|
|
122
|
+
buildTime: number;
|
|
123
|
+
testTime: number;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
declare interface EncodedSourceMap extends SourceMapV3 {
|
|
127
|
+
mappings: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
declare type EncodedSourceMapXInput = EncodedSourceMap & XInput;
|
|
131
|
+
|
|
132
|
+
declare type EntryInfo = {
|
|
133
|
+
distPath: DistPath;
|
|
134
|
+
testPath: TestPath;
|
|
135
|
+
files?: string[];
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
declare interface ExpectPollOptions {
|
|
139
|
+
/**
|
|
140
|
+
* @default 50
|
|
141
|
+
*/
|
|
142
|
+
interval?: number;
|
|
143
|
+
/**
|
|
144
|
+
* @default 1000
|
|
145
|
+
*/
|
|
146
|
+
timeout?: number;
|
|
147
|
+
message?: string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
declare interface ExpectStatic extends ExpectStatic_2 {
|
|
151
|
+
<T>(actual: T, message?: string): Assertion<T>;
|
|
152
|
+
unreachable: (message?: string) => never;
|
|
153
|
+
soft: <T>(actual: T, message?: string) => Assertion<T>;
|
|
154
|
+
poll: <T>(actual: () => T, options?: ExpectPollOptions) => Omit<PromisifyAssertion<Awaited<T>>, 'rejects' | 'resolves' | 'toThrow' | 'toThrowError' | 'throw' | 'throws' | 'matchSnapshot' | 'toMatchSnapshot' | 'toMatchInlineSnapshot' | 'toThrowErrorMatchingSnapshot' | 'toThrowErrorMatchingInlineSnapshot'>;
|
|
155
|
+
addEqualityTesters: (testers: Array<Tester>) => void;
|
|
156
|
+
assertions: (expected: number) => void;
|
|
157
|
+
hasAssertions: () => void;
|
|
158
|
+
addSnapshotSerializer: typeof addSerializer;
|
|
159
|
+
getState: () => MatcherState;
|
|
160
|
+
setState: (state: Partial<MatcherState>) => void;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
declare type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
|
|
164
|
+
|
|
165
|
+
declare interface FixtureOptions {
|
|
166
|
+
/**
|
|
167
|
+
* Whether to automatically set up current fixture, even though it's not being used in tests.
|
|
168
|
+
*/
|
|
169
|
+
auto?: boolean;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
declare type FormattedError = {
|
|
173
|
+
message: string;
|
|
174
|
+
name?: string;
|
|
175
|
+
stack?: string;
|
|
176
|
+
diff?: string;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
declare type GeneratedColumn = number;
|
|
180
|
+
|
|
181
|
+
declare type GetSourcemap = (sourcePath: string) => SourceMapInput | null;
|
|
182
|
+
|
|
183
|
+
declare interface InlineSnapshotMatcher<T> {
|
|
184
|
+
<U extends {
|
|
185
|
+
[P in keyof T]: any;
|
|
186
|
+
}>(properties: Partial<U>, snapshot?: string, message?: string): void;
|
|
187
|
+
(message?: string): void;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
declare interface MatcherState extends MatcherState_2 {
|
|
191
|
+
environment: string;
|
|
192
|
+
snapshotState: SnapshotState;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
declare type MaybePromise<T> = T | Promise<T>;
|
|
196
|
+
|
|
197
|
+
declare type NamesIndex = number;
|
|
198
|
+
|
|
199
|
+
declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool'>> & {
|
|
200
|
+
[key in OptionalKeys]?: RstestConfig[key];
|
|
201
|
+
} & {
|
|
202
|
+
pool: RstestPoolOptions;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
declare type NormalizedFixture = {
|
|
206
|
+
isFn: boolean;
|
|
207
|
+
deps?: string[];
|
|
208
|
+
value: FixtureFn<any, any, any> | any;
|
|
209
|
+
options?: FixtureOptions;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
declare type NormalizedFixtures = Record<string, NormalizedFixture>;
|
|
213
|
+
|
|
214
|
+
declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'tools' | 'onConsoleLog';
|
|
215
|
+
|
|
216
|
+
declare type Promisify<O> = {
|
|
217
|
+
[K in keyof O]: O[K] extends (...args: infer A) => infer R ? Promisify<O[K]> & ((...args: A) => Promise<R>) : O[K];
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
declare type PromisifyAssertion<T> = Promisify<Assertion<T>>;
|
|
221
|
+
|
|
222
|
+
declare interface Reporter {
|
|
223
|
+
/**
|
|
224
|
+
* Called before test file run.
|
|
225
|
+
*/
|
|
226
|
+
onTestFileStart?: (test: TestFileInfo) => void;
|
|
227
|
+
/**
|
|
228
|
+
* Called when the test file has finished running.
|
|
229
|
+
*/
|
|
230
|
+
onTestFileResult?: (test: TestFileResult) => void;
|
|
231
|
+
/**
|
|
232
|
+
* Called when the test has finished running or was just skipped.
|
|
233
|
+
*/
|
|
234
|
+
onTestCaseResult?: (result: TestResult) => void;
|
|
235
|
+
/**
|
|
236
|
+
* Called after all tests have finished running.
|
|
237
|
+
*/
|
|
238
|
+
onTestRunEnd?: ({ results, testResults, duration, getSourcemap, snapshotSummary, }: {
|
|
239
|
+
results: TestFileResult[];
|
|
240
|
+
testResults: TestResult[];
|
|
241
|
+
duration: Duration;
|
|
242
|
+
getSourcemap: GetSourcemap;
|
|
243
|
+
snapshotSummary: SnapshotSummary;
|
|
244
|
+
}) => MaybePromise<void>;
|
|
245
|
+
/**
|
|
246
|
+
* Called when console log is calling.
|
|
247
|
+
*/
|
|
248
|
+
onUserConsoleLog?: (log: UserConsoleLog) => void;
|
|
249
|
+
/**
|
|
250
|
+
* Called when rstest exit abnormally
|
|
251
|
+
*/
|
|
252
|
+
onExit?: () => void;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
declare const reportersMap: {
|
|
256
|
+
default: typeof DefaultReporter;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
declare type ReporterWithOptions<Name extends BuiltInReporterNames = BuiltInReporterNames> = Name extends keyof BuiltinReporterOptions ? [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
|
|
260
|
+
|
|
261
|
+
declare type RstestCommand = 'watch' | 'run' | 'list';
|
|
262
|
+
|
|
263
|
+
declare interface RstestConfig {
|
|
264
|
+
/**
|
|
265
|
+
* Project root
|
|
266
|
+
*
|
|
267
|
+
* @default process.cwd()
|
|
268
|
+
*/
|
|
269
|
+
root?: string;
|
|
270
|
+
/**
|
|
271
|
+
* Project name
|
|
272
|
+
*
|
|
273
|
+
* @default rstest
|
|
274
|
+
*/
|
|
275
|
+
name?: string;
|
|
276
|
+
/**
|
|
277
|
+
* A list of glob patterns that match your test files.
|
|
278
|
+
*
|
|
279
|
+
* @default ['**\/*.{test,spec}.?(c|m)[jt]s?(x)']
|
|
280
|
+
*/
|
|
281
|
+
include?: string[];
|
|
282
|
+
/**
|
|
283
|
+
* A list of glob patterns that should be excluded from your test files.
|
|
284
|
+
*
|
|
285
|
+
* @default ['**\/node_modules/**', '**\/dist/**']
|
|
286
|
+
*/
|
|
287
|
+
exclude?: string[];
|
|
288
|
+
/**
|
|
289
|
+
* A list of glob patterns that match your in-source test files
|
|
290
|
+
*
|
|
291
|
+
* @default []
|
|
292
|
+
*/
|
|
293
|
+
includeSource?: string[];
|
|
294
|
+
/**
|
|
295
|
+
* Path to setup files. They will be run before each test file.
|
|
296
|
+
*/
|
|
297
|
+
setupFiles?: string[] | string;
|
|
298
|
+
/**
|
|
299
|
+
* Retry the test specific number of times if it fails.
|
|
300
|
+
* @default 0
|
|
301
|
+
*/
|
|
302
|
+
retry?: number;
|
|
303
|
+
/**
|
|
304
|
+
* Allows the test suite to pass when no files are found.
|
|
305
|
+
*
|
|
306
|
+
* @default false
|
|
307
|
+
*/
|
|
308
|
+
passWithNoTests?: boolean;
|
|
309
|
+
/**
|
|
310
|
+
* Pool used to run tests in.
|
|
311
|
+
*/
|
|
312
|
+
pool?: RstestPoolType | RstestPoolOptions;
|
|
313
|
+
/**
|
|
314
|
+
* Run tests in an isolated environment
|
|
315
|
+
*
|
|
316
|
+
* @default true
|
|
317
|
+
*/
|
|
318
|
+
isolate?: boolean;
|
|
319
|
+
/**
|
|
320
|
+
* Provide global APIs
|
|
321
|
+
*
|
|
322
|
+
* @default false
|
|
323
|
+
*/
|
|
324
|
+
globals?: boolean;
|
|
325
|
+
/**
|
|
326
|
+
* The environment that will be used for testing
|
|
327
|
+
*
|
|
328
|
+
* TODO: support more test environments
|
|
329
|
+
* @default 'node'
|
|
330
|
+
*/
|
|
331
|
+
testEnvironment?: 'node';
|
|
332
|
+
/**
|
|
333
|
+
* print console traces when calling any console method.
|
|
334
|
+
*
|
|
335
|
+
* @default false
|
|
336
|
+
*/
|
|
337
|
+
printConsoleTrace?: boolean;
|
|
338
|
+
/**
|
|
339
|
+
* Disable console intercept. `onConsoleLog` & `printConsoleTrace` configuration will not take effect.
|
|
340
|
+
*
|
|
341
|
+
* @default false
|
|
342
|
+
*/
|
|
343
|
+
disableConsoleIntercept?: boolean;
|
|
344
|
+
/**
|
|
345
|
+
* Update snapshot files. Will update all changed snapshots and delete obsolete ones.
|
|
346
|
+
*
|
|
347
|
+
* @default false
|
|
348
|
+
*/
|
|
349
|
+
update?: boolean;
|
|
350
|
+
/**
|
|
351
|
+
* Custom reporter for output.
|
|
352
|
+
* @default ['default']
|
|
353
|
+
*/
|
|
354
|
+
reporters?: Reporter | BuiltInReporterNames | (Reporter | BuiltInReporterNames | [BuiltInReporterNames] | ReporterWithOptions)[];
|
|
355
|
+
/**
|
|
356
|
+
* Run only tests with a name that matches the regex.
|
|
357
|
+
*/
|
|
358
|
+
testNamePattern?: string | RegExp;
|
|
359
|
+
/**
|
|
360
|
+
* Timeout of a test in milliseconds.
|
|
361
|
+
* @default 5000
|
|
362
|
+
*/
|
|
363
|
+
testTimeout?: number;
|
|
364
|
+
/**
|
|
365
|
+
* Automatically clear mock calls, instances, contexts and results before every test.
|
|
366
|
+
* @default false
|
|
367
|
+
*/
|
|
368
|
+
clearMocks?: boolean;
|
|
369
|
+
/**
|
|
370
|
+
* Automatically reset mock state before every test.
|
|
371
|
+
* @default false
|
|
372
|
+
*/
|
|
373
|
+
resetMocks?: boolean;
|
|
374
|
+
/**
|
|
375
|
+
* Automatically restore mock state and implementation before every test.
|
|
376
|
+
* @default false
|
|
377
|
+
*/
|
|
378
|
+
restoreMocks?: boolean;
|
|
379
|
+
/**
|
|
380
|
+
* The number of milliseconds after which a test or suite is considered slow and reported as such in the results.
|
|
381
|
+
* @default 300
|
|
382
|
+
*/
|
|
383
|
+
slowTestThreshold?: number;
|
|
384
|
+
/**
|
|
385
|
+
* Restores all global variables that were changed with `rstest.stubGlobal` before every test.
|
|
386
|
+
* @default false
|
|
387
|
+
*/
|
|
388
|
+
unstubGlobals?: boolean;
|
|
389
|
+
/**
|
|
390
|
+
* Restores all `process.env` values that were changed with `rstest.stubEnv` before every test.
|
|
391
|
+
* @default false
|
|
392
|
+
*/
|
|
393
|
+
unstubEnvs?: boolean;
|
|
394
|
+
/**
|
|
395
|
+
* Maximum number of concurrent tests
|
|
396
|
+
* @default 5
|
|
397
|
+
*/
|
|
398
|
+
maxConcurrency?: number;
|
|
399
|
+
/**
|
|
400
|
+
* Custom handler for console log in tests
|
|
401
|
+
*/
|
|
402
|
+
onConsoleLog?: (content: string) => boolean | void;
|
|
403
|
+
plugins?: RsbuildConfig['plugins'];
|
|
404
|
+
source?: Pick<NonNullable<RsbuildConfig['source']>, 'define' | 'tsconfigPath' | 'decorators' | 'include' | 'exclude'>;
|
|
405
|
+
output?: Pick<NonNullable<RsbuildConfig['output']>, 'cssModules'>;
|
|
406
|
+
resolve?: RsbuildConfig['resolve'];
|
|
407
|
+
tools?: Pick<NonNullable<RsbuildConfig['tools']>, 'rspack' | 'swc' | 'bundlerChain'>;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
declare type RstestContext = {
|
|
411
|
+
/** The Rstest core version. */
|
|
412
|
+
version: string;
|
|
413
|
+
/** The root path of current project. */
|
|
414
|
+
rootPath: string;
|
|
415
|
+
/** The original Rstest config passed from the createRstest method. */
|
|
416
|
+
originalConfig: Readonly<RstestConfig>;
|
|
417
|
+
/** The normalized Rstest config. */
|
|
418
|
+
normalizedConfig: NormalizedConfig;
|
|
419
|
+
/**
|
|
420
|
+
* The command type.
|
|
421
|
+
*
|
|
422
|
+
* - dev: `rstest dev`
|
|
423
|
+
* - run: `rstest run`
|
|
424
|
+
*/
|
|
425
|
+
command: RstestCommand;
|
|
426
|
+
reporters: Reporter[];
|
|
427
|
+
snapshotManager: SnapshotManager;
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
declare type RstestExpect = ExpectStatic;
|
|
431
|
+
|
|
432
|
+
declare type RstestPoolOptions = {
|
|
433
|
+
/** Pool used to run tests in. */
|
|
434
|
+
type: RstestPoolType;
|
|
435
|
+
/** Maximum number or percentage of workers to run tests in. */
|
|
436
|
+
maxWorkers?: number | string;
|
|
437
|
+
/** Minimum number or percentage of workers to run tests in. */
|
|
438
|
+
minWorkers?: number | string;
|
|
439
|
+
/** Pass additional arguments to node process in the child processes. */
|
|
440
|
+
execArgv?: string[];
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
declare type RstestPoolType = 'forks';
|
|
444
|
+
|
|
445
|
+
declare const runInPool: (options: RunWorkerOptions["options"]) => Promise<{
|
|
446
|
+
tests: Test[];
|
|
447
|
+
testPath: string;
|
|
448
|
+
} | TestFileResult>;
|
|
449
|
+
export default runInPool;
|
|
450
|
+
|
|
451
|
+
declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment'>;
|
|
452
|
+
|
|
453
|
+
/** Runtime to Server */
|
|
454
|
+
declare type RuntimeRPC = {
|
|
455
|
+
onTestFileStart: (test: TestFileInfo) => Promise<void>;
|
|
456
|
+
onTestFileResult: (test: TestFileResult) => Promise<void>;
|
|
457
|
+
onTestCaseResult: (result: TestResult) => Promise<void>;
|
|
458
|
+
onConsoleLog: (log: UserConsoleLog) => void;
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
declare type RunWorkerOptions = {
|
|
462
|
+
options: {
|
|
463
|
+
entryInfo: EntryInfo;
|
|
464
|
+
setupEntries: EntryInfo[];
|
|
465
|
+
assetFiles: Record<string, string>;
|
|
466
|
+
sourceMaps: Record<string, SourceMapInput>;
|
|
467
|
+
context: WorkerContext;
|
|
468
|
+
updateSnapshot: SnapshotUpdateState;
|
|
469
|
+
type: 'run' | 'collect';
|
|
470
|
+
};
|
|
471
|
+
rpcMethods: RuntimeRPC;
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
declare interface SnapshotMatcher<T> {
|
|
475
|
+
<U extends {
|
|
476
|
+
[P in keyof T]: any;
|
|
477
|
+
}>(snapshot: Partial<U>, message?: string): void;
|
|
478
|
+
(message?: string): void;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
declare type SourceColumn = number;
|
|
482
|
+
|
|
483
|
+
declare type SourceLine = number;
|
|
484
|
+
|
|
485
|
+
declare abstract class SourceMap {
|
|
486
|
+
version: SourceMapV3['version'];
|
|
487
|
+
file: SourceMapV3['file'];
|
|
488
|
+
names: SourceMapV3['names'];
|
|
489
|
+
sourceRoot: SourceMapV3['sourceRoot'];
|
|
490
|
+
sources: SourceMapV3['sources'];
|
|
491
|
+
sourcesContent: SourceMapV3['sourcesContent'];
|
|
492
|
+
resolvedSources: SourceMapV3['sources'];
|
|
493
|
+
ignoreList: SourceMapV3['ignoreList'];
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
declare type SourceMapInput = string | EncodedSourceMapXInput | DecodedSourceMapXInput | TraceMap;
|
|
497
|
+
|
|
498
|
+
declare type SourceMapSegment = [GeneratedColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
|
|
499
|
+
|
|
500
|
+
declare interface SourceMapV3 {
|
|
501
|
+
file?: string | null;
|
|
502
|
+
names: string[];
|
|
503
|
+
sourceRoot?: string;
|
|
504
|
+
sources: (string | null)[];
|
|
505
|
+
sourcesContent?: (string | null)[];
|
|
506
|
+
version: 3;
|
|
507
|
+
ignoreList?: number[];
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
declare type SourcesIndex = number;
|
|
511
|
+
|
|
512
|
+
declare type SuiteContext = {
|
|
513
|
+
filepath: TestPath;
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
declare interface TaskResult {
|
|
517
|
+
/**
|
|
518
|
+
* State of the task. Inherits the `task.mode` during collection.
|
|
519
|
+
* When the task has finished, it will be changed to `pass` or `fail`.
|
|
520
|
+
* - **pass**: task ran successfully
|
|
521
|
+
* - **fail**: task failed
|
|
522
|
+
*/
|
|
523
|
+
state: TaskState;
|
|
524
|
+
/**
|
|
525
|
+
* Errors that occurred during the task execution. It is possible to have several errors
|
|
526
|
+
* if `expect.soft()` failed multiple times or `retry` was triggered.
|
|
527
|
+
*/
|
|
528
|
+
errors?: FormattedError[];
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
declare type TaskState = 'pass' | 'fail';
|
|
532
|
+
|
|
533
|
+
declare type Test = TestSuite | TestCase;
|
|
534
|
+
|
|
535
|
+
declare type TestCase = {
|
|
536
|
+
testPath: TestPath;
|
|
537
|
+
name: string;
|
|
538
|
+
originalFn?: (context: TestContext) => void | Promise<void>;
|
|
539
|
+
fn?: (context: TestContext) => void | Promise<void>;
|
|
540
|
+
runMode: TestRunMode;
|
|
541
|
+
timeout?: number;
|
|
542
|
+
fails?: boolean;
|
|
543
|
+
each?: boolean;
|
|
544
|
+
fixtures?: NormalizedFixtures;
|
|
545
|
+
concurrent?: boolean;
|
|
546
|
+
sequential?: boolean;
|
|
547
|
+
inTestEach?: boolean;
|
|
548
|
+
context: TestContext;
|
|
549
|
+
only?: boolean;
|
|
550
|
+
onFinished?: any[];
|
|
551
|
+
type: 'case';
|
|
552
|
+
parentNames?: string[];
|
|
553
|
+
/**
|
|
554
|
+
* Store promises (from async expects) to wait for them before finishing the test
|
|
555
|
+
*/
|
|
556
|
+
promises?: Promise<any>[];
|
|
557
|
+
/**
|
|
558
|
+
* Result of the task. if `expect.soft()` failed multiple times or `retry` was triggered.
|
|
559
|
+
*/
|
|
560
|
+
result?: TaskResult;
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
declare type TestContext = {
|
|
564
|
+
expect: RstestExpect;
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
declare type TestFileInfo = {
|
|
568
|
+
testPath: TestPath;
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
declare type TestFileResult = TestResult & {
|
|
572
|
+
results: TestResult[];
|
|
573
|
+
snapshotResult?: SnapshotResult;
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
/** The test file original path */
|
|
577
|
+
declare type TestPath = string;
|
|
578
|
+
|
|
579
|
+
declare type TestResult = {
|
|
580
|
+
status: TestResultStatus;
|
|
581
|
+
name: string;
|
|
582
|
+
testPath: TestPath;
|
|
583
|
+
parentNames?: string[];
|
|
584
|
+
duration?: number;
|
|
585
|
+
errors?: FormattedError[];
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
declare type TestResultStatus = 'skip' | 'pass' | 'fail' | 'todo';
|
|
589
|
+
|
|
590
|
+
declare type TestRunMode = 'run' | 'skip' | 'todo' | 'only';
|
|
591
|
+
|
|
592
|
+
declare type TestSuite = {
|
|
593
|
+
name: string;
|
|
594
|
+
parentNames?: string[];
|
|
595
|
+
runMode: TestRunMode;
|
|
596
|
+
each?: boolean;
|
|
597
|
+
inTestEach?: boolean;
|
|
598
|
+
concurrent?: boolean;
|
|
599
|
+
sequential?: boolean;
|
|
600
|
+
testPath: TestPath;
|
|
601
|
+
/** nested cases and suite could in a suite */
|
|
602
|
+
tests: Array<TestSuite | TestCase>;
|
|
603
|
+
type: 'suite';
|
|
604
|
+
afterAllListeners?: AfterAllListener[];
|
|
605
|
+
beforeAllListeners?: BeforeAllListener[];
|
|
606
|
+
afterEachListeners?: AfterEachListener[];
|
|
607
|
+
beforeEachListeners?: BeforeEachListener[];
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
declare class TraceMap implements SourceMap {
|
|
611
|
+
version: SourceMapV3['version'];
|
|
612
|
+
file: SourceMapV3['file'];
|
|
613
|
+
names: SourceMapV3['names'];
|
|
614
|
+
sourceRoot: SourceMapV3['sourceRoot'];
|
|
615
|
+
sources: SourceMapV3['sources'];
|
|
616
|
+
sourcesContent: SourceMapV3['sourcesContent'];
|
|
617
|
+
ignoreList: SourceMapV3['ignoreList'];
|
|
618
|
+
resolvedSources: string[];
|
|
619
|
+
private _encoded;
|
|
620
|
+
private _decoded;
|
|
621
|
+
private _decodedMemo;
|
|
622
|
+
private _bySources;
|
|
623
|
+
private _bySourceMemos;
|
|
624
|
+
constructor(map: SourceMapInput, mapUrl?: string | null);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
declare type Use<T> = (value: T) => Promise<void>;
|
|
628
|
+
|
|
629
|
+
declare interface UserConsoleLog {
|
|
630
|
+
content: string;
|
|
631
|
+
name: string;
|
|
632
|
+
trace?: string;
|
|
633
|
+
testPath: TestPath;
|
|
634
|
+
type: 'stdout' | 'stderr';
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
declare type WorkerContext = {
|
|
638
|
+
rootPath: RstestContext['rootPath'];
|
|
639
|
+
runtimeConfig: RuntimeConfig;
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
declare type XInput = {
|
|
643
|
+
x_google_ignoreList?: SourceMapV3['ignoreList'];
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
export { }
|
package/globals.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
const test: typeof import('@rstest/core')['test'];
|
|
3
|
+
const describe: typeof import('@rstest/core')['describe'];
|
|
4
|
+
const it: typeof import('@rstest/core')['it'];
|
|
5
|
+
const expect: typeof import('@rstest/core')['expect'];
|
|
6
|
+
const assert: typeof import('@rstest/core')['assert'];
|
|
7
|
+
const beforeAll: typeof import('@rstest/core')['beforeAll'];
|
|
8
|
+
const afterAll: typeof import('@rstest/core')['afterAll'];
|
|
9
|
+
const beforeEach: typeof import('@rstest/core')['beforeEach'];
|
|
10
|
+
const afterEach: typeof import('@rstest/core')['afterEach'];
|
|
11
|
+
const rstest: typeof import('@rstest/core')['rstest'];
|
|
12
|
+
}
|
|
13
|
+
export {};
|
package/importMeta.d.ts
ADDED