@rstest/core 0.1.2 → 0.2.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/LICENSE.md +26 -0
- package/bin/rstest.js +1 -1
- package/dist/208.js +1 -1
- package/dist/25.js +91 -0
- package/dist/285.js +12 -9
- package/dist/355.js +1 -1
- package/dist/359.js +13 -9
- 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 +72 -55
- package/dist/867.js +1 -1
- package/dist/920.js +321 -0
- package/dist/{cli.js → index.js} +688 -609
- package/dist/worker.js +11 -10
- package/dist-types/{public.d.ts → index.d.ts} +25 -17
- package/dist-types/worker.d.ts +6 -2
- package/package.json +10 -13
- package/dist/629.js +0 -84
- 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
|
@@ -9,7 +9,6 @@ export const __webpack_modules__ = {
|
|
|
9
9
|
r: ()=>createRsbuildServer,
|
|
10
10
|
z: ()=>prepareRsbuild
|
|
11
11
|
});
|
|
12
|
-
var external_node_fs_ = __webpack_require__("fs");
|
|
13
12
|
var core_ = __webpack_require__("@rsbuild/core");
|
|
14
13
|
var external_pathe_ = __webpack_require__("pathe");
|
|
15
14
|
var utils = __webpack_require__("./src/utils/index.ts");
|
|
@@ -142,7 +141,7 @@ export const __webpack_modules__ = {
|
|
|
142
141
|
});
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
|
-
const pluginEntryWatch = ({ isWatch, globTestSourceEntries, setupFiles })=>({
|
|
144
|
+
const pluginEntryWatch = ({ isWatch, globTestSourceEntries, setupFiles, configFilePath })=>({
|
|
146
145
|
name: 'rstest:entry-watch',
|
|
147
146
|
setup: (api)=>{
|
|
148
147
|
api.modifyRspackConfig(async (config)=>{
|
|
@@ -158,7 +157,8 @@ export const __webpack_modules__ = {
|
|
|
158
157
|
config.watchOptions ??= {};
|
|
159
158
|
config.watchOptions.ignored = (0, utils.XQ)(config.watchOptions.ignored || []);
|
|
160
159
|
if (0 === config.watchOptions.ignored.length) config.watchOptions.ignored.push('**/.git', '**/node_modules');
|
|
161
|
-
config.watchOptions.ignored.push(utils.f1);
|
|
160
|
+
config.watchOptions.ignored.push(utils.f1, '**/*.snap');
|
|
161
|
+
if (configFilePath) config.watchOptions.ignored.push(configFilePath);
|
|
162
162
|
} else {
|
|
163
163
|
config.watch = false;
|
|
164
164
|
config.watchOptions ??= {};
|
|
@@ -476,6 +476,7 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
476
476
|
pluginEntryWatch({
|
|
477
477
|
globTestSourceEntries,
|
|
478
478
|
setupFiles,
|
|
479
|
+
configFilePath: context.configFilePath,
|
|
479
480
|
isWatch: 'watch' === command
|
|
480
481
|
}),
|
|
481
482
|
pluginExternal(testEnvironment),
|
|
@@ -508,12 +509,15 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
508
509
|
rstest: normalizedConfig
|
|
509
510
|
}
|
|
510
511
|
});
|
|
511
|
-
|
|
512
|
-
const
|
|
512
|
+
if (!rspackCompiler) throw new Error('rspackCompiler was not initialized');
|
|
513
|
+
const outputFileSystem = isMultiCompiler(rspackCompiler) ? rspackCompiler.compilers[0].outputFileSystem : rspackCompiler.outputFileSystem;
|
|
514
|
+
if (!outputFileSystem) throw new Error(`Expect outputFileSystem to be defined, but got ${outputFileSystem}`);
|
|
515
|
+
const getRsbuildStats = async ({ fileFilters } = {})=>{
|
|
513
516
|
const stats = await devServer.environments[name].getStats();
|
|
514
517
|
const manifest = devServer.environments[name].context.manifest;
|
|
515
|
-
const { entrypoints, outputPath, assets, time: buildTime } = stats.toJson({
|
|
518
|
+
const { entrypoints, outputPath, assets, hash, time: buildTime } = stats.toJson({
|
|
516
519
|
all: false,
|
|
520
|
+
hash: true,
|
|
517
521
|
entrypoints: true,
|
|
518
522
|
outputPath: true,
|
|
519
523
|
assets: true,
|
|
@@ -548,11 +552,14 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
548
552
|
testPath: setupFiles[entry],
|
|
549
553
|
files: entryFiles[entry]
|
|
550
554
|
});
|
|
551
|
-
else if (sourceEntries[entry])
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
555
|
+
else if (sourceEntries[entry]) {
|
|
556
|
+
if (fileFilters?.length && !fileFilters.includes(sourceEntries[entry])) continue;
|
|
557
|
+
entries.push({
|
|
558
|
+
distPath,
|
|
559
|
+
testPath: sourceEntries[entry],
|
|
560
|
+
files: entryFiles[entry]
|
|
561
|
+
});
|
|
562
|
+
}
|
|
556
563
|
}
|
|
557
564
|
const inlineSourceMap = 'inline-source-map' === stats.compilation.options.devtool;
|
|
558
565
|
const sourceMaps = Object.fromEntries((await Promise.all(assets.map(async (asset)=>{
|
|
@@ -579,6 +586,7 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
579
586
|
];
|
|
580
587
|
}))).filter((asset)=>null !== asset[1]));
|
|
581
588
|
return {
|
|
589
|
+
hash,
|
|
582
590
|
entries,
|
|
583
591
|
setupEntries,
|
|
584
592
|
buildTime: buildTime,
|
|
@@ -590,11 +598,13 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
590
598
|
];
|
|
591
599
|
}))),
|
|
592
600
|
sourceMaps,
|
|
593
|
-
getSourcemap: (sourcePath)=>sourceMaps[sourcePath] || null
|
|
594
|
-
close: devServer.close
|
|
601
|
+
getSourcemap: (sourcePath)=>sourceMaps[sourcePath] || null
|
|
595
602
|
};
|
|
596
603
|
};
|
|
597
|
-
return
|
|
604
|
+
return {
|
|
605
|
+
closeServer: devServer.close,
|
|
606
|
+
getRsbuildStats
|
|
607
|
+
};
|
|
598
608
|
};
|
|
599
609
|
},
|
|
600
610
|
"./src/pool/index.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
@@ -689,12 +699,41 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
689
699
|
}
|
|
690
700
|
return parsed > 0 ? parsed : 1;
|
|
691
701
|
};
|
|
692
|
-
const
|
|
702
|
+
const getRuntimeConfig = (context)=>{
|
|
703
|
+
const { testNamePattern, testTimeout, passWithNoTests, retry, globals, clearMocks, resetMocks, restoreMocks, unstubEnvs, unstubGlobals, maxConcurrency, printConsoleTrace, disableConsoleIntercept, testEnvironment, hookTimeout, isolate } = context.normalizedConfig;
|
|
704
|
+
return {
|
|
705
|
+
testNamePattern,
|
|
706
|
+
testTimeout,
|
|
707
|
+
hookTimeout,
|
|
708
|
+
passWithNoTests,
|
|
709
|
+
retry,
|
|
710
|
+
globals,
|
|
711
|
+
clearMocks,
|
|
712
|
+
resetMocks,
|
|
713
|
+
restoreMocks,
|
|
714
|
+
unstubEnvs,
|
|
715
|
+
unstubGlobals,
|
|
716
|
+
maxConcurrency,
|
|
717
|
+
printConsoleTrace,
|
|
718
|
+
disableConsoleIntercept,
|
|
719
|
+
testEnvironment,
|
|
720
|
+
isolate
|
|
721
|
+
};
|
|
722
|
+
};
|
|
723
|
+
const filterAssetsByEntry = (entryInfo, assetFiles, setupAssets, sourceMaps, entryLength)=>{
|
|
724
|
+
const neededFiles = entryLength > 1 && entryInfo.files ? Object.fromEntries(Object.entries(assetFiles).filter(([key])=>entryInfo.files.includes(key) || setupAssets.includes(key))) : assetFiles;
|
|
725
|
+
const neededSourceMaps = entryLength > 1 ? Object.fromEntries(Object.entries(sourceMaps).filter(([key])=>neededFiles[key])) : sourceMaps;
|
|
726
|
+
return {
|
|
727
|
+
assetFiles: neededFiles,
|
|
728
|
+
sourceMaps: neededSourceMaps
|
|
729
|
+
};
|
|
730
|
+
};
|
|
731
|
+
const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
|
|
693
732
|
const execArgv = process.execArgv.filter((execArg)=>execArg.startsWith('--perf') || execArg.startsWith('--cpu-prof') || execArg.startsWith('--heap-prof') || execArg.startsWith('--diagnostic-dir'));
|
|
694
733
|
const numCpus = getNumCpus();
|
|
695
734
|
const { normalizedConfig: { pool: poolOptions, isolate }, reporters } = context;
|
|
696
735
|
const threadsCount = 'watch' === context.command ? Math.max(Math.floor(numCpus / 2), 1) : Math.max(numCpus - 1, 1);
|
|
697
|
-
const recommendCount = 'watch' === context.command ? threadsCount : Math.min(
|
|
736
|
+
const recommendCount = 'watch' === context.command ? threadsCount : Math.min(recommendWorkerCount, threadsCount);
|
|
698
737
|
const maxWorkers = poolOptions.maxWorkers ? parseWorkers(poolOptions.maxWorkers) : recommendCount;
|
|
699
738
|
const minWorkers = poolOptions.minWorkers ? parseWorkers(poolOptions.minWorkers) : maxWorkers < recommendCount ? maxWorkers : recommendCount;
|
|
700
739
|
if (maxWorkers < minWorkers) throw `Invalid pool configuration: maxWorkers(${maxWorkers}) cannot be less than minWorkers(${minWorkers}).`;
|
|
@@ -717,26 +756,6 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
717
756
|
...process.env
|
|
718
757
|
}
|
|
719
758
|
});
|
|
720
|
-
const { updateSnapshot } = context.snapshotManager.options;
|
|
721
|
-
const { testNamePattern, testTimeout, passWithNoTests, retry, globals, clearMocks, resetMocks, restoreMocks, unstubEnvs, unstubGlobals, maxConcurrency, printConsoleTrace, disableConsoleIntercept, testEnvironment, hookTimeout } = context.normalizedConfig;
|
|
722
|
-
const runtimeConfig = {
|
|
723
|
-
testNamePattern,
|
|
724
|
-
testTimeout,
|
|
725
|
-
hookTimeout,
|
|
726
|
-
passWithNoTests,
|
|
727
|
-
retry,
|
|
728
|
-
globals,
|
|
729
|
-
clearMocks,
|
|
730
|
-
resetMocks,
|
|
731
|
-
restoreMocks,
|
|
732
|
-
unstubEnvs,
|
|
733
|
-
unstubGlobals,
|
|
734
|
-
maxConcurrency,
|
|
735
|
-
printConsoleTrace,
|
|
736
|
-
disableConsoleIntercept,
|
|
737
|
-
testEnvironment,
|
|
738
|
-
isolate
|
|
739
|
-
};
|
|
740
759
|
const rpcMethods = {
|
|
741
760
|
onTestCaseResult: async (result)=>{
|
|
742
761
|
await Promise.all(reporters.map((reporter)=>reporter.onTestCaseResult?.(result)));
|
|
@@ -751,30 +770,23 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
751
770
|
await Promise.all(reporters.map((reporter)=>reporter.onTestFileResult?.(test)));
|
|
752
771
|
}
|
|
753
772
|
};
|
|
754
|
-
const setupAssets = setupEntries.flatMap((entry)=>entry.files);
|
|
755
|
-
const entryLength = Object.keys(entries).length;
|
|
756
|
-
const filterAssetsByEntry = (entryInfo)=>{
|
|
757
|
-
const neededFiles = entryLength > 1 && entryInfo.files ? Object.fromEntries(Object.entries(assetFiles).filter(([key])=>entryInfo.files.includes(key) || setupAssets.includes(key))) : assetFiles;
|
|
758
|
-
const neededSourceMaps = entryLength > 1 ? Object.fromEntries(Object.entries(sourceMaps).filter(([key])=>neededFiles[key])) : sourceMaps;
|
|
759
|
-
return {
|
|
760
|
-
assetFiles: neededFiles,
|
|
761
|
-
sourceMaps: neededSourceMaps
|
|
762
|
-
};
|
|
763
|
-
};
|
|
764
773
|
return {
|
|
765
|
-
runTests: async ()=>{
|
|
774
|
+
runTests: async ({ entries, assetFiles, setupEntries, sourceMaps, updateSnapshot })=>{
|
|
775
|
+
const setupAssets = setupEntries.flatMap((entry)=>entry.files || []);
|
|
776
|
+
const entryLength = Object.keys(entries).length;
|
|
777
|
+
const runtimeConfig = getRuntimeConfig(context);
|
|
766
778
|
const results = await Promise.all(entries.map((entryInfo)=>{
|
|
767
|
-
const { assetFiles, sourceMaps } = filterAssetsByEntry(entryInfo);
|
|
779
|
+
const { assetFiles: neededFiles, sourceMaps: neededSourceMaps } = filterAssetsByEntry(entryInfo, assetFiles, setupAssets, sourceMaps, entryLength);
|
|
768
780
|
return pool.runTest({
|
|
769
781
|
options: {
|
|
770
782
|
entryInfo,
|
|
771
|
-
assetFiles,
|
|
783
|
+
assetFiles: neededFiles,
|
|
772
784
|
context: {
|
|
773
785
|
rootPath: context.rootPath,
|
|
774
786
|
runtimeConfig: (0, utils.v8)(runtimeConfig)
|
|
775
787
|
},
|
|
776
788
|
type: 'run',
|
|
777
|
-
sourceMaps,
|
|
789
|
+
sourceMaps: neededSourceMaps,
|
|
778
790
|
setupEntries,
|
|
779
791
|
updateSnapshot
|
|
780
792
|
},
|
|
@@ -799,18 +811,22 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
799
811
|
testResults
|
|
800
812
|
};
|
|
801
813
|
},
|
|
802
|
-
collectTests: async (
|
|
803
|
-
|
|
814
|
+
collectTests: async ({ entries, assetFiles, setupEntries, sourceMaps, updateSnapshot })=>{
|
|
815
|
+
const setupAssets = setupEntries.flatMap((entry)=>entry.files || []);
|
|
816
|
+
const entryLength = Object.keys(entries).length;
|
|
817
|
+
const runtimeConfig = getRuntimeConfig(context);
|
|
818
|
+
return Promise.all(entries.map((entryInfo)=>{
|
|
819
|
+
const { assetFiles: neededFiles, sourceMaps: neededSourceMaps } = filterAssetsByEntry(entryInfo, assetFiles, setupAssets, sourceMaps, entryLength);
|
|
804
820
|
return pool.collectTests({
|
|
805
821
|
options: {
|
|
806
822
|
entryInfo,
|
|
807
|
-
assetFiles,
|
|
823
|
+
assetFiles: neededFiles,
|
|
808
824
|
context: {
|
|
809
825
|
rootPath: context.rootPath,
|
|
810
826
|
runtimeConfig: (0, utils.v8)(runtimeConfig)
|
|
811
827
|
},
|
|
812
828
|
type: 'collect',
|
|
813
|
-
sourceMaps,
|
|
829
|
+
sourceMaps: neededSourceMaps,
|
|
814
830
|
setupEntries,
|
|
815
831
|
updateSnapshot
|
|
816
832
|
},
|
|
@@ -825,7 +841,8 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
825
841
|
]
|
|
826
842
|
};
|
|
827
843
|
});
|
|
828
|
-
}))
|
|
844
|
+
}));
|
|
845
|
+
},
|
|
829
846
|
close: ()=>pool.close()
|
|
830
847
|
};
|
|
831
848
|
};
|
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
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import 'module';
|
|
2
|
+
/*#__PURE__*/ import.meta.url;
|
|
3
|
+
export const __webpack_ids__ = [
|
|
4
|
+
"920"
|
|
5
|
+
];
|
|
6
|
+
export const __webpack_modules__ = {
|
|
7
|
+
"./src/core/runTests.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
8
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
9
|
+
runTests: ()=>runTests
|
|
10
|
+
});
|
|
11
|
+
var src_pool = __webpack_require__("./src/pool/index.ts");
|
|
12
|
+
var utils = __webpack_require__("./src/utils/index.ts");
|
|
13
|
+
const isCliShortcutsEnabled = ()=>(0, utils._l)('stdin');
|
|
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;
|
|
48
|
+
}
|
|
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 = [
|
|
68
|
+
{
|
|
69
|
+
key: 'f',
|
|
70
|
+
description: `${utils.$_.bold('f')} ${utils.$_.dim('rerun failed tests')}`,
|
|
71
|
+
action: async ()=>{
|
|
72
|
+
await runFailedTests();
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
key: 'a',
|
|
77
|
+
description: `${utils.$_.bold('a')} ${utils.$_.dim('rerun all tests')}`,
|
|
78
|
+
action: async ()=>{
|
|
79
|
+
await runAll();
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
key: 'u',
|
|
84
|
+
description: `${utils.$_.bold('u')} ${utils.$_.dim('update snapshot')}`,
|
|
85
|
+
action: async ()=>{
|
|
86
|
+
await updateSnapshot();
|
|
87
|
+
}
|
|
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
|
+
},
|
|
117
|
+
{
|
|
118
|
+
key: 'q',
|
|
119
|
+
description: `${utils.$_.bold('q')} ${utils.$_.dim('quit process')}`,
|
|
120
|
+
action: async ()=>{
|
|
121
|
+
try {
|
|
122
|
+
await closeServer();
|
|
123
|
+
} finally{
|
|
124
|
+
process.exit(0);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
];
|
|
129
|
+
const handleKeypress = (str, key)=>{
|
|
130
|
+
if (isPrompting) return;
|
|
131
|
+
if (key.ctrl && 'c' === key.name) process.exit(0);
|
|
132
|
+
for (const shortcut of shortcuts)if (str === shortcut.key) {
|
|
133
|
+
clearCurrentInputLine();
|
|
134
|
+
shortcut.action();
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if ('h' === str) {
|
|
138
|
+
clearCurrentInputLine();
|
|
139
|
+
let message = `\n ${utils.$_.bold(utils.$_.blue('Shortcuts:'))}\n`;
|
|
140
|
+
for (const shortcut of shortcuts)message += ` ${shortcut.description}\n`;
|
|
141
|
+
utils.kg.log(message);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
process.stdin.on('keypress', handleKeypress);
|
|
145
|
+
return ()=>{
|
|
146
|
+
try {
|
|
147
|
+
process.stdin.setRawMode(false);
|
|
148
|
+
process.stdin.pause();
|
|
149
|
+
} catch {}
|
|
150
|
+
process.stdin.off('keypress', handleKeypress);
|
|
151
|
+
rl.close();
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
var rsbuild = __webpack_require__("./src/core/rsbuild.ts");
|
|
155
|
+
async function runTests(context) {
|
|
156
|
+
const { normalizedConfig: { include, exclude, root, name, setupFiles: setups, includeSource }, rootPath, reporters, snapshotManager, command } = context;
|
|
157
|
+
const entriesCache = new Map();
|
|
158
|
+
const globTestSourceEntries = async ()=>{
|
|
159
|
+
const entries = await (0, utils.GL)({
|
|
160
|
+
include,
|
|
161
|
+
exclude,
|
|
162
|
+
includeSource,
|
|
163
|
+
root,
|
|
164
|
+
fileFilters: context.fileFilters || []
|
|
165
|
+
});
|
|
166
|
+
entriesCache.set(name, {
|
|
167
|
+
entries,
|
|
168
|
+
fileFilters: context.fileFilters
|
|
169
|
+
});
|
|
170
|
+
if (!Object.keys(entries).length) {
|
|
171
|
+
utils.kg.log(utils.$_.red('No test files found.'));
|
|
172
|
+
utils.kg.log('');
|
|
173
|
+
if (context.fileFilters?.length) utils.kg.log(utils.$_.gray('filter: '), context.fileFilters.join(utils.$_.gray(', ')));
|
|
174
|
+
utils.kg.log(utils.$_.gray('include:'), include.join(utils.$_.gray(', ')));
|
|
175
|
+
utils.kg.log(utils.$_.gray('exclude:'), exclude.join(utils.$_.gray(', ')));
|
|
176
|
+
utils.kg.log('');
|
|
177
|
+
}
|
|
178
|
+
return entries;
|
|
179
|
+
};
|
|
180
|
+
const setupFiles = (0, utils.aA)(setups, rootPath);
|
|
181
|
+
const rsbuildInstance = await (0, rsbuild.z)(context, globTestSourceEntries, setupFiles);
|
|
182
|
+
const { getRsbuildStats, closeServer } = await (0, rsbuild.r)({
|
|
183
|
+
name,
|
|
184
|
+
normalizedConfig: context.normalizedConfig,
|
|
185
|
+
globTestSourceEntries: 'watch' === command ? globTestSourceEntries : async ()=>{
|
|
186
|
+
if (entriesCache.has(name)) return entriesCache.get(name).entries;
|
|
187
|
+
return globTestSourceEntries();
|
|
188
|
+
},
|
|
189
|
+
setupFiles,
|
|
190
|
+
rsbuildInstance,
|
|
191
|
+
rootPath
|
|
192
|
+
});
|
|
193
|
+
const recommendWorkerCount = 'watch' === command ? 1 / 0 : Array.from(entriesCache.values()).reduce((acc, entries)=>acc + Object.keys(entries).length, 0);
|
|
194
|
+
const pool = await (0, src_pool.K)({
|
|
195
|
+
context,
|
|
196
|
+
recommendWorkerCount
|
|
197
|
+
});
|
|
198
|
+
let testFileResult = [];
|
|
199
|
+
let buildHash;
|
|
200
|
+
const run = async ({ fileFilters } = {})=>{
|
|
201
|
+
const { entries, setupEntries, assetFiles, sourceMaps, getSourcemap, buildTime, hash } = await getRsbuildStats({
|
|
202
|
+
fileFilters
|
|
203
|
+
});
|
|
204
|
+
const testStart = Date.now();
|
|
205
|
+
const { results, testResults } = await pool.runTests({
|
|
206
|
+
context,
|
|
207
|
+
entries,
|
|
208
|
+
sourceMaps,
|
|
209
|
+
setupEntries,
|
|
210
|
+
assetFiles,
|
|
211
|
+
updateSnapshot: snapshotManager.options.updateSnapshot
|
|
212
|
+
});
|
|
213
|
+
const actualBuildTime = buildHash === hash ? 0 : buildTime;
|
|
214
|
+
const testTime = Date.now() - testStart;
|
|
215
|
+
const duration = {
|
|
216
|
+
totalTime: testTime + actualBuildTime,
|
|
217
|
+
buildTime: actualBuildTime,
|
|
218
|
+
testTime
|
|
219
|
+
};
|
|
220
|
+
buildHash = hash;
|
|
221
|
+
testFileResult = results;
|
|
222
|
+
if (results.some((r)=>'fail' === r.status)) process.exitCode = 1;
|
|
223
|
+
for (const reporter of reporters)await reporter.onTestRunEnd?.({
|
|
224
|
+
results,
|
|
225
|
+
testResults,
|
|
226
|
+
snapshotSummary: snapshotManager.summary,
|
|
227
|
+
duration,
|
|
228
|
+
getSourcemap
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
if ('watch' === command) {
|
|
232
|
+
const enableCliShortcuts = isCliShortcutsEnabled();
|
|
233
|
+
const afterTestsWatchRun = ()=>{
|
|
234
|
+
utils.kg.log(utils.$_.green(' Waiting for file changes...'));
|
|
235
|
+
if (enableCliShortcuts) if (snapshotManager.summary.unmatched) utils.kg.log(` ${utils.$_.dim('press')} ${utils.$_.yellow(utils.$_.bold('u'))} ${utils.$_.dim('to update snapshot')}${utils.$_.dim(', press')} ${utils.$_.bold('h')} ${utils.$_.dim('to show help')}\n`);
|
|
236
|
+
else utils.kg.log(` ${utils.$_.dim('press')} ${utils.$_.bold('h')} ${utils.$_.dim('to show help')}${utils.$_.dim(', press')} ${utils.$_.bold('q')} ${utils.$_.dim('to quit')}\n`);
|
|
237
|
+
};
|
|
238
|
+
const clearLogs = ()=>{
|
|
239
|
+
console.clear();
|
|
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
|
+
});
|
|
246
|
+
rsbuildInstance.onDevCompileDone(async ({ isFirstCompile })=>{
|
|
247
|
+
if (!isFirstCompile) clearLogs();
|
|
248
|
+
snapshotManager.clear();
|
|
249
|
+
await run();
|
|
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
|
+
}
|
|
312
|
+
afterTestsWatchRun();
|
|
313
|
+
});
|
|
314
|
+
} else {
|
|
315
|
+
await run();
|
|
316
|
+
await pool.close();
|
|
317
|
+
await closeServer();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
};
|