@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/LICENSE.md +26 -0
- package/bin/rstest.js +1 -1
- package/dist/25.js +91 -0
- package/dist/285.js +4 -3
- package/dist/355.js +1 -1
- package/dist/359.js +10 -6
- package/dist/64.js +1 -1
- package/dist/668.js +1439 -0
- package/dist/668.js.LICENSE.txt +1 -0
- package/dist/813.js +1 -1
- package/dist/854.js +6 -3
- package/dist/867.js +1 -1
- package/dist/920.js +170 -57
- package/dist/{cli.js → index.js} +681 -606
- package/dist/worker.js +2 -2
- package/dist-types/{public.d.ts → index.d.ts} +13 -5
- package/dist-types/worker.d.ts +4 -0
- package/package.json +7 -10
- package/dist/node.js +0 -2
- package/dist/public.js +0 -6
- package/dist-types/cli.d.ts +0 -3
- package/dist-types/node.d.ts +0 -450
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
package/dist/813.js
CHANGED
|
@@ -134,7 +134,7 @@ export const __webpack_modules__ = {
|
|
|
134
134
|
var constants = __webpack_require__("./src/utils/constants.ts");
|
|
135
135
|
var helper = __webpack_require__("./src/utils/helper.ts");
|
|
136
136
|
__webpack_require__("./src/utils/logger.ts");
|
|
137
|
-
__webpack_require__("fs");
|
|
137
|
+
__webpack_require__("node:fs");
|
|
138
138
|
__webpack_require__("node:fs/promises");
|
|
139
139
|
__webpack_require__("node:module");
|
|
140
140
|
__webpack_require__("pathe");
|
package/dist/854.js
CHANGED
|
@@ -141,7 +141,7 @@ export const __webpack_modules__ = {
|
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
const pluginEntryWatch = ({ isWatch, globTestSourceEntries, setupFiles })=>({
|
|
144
|
+
const pluginEntryWatch = ({ isWatch, globTestSourceEntries, setupFiles, configFilePath })=>({
|
|
145
145
|
name: 'rstest:entry-watch',
|
|
146
146
|
setup: (api)=>{
|
|
147
147
|
api.modifyRspackConfig(async (config)=>{
|
|
@@ -157,7 +157,8 @@ export const __webpack_modules__ = {
|
|
|
157
157
|
config.watchOptions ??= {};
|
|
158
158
|
config.watchOptions.ignored = (0, utils.XQ)(config.watchOptions.ignored || []);
|
|
159
159
|
if (0 === config.watchOptions.ignored.length) config.watchOptions.ignored.push('**/.git', '**/node_modules');
|
|
160
|
-
config.watchOptions.ignored.push(utils.f1);
|
|
160
|
+
config.watchOptions.ignored.push(utils.f1, '**/*.snap');
|
|
161
|
+
if (configFilePath) config.watchOptions.ignored.push(configFilePath);
|
|
161
162
|
} else {
|
|
162
163
|
config.watch = false;
|
|
163
164
|
config.watchOptions ??= {};
|
|
@@ -475,6 +476,7 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
475
476
|
pluginEntryWatch({
|
|
476
477
|
globTestSourceEntries,
|
|
477
478
|
setupFiles,
|
|
479
|
+
configFilePath: context.configFilePath,
|
|
478
480
|
isWatch: 'watch' === command
|
|
479
481
|
}),
|
|
480
482
|
pluginExternal(testEnvironment),
|
|
@@ -754,7 +756,6 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
754
756
|
...process.env
|
|
755
757
|
}
|
|
756
758
|
});
|
|
757
|
-
const runtimeConfig = getRuntimeConfig(context);
|
|
758
759
|
const rpcMethods = {
|
|
759
760
|
onTestCaseResult: async (result)=>{
|
|
760
761
|
await Promise.all(reporters.map((reporter)=>reporter.onTestCaseResult?.(result)));
|
|
@@ -773,6 +774,7 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
773
774
|
runTests: async ({ entries, assetFiles, setupEntries, sourceMaps, updateSnapshot })=>{
|
|
774
775
|
const setupAssets = setupEntries.flatMap((entry)=>entry.files || []);
|
|
775
776
|
const entryLength = Object.keys(entries).length;
|
|
777
|
+
const runtimeConfig = getRuntimeConfig(context);
|
|
776
778
|
const results = await Promise.all(entries.map((entryInfo)=>{
|
|
777
779
|
const { assetFiles: neededFiles, sourceMaps: neededSourceMaps } = filterAssetsByEntry(entryInfo, assetFiles, setupAssets, sourceMaps, entryLength);
|
|
778
780
|
return pool.runTest({
|
|
@@ -812,6 +814,7 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
812
814
|
collectTests: async ({ entries, assetFiles, setupEntries, sourceMaps, updateSnapshot })=>{
|
|
813
815
|
const setupAssets = setupEntries.flatMap((entry)=>entry.files || []);
|
|
814
816
|
const entryLength = Object.keys(entries).length;
|
|
817
|
+
const runtimeConfig = getRuntimeConfig(context);
|
|
815
818
|
return Promise.all(entries.map((entryInfo)=>{
|
|
816
819
|
const { assetFiles: neededFiles, sourceMaps: neededSourceMaps } = filterAssetsByEntry(entryInfo, assetFiles, setupAssets, sourceMaps, entryLength);
|
|
817
820
|
return pool.collectTests({
|
package/dist/867.js
CHANGED
|
@@ -1757,7 +1757,7 @@ export const __webpack_modules__ = {
|
|
|
1757
1757
|
var constants = __webpack_require__("./src/utils/constants.ts");
|
|
1758
1758
|
var helper = __webpack_require__("./src/utils/helper.ts");
|
|
1759
1759
|
__webpack_require__("./src/utils/logger.ts");
|
|
1760
|
-
__webpack_require__("fs");
|
|
1760
|
+
__webpack_require__("node:fs");
|
|
1761
1761
|
__webpack_require__("node:fs/promises");
|
|
1762
1762
|
__webpack_require__("node:module");
|
|
1763
1763
|
__webpack_require__("pathe");
|
package/dist/920.js
CHANGED
|
@@ -11,15 +11,60 @@ export const __webpack_modules__ = {
|
|
|
11
11
|
var src_pool = __webpack_require__("./src/pool/index.ts");
|
|
12
12
|
var utils = __webpack_require__("./src/utils/index.ts");
|
|
13
13
|
const isCliShortcutsEnabled = ()=>(0, utils._l)('stdin');
|
|
14
|
-
async function setupCliShortcuts({ closeServer, runAll, updateSnapshot, runFailedTests }) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
async function setupCliShortcuts({ closeServer, runAll, updateSnapshot, runFailedTests, runWithTestNamePattern, runWithFileFilters }) {
|
|
15
|
+
const { createInterface, emitKeypressEvents } = await import("node:readline");
|
|
16
|
+
const rl = createInterface({
|
|
17
|
+
input: process.stdin,
|
|
18
|
+
output: process.stdout
|
|
19
|
+
});
|
|
20
|
+
emitKeypressEvents(process.stdin);
|
|
21
|
+
process.stdin.setRawMode(true);
|
|
22
|
+
process.stdin.resume();
|
|
23
|
+
process.stdin.setEncoding('utf8');
|
|
24
|
+
let isPrompting = false;
|
|
25
|
+
const clearCurrentInputLine = ()=>{
|
|
26
|
+
try {
|
|
27
|
+
process.stdout.write('\r\x1b[2K');
|
|
28
|
+
} catch {}
|
|
29
|
+
};
|
|
30
|
+
const promptInput = async (promptText, onComplete)=>{
|
|
31
|
+
if (isPrompting) return;
|
|
32
|
+
isPrompting = true;
|
|
33
|
+
let buffer = '';
|
|
34
|
+
const render = ()=>{
|
|
35
|
+
process.stdout.write(`\r\x1b[2K${promptText}${buffer}`);
|
|
36
|
+
};
|
|
37
|
+
render();
|
|
38
|
+
const onPromptKey = async (str, key)=>{
|
|
39
|
+
if (!isPrompting) return;
|
|
40
|
+
if (key.ctrl && 'c' === key.name) process.exit(0);
|
|
41
|
+
if ('return' === key.name || 'enter' === key.name) {
|
|
42
|
+
process.stdin.off('keypress', onPromptKey);
|
|
43
|
+
process.stdout.write('\n');
|
|
44
|
+
const value = '' === buffer.trim() ? void 0 : buffer.trim();
|
|
45
|
+
isPrompting = false;
|
|
46
|
+
await onComplete(value);
|
|
47
|
+
return;
|
|
21
48
|
}
|
|
22
|
-
|
|
49
|
+
if ('escape' === key.name) {
|
|
50
|
+
clearCurrentInputLine();
|
|
51
|
+
process.stdin.off('keypress', onPromptKey);
|
|
52
|
+
isPrompting = false;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if ('backspace' === key.name) {
|
|
56
|
+
buffer = buffer.slice(0, -1);
|
|
57
|
+
render();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if ('string' == typeof str && 1 === str.length) {
|
|
61
|
+
buffer += str;
|
|
62
|
+
render();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
process.stdin.on('keypress', onPromptKey);
|
|
66
|
+
};
|
|
67
|
+
const shortcuts = [
|
|
23
68
|
{
|
|
24
69
|
key: 'f',
|
|
25
70
|
description: `${utils.$_.bold('f')} ${utils.$_.dim('rerun failed tests')}`,
|
|
@@ -41,6 +86,34 @@ export const __webpack_modules__ = {
|
|
|
41
86
|
await updateSnapshot();
|
|
42
87
|
}
|
|
43
88
|
},
|
|
89
|
+
{
|
|
90
|
+
key: 't',
|
|
91
|
+
description: `${utils.$_.bold('t')} ${utils.$_.dim('filter by a test name regex pattern')}`,
|
|
92
|
+
action: async ()=>{
|
|
93
|
+
clearCurrentInputLine();
|
|
94
|
+
await promptInput('Enter test name pattern (empty to clear): ', async (pattern)=>{
|
|
95
|
+
await runWithTestNamePattern(pattern);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
key: 'p',
|
|
101
|
+
description: `${utils.$_.bold('p')} ${utils.$_.dim('filter by a filename regex pattern')}`,
|
|
102
|
+
action: async ()=>{
|
|
103
|
+
clearCurrentInputLine();
|
|
104
|
+
await promptInput('Enter file name pattern (empty to clear): ', async (input)=>{
|
|
105
|
+
const filters = input ? input.split(/\s+/).filter(Boolean) : void 0;
|
|
106
|
+
await runWithFileFilters(filters);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
key: 'c',
|
|
112
|
+
description: `${utils.$_.bold('c')} ${utils.$_.dim('clear console')}`,
|
|
113
|
+
action: ()=>{
|
|
114
|
+
console.clear();
|
|
115
|
+
}
|
|
116
|
+
},
|
|
44
117
|
{
|
|
45
118
|
key: 'q',
|
|
46
119
|
description: `${utils.$_.bold('q')} ${utils.$_.dim('quit process')}`,
|
|
@@ -53,18 +126,16 @@ export const __webpack_modules__ = {
|
|
|
53
126
|
}
|
|
54
127
|
}
|
|
55
128
|
];
|
|
56
|
-
const { createInterface } = await import("node:readline");
|
|
57
|
-
const rl = createInterface({
|
|
58
|
-
input: process.stdin,
|
|
59
|
-
output: process.stdout
|
|
60
|
-
});
|
|
61
|
-
process.stdin.setRawMode(true);
|
|
62
|
-
process.stdin.resume();
|
|
63
|
-
process.stdin.setEncoding('utf8');
|
|
64
129
|
const handleKeypress = (str, key)=>{
|
|
130
|
+
if (isPrompting) return;
|
|
65
131
|
if (key.ctrl && 'c' === key.name) process.exit(0);
|
|
66
|
-
for (const shortcut of shortcuts)if (str === shortcut.key)
|
|
132
|
+
for (const shortcut of shortcuts)if (str === shortcut.key) {
|
|
133
|
+
clearCurrentInputLine();
|
|
134
|
+
shortcut.action();
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
67
137
|
if ('h' === str) {
|
|
138
|
+
clearCurrentInputLine();
|
|
68
139
|
let message = `\n ${utils.$_.bold(utils.$_.blue('Shortcuts:'))}\n`;
|
|
69
140
|
for (const shortcut of shortcuts)message += ` ${shortcut.description}\n`;
|
|
70
141
|
utils.kg.log(message);
|
|
@@ -72,13 +143,16 @@ export const __webpack_modules__ = {
|
|
|
72
143
|
};
|
|
73
144
|
process.stdin.on('keypress', handleKeypress);
|
|
74
145
|
return ()=>{
|
|
75
|
-
|
|
76
|
-
|
|
146
|
+
try {
|
|
147
|
+
process.stdin.setRawMode(false);
|
|
148
|
+
process.stdin.pause();
|
|
149
|
+
} catch {}
|
|
150
|
+
process.stdin.off('keypress', handleKeypress);
|
|
77
151
|
rl.close();
|
|
78
152
|
};
|
|
79
153
|
}
|
|
80
154
|
var rsbuild = __webpack_require__("./src/core/rsbuild.ts");
|
|
81
|
-
async function runTests(context
|
|
155
|
+
async function runTests(context) {
|
|
82
156
|
const { normalizedConfig: { include, exclude, root, name, setupFiles: setups, includeSource }, rootPath, reporters, snapshotManager, command } = context;
|
|
83
157
|
const entriesCache = new Map();
|
|
84
158
|
const globTestSourceEntries = async ()=>{
|
|
@@ -87,13 +161,16 @@ export const __webpack_modules__ = {
|
|
|
87
161
|
exclude,
|
|
88
162
|
includeSource,
|
|
89
163
|
root,
|
|
90
|
-
fileFilters
|
|
164
|
+
fileFilters: context.fileFilters || []
|
|
165
|
+
});
|
|
166
|
+
entriesCache.set(name, {
|
|
167
|
+
entries,
|
|
168
|
+
fileFilters: context.fileFilters
|
|
91
169
|
});
|
|
92
|
-
entriesCache.set(name, entries);
|
|
93
170
|
if (!Object.keys(entries).length) {
|
|
94
171
|
utils.kg.log(utils.$_.red('No test files found.'));
|
|
95
172
|
utils.kg.log('');
|
|
96
|
-
if (fileFilters
|
|
173
|
+
if (context.fileFilters?.length) utils.kg.log(utils.$_.gray('filter: '), context.fileFilters.join(utils.$_.gray(', ')));
|
|
97
174
|
utils.kg.log(utils.$_.gray('include:'), include.join(utils.$_.gray(', ')));
|
|
98
175
|
utils.kg.log(utils.$_.gray('exclude:'), exclude.join(utils.$_.gray(', ')));
|
|
99
176
|
utils.kg.log('');
|
|
@@ -106,14 +183,14 @@ export const __webpack_modules__ = {
|
|
|
106
183
|
name,
|
|
107
184
|
normalizedConfig: context.normalizedConfig,
|
|
108
185
|
globTestSourceEntries: 'watch' === command ? globTestSourceEntries : async ()=>{
|
|
109
|
-
if (entriesCache.has(name)) return entriesCache.get(name);
|
|
186
|
+
if (entriesCache.has(name)) return entriesCache.get(name).entries;
|
|
110
187
|
return globTestSourceEntries();
|
|
111
188
|
},
|
|
112
189
|
setupFiles,
|
|
113
190
|
rsbuildInstance,
|
|
114
191
|
rootPath
|
|
115
192
|
});
|
|
116
|
-
const recommendWorkerCount = 'watch' === command ? 1 / 0 : Array.from(entriesCache.values()).reduce((acc,
|
|
193
|
+
const recommendWorkerCount = 'watch' === command ? 1 / 0 : Array.from(entriesCache.values()).reduce((acc, entry)=>acc + Object.keys(entry.entries).length, 0);
|
|
117
194
|
const pool = await (0, src_pool.K)({
|
|
118
195
|
context,
|
|
119
196
|
recommendWorkerCount
|
|
@@ -126,6 +203,7 @@ export const __webpack_modules__ = {
|
|
|
126
203
|
});
|
|
127
204
|
const testStart = Date.now();
|
|
128
205
|
const { results, testResults } = await pool.runTests({
|
|
206
|
+
context,
|
|
129
207
|
entries,
|
|
130
208
|
sourceMaps,
|
|
131
209
|
setupEntries,
|
|
@@ -160,42 +238,77 @@ export const __webpack_modules__ = {
|
|
|
160
238
|
const clearLogs = ()=>{
|
|
161
239
|
console.clear();
|
|
162
240
|
};
|
|
241
|
+
const { onBeforeRestart } = await __webpack_require__.e("25").then(__webpack_require__.bind(__webpack_require__, "./src/core/restart.ts"));
|
|
242
|
+
onBeforeRestart(async ()=>{
|
|
243
|
+
await pool.close();
|
|
244
|
+
await closeServer();
|
|
245
|
+
});
|
|
163
246
|
rsbuildInstance.onDevCompileDone(async ({ isFirstCompile })=>{
|
|
164
247
|
if (!isFirstCompile) clearLogs();
|
|
165
248
|
snapshotManager.clear();
|
|
166
249
|
await run();
|
|
167
|
-
if (isFirstCompile && enableCliShortcuts)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
250
|
+
if (isFirstCompile && enableCliShortcuts) {
|
|
251
|
+
const closeCliShortcuts = await setupCliShortcuts({
|
|
252
|
+
closeServer: async ()=>{
|
|
253
|
+
await pool.close();
|
|
254
|
+
await closeServer();
|
|
255
|
+
},
|
|
256
|
+
runAll: async ()=>{
|
|
257
|
+
clearLogs();
|
|
258
|
+
snapshotManager.clear();
|
|
259
|
+
context.normalizedConfig.testNamePattern = void 0;
|
|
260
|
+
context.fileFilters = void 0;
|
|
261
|
+
await run();
|
|
262
|
+
afterTestsWatchRun();
|
|
263
|
+
},
|
|
264
|
+
runWithTestNamePattern: async (pattern)=>{
|
|
265
|
+
clearLogs();
|
|
266
|
+
context.normalizedConfig.testNamePattern = pattern;
|
|
267
|
+
if (pattern) utils.kg.log(`\n${utils.$_.dim('Applied testNamePattern:')} ${utils.$_.bold(pattern)}\n`);
|
|
268
|
+
else utils.kg.log(`\n${utils.$_.dim('Cleared testNamePattern filter')}\n`);
|
|
269
|
+
snapshotManager.clear();
|
|
270
|
+
await run();
|
|
271
|
+
afterTestsWatchRun();
|
|
272
|
+
},
|
|
273
|
+
runWithFileFilters: async (filters)=>{
|
|
274
|
+
clearLogs();
|
|
275
|
+
if (filters && filters.length > 0) utils.kg.log(`\n${utils.$_.dim('Applied file filters:')} ${utils.$_.bold(filters.join(', '))}\n`);
|
|
276
|
+
else utils.kg.log(`\n${utils.$_.dim('Cleared file filters')}\n`);
|
|
277
|
+
snapshotManager.clear();
|
|
278
|
+
context.fileFilters = filters;
|
|
279
|
+
const entries = await globTestSourceEntries();
|
|
280
|
+
if (!Object.keys(entries).length) return;
|
|
281
|
+
await run({
|
|
282
|
+
fileFilters: Object.values(entries)
|
|
283
|
+
});
|
|
284
|
+
afterTestsWatchRun();
|
|
285
|
+
},
|
|
286
|
+
runFailedTests: async ()=>{
|
|
287
|
+
const failedTests = testFileResult.filter((result)=>'fail' === result.status).map((r)=>r.testPath);
|
|
288
|
+
if (!failedTests.length) return void utils.kg.log(utils.$_.yellow('\nNo failed tests were found that needed to be rerun.'));
|
|
289
|
+
clearLogs();
|
|
290
|
+
snapshotManager.clear();
|
|
291
|
+
await run({
|
|
292
|
+
fileFilters: failedTests
|
|
293
|
+
});
|
|
294
|
+
afterTestsWatchRun();
|
|
295
|
+
},
|
|
296
|
+
updateSnapshot: async ()=>{
|
|
297
|
+
if (!snapshotManager.summary.unmatched) return void utils.kg.log(utils.$_.yellow('\nNo snapshots were found that needed to be updated.'));
|
|
298
|
+
const failedTests = testFileResult.filter((result)=>result.snapshotResult?.unmatched).map((r)=>r.testPath);
|
|
299
|
+
clearLogs();
|
|
300
|
+
const originalUpdateSnapshot = snapshotManager.options.updateSnapshot;
|
|
301
|
+
snapshotManager.clear();
|
|
302
|
+
snapshotManager.options.updateSnapshot = 'all';
|
|
303
|
+
await run({
|
|
304
|
+
fileFilters: failedTests
|
|
305
|
+
});
|
|
306
|
+
afterTestsWatchRun();
|
|
307
|
+
snapshotManager.options.updateSnapshot = originalUpdateSnapshot;
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
onBeforeRestart(closeCliShortcuts);
|
|
311
|
+
}
|
|
199
312
|
afterTestsWatchRun();
|
|
200
313
|
});
|
|
201
314
|
} else {
|