@rstest/core 0.1.3 → 0.2.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/dist/worker.js CHANGED
@@ -5418,7 +5418,7 @@ var __webpack_modules__ = {
5418
5418
  "node:console": function(module) {
5419
5419
  module.exports = __WEBPACK_EXTERNAL_MODULE_node_console_8631dfae__;
5420
5420
  },
5421
- fs: function(module) {
5421
+ "node:fs": function(module) {
5422
5422
  module.exports = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__;
5423
5423
  },
5424
5424
  "node:fs/promises": function(module) {
@@ -5763,7 +5763,7 @@ function createRuntimeRpc(options) {
5763
5763
  rpc
5764
5764
  };
5765
5765
  }
5766
- var external_node_fs_ = __webpack_require__("fs");
5766
+ var external_node_fs_ = __webpack_require__("node:fs");
5767
5767
  class NodeSnapshotEnvironment {
5768
5768
  constructor(options = {}){
5769
5769
  this.options = options;
@@ -1107,6 +1107,8 @@ declare interface MatcherState_2 extends MatcherState {
1107
1107
 
1108
1108
  declare type MaybePromise<T> = T | Promise<T>;
1109
1109
 
1110
+ export declare const mergeRstestConfig: (...configs: RstestConfig[]) => RstestConfig;
1111
+
1110
1112
  export declare interface Mock<T extends FunctionLike = FunctionLike> extends MockInstance_2<T> {
1111
1113
  new (...args: Parameters<T>): ReturnType<T>;
1112
1114
  (...args: Parameters<T>): ReturnType<T>;
@@ -1650,7 +1652,7 @@ declare interface RawSnapshotInfo {
1650
1652
 
1651
1653
  declare type Refs = Array<unknown>;
1652
1654
 
1653
- declare interface Reporter {
1655
+ export declare interface Reporter {
1654
1656
  /**
1655
1657
  * Called before test file run.
1656
1658
  */
@@ -1710,7 +1712,7 @@ declare type Rstest = RunnerAPI & {
1710
1712
 
1711
1713
  export declare const rstest: RstestUtilities;
1712
1714
 
1713
- declare type RstestCommand = 'watch' | 'run' | 'list';
1715
+ export declare type RstestCommand = 'watch' | 'run' | 'list';
1714
1716
 
1715
1717
  export declare interface RstestConfig {
1716
1718
  /**
@@ -1880,6 +1882,10 @@ declare type RstestContext = {
1880
1882
  originalConfig: Readonly<RstestConfig>;
1881
1883
  /** The normalized Rstest config. */
1882
1884
  normalizedConfig: NormalizedConfig;
1885
+ /** filter by a filename regex pattern */
1886
+ fileFilters?: string[];
1887
+ /** The config file path. */
1888
+ configFilePath?: string;
1883
1889
  /**
1884
1890
  * The command type.
1885
1891
  *
@@ -2030,6 +2036,8 @@ declare interface RstestUtilities {
2030
2036
  clearAllTimers: () => RstestUtilities;
2031
2037
  }
2032
2038
 
2039
+ export declare function runCLI(): Promise<void>;
2040
+
2033
2041
  declare type RunnerAPI = {
2034
2042
  describe: DescribeAPI;
2035
2043
  it: TestAPIs;
@@ -2280,11 +2288,11 @@ declare interface TesterContext {
2280
2288
  equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
2281
2289
  }
2282
2290
 
2283
- declare type TestFileInfo = {
2291
+ export declare type TestFileInfo = {
2284
2292
  testPath: TestPath;
2285
2293
  };
2286
2294
 
2287
- declare type TestFileResult = TestResult & {
2295
+ export declare type TestFileResult = TestResult & {
2288
2296
  results: TestResult[];
2289
2297
  snapshotResult?: SnapshotResult;
2290
2298
  };
@@ -2296,7 +2304,7 @@ declare type TestForFn<ExtraContext = object> = <T>(cases: readonly T[]) => (des
2296
2304
  /** The test file original path */
2297
2305
  declare type TestPath = string;
2298
2306
 
2299
- declare type TestResult = {
2307
+ export declare type TestResult = {
2300
2308
  status: TestResultStatus;
2301
2309
  name: string;
2302
2310
  testPath: TestPath;
@@ -1616,6 +1616,10 @@ declare type RstestContext = {
1616
1616
  originalConfig: Readonly<RstestConfig>;
1617
1617
  /** The normalized Rstest config. */
1618
1618
  normalizedConfig: NormalizedConfig;
1619
+ /** filter by a filename regex pattern */
1620
+ fileFilters?: string[];
1621
+ /** The config file path. */
1622
+ configFilePath?: string;
1619
1623
  /**
1620
1624
  * The command type.
1621
1625
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstest/core",
3
- "version": "0.1.3",
3
+ "version": "0.2.1",
4
4
  "description": "The Rsbuild-based test tool.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/web-infra-dev/rstest/issues"
@@ -18,19 +18,15 @@
18
18
  ],
19
19
  "license": "MIT",
20
20
  "type": "module",
21
- "main": "./dist/public.js",
22
- "types": "./dist-types/public.d.ts",
21
+ "main": "./dist/index.js",
22
+ "types": "./dist-types/index.d.ts",
23
23
  "bin": {
24
24
  "rstest": "./bin/rstest.js"
25
25
  },
26
26
  "exports": {
27
27
  ".": {
28
- "types": "./dist-types/public.d.ts",
29
- "default": "./dist/public.js"
30
- },
31
- "./node": {
32
- "types": "./dist-types/node.d.ts",
33
- "default": "./dist/node.js"
28
+ "types": "./dist-types/index.d.ts",
29
+ "default": "./dist/index.js"
34
30
  },
35
31
  "./globals": {
36
32
  "types": "./globals.d.ts"
@@ -69,6 +65,7 @@
69
65
  "@types/sinonjs__fake-timers": "^8.1.5",
70
66
  "@types/source-map-support": "^0.5.10",
71
67
  "cac": "^6.7.14",
68
+ "chokidar": "^4.0.3",
72
69
  "happy-dom": "^18.0.1",
73
70
  "jest-diff": "^30.0.5",
74
71
  "jsdom": "^26.1.0",
@@ -94,7 +91,7 @@
94
91
  }
95
92
  },
96
93
  "engines": {
97
- "node": ">=18.0.0"
94
+ "node": ">=18.12.0"
98
95
  },
99
96
  "publishConfig": {
100
97
  "access": "public",
package/dist/node.js DELETED
@@ -1,2 +0,0 @@
1
- import 'module';
2
- /*#__PURE__*/ import.meta.url;
package/dist/public.js DELETED
@@ -1,6 +0,0 @@
1
- import 'module';
2
- /*#__PURE__*/ import.meta.url;
3
- function defineConfig(config) {
4
- return config;
5
- }
6
- export { defineConfig };
@@ -1,3 +0,0 @@
1
- export declare function runCLI(): Promise<void>;
2
-
3
- export { }
@@ -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 { }