@rstest/core 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +270 -12
- package/dist/0~33.js +12 -6
- package/dist/0~655.js +3 -3
- package/dist/0~816.js +105 -52
- package/dist/0~85.js +0 -4
- package/dist/0~971.js +12 -6
- package/dist/index.js +1863 -32
- package/dist/worker.js +1786 -68
- package/dist-types/index.d.ts +80 -5
- package/dist-types/worker.d.ts +21 -8
- package/package.json +6 -3
- package/dist/0~223.js +0 -158
- package/dist/0~876.js +0 -771
- package/dist/0~908.js +0 -920
- package/dist/0~969.js +0 -1738
package/dist/0~816.js
CHANGED
|
@@ -18,6 +18,7 @@ export const __webpack_modules__ = {
|
|
|
18
18
|
var core_ = __webpack_require__("@rsbuild/core");
|
|
19
19
|
var dist = __webpack_require__("../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.mjs");
|
|
20
20
|
var utils = __webpack_require__("./src/utils/index.ts");
|
|
21
|
+
var memory = __webpack_require__("./src/utils/memory.ts");
|
|
21
22
|
const RUNTIME_CHUNK_NAME = 'runtime';
|
|
22
23
|
const pluginBasic = (context)=>({
|
|
23
24
|
name: 'rstest:basic',
|
|
@@ -442,15 +443,14 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
442
443
|
});
|
|
443
444
|
}
|
|
444
445
|
});
|
|
445
|
-
function
|
|
446
|
+
function parseInlineSourceMapStr(code) {
|
|
446
447
|
const inlineSourceMapRegex = /\/\/# sourceMappingURL=data:application\/json(?:;charset=utf-8)?;base64,(.+)\s*$/m;
|
|
447
448
|
const match = code.match(inlineSourceMapRegex);
|
|
448
449
|
if (!match || !match[1]) return null;
|
|
449
450
|
try {
|
|
450
451
|
const base64Data = match[1];
|
|
451
452
|
const decodedStr = Buffer.from(base64Data, 'base64').toString('utf-8');
|
|
452
|
-
|
|
453
|
-
return sourceMap;
|
|
453
|
+
return decodedStr;
|
|
454
454
|
} catch (_error) {
|
|
455
455
|
return null;
|
|
456
456
|
}
|
|
@@ -562,6 +562,13 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
562
562
|
deletedEntries
|
|
563
563
|
};
|
|
564
564
|
};
|
|
565
|
+
class AssetsMemorySafeMap extends Map {
|
|
566
|
+
set(key, value) {
|
|
567
|
+
if (this.has(key)) return this;
|
|
568
|
+
if (!(0, memory.i)()) this.clear();
|
|
569
|
+
return super.set(key, value);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
565
572
|
const createRsbuildServer = async ({ globTestSourceEntries, setupFiles, rsbuildInstance, inspectedConfig })=>{
|
|
566
573
|
let rspackCompiler;
|
|
567
574
|
const rstestCompilerPlugin = {
|
|
@@ -605,8 +612,9 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
605
612
|
};
|
|
606
613
|
const getRsbuildStats = async ({ environmentName, fileFilters })=>{
|
|
607
614
|
const stats = await devServer.environments[environmentName].getStats();
|
|
615
|
+
const enableAssetsCache = (0, memory.i)();
|
|
608
616
|
const manifest = devServer.environments[environmentName].context.manifest;
|
|
609
|
-
const { entrypoints, outputPath, assets, hash,
|
|
617
|
+
const { entrypoints, outputPath, assets, hash, chunks } = stats.toJson({
|
|
610
618
|
all: false,
|
|
611
619
|
hash: true,
|
|
612
620
|
entrypoints: true,
|
|
@@ -641,47 +649,72 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
641
649
|
}
|
|
642
650
|
}
|
|
643
651
|
const inlineSourceMap = 'inline-source-map' === stats.compilation.options.devtool;
|
|
644
|
-
const
|
|
652
|
+
const sourceMapPaths = Object.fromEntries(assets.map((asset)=>{
|
|
645
653
|
const assetFilePath = dist.Ay.join(outputPath, asset.name);
|
|
646
|
-
if (inlineSourceMap)
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
parseInlineSourceMap(content)
|
|
651
|
-
];
|
|
652
|
-
}
|
|
654
|
+
if (inlineSourceMap) return [
|
|
655
|
+
assetFilePath,
|
|
656
|
+
assetFilePath
|
|
657
|
+
];
|
|
653
658
|
const sourceMapPath = asset?.info.related?.sourceMap?.[0];
|
|
654
659
|
if (sourceMapPath) {
|
|
655
660
|
const filePath = dist.Ay.join(outputPath, sourceMapPath);
|
|
656
|
-
const sourceMap = await readFile(filePath);
|
|
657
661
|
return [
|
|
658
662
|
assetFilePath,
|
|
659
|
-
|
|
663
|
+
filePath
|
|
660
664
|
];
|
|
661
665
|
}
|
|
662
666
|
return [
|
|
663
667
|
assetFilePath,
|
|
664
668
|
null
|
|
665
669
|
];
|
|
666
|
-
}))
|
|
670
|
+
}));
|
|
667
671
|
buildData[environmentName] ??= {};
|
|
668
672
|
const { affectedEntries, deletedEntries } = calcEntriesToRerun(entries, chunks, buildData[environmentName], `${environmentName}-${RUNTIME_CHUNK_NAME}`);
|
|
673
|
+
const cachedAssetFiles = new AssetsMemorySafeMap();
|
|
674
|
+
const cachedSourceMaps = new AssetsMemorySafeMap();
|
|
675
|
+
const readFileWithCache = async (name)=>{
|
|
676
|
+
if (enableAssetsCache && cachedAssetFiles.has(name)) return cachedAssetFiles.get(name);
|
|
677
|
+
const content = await readFile(name);
|
|
678
|
+
enableAssetsCache && cachedAssetFiles.set(name, content);
|
|
679
|
+
return content;
|
|
680
|
+
};
|
|
681
|
+
const getSourceMap = async (name)=>{
|
|
682
|
+
const sourceMapPath = sourceMapPaths[name];
|
|
683
|
+
if (!sourceMapPath) return null;
|
|
684
|
+
if (enableAssetsCache && cachedSourceMaps.has(name)) return cachedSourceMaps.get(name);
|
|
685
|
+
let content = null;
|
|
686
|
+
if (inlineSourceMap) {
|
|
687
|
+
const file = await readFile(sourceMapPath);
|
|
688
|
+
content = parseInlineSourceMapStr(file);
|
|
689
|
+
} else {
|
|
690
|
+
const sourceMap = await readFile(sourceMapPath);
|
|
691
|
+
content = sourceMap;
|
|
692
|
+
}
|
|
693
|
+
enableAssetsCache && content && cachedSourceMaps.set(name, content);
|
|
694
|
+
return content;
|
|
695
|
+
};
|
|
696
|
+
const assetNames = assets.map((asset)=>dist.Ay.join(outputPath, asset.name));
|
|
669
697
|
return {
|
|
670
698
|
affectedEntries,
|
|
671
699
|
deletedEntries,
|
|
672
700
|
hash,
|
|
673
701
|
entries,
|
|
674
702
|
setupEntries,
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
703
|
+
assetNames,
|
|
704
|
+
getAssetFiles: async (names)=>Object.fromEntries(await Promise.all(names.map(async (name)=>{
|
|
705
|
+
const content = await readFileWithCache(name);
|
|
706
|
+
return [
|
|
707
|
+
name,
|
|
708
|
+
content
|
|
709
|
+
];
|
|
710
|
+
}))),
|
|
711
|
+
getSourceMaps: async (names)=>Object.fromEntries(await Promise.all(names.map(async (name)=>{
|
|
712
|
+
const content = await getSourceMap(name);
|
|
713
|
+
return [
|
|
714
|
+
name,
|
|
715
|
+
content
|
|
716
|
+
];
|
|
717
|
+
})))
|
|
685
718
|
};
|
|
686
719
|
};
|
|
687
720
|
return {
|
|
@@ -696,6 +729,7 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
696
729
|
});
|
|
697
730
|
var external_node_os_ = __webpack_require__("node:os");
|
|
698
731
|
var utils = __webpack_require__("./src/utils/index.ts");
|
|
732
|
+
var memory = __webpack_require__("./src/utils/memory.ts");
|
|
699
733
|
var external_node_url_ = __webpack_require__("node:url");
|
|
700
734
|
const TYPE_REQUEST = "q";
|
|
701
735
|
const TYPE_RESPONSE = "s";
|
|
@@ -941,8 +975,9 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
941
975
|
return parsed > 0 ? parsed : 1;
|
|
942
976
|
};
|
|
943
977
|
const getRuntimeConfig = (context)=>{
|
|
944
|
-
const { testNamePattern, testTimeout, passWithNoTests, retry, globals, clearMocks, resetMocks, restoreMocks, unstubEnvs, unstubGlobals, maxConcurrency, printConsoleTrace, disableConsoleIntercept, testEnvironment, hookTimeout, isolate, coverage, snapshotFormat } = context.normalizedConfig;
|
|
978
|
+
const { testNamePattern, testTimeout, passWithNoTests, retry, globals, clearMocks, resetMocks, restoreMocks, unstubEnvs, unstubGlobals, maxConcurrency, printConsoleTrace, disableConsoleIntercept, testEnvironment, hookTimeout, isolate, coverage, snapshotFormat, env } = context.normalizedConfig;
|
|
945
979
|
return {
|
|
980
|
+
env,
|
|
946
981
|
testNamePattern,
|
|
947
982
|
testTimeout,
|
|
948
983
|
hookTimeout,
|
|
@@ -963,9 +998,13 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
963
998
|
snapshotFormat
|
|
964
999
|
};
|
|
965
1000
|
};
|
|
966
|
-
const filterAssetsByEntry = (entryInfo,
|
|
967
|
-
const
|
|
968
|
-
|
|
1001
|
+
const filterAssetsByEntry = async (entryInfo, getAssetFiles, getSourceMaps, setupAssets)=>{
|
|
1002
|
+
const assetNames = Array.from(new Set([
|
|
1003
|
+
...entryInfo.files,
|
|
1004
|
+
...setupAssets
|
|
1005
|
+
]));
|
|
1006
|
+
const neededFiles = await getAssetFiles(assetNames);
|
|
1007
|
+
const neededSourceMaps = await getSourceMaps(assetNames);
|
|
969
1008
|
return {
|
|
970
1009
|
assetFiles: neededFiles,
|
|
971
1010
|
sourceMaps: neededSourceMaps
|
|
@@ -1008,23 +1047,17 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
1008
1047
|
},
|
|
1009
1048
|
onTestFileStart: async (test)=>{
|
|
1010
1049
|
await Promise.all(reporters.map((reporter)=>reporter.onTestFileStart?.(test)));
|
|
1011
|
-
},
|
|
1012
|
-
onTestFileResult: async (test)=>{
|
|
1013
|
-
await Promise.all(reporters.map((reporter)=>reporter.onTestFileResult?.(test)));
|
|
1014
1050
|
}
|
|
1015
1051
|
};
|
|
1016
1052
|
return {
|
|
1017
|
-
runTests: async ({ entries,
|
|
1053
|
+
runTests: async ({ entries, getAssetFiles, getSourceMaps, setupEntries, project, updateSnapshot })=>{
|
|
1018
1054
|
const projectName = context.normalizedConfig.name;
|
|
1019
1055
|
const runtimeConfig = getRuntimeConfig(project);
|
|
1020
1056
|
const setupAssets = setupEntries.flatMap((entry)=>entry.files || []);
|
|
1021
|
-
const
|
|
1022
|
-
|
|
1023
|
-
const { assetFiles: neededFiles, sourceMaps: neededSourceMaps } = filterAssetsByEntry(entryInfo, assetFiles, setupAssets, sourceMaps, entryLength);
|
|
1024
|
-
return pool.runTest({
|
|
1057
|
+
const results = await Promise.all(entries.map(async (entryInfo)=>{
|
|
1058
|
+
const result = await pool.runTest({
|
|
1025
1059
|
options: {
|
|
1026
1060
|
entryInfo,
|
|
1027
|
-
assetFiles: neededFiles,
|
|
1028
1061
|
context: {
|
|
1029
1062
|
project: projectName,
|
|
1030
1063
|
rootPath: context.rootPath,
|
|
@@ -1032,11 +1065,14 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
1032
1065
|
runtimeConfig: (0, utils.Ok)(runtimeConfig)
|
|
1033
1066
|
},
|
|
1034
1067
|
type: 'run',
|
|
1035
|
-
sourceMaps: neededSourceMaps,
|
|
1036
1068
|
setupEntries,
|
|
1037
|
-
updateSnapshot
|
|
1069
|
+
updateSnapshot,
|
|
1070
|
+
assets: (0, memory.i)() ? await filterAssetsByEntry(entryInfo, getAssetFiles, getSourceMaps, setupAssets) : void 0
|
|
1038
1071
|
},
|
|
1039
|
-
rpcMethods
|
|
1072
|
+
rpcMethods: {
|
|
1073
|
+
...rpcMethods,
|
|
1074
|
+
getAssetsByEntry: async ()=>filterAssetsByEntry(entryInfo, getAssetFiles, getSourceMaps, setupAssets)
|
|
1075
|
+
}
|
|
1040
1076
|
}).catch((err)=>{
|
|
1041
1077
|
err.fullStack = true;
|
|
1042
1078
|
return {
|
|
@@ -1050,6 +1086,8 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
1050
1086
|
]
|
|
1051
1087
|
};
|
|
1052
1088
|
});
|
|
1089
|
+
reporters.map((reporter)=>reporter.onTestFileResult?.(result));
|
|
1090
|
+
return result;
|
|
1053
1091
|
}));
|
|
1054
1092
|
for (const result of results)if (result.snapshotResult) context.snapshotManager.add(result.snapshotResult);
|
|
1055
1093
|
const testResults = results.flatMap((r)=>r.results);
|
|
@@ -1059,17 +1097,13 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
1059
1097
|
project
|
|
1060
1098
|
};
|
|
1061
1099
|
},
|
|
1062
|
-
collectTests: async ({ entries,
|
|
1100
|
+
collectTests: async ({ entries, getAssetFiles, getSourceMaps, setupEntries, project, updateSnapshot })=>{
|
|
1063
1101
|
const runtimeConfig = getRuntimeConfig(project);
|
|
1064
1102
|
const projectName = project.normalizedConfig.name;
|
|
1065
1103
|
const setupAssets = setupEntries.flatMap((entry)=>entry.files || []);
|
|
1066
|
-
|
|
1067
|
-
return Promise.all(entries.map((entryInfo)=>{
|
|
1068
|
-
const { assetFiles: neededFiles, sourceMaps: neededSourceMaps } = filterAssetsByEntry(entryInfo, assetFiles, setupAssets, sourceMaps, entryLength);
|
|
1069
|
-
return pool.collectTests({
|
|
1104
|
+
return Promise.all(entries.map(async (entryInfo)=>pool.collectTests({
|
|
1070
1105
|
options: {
|
|
1071
1106
|
entryInfo,
|
|
1072
|
-
assetFiles: neededFiles,
|
|
1073
1107
|
context: {
|
|
1074
1108
|
project: projectName,
|
|
1075
1109
|
rootPath: context.rootPath,
|
|
@@ -1077,11 +1111,14 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
1077
1111
|
runtimeConfig: (0, utils.Ok)(runtimeConfig)
|
|
1078
1112
|
},
|
|
1079
1113
|
type: 'collect',
|
|
1080
|
-
sourceMaps: neededSourceMaps,
|
|
1081
1114
|
setupEntries,
|
|
1082
|
-
updateSnapshot
|
|
1115
|
+
updateSnapshot,
|
|
1116
|
+
assets: (0, memory.i)() ? await filterAssetsByEntry(entryInfo, getAssetFiles, getSourceMaps, setupAssets) : void 0
|
|
1083
1117
|
},
|
|
1084
|
-
rpcMethods
|
|
1118
|
+
rpcMethods: {
|
|
1119
|
+
...rpcMethods,
|
|
1120
|
+
getAssetsByEntry: async ()=>filterAssetsByEntry(entryInfo, getAssetFiles, getSourceMaps, setupAssets)
|
|
1121
|
+
}
|
|
1085
1122
|
}).catch((err)=>{
|
|
1086
1123
|
err.fullStack = true;
|
|
1087
1124
|
return {
|
|
@@ -1092,13 +1129,29 @@ global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
|
1092
1129
|
err
|
|
1093
1130
|
]
|
|
1094
1131
|
};
|
|
1095
|
-
});
|
|
1096
|
-
}));
|
|
1132
|
+
})));
|
|
1097
1133
|
},
|
|
1098
1134
|
close: ()=>pool.close()
|
|
1099
1135
|
};
|
|
1100
1136
|
};
|
|
1101
1137
|
},
|
|
1138
|
+
"./src/utils/memory.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
1139
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
1140
|
+
i: ()=>isMemorySufficient
|
|
1141
|
+
});
|
|
1142
|
+
var node_process__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:process");
|
|
1143
|
+
const DefaultMaxHeapSize = 1073741824;
|
|
1144
|
+
function isMemorySufficient(options) {
|
|
1145
|
+
const { memoryThreshold = 0.7, maxHeapSize = DefaultMaxHeapSize } = options || {};
|
|
1146
|
+
if (!node_process__WEBPACK_IMPORTED_MODULE_0__["default"]?.memoryUsage) return true;
|
|
1147
|
+
const memoryUsage = node_process__WEBPACK_IMPORTED_MODULE_0__["default"].memoryUsage();
|
|
1148
|
+
const heapUsed = memoryUsage.heapUsed;
|
|
1149
|
+
const heapTotal = memoryUsage.heapTotal;
|
|
1150
|
+
const memoryUsageRatio = heapUsed / heapTotal;
|
|
1151
|
+
const isMemorySufficient = memoryUsageRatio < memoryThreshold && heapUsed < maxHeapSize;
|
|
1152
|
+
return isMemorySufficient;
|
|
1153
|
+
}
|
|
1154
|
+
},
|
|
1102
1155
|
"node:url": function(module) {
|
|
1103
1156
|
module.exports = __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__;
|
|
1104
1157
|
}
|
package/dist/0~85.js
CHANGED
|
@@ -621,9 +621,6 @@ export const __webpack_modules__ = {
|
|
|
621
621
|
const results = [];
|
|
622
622
|
const errors = [];
|
|
623
623
|
let defaultStatus = 'pass';
|
|
624
|
-
hooks.onTestFileStart?.({
|
|
625
|
-
testPath
|
|
626
|
-
});
|
|
627
624
|
const snapshotClient = getSnapshotClient();
|
|
628
625
|
await snapshotClient.setup(testPath, snapshotOptions);
|
|
629
626
|
const runTestsCase = async (test, parentHooks)=>{
|
|
@@ -1395,7 +1392,6 @@ export const __webpack_modules__ = {
|
|
|
1395
1392
|
hooks,
|
|
1396
1393
|
api
|
|
1397
1394
|
});
|
|
1398
|
-
hooks.onTestFileResult?.(results);
|
|
1399
1395
|
return results;
|
|
1400
1396
|
},
|
|
1401
1397
|
collectTests: async ()=>{
|
package/dist/0~971.js
CHANGED
|
@@ -54,24 +54,24 @@ export const __webpack_modules__ = {
|
|
|
54
54
|
});
|
|
55
55
|
const updateSnapshot = context.snapshotManager.options.updateSnapshot;
|
|
56
56
|
const returns = await Promise.all(context.projects.map(async (project)=>{
|
|
57
|
-
const { entries, setupEntries,
|
|
57
|
+
const { entries, setupEntries, getSourceMaps, getAssetFiles, assetNames } = await getRsbuildStats({
|
|
58
58
|
environmentName: project.environmentName
|
|
59
59
|
});
|
|
60
60
|
const list = await pool.collectTests({
|
|
61
61
|
entries,
|
|
62
|
-
sourceMaps,
|
|
63
62
|
setupEntries,
|
|
64
|
-
|
|
63
|
+
getAssetFiles,
|
|
64
|
+
getSourceMaps,
|
|
65
65
|
project,
|
|
66
66
|
updateSnapshot
|
|
67
67
|
});
|
|
68
68
|
return {
|
|
69
69
|
list,
|
|
70
|
-
|
|
70
|
+
getSourceMaps,
|
|
71
|
+
assetNames
|
|
71
72
|
};
|
|
72
73
|
}));
|
|
73
74
|
const list = returns.flatMap((r)=>r.list);
|
|
74
|
-
const sourceMaps = Object.assign({}, ...returns.map((r)=>r.sourceMaps));
|
|
75
75
|
const tests = [];
|
|
76
76
|
const traverseTests = (test)=>{
|
|
77
77
|
if ([
|
|
@@ -98,7 +98,13 @@ export const __webpack_modules__ = {
|
|
|
98
98
|
const relativePath = (0, node_path__WEBPACK_IMPORTED_MODULE_1__.relative)(rootPath, file.testPath);
|
|
99
99
|
if (file.errors?.length) {
|
|
100
100
|
_utils__WEBPACK_IMPORTED_MODULE_3__.vF.log(`${_utils__WEBPACK_IMPORTED_MODULE_3__.yW.bgRed(' FAIL ')} ${relativePath}`);
|
|
101
|
-
for (const error of file.errors)await printError(error, (name)=>
|
|
101
|
+
for (const error of file.errors)await printError(error, async (name)=>{
|
|
102
|
+
const resource = returns.find((r)=>r.assetNames.includes(name));
|
|
103
|
+
const sourceMap = (await resource?.getSourceMaps([
|
|
104
|
+
name
|
|
105
|
+
]))?.[name];
|
|
106
|
+
return sourceMap ? JSON.parse(sourceMap) : null;
|
|
107
|
+
}, rootPath);
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
await closeServer();
|