@rstest/core 0.5.1 → 0.5.3

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,4 +1,5 @@
1
1
  import type { assert as assert_2 } from 'chai';
2
+ import { LoadConfigOptions } from '@rsbuild/core';
2
3
  import type { RsbuildConfig } from '@rsbuild/core';
3
4
  import type { RsbuildPlugin } from '@rsbuild/core';
4
5
 
@@ -304,6 +305,35 @@ declare interface Colors {
304
305
  };
305
306
  }
306
307
 
308
+ declare type CommonOptions = {
309
+ root?: string;
310
+ config?: string;
311
+ configLoader?: LoadConfigOptions['loader'];
312
+ globals?: boolean;
313
+ isolate?: boolean;
314
+ include?: string[];
315
+ exclude?: string[];
316
+ reporter?: string[];
317
+ project?: string[];
318
+ coverage?: boolean;
319
+ passWithNoTests?: boolean;
320
+ printConsoleTrace?: boolean;
321
+ disableConsoleIntercept?: boolean;
322
+ update?: boolean;
323
+ testNamePattern?: RegExp | string;
324
+ testTimeout?: number;
325
+ hookTimeout?: number;
326
+ testEnvironment?: string;
327
+ clearMocks?: boolean;
328
+ resetMocks?: boolean;
329
+ restoreMocks?: boolean;
330
+ unstubGlobals?: boolean;
331
+ unstubEnvs?: boolean;
332
+ retry?: number;
333
+ maxConcurrency?: number;
334
+ slowTestThreshold?: number;
335
+ };
336
+
307
337
  declare type CompareKeys = ((a: string, b: string) => number) | null | undefined;
308
338
 
309
339
  declare interface Config {
@@ -494,6 +524,12 @@ declare type CoverageThresholds = CoverageThreshold | (CoverageThreshold & {
494
524
  };
495
525
  });
496
526
 
