@rstest/core 0.2.1 → 0.3.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.
- package/dist/{359.js → 12.js} +156 -94
- package/dist/{72.js → 171.js} +2 -1
- package/dist/223.js +135 -0
- package/dist/{920.js → 33.js} +125 -81
- package/dist/{44.js → 350.js} +6 -5
- package/dist/{813.js → 607.js} +16 -15
- package/dist/{208.js → 655.js} +60 -59
- package/dist/{355.js → 704.js} +17 -16
- package/dist/{965.js → 711.js} +6 -5
- package/dist/{443.js → 755.js} +2 -1
- package/dist/{723.js → 829.js} +5 -4
- package/dist/{867.js → 85.js} +140 -67
- package/dist/{668.js → 928.js} +3 -2
- package/dist/{25.js → 967.js} +19 -14
- package/dist/{64.js → 969.js} +2 -1
- package/dist/{285.js → 971.js} +66 -33
- package/dist/{854.js → 985.js} +153 -81
- package/dist/index.js +93 -121
- package/dist/worker.js +45 -38
- package/dist-types/index.d.ts +55 -3
- package/dist-types/worker.d.ts +124 -4
- package/globals.d.ts +2 -0
- package/package.json +6 -6
- /package/dist/{208.js.LICENSE.txt → 655.js.LICENSE.txt} +0 -0
- /package/dist/{668.js.LICENSE.txt → 928.js.LICENSE.txt} +0 -0
package/dist/{285.js → 971.js}
RENAMED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import 'module';
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
export const __webpack_id__ = "971";
|
|
3
4
|
export const __webpack_ids__ = [
|
|
4
|
-
"
|
|
5
|
+
"971"
|
|
5
6
|
];
|
|
6
7
|
export const __webpack_modules__ = {
|
|
7
8
|
"./src/core/listTests.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
@@ -14,61 +15,89 @@ export const __webpack_modules__ = {
|
|
|
14
15
|
var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./src/utils/index.ts");
|
|
15
16
|
var _rsbuild__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./src/core/rsbuild.ts");
|
|
16
17
|
async function listTests(context, { filesOnly, json }) {
|
|
17
|
-
const {
|
|
18
|
-
const testEntries =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
root
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
name
|
|
18
|
+
const { rootPath } = context;
|
|
19
|
+
const testEntries = {};
|
|
20
|
+
const globTestSourceEntries = async (name)=>{
|
|
21
|
+
if (testEntries[name]) return testEntries[name];
|
|
22
|
+
const { include, exclude, includeSource, root } = context.projects.find((p)=>p.environmentName === name).normalizedConfig;
|
|
23
|
+
const entries = await (0, _utils__WEBPACK_IMPORTED_MODULE_3__.tG)({
|
|
24
|
+
include,
|
|
25
|
+
exclude,
|
|
26
|
+
root,
|
|
27
|
+
fileFilters: context.fileFilters || [],
|
|
28
|
+
includeSource
|
|
29
|
+
});
|
|
30
|
+
testEntries[name] = entries;
|
|
31
|
+
return entries;
|
|
32
|
+
};
|
|
33
|
+
const setupFiles = Object.fromEntries(context.projects.map((project)=>{
|
|
34
|
+
const { environmentName, rootPath, normalizedConfig: { setupFiles } } = project;
|
|
35
|
+
return [
|
|
36
|
+
environmentName,
|
|
37
|
+
(0, _utils__WEBPACK_IMPORTED_MODULE_3__.pr)(setupFiles, rootPath)
|
|
38
|
+
];
|
|
39
|
+
}));
|
|
40
|
+
const rsbuildInstance = await (0, _rsbuild__WEBPACK_IMPORTED_MODULE_4__.zh)(context, globTestSourceEntries, setupFiles);
|
|
41
|
+
const { getRsbuildStats, closeServer } = await (0, _rsbuild__WEBPACK_IMPORTED_MODULE_4__.XD)({
|
|
30
42
|
globTestSourceEntries,
|
|
31
43
|
normalizedConfig: context.normalizedConfig,
|
|
32
44
|
setupFiles,
|
|
33
45
|
rsbuildInstance,
|
|
34
46
|
rootPath
|
|
35
47
|
});
|
|
36
|
-
const
|
|
37
|
-
const pool = await (0, _pool__WEBPACK_IMPORTED_MODULE_2__.K)({
|
|
48
|
+
const pool = await (0, _pool__WEBPACK_IMPORTED_MODULE_2__.b)({
|
|
38
49
|
context
|
|
39
50
|
});
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
entries,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
const updateSnapshot = context.snapshotManager.options.updateSnapshot;
|
|
52
|
+
const returns = await Promise.all(context.projects.map(async (project)=>{
|
|
53
|
+
const { entries, setupEntries, assetFiles, sourceMaps } = await getRsbuildStats({
|
|
54
|
+
environmentName: project.environmentName
|
|
55
|
+
});
|
|
56
|
+
const list = await pool.collectTests({
|
|
57
|
+
entries,
|
|
58
|
+
sourceMaps,
|
|
59
|
+
setupEntries,
|
|
60
|
+
assetFiles,
|
|
61
|
+
project,
|
|
62
|
+
updateSnapshot
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
list,
|
|
66
|
+
sourceMaps
|
|
67
|
+
};
|
|
68
|
+
}));
|
|
69
|
+
const list = returns.flatMap((r)=>r.list);
|
|
70
|
+
const sourceMaps = Object.assign({}, ...returns.map((r)=>r.sourceMaps));
|
|
48
71
|
const tests = [];
|
|
49
72
|
const traverseTests = (test)=>{
|
|
50
73
|
if ([
|
|
51
74
|
'skip',
|
|
52
75
|
'todo'
|
|
53
76
|
].includes(test.runMode)) return;
|
|
54
|
-
if ('case' === test.type) tests.push({
|
|
77
|
+
if ('case' === test.type) if (showProject) tests.push({
|
|
78
|
+
file: test.testPath,
|
|
79
|
+
name: (0, _utils__WEBPACK_IMPORTED_MODULE_3__.fN)(test),
|
|
80
|
+
project: test.project
|
|
81
|
+
});
|
|
82
|
+
else tests.push({
|
|
55
83
|
file: test.testPath,
|
|
56
|
-
name: (0, _utils__WEBPACK_IMPORTED_MODULE_3__.
|
|
84
|
+
name: (0, _utils__WEBPACK_IMPORTED_MODULE_3__.fN)(test)
|
|
57
85
|
});
|
|
58
86
|
else for (const child of test.tests)traverseTests(child);
|
|
59
87
|
};
|
|
60
88
|
const hasError = list.some((file)=>file.errors?.length);
|
|
89
|
+
const showProject = context.projects.length > 1;
|
|
61
90
|
if (hasError) {
|
|
62
91
|
const { printError } = await Promise.all([
|
|
63
|
-
__webpack_require__.e("
|
|
64
|
-
__webpack_require__.e("
|
|
92
|
+
__webpack_require__.e("829"),
|
|
93
|
+
__webpack_require__.e("704")
|
|
65
94
|
]).then(__webpack_require__.bind(__webpack_require__, "./src/utils/error.ts"));
|
|
66
95
|
process.exitCode = 1;
|
|
67
96
|
for (const file of list){
|
|
68
97
|
const relativePath = (0, node_path__WEBPACK_IMPORTED_MODULE_1__.relative)(rootPath, file.testPath);
|
|
69
98
|
if (file.errors?.length) {
|
|
70
|
-
_utils__WEBPACK_IMPORTED_MODULE_3__.
|
|
71
|
-
for (const error of file.errors)await printError(error,
|
|
99
|
+
_utils__WEBPACK_IMPORTED_MODULE_3__.vF.log(`${_utils__WEBPACK_IMPORTED_MODULE_3__.yW.bgRed(' FAIL ')} ${relativePath}`);
|
|
100
|
+
for (const error of file.errors)await printError(error, (name)=>sourceMaps[name] || null, rootPath);
|
|
72
101
|
}
|
|
73
102
|
}
|
|
74
103
|
await closeServer();
|
|
@@ -77,7 +106,11 @@ export const __webpack_modules__ = {
|
|
|
77
106
|
}
|
|
78
107
|
for (const file of list){
|
|
79
108
|
if (filesOnly) {
|
|
80
|
-
tests.push({
|
|
109
|
+
if (showProject) tests.push({
|
|
110
|
+
file: file.testPath,
|
|
111
|
+
project: file.project
|
|
112
|
+
});
|
|
113
|
+
else tests.push({
|
|
81
114
|
file: file.testPath
|
|
82
115
|
});
|
|
83
116
|
continue;
|
|
@@ -92,10 +125,10 @@ export const __webpack_modules__ = {
|
|
|
92
125
|
recursive: true
|
|
93
126
|
});
|
|
94
127
|
(0, node_fs__WEBPACK_IMPORTED_MODULE_0__.writeFileSync)(jsonPath, content);
|
|
95
|
-
} else _utils__WEBPACK_IMPORTED_MODULE_3__.
|
|
128
|
+
} else _utils__WEBPACK_IMPORTED_MODULE_3__.vF.log(content);
|
|
96
129
|
} else for (const test of tests){
|
|
97
130
|
const shortPath = (0, node_path__WEBPACK_IMPORTED_MODULE_1__.relative)(rootPath, test.file);
|
|
98
|
-
_utils__WEBPACK_IMPORTED_MODULE_3__.
|
|
131
|
+
_utils__WEBPACK_IMPORTED_MODULE_3__.vF.log(test.name ? `${_utils__WEBPACK_IMPORTED_MODULE_3__.yW.dim(`${shortPath} > `)}${test.name}` : (0, _utils__WEBPACK_IMPORTED_MODULE_3__.EQ)(shortPath));
|
|
99
132
|
}
|
|
100
133
|
await closeServer();
|
|
101
134
|
await pool.close();
|
package/dist/{854.js → 985.js}
RENAMED
|
@@ -1,42 +1,44 @@
|
|
|
1
1
|
import 'module';
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
export const __webpack_id__ = "985";
|
|
3
4
|
export const __webpack_ids__ = [
|
|
4
|
-
"
|
|
5
|
+
"985"
|
|
5
6
|
];
|
|
6
7
|
export const __webpack_modules__ = {
|
|
7
8
|
"./src/core/rsbuild.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
8
9
|
__webpack_require__.d(__webpack_exports__, {
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
XD: ()=>createRsbuildServer,
|
|
11
|
+
zh: ()=>prepareRsbuild
|
|
11
12
|
});
|
|
12
13
|
var core_ = __webpack_require__("@rsbuild/core");
|
|
13
14
|
var external_pathe_ = __webpack_require__("pathe");
|
|
14
15
|
var utils = __webpack_require__("./src/utils/index.ts");
|
|
16
|
+
const RUNTIME_CHUNK_NAME = 'runtime';
|
|
15
17
|
const pluginBasic = (context)=>({
|
|
16
18
|
name: 'rstest:basic',
|
|
17
19
|
setup: (api)=>{
|
|
18
|
-
api.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
api.modifyEnvironmentConfig(async (config, { mergeEnvironmentConfig, name })=>{
|
|
21
|
+
const { normalizedConfig: { resolve, source, output, tools, performance, dev, testEnvironment }, rootPath } = context.projects.find((p)=>p.environmentName === name);
|
|
22
|
+
return mergeEnvironmentConfig(config, {
|
|
23
|
+
performance,
|
|
24
|
+
tools,
|
|
25
|
+
resolve,
|
|
26
|
+
source,
|
|
27
|
+
output,
|
|
28
|
+
dev
|
|
29
|
+
}, {
|
|
28
30
|
source: {
|
|
29
31
|
define: {
|
|
30
32
|
'import.meta.rstest': "global['@rstest/core']"
|
|
31
33
|
}
|
|
32
34
|
},
|
|
33
35
|
output: {
|
|
34
|
-
manifest:
|
|
36
|
+
manifest: `${name}-manifest.json`,
|
|
35
37
|
sourceMap: {
|
|
36
38
|
js: 'source-map'
|
|
37
39
|
},
|
|
38
40
|
distPath: {
|
|
39
|
-
root: utils.
|
|
41
|
+
root: context.projects.length > 1 ? `${utils.zZ}/${name}` : utils.zZ
|
|
40
42
|
}
|
|
41
43
|
},
|
|
42
44
|
tools: {
|
|
@@ -50,7 +52,7 @@ export const __webpack_modules__ = {
|
|
|
50
52
|
injectModulePathName: true,
|
|
51
53
|
importMetaPathName: true,
|
|
52
54
|
hoistMockModule: true,
|
|
53
|
-
manualMockRoot: external_pathe_["default"].resolve(
|
|
55
|
+
manualMockRoot: external_pathe_["default"].resolve(rootPath, '__mocks__')
|
|
54
56
|
}));
|
|
55
57
|
config.module.parser ??= {};
|
|
56
58
|
config.module.parser.javascript = {
|
|
@@ -73,7 +75,7 @@ export const __webpack_modules__ = {
|
|
|
73
75
|
'.jsx',
|
|
74
76
|
'.tsx'
|
|
75
77
|
];
|
|
76
|
-
if ('node' ===
|
|
78
|
+
if ('node' === testEnvironment) config.resolve.mainFields = config.resolve.mainFields?.filter((filed)=>'module' !== filed) || [
|
|
77
79
|
'main'
|
|
78
80
|
];
|
|
79
81
|
config.resolve.byDependency ??= {};
|
|
@@ -88,12 +90,13 @@ export const __webpack_modules__ = {
|
|
|
88
90
|
nodeEnv: false,
|
|
89
91
|
...config.optimization || {},
|
|
90
92
|
runtimeChunk: {
|
|
91
|
-
name:
|
|
93
|
+
name: `${name}-${RUNTIME_CHUNK_NAME}`
|
|
92
94
|
}
|
|
93
95
|
};
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
|
-
})
|
|
98
|
+
});
|
|
99
|
+
});
|
|
97
100
|
}
|
|
98
101
|
});
|
|
99
102
|
var external_node_path_ = __webpack_require__("node:path");
|
|
@@ -141,31 +144,32 @@ export const __webpack_modules__ = {
|
|
|
141
144
|
});
|
|
142
145
|
}
|
|
143
146
|
}
|
|
144
|
-
const pluginEntryWatch = ({ isWatch, globTestSourceEntries, setupFiles,
|
|
147
|
+
const pluginEntryWatch = ({ isWatch, globTestSourceEntries, setupFiles, context })=>({
|
|
145
148
|
name: 'rstest:entry-watch',
|
|
146
149
|
setup: (api)=>{
|
|
147
|
-
api.modifyRspackConfig(async (config)=>{
|
|
150
|
+
api.modifyRspackConfig(async (config, { environment })=>{
|
|
148
151
|
if (isWatch) {
|
|
149
|
-
config.plugins.push(new TestFileWatchPlugin(
|
|
152
|
+
config.plugins.push(new TestFileWatchPlugin(environment.config.root));
|
|
150
153
|
config.entry = async ()=>{
|
|
151
|
-
const sourceEntries = await globTestSourceEntries();
|
|
154
|
+
const sourceEntries = await globTestSourceEntries(environment.name);
|
|
152
155
|
return {
|
|
153
156
|
...sourceEntries,
|
|
154
|
-
...setupFiles
|
|
157
|
+
...setupFiles[environment.name]
|
|
155
158
|
};
|
|
156
159
|
};
|
|
157
160
|
config.watchOptions ??= {};
|
|
158
|
-
config.watchOptions.ignored = (0, utils.
|
|
161
|
+
config.watchOptions.ignored = (0, utils.bg)(config.watchOptions.ignored || []);
|
|
159
162
|
if (0 === config.watchOptions.ignored.length) config.watchOptions.ignored.push('**/.git', '**/node_modules');
|
|
160
|
-
config.watchOptions.ignored.push(utils.
|
|
163
|
+
config.watchOptions.ignored.push(utils.EJ, '**/*.snap');
|
|
164
|
+
const configFilePath = context.projects.find((project)=>project.environmentName === environment.name)?.configFilePath;
|
|
161
165
|
if (configFilePath) config.watchOptions.ignored.push(configFilePath);
|
|
162
166
|
} else {
|
|
163
167
|
config.watch = false;
|
|
164
168
|
config.watchOptions ??= {};
|
|
165
169
|
config.watchOptions.ignored = '**/**';
|
|
166
|
-
const sourceEntries = await globTestSourceEntries();
|
|
170
|
+
const sourceEntries = await globTestSourceEntries(environment.name);
|
|
167
171
|
config.entry = {
|
|
168
|
-
...setupFiles,
|
|
172
|
+
...setupFiles[environment.name],
|
|
169
173
|
...sourceEntries
|
|
170
174
|
};
|
|
171
175
|
}
|
|
@@ -188,17 +192,19 @@ export const __webpack_modules__ = {
|
|
|
188
192
|
};
|
|
189
193
|
function autoExternalNodeBuiltin({ request, dependencyType }, callback) {
|
|
190
194
|
if (!request) return void callback();
|
|
191
|
-
const isNodeBuiltin = utils.
|
|
195
|
+
const isNodeBuiltin = utils.Kv.some((builtin)=>{
|
|
192
196
|
if ('string' == typeof builtin) return builtin === request;
|
|
193
197
|
return builtin.test(request);
|
|
194
198
|
});
|
|
195
199
|
if (isNodeBuiltin) callback(void 0, request, 'commonjs' === dependencyType ? 'commonjs' : 'module-import');
|
|
196
200
|
else callback();
|
|
197
201
|
}
|
|
198
|
-
const pluginExternal = (
|
|
202
|
+
const pluginExternal = (context)=>({
|
|
199
203
|
name: 'rstest:external',
|
|
200
204
|
setup: (api)=>{
|
|
201
|
-
api.
|
|
205
|
+
api.modifyEnvironmentConfig(async (config, { mergeEnvironmentConfig, name })=>{
|
|
206
|
+
const { normalizedConfig: { testEnvironment } } = context.projects.find((p)=>p.environmentName === name);
|
|
207
|
+
return mergeEnvironmentConfig(config, {
|
|
202
208
|
output: {
|
|
203
209
|
externals: 'node' === testEnvironment ? [
|
|
204
210
|
autoExternalNodeModules
|
|
@@ -206,7 +212,7 @@ export const __webpack_modules__ = {
|
|
|
206
212
|
},
|
|
207
213
|
tools: {
|
|
208
214
|
rspack: (config)=>{
|
|
209
|
-
config.externals = (0, utils.
|
|
215
|
+
config.externals = (0, utils.bg)(config.externals) || [];
|
|
210
216
|
config.externals.unshift({
|
|
211
217
|
'@rstest/core': 'global @rstest/core'
|
|
212
218
|
});
|
|
@@ -215,7 +221,8 @@ export const __webpack_modules__ = {
|
|
|
215
221
|
config.externals.push(autoExternalNodeBuiltin);
|
|
216
222
|
}
|
|
217
223
|
}
|
|
218
|
-
})
|
|
224
|
+
});
|
|
225
|
+
});
|
|
219
226
|
}
|
|
220
227
|
});
|
|
221
228
|
class IgnoreModuleNotFoundErrorPlugin {
|
|
@@ -443,17 +450,13 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
443
450
|
}
|
|
444
451
|
const isMultiCompiler = (compiler)=>'compilers' in compiler && Array.isArray(compiler.compilers);
|
|
445
452
|
const prepareRsbuild = async (context, globTestSourceEntries, setupFiles)=>{
|
|
446
|
-
const { command, normalizedConfig: { isolate,
|
|
447
|
-
const debugMode = (0, utils.
|
|
453
|
+
const { command, normalizedConfig: { isolate, dev = {} } } = context;
|
|
454
|
+
const debugMode = (0, utils._o)();
|
|
448
455
|
core_.logger.level = debugMode ? 'verbose' : 'error';
|
|
449
456
|
const writeToDisk = dev.writeToDisk || debugMode;
|
|
450
457
|
const rsbuildInstance = await (0, core_.createRsbuild)({
|
|
451
458
|
callerName: 'rstest',
|
|
452
459
|
rsbuildConfig: {
|
|
453
|
-
tools,
|
|
454
|
-
resolve,
|
|
455
|
-
source,
|
|
456
|
-
output,
|
|
457
460
|
server: {
|
|
458
461
|
printUrls: false,
|
|
459
462
|
strictPort: false,
|
|
@@ -466,9 +469,17 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
466
469
|
hmr: false,
|
|
467
470
|
writeToDisk
|
|
468
471
|
},
|
|
469
|
-
|
|
472
|
+
environments: Object.fromEntries(context.projects.map((project)=>[
|
|
473
|
+
project.environmentName,
|
|
474
|
+
{
|
|
475
|
+
plugins: project.normalizedConfig.plugins,
|
|
476
|
+
root: project.rootPath,
|
|
477
|
+
output: {
|
|
478
|
+
target: 'node'
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
])),
|
|
470
482
|
plugins: [
|
|
471
|
-
...plugins || [],
|
|
472
483
|
pluginBasic(context),
|
|
473
484
|
pluginIgnoreResolveError,
|
|
474
485
|
pluginMockRuntime,
|
|
@@ -476,18 +487,64 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
476
487
|
pluginEntryWatch({
|
|
477
488
|
globTestSourceEntries,
|
|
478
489
|
setupFiles,
|
|
479
|
-
|
|
490
|
+
context,
|
|
480
491
|
isWatch: 'watch' === command
|
|
481
492
|
}),
|
|
482
|
-
pluginExternal(
|
|
483
|
-
!isolate ? pluginCacheControl(Object.values(setupFiles)) : null,
|
|
493
|
+
pluginExternal(context),
|
|
494
|
+
!isolate ? pluginCacheControl(Object.values(setupFiles).flatMap((files)=>Object.values(files))) : null,
|
|
484
495
|
pluginInspect()
|
|
485
496
|
].filter(Boolean)
|
|
486
497
|
}
|
|
487
498
|
});
|
|
488
499
|
return rsbuildInstance;
|
|
489
500
|
};
|
|
490
|
-
const
|
|
501
|
+
const calcEntriesToRerun = (entries, chunks, buildData, runtimeChunkName)=>{
|
|
502
|
+
const entryToChunkHashesMap = new Map();
|
|
503
|
+
const buildChunkHashes = (entry)=>{
|
|
504
|
+
const validChunks = (entry.chunks || []).filter((chunk)=>chunk !== runtimeChunkName);
|
|
505
|
+
validChunks.forEach((chunkName)=>{
|
|
506
|
+
const chunkInfo = chunks?.find((c)=>c.names?.includes(chunkName));
|
|
507
|
+
if (chunkInfo) {
|
|
508
|
+
const existing = entryToChunkHashesMap.get(entry.testPath) || {};
|
|
509
|
+
existing[chunkName] = chunkInfo.hash ?? '';
|
|
510
|
+
entryToChunkHashesMap.set(entry.testPath, existing);
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
};
|
|
514
|
+
(entries || []).forEach(buildChunkHashes);
|
|
515
|
+
const entryToChunkHashes = Array.from(entryToChunkHashesMap.entries()).map(([name, chunks])=>({
|
|
516
|
+
name,
|
|
517
|
+
chunks
|
|
518
|
+
}));
|
|
519
|
+
const affectedTestPaths = new Set();
|
|
520
|
+
const deletedEntries = [];
|
|
521
|
+
if (buildData.entryToChunkHashes) {
|
|
522
|
+
const prevMap = new Map(buildData.entryToChunkHashes.map((e)=>[
|
|
523
|
+
e.name,
|
|
524
|
+
e.chunks
|
|
525
|
+
]));
|
|
526
|
+
const currentNames = new Set(entryToChunkHashesMap.keys());
|
|
527
|
+
deletedEntries.push(...Array.from(prevMap.keys()).filter((name)=>!currentNames.has(name)));
|
|
528
|
+
const findAffectedEntry = (testPath)=>{
|
|
529
|
+
const currentChunks = entryToChunkHashesMap.get(testPath);
|
|
530
|
+
const prevChunks = prevMap.get(testPath);
|
|
531
|
+
if (!currentChunks) return;
|
|
532
|
+
if (!prevChunks) return void affectedTestPaths.add(testPath);
|
|
533
|
+
const hasChanges = Object.entries(currentChunks).some(([chunkName, hash])=>prevChunks[chunkName] !== hash);
|
|
534
|
+
if (hasChanges) affectedTestPaths.add(testPath);
|
|
535
|
+
};
|
|
536
|
+
entryToChunkHashesMap.forEach((_, testPath)=>{
|
|
537
|
+
findAffectedEntry(testPath);
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
buildData.entryToChunkHashes = entryToChunkHashes;
|
|
541
|
+
const affectedEntries = Array.from(affectedTestPaths).map((testPath)=>entries.find((e)=>e.testPath === testPath)).filter((entry)=>void 0 !== entry);
|
|
542
|
+
return {
|
|
543
|
+
affectedEntries,
|
|
544
|
+
deletedEntries
|
|
545
|
+
};
|
|
546
|
+
};
|
|
547
|
+
const createRsbuildServer = async ({ globTestSourceEntries, setupFiles, rsbuildInstance, normalizedConfig })=>{
|
|
491
548
|
let rspackCompiler;
|
|
492
549
|
const rstestCompilerPlugin = {
|
|
493
550
|
name: 'rstest:compiler',
|
|
@@ -503,7 +560,7 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
503
560
|
const devServer = await rsbuildInstance.createDevServer({
|
|
504
561
|
getPortSilently: true
|
|
505
562
|
});
|
|
506
|
-
if ((0, utils.
|
|
563
|
+
if ((0, utils._o)()) await rsbuildInstance.inspectConfig({
|
|
507
564
|
writeToDisk: true,
|
|
508
565
|
extraConfigs: {
|
|
509
566
|
rstest: normalizedConfig
|
|
@@ -512,10 +569,26 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
512
569
|
if (!rspackCompiler) throw new Error('rspackCompiler was not initialized');
|
|
513
570
|
const outputFileSystem = isMultiCompiler(rspackCompiler) ? rspackCompiler.compilers[0].outputFileSystem : rspackCompiler.outputFileSystem;
|
|
514
571
|
if (!outputFileSystem) throw new Error(`Expect outputFileSystem to be defined, but got ${outputFileSystem}`);
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
572
|
+
const readFile = async (fileName)=>new Promise((resolve, reject)=>{
|
|
573
|
+
outputFileSystem.readFile(fileName, (err, data)=>{
|
|
574
|
+
if (err) reject(err);
|
|
575
|
+
resolve('string' == typeof data ? data : data.toString());
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
const buildData = {};
|
|
579
|
+
const getEntryFiles = async (manifest, outputPath)=>{
|
|
580
|
+
const entryFiles = {};
|
|
581
|
+
const entries = Object.keys(manifest.entries);
|
|
582
|
+
for (const entry of entries){
|
|
583
|
+
const data = manifest.entries[entry];
|
|
584
|
+
entryFiles[entry] = ((data?.initial?.js || []).concat(data?.async?.js || []) || []).map((file)=>external_pathe_["default"].join(outputPath, file));
|
|
585
|
+
}
|
|
586
|
+
return entryFiles;
|
|
587
|
+
};
|
|
588
|
+
const getRsbuildStats = async ({ environmentName, fileFilters })=>{
|
|
589
|
+
const stats = await devServer.environments[environmentName].getStats();
|
|
590
|
+
const manifest = devServer.environments[environmentName].context.manifest;
|
|
591
|
+
const { entrypoints, outputPath, assets, hash, time: buildTime, chunks } = stats.toJson({
|
|
519
592
|
all: false,
|
|
520
593
|
hash: true,
|
|
521
594
|
entrypoints: true,
|
|
@@ -523,41 +596,29 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
523
596
|
assets: true,
|
|
524
597
|
relatedAssets: true,
|
|
525
598
|
cachedAssets: true,
|
|
599
|
+
chunks: true,
|
|
526
600
|
timings: true
|
|
527
601
|
});
|
|
528
|
-
const
|
|
529
|
-
outputFileSystem.readFile(fileName, (err, data)=>{
|
|
530
|
-
if (err) reject(err);
|
|
531
|
-
resolve('string' == typeof data ? data : data.toString());
|
|
532
|
-
});
|
|
533
|
-
});
|
|
534
|
-
const getEntryFiles = async ()=>{
|
|
535
|
-
const entryFiles = {};
|
|
536
|
-
const entries = Object.keys(manifest.entries);
|
|
537
|
-
for (const entry of entries){
|
|
538
|
-
const data = manifest.entries[entry];
|
|
539
|
-
entryFiles[entry] = ((data?.initial?.js || []).concat(data?.async?.js || []) || []).map((file)=>external_pathe_["default"].join(outputPath, file));
|
|
540
|
-
}
|
|
541
|
-
return entryFiles;
|
|
542
|
-
};
|
|
543
|
-
const entryFiles = await getEntryFiles();
|
|
602
|
+
const entryFiles = await getEntryFiles(manifest, outputPath);
|
|
544
603
|
const entries = [];
|
|
545
604
|
const setupEntries = [];
|
|
546
|
-
const sourceEntries = await globTestSourceEntries();
|
|
605
|
+
const sourceEntries = await globTestSourceEntries(environmentName);
|
|
547
606
|
for (const entry of Object.keys(entrypoints)){
|
|
548
607
|
const e = entrypoints[entry];
|
|
549
608
|
const distPath = external_pathe_["default"].join(outputPath, e.assets[e.assets.length - 1].name);
|
|
550
|
-
if (setupFiles[entry]) setupEntries.push({
|
|
609
|
+
if (setupFiles[environmentName][entry]) setupEntries.push({
|
|
551
610
|
distPath,
|
|
552
|
-
testPath: setupFiles[entry],
|
|
553
|
-
files: entryFiles[entry]
|
|
611
|
+
testPath: setupFiles[environmentName][entry],
|
|
612
|
+
files: entryFiles[entry],
|
|
613
|
+
chunks: e.chunks || []
|
|
554
614
|
});
|
|
555
615
|
else if (sourceEntries[entry]) {
|
|
556
616
|
if (fileFilters?.length && !fileFilters.includes(sourceEntries[entry])) continue;
|
|
557
617
|
entries.push({
|
|
558
618
|
distPath,
|
|
559
619
|
testPath: sourceEntries[entry],
|
|
560
|
-
files: entryFiles[entry]
|
|
620
|
+
files: entryFiles[entry],
|
|
621
|
+
chunks: e.chunks || []
|
|
561
622
|
});
|
|
562
623
|
}
|
|
563
624
|
}
|
|
@@ -585,7 +646,11 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
585
646
|
null
|
|
586
647
|
];
|
|
587
648
|
}))).filter((asset)=>null !== asset[1]));
|
|
649
|
+
buildData[environmentName] ??= {};
|
|
650
|
+
const { affectedEntries, deletedEntries } = calcEntriesToRerun(entries, chunks, buildData[environmentName], `${environmentName}-${RUNTIME_CHUNK_NAME}`);
|
|
588
651
|
return {
|
|
652
|
+
affectedEntries,
|
|
653
|
+
deletedEntries,
|
|
589
654
|
hash,
|
|
590
655
|
entries,
|
|
591
656
|
setupEntries,
|
|
@@ -609,7 +674,7 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
609
674
|
},
|
|
610
675
|
"./src/pool/index.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
611
676
|
__webpack_require__.d(__webpack_exports__, {
|
|
612
|
-
|
|
677
|
+
b: ()=>createPool
|
|
613
678
|
});
|
|
614
679
|
var external_node_os_ = __webpack_require__("node:os");
|
|
615
680
|
var utils = __webpack_require__("./src/utils/index.ts");
|
|
@@ -748,11 +813,11 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
748
813
|
'--experimental-vm-modules',
|
|
749
814
|
'--experimental-import-meta-resolve',
|
|
750
815
|
'--no-warnings',
|
|
751
|
-
(0, utils.
|
|
816
|
+
(0, utils.C3)() ? '--experimental-detect-module' : void 0
|
|
752
817
|
].filter(Boolean),
|
|
753
818
|
env: {
|
|
754
819
|
NODE_ENV: 'test',
|
|
755
|
-
FORCE_COLOR: '1',
|
|
820
|
+
FORCE_COLOR: '1' === process.env.NO_COLOR ? '0' : '1',
|
|
756
821
|
...process.env
|
|
757
822
|
}
|
|
758
823
|
});
|
|
@@ -771,10 +836,11 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
771
836
|
}
|
|
772
837
|
};
|
|
773
838
|
return {
|
|
774
|
-
runTests: async ({ entries, assetFiles, setupEntries, sourceMaps, updateSnapshot })=>{
|
|
839
|
+
runTests: async ({ entries, assetFiles, setupEntries, sourceMaps, project, updateSnapshot })=>{
|
|
840
|
+
const projectName = context.normalizedConfig.name;
|
|
841
|
+
const runtimeConfig = getRuntimeConfig(project);
|
|
775
842
|
const setupAssets = setupEntries.flatMap((entry)=>entry.files || []);
|
|
776
843
|
const entryLength = Object.keys(entries).length;
|
|
777
|
-
const runtimeConfig = getRuntimeConfig(context);
|
|
778
844
|
const results = await Promise.all(entries.map((entryInfo)=>{
|
|
779
845
|
const { assetFiles: neededFiles, sourceMaps: neededSourceMaps } = filterAssetsByEntry(entryInfo, assetFiles, setupAssets, sourceMaps, entryLength);
|
|
780
846
|
return pool.runTest({
|
|
@@ -782,8 +848,9 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
782
848
|
entryInfo,
|
|
783
849
|
assetFiles: neededFiles,
|
|
784
850
|
context: {
|
|
851
|
+
project: projectName,
|
|
785
852
|
rootPath: context.rootPath,
|
|
786
|
-
runtimeConfig: (0, utils.
|
|
853
|
+
runtimeConfig: (0, utils.Ok)(runtimeConfig)
|
|
787
854
|
},
|
|
788
855
|
type: 'run',
|
|
789
856
|
sourceMaps: neededSourceMaps,
|
|
@@ -794,6 +861,7 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
794
861
|
}).catch((err)=>{
|
|
795
862
|
err.fullStack = true;
|
|
796
863
|
return {
|
|
864
|
+
project: projectName,
|
|
797
865
|
testPath: entryInfo.testPath,
|
|
798
866
|
status: 'fail',
|
|
799
867
|
name: '',
|
|
@@ -808,13 +876,15 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
808
876
|
const testResults = results.flatMap((r)=>r.results);
|
|
809
877
|
return {
|
|
810
878
|
results,
|
|
811
|
-
testResults
|
|
879
|
+
testResults,
|
|
880
|
+
project
|
|
812
881
|
};
|
|
813
882
|
},
|
|
814
|
-
collectTests: async ({ entries, assetFiles, setupEntries, sourceMaps, updateSnapshot })=>{
|
|
883
|
+
collectTests: async ({ entries, assetFiles, setupEntries, sourceMaps, project, updateSnapshot })=>{
|
|
884
|
+
const runtimeConfig = getRuntimeConfig(project);
|
|
885
|
+
const projectName = project.normalizedConfig.name;
|
|
815
886
|
const setupAssets = setupEntries.flatMap((entry)=>entry.files || []);
|
|
816
887
|
const entryLength = Object.keys(entries).length;
|
|
817
|
-
const runtimeConfig = getRuntimeConfig(context);
|
|
818
888
|
return Promise.all(entries.map((entryInfo)=>{
|
|
819
889
|
const { assetFiles: neededFiles, sourceMaps: neededSourceMaps } = filterAssetsByEntry(entryInfo, assetFiles, setupAssets, sourceMaps, entryLength);
|
|
820
890
|
return pool.collectTests({
|
|
@@ -822,8 +892,9 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
822
892
|
entryInfo,
|
|
823
893
|
assetFiles: neededFiles,
|
|
824
894
|
context: {
|
|
895
|
+
project: projectName,
|
|
825
896
|
rootPath: context.rootPath,
|
|
826
|
-
runtimeConfig: (0, utils.
|
|
897
|
+
runtimeConfig: (0, utils.Ok)(runtimeConfig)
|
|
827
898
|
},
|
|
828
899
|
type: 'collect',
|
|
829
900
|
sourceMaps: neededSourceMaps,
|
|
@@ -834,6 +905,7 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
834
905
|
}).catch((err)=>{
|
|
835
906
|
err.fullStack = true;
|
|
836
907
|
return {
|
|
908
|
+
project: projectName,
|
|
837
909
|
testPath: entryInfo.testPath,
|
|
838
910
|
tests: [],
|
|
839
911
|
errors: [
|