@rstest/core 0.2.2 → 0.3.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/{698.js → 12.js} +88 -33
- package/dist/223.js +155 -0
- package/dist/33.js +101 -59
- package/dist/85.js +84 -12
- package/dist/967.js +12 -8
- package/dist/971.js +58 -25
- package/dist/985.js +141 -70
- package/dist/index.js +52 -68
- package/dist/worker.js +9 -4
- package/dist-types/index.d.ts +60 -3
- package/dist-types/worker.d.ts +129 -4
- package/globals.d.ts +2 -0
- package/package.json +4 -4
package/dist/{698.js → 12.js}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import 'module';
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
export const __webpack_id__ = "
|
|
3
|
+
export const __webpack_id__ = "12";
|
|
4
4
|
export const __webpack_ids__ = [
|
|
5
|
-
"
|
|
5
|
+
"12"
|
|
6
6
|
];
|
|
7
7
|
export const __webpack_modules__ = {
|
|
8
8
|
"../../node_modules/.pnpm/stacktrace-parser@0.1.11/node_modules/stacktrace-parser/dist/stack-trace-parser.esm.js": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
@@ -367,10 +367,10 @@ export const __webpack_modules__ = {
|
|
|
367
367
|
utils.vF.log(`${utils.yW.gray('Duration'.padStart(11))} ${(0, utils.kV)(duration.totalTime)} ${utils.yW.gray(`(build ${(0, utils.kV)(duration.buildTime)}, tests ${(0, utils.kV)(duration.testTime)})`)}`);
|
|
368
368
|
utils.vF.log('');
|
|
369
369
|
};
|
|
370
|
-
const printSummaryErrorLogs = async ({ testResults, results, rootPath, getSourcemap })=>{
|
|
370
|
+
const printSummaryErrorLogs = async ({ testResults, results, rootPath, getSourcemap, filterRerunTestPaths })=>{
|
|
371
371
|
const failedTests = [
|
|
372
|
-
...results.filter((i)=>'fail' === i.status && i.errors?.length),
|
|
373
|
-
...testResults.filter((i)=>'fail' === i.status)
|
|
372
|
+
...results.filter((i)=>'fail' === i.status && i.errors?.length && (filterRerunTestPaths ? filterRerunTestPaths.includes(i.testPath) : true)),
|
|
373
|
+
...testResults.filter((i)=>'fail' === i.status && (filterRerunTestPaths ? filterRerunTestPaths.includes(i.testPath) : true))
|
|
374
374
|
];
|
|
375
375
|
if (0 === failedTests.length) return;
|
|
376
376
|
utils.vF.log('');
|
|
@@ -468,14 +468,15 @@ export const __webpack_modules__ = {
|
|
|
468
468
|
async onExit() {
|
|
469
469
|
this.statusRenderer?.clear();
|
|
470
470
|
}
|
|
471
|
-
async onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary }) {
|
|
471
|
+
async onTestRunEnd({ results, testResults, duration, getSourcemap, snapshotSummary, filterRerunTestPaths }) {
|
|
472
472
|
this.statusRenderer?.clear();
|
|
473
473
|
if (false === this.options.summary) return;
|
|
474
474
|
await printSummaryErrorLogs({
|
|
475
475
|
testResults,
|
|
476
476
|
results,
|
|
477
477
|
rootPath: this.rootPath,
|
|
478
|
-
getSourcemap
|
|
478
|
+
getSourcemap,
|
|
479
|
+
filterRerunTestPaths
|
|
479
480
|
});
|
|
480
481
|
printSummaryLog({
|
|
481
482
|
results,
|
|
@@ -551,6 +552,82 @@ export const __webpack_modules__ = {
|
|
|
551
552
|
}
|
|
552
553
|
}
|
|
553
554
|
var helper = __webpack_require__("./src/utils/helper.ts");
|
|
555
|
+
function formatEnvironmentName(name) {
|
|
556
|
+
return name.replace(/[^a-zA-Z0-9\-_$]/g, '_');
|
|
557
|
+
}
|
|
558
|
+
class Rstest {
|
|
559
|
+
cwd;
|
|
560
|
+
command;
|
|
561
|
+
fileFilters;
|
|
562
|
+
configFilePath;
|
|
563
|
+
reporters;
|
|
564
|
+
snapshotManager;
|
|
565
|
+
version;
|
|
566
|
+
rootPath;
|
|
567
|
+
originalConfig;
|
|
568
|
+
normalizedConfig;
|
|
569
|
+
idMap = new Map();
|
|
570
|
+
reporterResults = {
|
|
571
|
+
results: [],
|
|
572
|
+
testResults: []
|
|
573
|
+
};
|
|
574
|
+
projects = [];
|
|
575
|
+
constructor({ cwd = process.cwd(), command, fileFilters, configFilePath, projects }, userConfig){
|
|
576
|
+
this.cwd = cwd;
|
|
577
|
+
this.command = command;
|
|
578
|
+
this.fileFilters = fileFilters;
|
|
579
|
+
this.configFilePath = configFilePath;
|
|
580
|
+
const rootPath = userConfig.root ? (0, helper.FI)(cwd, userConfig.root) : cwd;
|
|
581
|
+
const rstestConfig = (0, src_config.wX)(userConfig);
|
|
582
|
+
const reporters = 'list' !== command ? createReporters(rstestConfig.reporters, {
|
|
583
|
+
rootPath,
|
|
584
|
+
config: rstestConfig
|
|
585
|
+
}) : [];
|
|
586
|
+
const snapshotManager = new SnapshotManager({
|
|
587
|
+
updateSnapshot: rstestConfig.update ? 'all' : external_std_env_.isCI ? 'none' : 'new'
|
|
588
|
+
});
|
|
589
|
+
this.reporters = reporters;
|
|
590
|
+
this.snapshotManager = snapshotManager;
|
|
591
|
+
this.version = "0.3.1";
|
|
592
|
+
this.rootPath = rootPath;
|
|
593
|
+
this.originalConfig = userConfig;
|
|
594
|
+
this.normalizedConfig = rstestConfig;
|
|
595
|
+
this.projects = projects.length ? projects.map((project)=>{
|
|
596
|
+
const config = (0, src_config.wX)(project.config);
|
|
597
|
+
config.isolate = rstestConfig.isolate;
|
|
598
|
+
return {
|
|
599
|
+
configFilePath: project.configFilePath,
|
|
600
|
+
rootPath: config.root,
|
|
601
|
+
name: config.name,
|
|
602
|
+
environmentName: formatEnvironmentName(config.name),
|
|
603
|
+
normalizedConfig: config
|
|
604
|
+
};
|
|
605
|
+
}) : [
|
|
606
|
+
{
|
|
607
|
+
configFilePath,
|
|
608
|
+
rootPath,
|
|
609
|
+
name: rstestConfig.name,
|
|
610
|
+
environmentName: formatEnvironmentName(rstestConfig.name),
|
|
611
|
+
normalizedConfig: rstestConfig
|
|
612
|
+
}
|
|
613
|
+
];
|
|
614
|
+
}
|
|
615
|
+
updateReporterResultState(results, testResults, deletedEntries = []) {
|
|
616
|
+
results.forEach((item)=>{
|
|
617
|
+
const existingIndex = this.reporterResults.results.findIndex((r)=>r.testPath === item.testPath);
|
|
618
|
+
if (-1 !== existingIndex) this.reporterResults.results[existingIndex] = item;
|
|
619
|
+
else this.reporterResults.results.push(item);
|
|
620
|
+
});
|
|
621
|
+
const testPathsToUpdate = new Set(testResults.map((r)=>r.testPath));
|
|
622
|
+
this.reporterResults.testResults = this.reporterResults.testResults.filter((r)=>!testPathsToUpdate.has(r.testPath));
|
|
623
|
+
this.reporterResults.testResults.push(...testResults);
|
|
624
|
+
if (deletedEntries.length > 0) {
|
|
625
|
+
const deletedPathsSet = new Set(deletedEntries);
|
|
626
|
+
this.reporterResults.results = this.reporterResults.results.filter((r)=>!deletedPathsSet.has(r.testPath));
|
|
627
|
+
this.reporterResults.testResults = this.reporterResults.testResults.filter((r)=>!deletedPathsSet.has(r.testPath));
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
554
631
|
const reportersMap = {
|
|
555
632
|
default: DefaultReporter,
|
|
556
633
|
verbose: VerboseReporter,
|
|
@@ -576,35 +653,13 @@ export const __webpack_modules__ = {
|
|
|
576
653
|
});
|
|
577
654
|
return result;
|
|
578
655
|
}
|
|
579
|
-
function
|
|
580
|
-
const
|
|
581
|
-
const rootPath = userConfig.root ? (0, helper.FI)(cwd, userConfig.root) : cwd;
|
|
582
|
-
const rstestConfig = (0, src_config.wX)(userConfig);
|
|
583
|
-
const reporters = 'list' !== command ? createReporters(rstestConfig.reporters, {
|
|
584
|
-
rootPath,
|
|
585
|
-
config: rstestConfig
|
|
586
|
-
}) : [];
|
|
587
|
-
const snapshotManager = new SnapshotManager({
|
|
588
|
-
updateSnapshot: rstestConfig.update ? 'all' : external_std_env_.isCI ? 'none' : 'new'
|
|
589
|
-
});
|
|
590
|
-
return {
|
|
591
|
-
configFilePath,
|
|
592
|
-
command,
|
|
593
|
-
version: "0.2.2",
|
|
594
|
-
rootPath,
|
|
595
|
-
reporters,
|
|
596
|
-
fileFilters,
|
|
597
|
-
snapshotManager,
|
|
598
|
-
originalConfig: userConfig,
|
|
599
|
-
normalizedConfig: rstestConfig
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
function createRstest({ config, configFilePath }, command, fileFilters) {
|
|
603
|
-
const context = createContext({
|
|
656
|
+
function createRstest({ config, projects, configFilePath }, command, fileFilters) {
|
|
657
|
+
const context = new Rstest({
|
|
604
658
|
cwd: process.cwd(),
|
|
605
659
|
command,
|
|
606
660
|
fileFilters,
|
|
607
|
-
configFilePath
|
|
661
|
+
configFilePath,
|
|
662
|
+
projects
|
|
608
663
|
}, config);
|
|
609
664
|
const runTests = async ()=>{
|
|
610
665
|
const { runTests } = await Promise.all([
|
package/dist/223.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
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_1__ = __webpack_require__("pathe");
|
|
14
|
+
var tinyglobby__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("../../node_modules/.pnpm/tinyglobby@0.2.14/node_modules/tinyglobby/dist/index.mjs");
|
|
15
|
+
var _config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./src/config.ts");
|
|
16
|
+
var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./src/utils/index.ts");
|
|
17
|
+
async function resolveConfig(options) {
|
|
18
|
+
const { content: config, filePath: configFilePath } = await (0, _config__WEBPACK_IMPORTED_MODULE_2__.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_3__.bg)(options.reporter);
|
|
46
|
+
if (options.exclude) config.exclude = (0, _utils__WEBPACK_IMPORTED_MODULE_3__.bg)(options.exclude);
|
|
47
|
+
if (options.include) config.include = (0, _utils__WEBPACK_IMPORTED_MODULE_3__.bg)(options.include);
|
|
48
|
+
return {
|
|
49
|
+
config,
|
|
50
|
+
configFilePath: configFilePath ?? void 0
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async function resolveProjects({ config, root, options }) {
|
|
54
|
+
if (!config.projects) return [];
|
|
55
|
+
const getDefaultProjectName = (dir)=>{
|
|
56
|
+
const pkgJsonPath = (0, pathe__WEBPACK_IMPORTED_MODULE_1__.resolve)(dir, 'package.json');
|
|
57
|
+
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 : '';
|
|
58
|
+
if ('string' != typeof name || !name) return (0, pathe__WEBPACK_IMPORTED_MODULE_1__.basename)(dir);
|
|
59
|
+
return name;
|
|
60
|
+
};
|
|
61
|
+
const globProjects = async (patterns)=>{
|
|
62
|
+
const globOptions = {
|
|
63
|
+
absolute: true,
|
|
64
|
+
dot: true,
|
|
65
|
+
onlyFiles: false,
|
|
66
|
+
cwd: root,
|
|
67
|
+
expandDirectories: false,
|
|
68
|
+
ignore: [
|
|
69
|
+
'**/node_modules/**',
|
|
70
|
+
'**/.DS_Store'
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
return (0, tinyglobby__WEBPACK_IMPORTED_MODULE_4__.glob)(patterns, globOptions);
|
|
74
|
+
};
|
|
75
|
+
const formatRootStr = (rootStr)=>rootStr.replace('<rootDir>', root);
|
|
76
|
+
const { projectPaths, projectPatterns, projectConfigs } = (config.projects || []).reduce((total, p)=>{
|
|
77
|
+
if ('object' == typeof p) {
|
|
78
|
+
const projectRoot = p.root ? formatRootStr(p.root) : root;
|
|
79
|
+
total.projectConfigs.push({
|
|
80
|
+
config: {
|
|
81
|
+
root: projectRoot,
|
|
82
|
+
name: p.name ? p.name : getDefaultProjectName(projectRoot),
|
|
83
|
+
...p
|
|
84
|
+
},
|
|
85
|
+
configFilePath: void 0
|
|
86
|
+
});
|
|
87
|
+
return total;
|
|
88
|
+
}
|
|
89
|
+
const projectStr = formatRootStr(p);
|
|
90
|
+
if ((0, tinyglobby__WEBPACK_IMPORTED_MODULE_4__.ey)(projectStr)) total.projectPatterns.push(projectStr);
|
|
91
|
+
else {
|
|
92
|
+
const absolutePath = (0, _utils__WEBPACK_IMPORTED_MODULE_3__.FI)(root, projectStr);
|
|
93
|
+
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.`;
|
|
94
|
+
total.projectPaths.push(absolutePath);
|
|
95
|
+
}
|
|
96
|
+
return total;
|
|
97
|
+
}, {
|
|
98
|
+
projectPaths: [],
|
|
99
|
+
projectPatterns: [],
|
|
100
|
+
projectConfigs: []
|
|
101
|
+
});
|
|
102
|
+
projectPaths.push(...await globProjects(projectPatterns));
|
|
103
|
+
const projects = await Promise.all(projectPaths.map(async (project)=>{
|
|
104
|
+
const isDirectory = (0, node_fs__WEBPACK_IMPORTED_MODULE_0__.statSync)(project).isDirectory();
|
|
105
|
+
const { config, configFilePath } = await resolveConfig({
|
|
106
|
+
...options,
|
|
107
|
+
config: isDirectory ? void 0 : project,
|
|
108
|
+
root: isDirectory ? project : (0, pathe__WEBPACK_IMPORTED_MODULE_1__.dirname)(project)
|
|
109
|
+
});
|
|
110
|
+
config.name ??= getDefaultProjectName(project);
|
|
111
|
+
if (config.projects?.length && config.root !== root) _utils__WEBPACK_IMPORTED_MODULE_3__.vF.warn(`Projects cannot have nested projects, the "projects" field in project "${config.name}" will be ignored.`);
|
|
112
|
+
return {
|
|
113
|
+
config,
|
|
114
|
+
configFilePath
|
|
115
|
+
};
|
|
116
|
+
})).then((projects)=>(0, _utils__WEBPACK_IMPORTED_MODULE_3__.zz)(projects.concat(projectConfigs), options));
|
|
117
|
+
if (!projects.length) {
|
|
118
|
+
let errorMsg = `No projects found, please make sure you have at least one valid project.
|
|
119
|
+
${_utils__WEBPACK_IMPORTED_MODULE_3__.yW.gray('projects:')} ${JSON.stringify(config.projects, null, 2)}`;
|
|
120
|
+
if (options.project) errorMsg += `\n${_utils__WEBPACK_IMPORTED_MODULE_3__.yW.gray('projectName filter:')} ${JSON.stringify(options.project, null, 2)}`;
|
|
121
|
+
throw errorMsg;
|
|
122
|
+
}
|
|
123
|
+
const names = new Set();
|
|
124
|
+
projects.forEach((project)=>{
|
|
125
|
+
if (names.has(project.config.name)) {
|
|
126
|
+
const conflictProjects = projects.filter((p)=>p.config.name === project.config.name);
|
|
127
|
+
throw `Project name "${project.config.name}" is already used. Please ensure all projects have unique names.
|
|
128
|
+
Conflicting projects:
|
|
129
|
+
${conflictProjects.map((p)=>`- ${p.configFilePath || p.config.root}`).join('\n')}
|
|
130
|
+
`;
|
|
131
|
+
}
|
|
132
|
+
names.add(project.config.name);
|
|
133
|
+
});
|
|
134
|
+
return projects;
|
|
135
|
+
}
|
|
136
|
+
async function initCli(options) {
|
|
137
|
+
const cwd = process.cwd();
|
|
138
|
+
const root = options.root ? (0, _utils__WEBPACK_IMPORTED_MODULE_3__.FI)(cwd, options.root) : cwd;
|
|
139
|
+
const { config, configFilePath } = await resolveConfig({
|
|
140
|
+
...options,
|
|
141
|
+
root
|
|
142
|
+
});
|
|
143
|
+
const projects = await resolveProjects({
|
|
144
|
+
config,
|
|
145
|
+
root,
|
|
146
|
+
options
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
config,
|
|
150
|
+
configFilePath,
|
|
151
|
+
projects
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
package/dist/33.js
CHANGED
|
@@ -110,9 +110,9 @@ export const __webpack_modules__ = {
|
|
|
110
110
|
},
|
|
111
111
|
{
|
|
112
112
|
key: 'c',
|
|
113
|
-
description: `${utils.yW.bold('c')} ${utils.yW.dim('clear
|
|
113
|
+
description: `${utils.yW.bold('c')} ${utils.yW.dim('clear screen')}`,
|
|
114
114
|
action: ()=>{
|
|
115
|
-
|
|
115
|
+
(0, utils.mT)(true);
|
|
116
116
|
}
|
|
117
117
|
},
|
|
118
118
|
{
|
|
@@ -154,38 +154,37 @@ export const __webpack_modules__ = {
|
|
|
154
154
|
}
|
|
155
155
|
var rsbuild = __webpack_require__("./src/core/rsbuild.ts");
|
|
156
156
|
async function runTests(context) {
|
|
157
|
-
const {
|
|
157
|
+
const { rootPath, reporters, projects, snapshotManager, command } = context;
|
|
158
158
|
const entriesCache = new Map();
|
|
159
|
-
const globTestSourceEntries = async ()=>{
|
|
159
|
+
const globTestSourceEntries = async (name)=>{
|
|
160
|
+
const { include, exclude, includeSource, root } = projects.find((p)=>p.environmentName === name).normalizedConfig;
|
|
160
161
|
const entries = await (0, utils.tG)({
|
|
161
162
|
include,
|
|
162
163
|
exclude,
|
|
163
164
|
includeSource,
|
|
164
|
-
|
|
165
|
+
rootPath,
|
|
166
|
+
projectRoot: root,
|
|
165
167
|
fileFilters: context.fileFilters || []
|
|
166
168
|
});
|
|
167
169
|
entriesCache.set(name, {
|
|
168
170
|
entries,
|
|
169
171
|
fileFilters: context.fileFilters
|
|
170
172
|
});
|
|
171
|
-
if (!Object.keys(entries).length) {
|
|
172
|
-
utils.vF.log(utils.yW.red('No test files found.'));
|
|
173
|
-
utils.vF.log('');
|
|
174
|
-
if (context.fileFilters?.length) utils.vF.log(utils.yW.gray('filter: '), context.fileFilters.join(utils.yW.gray(', ')));
|
|
175
|
-
utils.vF.log(utils.yW.gray('include:'), include.join(utils.yW.gray(', ')));
|
|
176
|
-
utils.vF.log(utils.yW.gray('exclude:'), exclude.join(utils.yW.gray(', ')));
|
|
177
|
-
utils.vF.log('');
|
|
178
|
-
}
|
|
179
173
|
return entries;
|
|
180
174
|
};
|
|
181
|
-
const setupFiles = (
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
175
|
+
const setupFiles = Object.fromEntries(context.projects.map((project)=>{
|
|
176
|
+
const { environmentName, rootPath, normalizedConfig: { setupFiles } } = project;
|
|
177
|
+
return [
|
|
178
|
+
environmentName,
|
|
179
|
+
(0, utils.pr)(setupFiles, rootPath)
|
|
180
|
+
];
|
|
181
|
+
}));
|
|
182
|
+
const rsbuildInstance = await (0, rsbuild.zh)(context, globTestSourceEntries, setupFiles);
|
|
183
|
+
const { getRsbuildStats, closeServer } = await (0, rsbuild.XD)({
|
|
185
184
|
normalizedConfig: context.normalizedConfig,
|
|
186
|
-
globTestSourceEntries: 'watch' === command ? globTestSourceEntries : async ()=>{
|
|
185
|
+
globTestSourceEntries: 'watch' === command ? globTestSourceEntries : async (name)=>{
|
|
187
186
|
if (entriesCache.has(name)) return entriesCache.get(name).entries;
|
|
188
|
-
return globTestSourceEntries();
|
|
187
|
+
return globTestSourceEntries(name);
|
|
189
188
|
},
|
|
190
189
|
setupFiles,
|
|
191
190
|
rsbuildInstance,
|
|
@@ -196,37 +195,78 @@ export const __webpack_modules__ = {
|
|
|
196
195
|
context,
|
|
197
196
|
recommendWorkerCount
|
|
198
197
|
});
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
198
|
+
const run = async ({ fileFilters, mode = 'all' } = {})=>{
|
|
199
|
+
let testStart;
|
|
200
|
+
const buildStart = Date.now();
|
|
201
|
+
const currentEntries = [];
|
|
202
|
+
const currentDeletedEntries = [];
|
|
203
|
+
const returns = await Promise.all(context.projects.map(async (p)=>{
|
|
204
|
+
const { entries, setupEntries, assetFiles, sourceMaps, affectedEntries, deletedEntries } = await getRsbuildStats({
|
|
205
|
+
environmentName: p.environmentName,
|
|
206
|
+
fileFilters
|
|
207
|
+
});
|
|
208
|
+
testStart ??= Date.now();
|
|
209
|
+
currentDeletedEntries.push(...deletedEntries);
|
|
210
|
+
let finalEntries = entries;
|
|
211
|
+
if ('on-demand' === mode) {
|
|
212
|
+
if (0 === affectedEntries.length) utils.vF.debug(utils.yW.yellow(`No test files need re-run in project(${p.environmentName}).`));
|
|
213
|
+
else utils.vF.debug(utils.yW.yellow(`Test files to re-run in project(${p.environmentName}):\n`) + affectedEntries.map((e)=>e.testPath).join('\n') + '\n');
|
|
214
|
+
finalEntries = affectedEntries;
|
|
215
|
+
} else utils.vF.debug(utils.yW.yellow(fileFilters?.length ? `Run filtered tests in project(${p.environmentName}).\n` : `Run all tests in project(${p.environmentName}).\n`));
|
|
216
|
+
currentEntries.push(...finalEntries);
|
|
217
|
+
const { results, testResults } = await pool.runTests({
|
|
218
|
+
entries: finalEntries,
|
|
219
|
+
sourceMaps,
|
|
220
|
+
setupEntries,
|
|
221
|
+
assetFiles,
|
|
222
|
+
project: p,
|
|
223
|
+
updateSnapshot: context.snapshotManager.options.updateSnapshot
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
results,
|
|
227
|
+
testResults,
|
|
228
|
+
sourceMaps
|
|
229
|
+
};
|
|
230
|
+
}));
|
|
231
|
+
const buildTime = testStart - buildStart;
|
|
215
232
|
const testTime = Date.now() - testStart;
|
|
216
233
|
const duration = {
|
|
217
|
-
totalTime: testTime +
|
|
218
|
-
buildTime
|
|
234
|
+
totalTime: testTime + buildTime,
|
|
235
|
+
buildTime,
|
|
219
236
|
testTime
|
|
220
237
|
};
|
|
221
|
-
|
|
222
|
-
|
|
238
|
+
const results = returns.flatMap((r)=>r.results);
|
|
239
|
+
const testResults = returns.flatMap((r)=>r.testResults);
|
|
240
|
+
const sourceMaps = Object.assign({}, ...returns.map((r)=>r.sourceMaps));
|
|
241
|
+
context.updateReporterResultState(results, testResults, currentDeletedEntries);
|
|
242
|
+
if (0 === results.length) {
|
|
243
|
+
if ('watch' === command) if ('on-demand' === mode) utils.vF.log(utils.yW.yellow('No test files need re-run.'));
|
|
244
|
+
else utils.vF.log(utils.yW.yellow('No test files found.'));
|
|
245
|
+
else {
|
|
246
|
+
const code = context.normalizedConfig.passWithNoTests ? 0 : 1;
|
|
247
|
+
utils.vF.log(utils.yW[code ? 'red' : 'yellow'](`No test files found, exiting with code ${code}.`));
|
|
248
|
+
process.exitCode = code;
|
|
249
|
+
}
|
|
250
|
+
if ('all' === mode) {
|
|
251
|
+
if (context.fileFilters?.length) utils.vF.log(utils.yW.gray('filter: '), context.fileFilters.join(utils.yW.gray(', ')));
|
|
252
|
+
context.projects.forEach((p)=>{
|
|
253
|
+
if (context.projects.length > 1) {
|
|
254
|
+
utils.vF.log('');
|
|
255
|
+
utils.vF.log(utils.yW.gray('project:'), p.name);
|
|
256
|
+
}
|
|
257
|
+
utils.vF.log(utils.yW.gray('include:'), p.normalizedConfig.include.join(utils.yW.gray(', ')));
|
|
258
|
+
utils.vF.log(utils.yW.gray('exclude:'), p.normalizedConfig.exclude.join(utils.yW.gray(', ')));
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
223
262
|
if (results.some((r)=>'fail' === r.status)) process.exitCode = 1;
|
|
224
263
|
for (const reporter of reporters)await reporter.onTestRunEnd?.({
|
|
225
|
-
results,
|
|
226
|
-
testResults,
|
|
264
|
+
results: context.reporterResults.results,
|
|
265
|
+
testResults: context.reporterResults.testResults,
|
|
227
266
|
snapshotSummary: snapshotManager.summary,
|
|
228
267
|
duration,
|
|
229
|
-
getSourcemap
|
|
268
|
+
getSourcemap: (name)=>sourceMaps[name] || null,
|
|
269
|
+
filterRerunTestPaths: currentEntries.length ? currentEntries.map((e)=>e.testPath) : void 0
|
|
230
270
|
});
|
|
231
271
|
};
|
|
232
272
|
if ('watch' === command) {
|
|
@@ -236,20 +276,19 @@ export const __webpack_modules__ = {
|
|
|
236
276
|
if (enableCliShortcuts) if (snapshotManager.summary.unmatched) utils.vF.log(` ${utils.yW.dim('press')} ${utils.yW.yellow(utils.yW.bold('u'))} ${utils.yW.dim('to update snapshot')}${utils.yW.dim(', press')} ${utils.yW.bold('h')} ${utils.yW.dim('to show help')}\n`);
|
|
237
277
|
else utils.vF.log(` ${utils.yW.dim('press')} ${utils.yW.bold('h')} ${utils.yW.dim('to show help')}${utils.yW.dim(', press')} ${utils.yW.bold('q')} ${utils.yW.dim('to quit')}\n`);
|
|
238
278
|
};
|
|
239
|
-
const clearLogs = ()=>{
|
|
240
|
-
console.clear();
|
|
241
|
-
};
|
|
242
279
|
const { onBeforeRestart } = await __webpack_require__.e("967").then(__webpack_require__.bind(__webpack_require__, "./src/core/restart.ts"));
|
|
243
280
|
onBeforeRestart(async ()=>{
|
|
244
281
|
await pool.close();
|
|
245
282
|
await closeServer();
|
|
246
283
|
});
|
|
247
284
|
rsbuildInstance.onBeforeDevCompile(({ isFirstCompile })=>{
|
|
248
|
-
if (!isFirstCompile)
|
|
285
|
+
if (!isFirstCompile) (0, utils.mT)();
|
|
249
286
|
});
|
|
250
287
|
rsbuildInstance.onAfterDevCompile(async ({ isFirstCompile })=>{
|
|
251
288
|
snapshotManager.clear();
|
|
252
|
-
await run(
|
|
289
|
+
await run({
|
|
290
|
+
mode: isFirstCompile ? 'all' : 'on-demand'
|
|
291
|
+
});
|
|
253
292
|
if (isFirstCompile && enableCliShortcuts) {
|
|
254
293
|
const closeCliShortcuts = await setupCliShortcuts({
|
|
255
294
|
closeServer: async ()=>{
|
|
@@ -257,15 +296,17 @@ export const __webpack_modules__ = {
|
|
|
257
296
|
await closeServer();
|
|
258
297
|
},
|
|
259
298
|
runAll: async ()=>{
|
|
260
|
-
|
|
299
|
+
(0, utils.mT)();
|
|
261
300
|
snapshotManager.clear();
|
|
262
301
|
context.normalizedConfig.testNamePattern = void 0;
|
|
263
302
|
context.fileFilters = void 0;
|
|
264
|
-
await run(
|
|
303
|
+
await run({
|
|
304
|
+
mode: 'all'
|
|
305
|
+
});
|
|
265
306
|
afterTestsWatchRun();
|
|
266
307
|
},
|
|
267
308
|
runWithTestNamePattern: async (pattern)=>{
|
|
268
|
-
|
|
309
|
+
(0, utils.mT)();
|
|
269
310
|
context.normalizedConfig.testNamePattern = pattern;
|
|
270
311
|
if (pattern) utils.vF.log(`\n${utils.yW.dim('Applied testNamePattern:')} ${utils.yW.bold(pattern)}\n`);
|
|
271
312
|
else utils.vF.log(`\n${utils.yW.dim('Cleared testNamePattern filter')}\n`);
|
|
@@ -274,32 +315,33 @@ export const __webpack_modules__ = {
|
|
|
274
315
|
afterTestsWatchRun();
|
|
275
316
|
},
|
|
276
317
|
runWithFileFilters: async (filters)=>{
|
|
277
|
-
|
|
318
|
+
(0, utils.mT)();
|
|
278
319
|
if (filters && filters.length > 0) utils.vF.log(`\n${utils.yW.dim('Applied file filters:')} ${utils.yW.bold(filters.join(', '))}\n`);
|
|
279
320
|
else utils.vF.log(`\n${utils.yW.dim('Cleared file filters')}\n`);
|
|
280
321
|
snapshotManager.clear();
|
|
281
322
|
context.fileFilters = filters;
|
|
282
|
-
const entries = await globTestSourceEntries();
|
|
283
|
-
if (!
|
|
323
|
+
const entries = await Promise.all(projects.map(async (p)=>globTestSourceEntries(p.environmentName))).then((entries)=>entries.reduce((acc, entry)=>acc.concat(...Object.values(entry)), []));
|
|
324
|
+
if (!entries.length) return void utils.vF.log(filters ? utils.yW.yellow(`\nNo matching test files to run with current file filters: ${filters.join(',')}\n`) : utils.yW.yellow('\nNo matching test files to run.\n'));
|
|
284
325
|
await run({
|
|
285
|
-
fileFilters:
|
|
326
|
+
fileFilters: entries
|
|
286
327
|
});
|
|
287
328
|
afterTestsWatchRun();
|
|
288
329
|
},
|
|
289
330
|
runFailedTests: async ()=>{
|
|
290
|
-
const failedTests =
|
|
331
|
+
const failedTests = context.reporterResults.results.filter((result)=>'fail' === result.status).map((r)=>r.testPath);
|
|
291
332
|
if (!failedTests.length) return void utils.vF.log(utils.yW.yellow('\nNo failed tests were found that needed to be rerun.'));
|
|
292
|
-
|
|
333
|
+
(0, utils.mT)();
|
|
293
334
|
snapshotManager.clear();
|
|
294
335
|
await run({
|
|
295
|
-
fileFilters: failedTests
|
|
336
|
+
fileFilters: failedTests,
|
|
337
|
+
mode: 'all'
|
|
296
338
|
});
|
|
297
339
|
afterTestsWatchRun();
|
|
298
340
|
},
|
|
299
341
|
updateSnapshot: async ()=>{
|
|
300
342
|
if (!snapshotManager.summary.unmatched) return void utils.vF.log(utils.yW.yellow('\nNo snapshots were found that needed to be updated.'));
|
|
301
|
-
const failedTests =
|
|
302
|
-
|
|
343
|
+
const failedTests = context.reporterResults.results.filter((result)=>result.snapshotResult?.unmatched).map((r)=>r.testPath);
|
|
344
|
+
(0, utils.mT)();
|
|
303
345
|
const originalUpdateSnapshot = snapshotManager.options.updateSnapshot;
|
|
304
346
|
snapshotManager.clear();
|
|
305
347
|
snapshotManager.options.updateSnapshot = 'all';
|