527
+ export declare function createRstest({ config, projects, configFilePath, }: {
528
+ config: RstestConfig;
529
+ configFilePath?: string;
530
+ projects: Project[];
531
+ }, command: RstestCommand, fileFilters: string[]): RstestInstance;
532
+
497
533
  declare interface CustomMatcher {
498
534
  /**
499
535
  * Checks that a value satisfies a custom matcher function.
@@ -553,7 +589,7 @@ declare class DefaultReporter implements Reporter {
553
589
  });
554
590
  onTestFileStart(test: TestFileInfo): void;
555
591
  onTestFileResult(test: TestFileResult): void;
556
- onTestCaseResult(_result: TestResult): void;
592
+ onTestCaseResult(result: TestResult): void;
557
593
  onUserConsoleLog(log: UserConsoleLog): void;
558
594
  onExit(): Promise<void>;
559
595
  onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary, filterRerunTestPaths, }: {
@@ -849,7 +885,7 @@ declare function getMatcherUtils(): {
849
885
  printWithType: typeof printWithType
850
886
  };
851
887
 
852
- declare type GetSourcemap = (sourcePath: string) => SourceMapInput | null;
888
+ declare type GetSourcemap = (sourcePath: string) => Promise<SourceMapInput | null>;
853
889
 
854
890
  declare class GithubActionsReporter {
855
891
  private onWritePath;
@@ -884,6 +920,12 @@ declare interface HtmlSpaOptions extends HtmlOptions {
884
920
 
885
921
  declare type Indent = (arg0: string) => string;
886
922
 
923
+ export declare function initCli(options: CommonOptions): Promise<{
924
+ config: RstestConfig;
925
+ configFilePath?: string;
926
+ projects: Project[];
927
+ }>;
928
+
887
929
  declare interface InlineSnapshotMatcher<T> {
888
930
  <U extends {
889
931
  [P in keyof T]: any;
@@ -1318,6 +1360,21 @@ declare interface LinkMapper {
1318
1360
  assetPath(node: Node_2, name: string): string;
1319
1361
  }
1320
1362
 
1363
+ declare type ListCommandOptions = {
1364
+ filesOnly?: boolean;
1365
+ json?: boolean | string;
1366
+ };
1367
+
1368
+ export declare function loadConfig({ cwd, path, envMode, configLoader, }: {
1369
+ cwd?: string;
1370
+ path?: string;
1371
+ envMode?: string;
1372
+ configLoader?: LoadConfigOptions['loader'];
1373
+ }): Promise<{
1374
+ content: RstestConfig;
1375
+ filePath: string | null;
1376
+ }>;
1377
+
1321
1378
  declare interface Location_2 {
1322
1379
  line: number;
1323
1380
  column: number;
@@ -1933,6 +1990,11 @@ declare type Procedure = (...args: any[]) => any;
1933
1990
 
1934
1991
  declare type Procedure_2 = (...args: any[]) => any;
1935
1992
 
1993
+ declare type Project = {
1994
+ config: RstestConfig;
1995
+ configFilePath?: string;
1996
+ };
1997
+
1936
1998
  export declare type ProjectConfig = Omit<RstestConfig, 'projects' | 'reporters' | 'pool' | 'isolate' | 'coverage'>;
1937
1999
 
1938
2000
  declare type ProjectContext = {
@@ -2219,6 +2281,10 @@ export declare interface RstestConfig {
2219
2281
  onConsoleLog?: (content: string) => boolean | void;
2220
2282
  /** Format snapshot output */
2221
2283
  snapshotFormat?: SnapshotFormat;
2284
+ /**
2285
+ * Custom environment variables available on `process.env` during tests.
2286
+ */
2287
+ env?: Partial<NodeJS.ProcessEnv>;
2222
2288
  /**
2223
2289
  * Coverage options
2224
2290
  */
@@ -2269,6 +2335,12 @@ declare type RstestContext = {
2269
2335
 
2270
2336
  declare type RstestExpect = ExpectStatic;
2271
2337
 
2338
+ declare type RstestInstance = {
2339
+ context: RstestContext;
2340
+ runTests: () => Promise<void>;
2341
+ listTests: (options: ListCommandOptions) => Promise<void>;
2342
+ };
2343
+
2272
2344
  declare type RstestPoolOptions = {
2273
2345
  /** Pool used to run tests in. */
2274
2346
  type?: RstestPoolType;
@@ -2420,7 +2492,7 @@ declare type RunnerAPI = {
2420
2492
  onTestFailed: (fn: OnTestFailedHandler, timeout?: number) => void;
2421
2493
  };
2422
2494
 
2423
- declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate' | 'hookTimeout' | 'coverage' | 'snapshotFormat'>;
2495
+ declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate' | 'hookTimeout' | 'coverage' | 'snapshotFormat' | 'env'>;
2424
2496
 
2425
2497
  declare type RuntimeOptions = Partial<Pick<RuntimeConfig, 'testTimeout' | 'hookTimeout' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'maxConcurrency' | 'retry'>>;
2426
2498
 
@@ -2598,10 +2670,13 @@ declare class StatusRenderer {
2598
2670
  private rootPath;
2599
2671
  private renderer;
2600
2672
  private runningModules;
2673
+ private testModules;
2674
+ private startTime;
2601
2675
  constructor(rootPath: string);
2602
2676
  getContent(): string[];
2603
- addRunningModule(testPath: string): void;
2604
- removeRunningModule(testPath: string): void;
2677
+ onTestFileStart(testPath: string): void;
2678
+ onTestCaseResult(result: TestResult): void;
2679
+ onTestFileResult(test: TestFileResult): void;
2605
2680
  clear(): void;
2606
2681
  }
2607
2682
 
@@ -498,7 +498,7 @@ declare class DefaultReporter implements Reporter {
498
498
  });
499
499
  onTestFileStart(test: TestFileInfo): void;
500
500
  onTestFileResult(test: TestFileResult): void;
501
- onTestCaseResult(_result: TestResult): void;
501
+ onTestCaseResult(result: TestResult): void;
502
502
  onUserConsoleLog(log: UserConsoleLog): void;
503
503
  onExit(): Promise<void>;
504
504
  onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary, filterRerunTestPaths, }: {
@@ -730,7 +730,7 @@ declare function getMatcherUtils(): {
730
730
  printWithType: typeof printWithType
731
731
  };
732
732
 
733
- declare type GetSourcemap = (sourcePath: string) => SourceMapInput | null;
733
+ declare type GetSourcemap = (sourcePath: string) => Promise<SourceMapInput | null>;
734
734
 
735
735
  declare class GithubActionsReporter {
736
736
  private onWritePath;
@@ -1937,6 +1937,10 @@ declare interface RstestConfig {
1937
1937
  onConsoleLog?: (content: string) => boolean | void;
1938
1938
  /** Format snapshot output */
1939
1939
  snapshotFormat?: SnapshotFormat;
1940
+ /**
1941
+ * Custom environment variables available on `process.env` during tests.
1942
+ */
1943
+ env?: Partial<NodeJS.ProcessEnv>;
1940
1944
  /**
1941
1945
  * Coverage options
1942
1946
  */
@@ -2012,12 +2016,15 @@ declare type RunnerAPI = {
2012
2016
  onTestFailed: (fn: OnTestFailedHandler, timeout?: number) => void;
2013
2017
  };
2014
2018
 
2015
- declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate' | 'hookTimeout' | 'coverage' | 'snapshotFormat'>;
2019
+ declare type RuntimeConfig = Pick<RstestContext['normalizedConfig'], 'testTimeout' | 'testNamePattern' | 'globals' | 'passWithNoTests' | 'retry' | 'clearMocks' | 'resetMocks' | 'restoreMocks' | 'unstubEnvs' | 'unstubGlobals' | 'maxConcurrency' | 'printConsoleTrace' | 'disableConsoleIntercept' | 'testEnvironment' | 'isolate' | 'hookTimeout' | 'coverage' | 'snapshotFormat' | 'env'>;
2016
2020
 
2017
2021
  /** Runtime to Server */
2018
2022
  declare type RuntimeRPC = {
2019
2023
  onTestFileStart: (test: TestFileInfo) => Promise<void>;
2020
- onTestFileResult: (test: TestFileResult) => Promise<void>;
2024
+ getAssetsByEntry: () => Promise<{
2025
+ assetFiles: Record<string, string>;
2026
+ sourceMaps: Record<string, string>;
2027
+ }>;
2021
2028
  onTestCaseResult: (result: TestResult) => Promise<void>;
2022
2029
  onConsoleLog: (log: UserConsoleLog) => void;
2023
2030
  };
@@ -2026,11 +2033,14 @@ declare type RunWorkerOptions = {
2026
2033
  options: {
2027
2034
  entryInfo: EntryInfo;
2028
2035
  setupEntries: EntryInfo[];
2029
- assetFiles: Record<string, string>;
2030
- sourceMaps: Record<string, SourceMapInput>;
2031
2036
  context: WorkerContext;
2032
2037
  updateSnapshot: SnapshotUpdateState;
2033
2038
  type: 'run' | 'collect';
2039
+ /** assets is only defined when memory is sufficient, otherwise we should get them via rpc getAssetsByEntry method */
2040
+ assets?: {
2041
+ assetFiles: Record<string, string>;
2042
+ sourceMaps: Record<string, string>;
2043
+ };
2034
2044
  };
2035
2045
  rpcMethods: RuntimeRPC;
2036
2046
  };
@@ -2209,10 +2219,13 @@ declare class StatusRenderer {
2209
2219
  private rootPath;
2210
2220
  private renderer;
2211
2221
  private runningModules;
2222
+ private testModules;
2223
+ private startTime;
2212
2224
  constructor(rootPath: string);
2213
2225
  getContent(): string[];
2214
- addRunningModule(testPath: string): void;
2215
- removeRunningModule(testPath: string): void;
2226
+ onTestFileStart(testPath: string): void;
2227
+ onTestCaseResult(result: TestResult): void;
2228
+ onTestFileResult(test: TestFileResult): void;
2216
2229
  clear(): void;
2217
2230
  }
2218
2231
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstest/core",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "The Rsbuild-based test tool.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/web-infra-dev/rstest/issues"
@@ -28,6 +28,9 @@
28
28
  "types": "./dist-types/index.d.ts",
29
29
  "default": "./dist/index.js"
30
30
  },
31
+ "./package.json": {
32
+ "default": "./package.json"
33
+ },
31
34
  "./globals": {
32
35
  "types": "./globals.d.ts"
33
36
  },
@@ -68,10 +71,10 @@
68
71
  "@types/picomatch": "^4.0.2",
69
72
  "cac": "^6.7.14",
70
73
  "chokidar": "^4.0.3",
71
- "happy-dom": "^18.0.1",
74
+ "happy-dom": "^20.0.0",
72
75
  "jest-diff": "^30.1.2",
73
76
  "jsdom": "^26.1.0",
74
- "license-webpack-plugin": "^4.0.2",
77
+ "webpack-license-plugin": "^4.5.1",
75
78
  "picocolors": "^1.1.1",
76
79
  "rslog": "^1.2.11",
77
80
  "source-map-support": "^0.5.21",
package/dist/0~223.js DELETED
@@ -1,158 +0,0 @@
1
- import 'module';
2
- /*#__PURE__*/ import.meta.url;
3
- export const __webpack_id__ = "223";
4
- export const __webpack_ids__ = [
5
- "223"
6
- ];
7
- export const __webpack_modules__ = {
8
- "./src/cli/init.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
9
- __webpack_require__.d(__webpack_exports__, {
10
- initCli: ()=>initCli
11
- });
12
- var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:fs");
13
- var pathe__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs");
14
- var tinyglobby__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("../../node_modules/.pnpm/tinyglobby@0.2.15/node_modules/tinyglobby/dist/index.mjs");
15
- var _config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./src/config.ts");
16
- var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./src/utils/index.ts");
17
- async function resolveConfig(options) {
18
- const { content: config, filePath: configFilePath } = await (0, _config__WEBPACK_IMPORTED_MODULE_1__.Z9)({
19
- cwd: options.root,
20
- path: options.config,
21
- configLoader: options.configLoader
22
- });
23
- const keys = [
24
- 'root',
25
- 'globals',
26
- 'isolate',
27
- 'passWithNoTests',
28
- 'update',
29
- 'testNamePattern',
30
- 'testTimeout',
31
- 'hookTimeout',
32
- 'clearMocks',
33
- 'resetMocks',
34
- 'restoreMocks',
35
- 'unstubEnvs',
36
- 'unstubGlobals',
37
- 'retry',
38
- 'slowTestThreshold',
39
- 'maxConcurrency',
40
- 'printConsoleTrace',
41
- 'disableConsoleIntercept',
42
- 'testEnvironment'
43
- ];
44
- for (const key of keys)if (void 0 !== options[key]) config[key] = options[key];
45
- if (options.reporter) config.reporters = (0, _utils__WEBPACK_IMPORTED_MODULE_2__.bg)(options.reporter);
46
- if (void 0 !== options.coverage) {
47
- config.coverage ??= {};
48
- config.coverage.enabled = options.coverage;
49
- }
50
- if (options.exclude) config.exclude = (0, _utils__WEBPACK_IMPORTED_MODULE_2__.bg)(options.exclude);
51
- if (options.include) config.include = (0, _utils__WEBPACK_IMPORTED_MODULE_2__.bg)(options.include);
52
- return {
53
- config,
54
- configFilePath: configFilePath ?? void 0
55
- };
56
- }
57
- async function resolveProjects({ config, root, options }) {
58
- if (!config.projects) return [];
59
- const getDefaultProjectName = (dir)=>{
60
- const pkgJsonPath = (0, pathe__WEBPACK_IMPORTED_MODULE_3__.r)(dir, 'package.json');
61
- const name = (0, node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync)(pkgJsonPath) ? JSON.parse((0, node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync)(pkgJsonPath, 'utf-8')).name : '';
62
- if ('string' != typeof name || !name) return (0, pathe__WEBPACK_IMPORTED_MODULE_3__.c)(dir);
63
- return name;
64
- };
65
- const globProjects = async (patterns)=>{
66
- const globOptions = {
67
- absolute: true,
68
- dot: true,
69
- onlyFiles: false,
70
- cwd: root,
71
- expandDirectories: false,
72
- ignore: [
73
- '**/node_modules/**',
74
- '**/.DS_Store'
75
- ]
76
- };
77
- return (0, tinyglobby__WEBPACK_IMPORTED_MODULE_4__.glob)(patterns, globOptions);
78
- };
79
- const { projectPaths, projectPatterns, projectConfigs } = (config.projects || []).reduce((total, p)=>{
80
- if ('object' == typeof p) {
81
- const projectRoot = p.root ? (0, _utils__WEBPACK_IMPORTED_MODULE_2__.tS)(p.root, root) : root;
82
- total.projectConfigs.push({
83
- config: {
84
- root: projectRoot,
85
- name: p.name ? p.name : getDefaultProjectName(projectRoot),
86
- ...p
87
- },
88
- configFilePath: void 0
89
- });
90
- return total;
91
- }
92
- const projectStr = (0, _utils__WEBPACK_IMPORTED_MODULE_2__.tS)(p, root);
93
- if ((0, tinyglobby__WEBPACK_IMPORTED_MODULE_4__.ey)(projectStr)) total.projectPatterns.push(projectStr);
94
- else {
95
- const absolutePath = (0, _utils__WEBPACK_IMPORTED_MODULE_2__.FI)(root, projectStr);
96
- if (!(0, node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync)(absolutePath)) throw `Can't resolve project "${p}", please make sure "${p}" is a existing file or a directory.`;
97
- total.projectPaths.push(absolutePath);
98
- }
99
- return total;
100
- }, {
101
- projectPaths: [],
102
- projectPatterns: [],
103
- projectConfigs: []
104
- });
105
- projectPaths.push(...await globProjects(projectPatterns));
106
- const projects = await Promise.all(projectPaths.map(async (project)=>{
107
- const isDirectory = (0, node_fs__WEBPACK_IMPORTED_MODULE_0__.statSync)(project).isDirectory();
108
- const { config, configFilePath } = await resolveConfig({
109
- ...options,
110
- config: isDirectory ? void 0 : project,
111
- root: isDirectory ? project : (0, pathe__WEBPACK_IMPORTED_MODULE_3__.d)(project)
112
- });
113
- config.name ??= getDefaultProjectName(project);
114
- if (config.projects?.length && config.root !== root) _utils__WEBPACK_IMPORTED_MODULE_2__.vF.warn(`Projects cannot have nested projects, the "projects" field in project "${config.name}" will be ignored.`);
115
- return {
116
- config,
117
- configFilePath
118
- };
119
- })).then((projects)=>(0, _utils__WEBPACK_IMPORTED_MODULE_2__.zz)(projects.concat(projectConfigs), options));
120
- if (!projects.length) {
121
- let errorMsg = `No projects found, please make sure you have at least one valid project.
122
- ${_utils__WEBPACK_IMPORTED_MODULE_2__.yW.gray('projects:')} ${JSON.stringify(config.projects, null, 2)}`;
123
- if (options.project) errorMsg += `\n${_utils__WEBPACK_IMPORTED_MODULE_2__.yW.gray('projectName filter:')} ${JSON.stringify(options.project, null, 2)}`;
124
- throw errorMsg;
125
- }
126
- const names = new Set();
127
- projects.forEach((project)=>{
128
- if (names.has(project.config.name)) {
129
- const conflictProjects = projects.filter((p)=>p.config.name === project.config.name);
130
- throw `Project name "${project.config.name}" is already used. Please ensure all projects have unique names.
131
- Conflicting projects:
132
- ${conflictProjects.map((p)=>`- ${p.configFilePath || p.config.root}`).join('\n')}
133
- `;
134
- }
135
- names.add(project.config.name);
136
- });
137
- return projects;
138
- }
139
- async function initCli(options) {
140
- const cwd = process.cwd();
141
- const root = options.root ? (0, _utils__WEBPACK_IMPORTED_MODULE_2__.FI)(cwd, options.root) : cwd;
142
- const { config, configFilePath } = await resolveConfig({
143
- ...options,
144
- root
145
- });
146
- const projects = await resolveProjects({
147
- config,
148
- root,
149
- options
150
- });
151
- return {
152
- config,
153
- configFilePath,
154
- projects
155
- };
156
- }
157
- }
158
- };