@rstest/core 0.1.2 → 0.2.0

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.
@@ -1,450 +0,0 @@
1
- import type { RsbuildConfig } from '@rsbuild/core';
2
-
3
- declare type BuiltInReporterNames = keyof typeof reportersMap;
4
-
5
- declare type BuiltinReporterOptions = {
6
- default: DefaultReporterOptions;
7
- };
8
-
9
- declare interface DecodedSourceMap extends SourceMapV3 {
10
- mappings: SourceMapSegment[][];
11
- }
12
-
13
- declare type DecodedSourceMapXInput = DecodedSourceMap & XInput;
14
-
15
- declare class DefaultReporter implements Reporter {
16
- protected rootPath: string;
17
- protected config: NormalizedConfig;
18
- private options;
19
- protected statusRenderer: StatusRenderer | undefined;
20
- constructor({ rootPath, options, config, }: {
21
- rootPath: string;
22
- config: NormalizedConfig;
23
- options: DefaultReporterOptions;
24
- });
25
- onTestFileStart(test: TestFileInfo): void;
26
- onTestFileResult(test: TestFileResult): void;
27
- onTestCaseResult(_result: TestResult): void;
28
- onUserConsoleLog(log: UserConsoleLog): void;
29
- onExit(): Promise<void>;
30
- onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary, }: {
31
- results: TestFileResult[];
32
- testResults: TestResult[];
33
- duration: Duration;
34
- snapshotSummary: SnapshotSummary;
35
- getSourcemap: GetSourcemap;
36
- }): Promise<void>;
37
- }
38
-
39
- declare type DefaultReporterOptions = {
40
- /**
41
- * prints out summary of all tests
42
- * @default true
43
- */
44
- summary?: boolean;
45
- };
46
-
47
- declare type Duration = {
48
- totalTime: number;
49
- buildTime: number;
50
- testTime: number;
51
- };
52
-
53
- declare interface EncodedSourceMap extends SourceMapV3 {
54
- mappings: string;
55
- }
56
-
57
- declare type EncodedSourceMapXInput = EncodedSourceMap & XInput;
58
-
59
- declare type FormattedError = {
60
- fullStack?: boolean;
61
- message: string;
62
- name?: string;
63
- stack?: string;
64
- diff?: string;
65
- };
66
-
67
- declare type GeneratedColumn = number;
68
-
69
- declare type GetSourcemap = (sourcePath: string) => SourceMapInput | null;
70
-
71
- declare class GithubActionsReporter {
72
- private onWritePath;
73
- private rootPath;
74
- constructor({ options, rootPath, }: {
75
- rootPath: string;
76
- options: {
77
- onWritePath: (path: string) => string;
78
- };
79
- });
80
- onTestRunEnd({ results, testResults, getSourcemap, }: {
81
- results: TestFileResult[];
82
- testResults: TestResult[];
83
- duration: Duration;
84
- snapshotSummary: SnapshotSummary;
85
- getSourcemap: GetSourcemap;
86
- }): Promise<void>;
87
- }
88
-
89
- declare type MaybePromise<T> = T | Promise<T>;
90
-
91
- declare type NamesIndex = number;
92
-
93
- declare type NormalizedConfig = Required<Omit<RstestConfig, OptionalKeys | 'pool'>> & {
94
- [key in OptionalKeys]?: RstestConfig[key];
95
- } & {
96
- pool: RstestPoolOptions;
97
- };
98
-
99
- declare type OptionalKeys = 'setupFiles' | 'testNamePattern' | 'plugins' | 'source' | 'resolve' | 'output' | 'performance' | 'tools' | 'dev' | 'onConsoleLog';
100
-
101
- export declare interface Reporter {
102
- /**
103
- * Called before test file run.
104
- */
105
- onTestFileStart?: (test: TestFileInfo) => void;
106
- /**
107
- * Called when the test file has finished running.
108
- */
109
- onTestFileResult?: (test: TestFileResult) => void;
110
- /**
111
- * Called when the test has finished running or was just skipped.
112
- */
113
- onTestCaseResult?: (result: TestResult) => void;
114
- /**
115
- * Called after all tests have finished running.
116
- */
117
- onTestRunEnd?: ({ results, testResults, duration, getSourcemap, snapshotSummary, }: {
118
- results: TestFileResult[];
119
- testResults: TestResult[];
120
- duration: Duration;
121
- getSourcemap: GetSourcemap;
122
- snapshotSummary: SnapshotSummary;
123
- }) => MaybePromise<void>;
124
- /**
125
- * Called when console log is calling.
126
- */
127
- onUserConsoleLog?: (log: UserConsoleLog) => void;
128
- /**
129
- * Called when rstest exit abnormally
130
- */
131
- onExit?: () => void;
132
- }
133
-
134
- declare const reportersMap: {
135
- default: typeof DefaultReporter;
136
- verbose: typeof VerboseReporter;
137
- 'github-actions': typeof GithubActionsReporter;
138
- };
139
-
140
- declare type ReporterWithOptions<Name extends BuiltInReporterNames = BuiltInReporterNames> = Name extends keyof BuiltinReporterOptions ? [Name, Partial<BuiltinReporterOptions[Name]>] : [Name, Record<string, unknown>];
141
-
142
- declare type Ro<T> = T extends Array<infer V> ? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>> : T extends object ? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>> : T;
143
-
144
- declare type RoArray<T> = Ro<T>[];
145
-
146
- declare type RoObject<T> = {
147
- [K in keyof T]: T[K] | Ro<T[K]>;
148
- };
149
-
150
- export declare type RstestCommand = 'watch' | 'run' | 'list';
151
-
152
- export declare interface RstestConfig {
153
- /**
154
- * Project root
155
- *
156
- * @default process.cwd()
157
- */
158
- root?: string;
159
- /**
160
- * Project name
161
- *
162
- * @default rstest
163
- */
164
- name?: string;
165
- /**
166
- * A list of glob patterns that match your test files.
167
- *
168
- * @default ['**\/*.{test,spec}.?(c|m)[jt]s?(x)']
169
- */
170
- include?: string[];
171
- /**
172
- * A list of glob patterns that should be excluded from your test files.
173
- *
174
- * @default ['**\/node_modules/**', '**\/dist/**']
175
- */
176
- exclude?: string[];
177
- /**
178
- * A list of glob patterns that match your in-source test files
179
- *
180
- * @default []
181
- */
182
- includeSource?: string[];
183
- /**
184
- * Path to setup files. They will be run before each test file.
185
- */
186
- setupFiles?: string[] | string;
187
- /**
188
- * Retry the test specific number of times if it fails.
189
- * @default 0
190
- */
191
- retry?: number;
192
- /**
193
- * Pass when no tests are found.
194
- *
195
- * @default false
196
- */
197
- passWithNoTests?: boolean;
198
- /**
199
- * Pool used to run tests in.
200
- */
201
- pool?: RstestPoolType | RstestPoolOptions;
202
- /**
203
- * Run tests in an isolated environment
204
- *
205
- * @default true
206
- */
207
- isolate?: boolean;
208
- /**
209
- * Provide global APIs
210
- *
211
- * @default false
212
- */
213
- globals?: boolean;
214
- /**
215
- * The environment that will be used for testing
216
- *
217
- * @default 'node'
218
- */
219
- testEnvironment?: 'node' | 'jsdom' | 'happy-dom';
220
- /**
221
- * print console traces when calling any console method.
222
- *
223
- * @default false
224
- */
225
- printConsoleTrace?: boolean;
226
- /**
227
- * Disable console intercept. `onConsoleLog` & `printConsoleTrace` configuration will not take effect.
228
- *
229
- * @default false
230
- */
231
- disableConsoleIntercept?: boolean;
232
- /**
233
- * Update snapshot files. Will update all changed snapshots and delete obsolete ones.
234
- *
235
- * @default false
236
- */
237
- update?: boolean;
238
- /**
239
- * Custom reporter for output.
240
- * @default ['default']
241
- */
242
- reporters?: Reporter | BuiltInReporterNames | (Reporter | BuiltInReporterNames | [BuiltInReporterNames] | ReporterWithOptions)[];
243
- /**
244
- * Run only tests with a name that matches the regex.
245
- */
246
- testNamePattern?: string | RegExp;
247
- /**
248
- * Timeout of a test in milliseconds.
249
- * @default 5000
250
- */
251
- testTimeout?: number;
252
- /**
253
- * Timeout of hook in milliseconds.
254
- * @default 10000
255
- */
256
- hookTimeout?: number;
257
- /**
258
- * Automatically clear mock calls, instances, contexts and results before every test.
259
- * @default false
260
- */
261
- clearMocks?: boolean;
262
- /**
263
- * Automatically reset mock state before every test.
264
- * @default false
265
- */
266
- resetMocks?: boolean;
267
- /**
268
- * Automatically restore mock state and implementation before every test.
269
- * @default false
270
- */
271
- restoreMocks?: boolean;
272
- /**
273
- * The number of milliseconds after which a test or suite is considered slow and reported as such in the results.
274
- * @default 300
275
- */
276
- slowTestThreshold?: number;
277
- /**
278
- * Restores all global variables that were changed with `rstest.stubGlobal` before every test.
279
- * @default false
280
- */
281
- unstubGlobals?: boolean;
282
- /**
283
- * Restores all `process.env` values that were changed with `rstest.stubEnv` before every test.
284
- * @default false
285
- */
286
- unstubEnvs?: boolean;
287
- /**
288
- * Maximum number of concurrent tests
289
- * @default 5
290
- */
291
- maxConcurrency?: number;
292
- /**
293
- * Custom handler for console log in tests
294
- */
295
- onConsoleLog?: (content: string) => boolean | void;
296
- plugins?: RsbuildConfig['plugins'];
297
- source?: Pick<NonNullable<RsbuildConfig['source']>, 'define' | 'tsconfigPath' | 'decorators' | 'include' | 'exclude'>;
298
- performance?: Pick<NonNullable<RsbuildConfig['performance']>, 'bundleAnalyze'>;
299
- dev?: Pick<NonNullable<RsbuildConfig['dev']>, 'writeToDisk'>;
300
- output?: Pick<NonNullable<RsbuildConfig['output']>, 'cssModules' | 'externals' | 'cleanDistPath'>;
301
- resolve?: RsbuildConfig['resolve'];
302
- tools?: Pick<NonNullable<RsbuildConfig['tools']>, 'rspack' | 'swc' | 'bundlerChain'>;
303
- }
304
-
305
- declare type RstestPoolOptions = {
306
- /** Pool used to run tests in. */
307
- type: RstestPoolType;
308
- /** Maximum number or percentage of workers to run tests in. */
309
- maxWorkers?: number | string;
310
- /** Minimum number or percentage of workers to run tests in. */
311
- minWorkers?: number | string;
312
- /** Pass additional arguments to node process in the child processes. */
313
- execArgv?: string[];
314
- };
315
-
316
- declare type RstestPoolType = 'forks';
317
-
318
- declare interface SnapshotResult {
319
- filepath: string;
320
- added: number;
321
- fileDeleted: boolean;
322
- matched: number;
323
- unchecked: number;
324
- uncheckedKeys: Array<string>;
325
- unmatched: number;
326
- updated: number;
327
- }
328
-
329
- declare interface SnapshotSummary {
330
- added: number;
331
- didUpdate: boolean;
332
- failure: boolean;
333
- filesAdded: number;
334
- filesRemoved: number;
335
- filesRemovedList: Array<string>;
336
- filesUnmatched: number;
337
- filesUpdated: number;
338
- matched: number;
339
- total: number;
340
- unchecked: number;
341
- uncheckedKeysByFile: Array<UncheckedSnapshot>;
342
- unmatched: number;
343
- updated: number;
344
- }
345
-
346
- declare type SourceColumn = number;
347
-
348
- declare type SourceLine = number;
349
-
350
- declare abstract class SourceMap {
351
- version: SourceMapV3['version'];
352
- file: SourceMapV3['file'];
353
- names: SourceMapV3['names'];
354
- sourceRoot: SourceMapV3['sourceRoot'];
355
- sources: SourceMapV3['sources'];
356
- sourcesContent: SourceMapV3['sourcesContent'];
357
- resolvedSources: SourceMapV3['sources'];
358
- ignoreList: SourceMapV3['ignoreList'];
359
- }
360
-
361
- declare type SourceMapInput = string | EncodedSourceMapXInput | DecodedSourceMapXInput | TraceMap;
362
-
363
- declare type SourceMapSegment = [GeneratedColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
364
-
365
- declare interface SourceMapV3 {
366
- file?: string | null;
367
- names: string[];
368
- sourceRoot?: string;
369
- sources: (string | null)[];
370
- sourcesContent?: (string | null)[];
371
- version: 3;
372
- ignoreList?: number[];
373
- }
374
-
375
- declare type SourcesIndex = number;
376
-
377
- declare class StatusRenderer {
378
- private rootPath;
379
- private renderer;
380
- private runningModules;
381
- constructor(rootPath: string);
382
- getContent(): string[];
383
- addRunningModule(testPath: string): void;
384
- removeRunningModule(testPath: string): void;
385
- clear(): void;
386
- }
387
-
388
- export declare type TestFileInfo = {
389
- testPath: TestPath;
390
- };
391
-
392
- export declare type TestFileResult = TestResult & {
393
- results: TestResult[];
394
- snapshotResult?: SnapshotResult;
395
- };
396
-
397
- /** The test file original path */
398
- declare type TestPath = string;
399
-
400
- export declare type TestResult = {
401
- status: TestResultStatus;
402
- name: string;
403
- testPath: TestPath;
404
- parentNames?: string[];
405
- duration?: number;
406
- errors?: FormattedError[];
407
- retryCount?: number;
408
- };
409
-
410
- declare type TestResultStatus = 'skip' | 'pass' | 'fail' | 'todo';
411
-
412
- declare class TraceMap implements SourceMap {
413
- version: SourceMapV3['version'];
414
- file: SourceMapV3['file'];
415
- names: SourceMapV3['names'];
416
- sourceRoot: SourceMapV3['sourceRoot'];
417
- sources: SourceMapV3['sources'];
418
- sourcesContent: SourceMapV3['sourcesContent'];
419
- ignoreList: SourceMapV3['ignoreList'];
420
- resolvedSources: string[];
421
- private _encoded;
422
- private _decoded;
423
- private _decodedMemo;
424
- private _bySources;
425
- private _bySourceMemos;
426
- constructor(map: Ro<SourceMapInput>, mapUrl?: string | null);
427
- }
428
-
429
- declare interface UncheckedSnapshot {
430
- filePath: string;
431
- keys: Array<string>;
432
- }
433
-
434
- declare interface UserConsoleLog {
435
- content: string;
436
- name: string;
437
- trace?: string;
438
- testPath: TestPath;
439
- type: 'stdout' | 'stderr';
440
- }
441
-
442
- declare class VerboseReporter extends DefaultReporter {
443
- onTestFileResult(test: TestFileResult): void;
444
- }
445
-
446
- declare type XInput = {
447
- x_google_ignoreList?: SourceMapV3['ignoreList'];
448
- };
449
-
450
- export { }