@rstest/core 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{698.js → 12.js} +88 -33
- package/dist/223.js +155 -0
- package/dist/33.js +101 -59
- package/dist/85.js +84 -12
- package/dist/967.js +12 -8
- package/dist/971.js +58 -25
- package/dist/985.js +141 -70
- package/dist/index.js +52 -68
- package/dist/worker.js +9 -4
- package/dist-types/index.d.ts +60 -3
- package/dist-types/worker.d.ts +129 -4
- package/globals.d.ts +2 -0
- package/package.json +4 -4
package/dist/85.js
CHANGED
|
@@ -617,7 +617,7 @@ export const __webpack_modules__ = {
|
|
|
617
617
|
workerState;
|
|
618
618
|
async runTests({ tests, testPath, state, hooks, api }) {
|
|
619
619
|
this.workerState = state;
|
|
620
|
-
const { runtimeConfig: { passWithNoTests, retry, maxConcurrency }, snapshotOptions } = state;
|
|
620
|
+
const { runtimeConfig: { passWithNoTests, retry, maxConcurrency }, project, snapshotOptions } = state;
|
|
621
621
|
const results = [];
|
|
622
622
|
const errors = [];
|
|
623
623
|
let defaultStatus = 'pass';
|
|
@@ -633,7 +633,8 @@ export const __webpack_modules__ = {
|
|
|
633
633
|
status: 'skip',
|
|
634
634
|
parentNames: test.parentNames,
|
|
635
635
|
name: test.name,
|
|
636
|
-
testPath
|
|
636
|
+
testPath,
|
|
637
|
+
project
|
|
637
638
|
};
|
|
638
639
|
return result;
|
|
639
640
|
}
|
|
@@ -642,7 +643,8 @@ export const __webpack_modules__ = {
|
|
|
642
643
|
status: 'todo',
|
|
643
644
|
parentNames: test.parentNames,
|
|
644
645
|
name: test.name,
|
|
645
|
-
testPath
|
|
646
|
+
testPath,
|
|
647
|
+
project
|
|
646
648
|
};
|
|
647
649
|
return result;
|
|
648
650
|
}
|
|
@@ -660,7 +662,8 @@ export const __webpack_modules__ = {
|
|
|
660
662
|
parentNames: test.parentNames,
|
|
661
663
|
name: test.name,
|
|
662
664
|
errors: (0, runtime_util.o9)(error, test),
|
|
663
|
-
testPath
|
|
665
|
+
testPath,
|
|
666
|
+
project
|
|
664
667
|
};
|
|
665
668
|
}
|
|
666
669
|
if (result?.status !== 'fail') if (test.fails) try {
|
|
@@ -673,6 +676,7 @@ export const __webpack_modules__ = {
|
|
|
673
676
|
parentNames: test.parentNames,
|
|
674
677
|
name: test.name,
|
|
675
678
|
testPath,
|
|
679
|
+
project,
|
|
676
680
|
errors: [
|
|
677
681
|
{
|
|
678
682
|
message: 'Expect test to fail'
|
|
@@ -681,6 +685,7 @@ export const __webpack_modules__ = {
|
|
|
681
685
|
};
|
|
682
686
|
} catch (_err) {
|
|
683
687
|
result = {
|
|
688
|
+
project,
|
|
684
689
|
status: 'pass',
|
|
685
690
|
parentNames: test.parentNames,
|
|
686
691
|
name: test.name,
|
|
@@ -693,6 +698,7 @@ export const __webpack_modules__ = {
|
|
|
693
698
|
await test.fn?.(test.context);
|
|
694
699
|
this.afterRunTest(test);
|
|
695
700
|
result = {
|
|
701
|
+
project,
|
|
696
702
|
parentNames: test.parentNames,
|
|
697
703
|
name: test.name,
|
|
698
704
|
status: 'pass',
|
|
@@ -700,6 +706,7 @@ export const __webpack_modules__ = {
|
|
|
700
706
|
};
|
|
701
707
|
} catch (error) {
|
|
702
708
|
result = {
|
|
709
|
+
project,
|
|
703
710
|
status: 'fail',
|
|
704
711
|
parentNames: test.parentNames,
|
|
705
712
|
name: test.name,
|
|
@@ -709,14 +716,30 @@ export const __webpack_modules__ = {
|
|
|
709
716
|
}
|
|
710
717
|
const afterEachFns = [
|
|
711
718
|
...parentHooks.afterEachListeners || []
|
|
712
|
-
].reverse().concat(cleanups);
|
|
719
|
+
].reverse().concat(cleanups).concat(test.onFinished);
|
|
713
720
|
try {
|
|
714
|
-
for (const fn of afterEachFns)await fn(
|
|
721
|
+
for (const fn of afterEachFns)await fn({
|
|
722
|
+
task: {
|
|
723
|
+
result
|
|
724
|
+
}
|
|
725
|
+
});
|
|
715
726
|
} catch (error) {
|
|
716
727
|
result.status = 'fail';
|
|
717
728
|
result.errors ??= [];
|
|
718
729
|
result.errors.push(...(0, runtime_util.o9)(error));
|
|
719
730
|
}
|
|
731
|
+
if ('fail' === result.status) for (const fn of [
|
|
732
|
+
...test.onFailed
|
|
733
|
+
].reverse())try {
|
|
734
|
+
await fn({
|
|
735
|
+
task: {
|
|
736
|
+
result
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
} catch (error) {
|
|
740
|
+
result.errors ??= [];
|
|
741
|
+
result.errors.push(...(0, runtime_util.o9)(error));
|
|
742
|
+
}
|
|
720
743
|
this.resetCurrentTest();
|
|
721
744
|
return result;
|
|
722
745
|
};
|
|
@@ -764,7 +787,8 @@ export const __webpack_modules__ = {
|
|
|
764
787
|
testPath,
|
|
765
788
|
errors: [
|
|
766
789
|
noTestError
|
|
767
|
-
]
|
|
790
|
+
],
|
|
791
|
+
project
|
|
768
792
|
};
|
|
769
793
|
hooks.onTestCaseResult?.(result);
|
|
770
794
|
}
|
|
@@ -823,12 +847,14 @@ export const __webpack_modules__ = {
|
|
|
823
847
|
const start = RealDate.now();
|
|
824
848
|
if (0 === tests.length) {
|
|
825
849
|
if (passWithNoTests) return {
|
|
850
|
+
project,
|
|
826
851
|
testPath,
|
|
827
852
|
name: '',
|
|
828
853
|
status: 'pass',
|
|
829
854
|
results
|
|
830
855
|
};
|
|
831
856
|
return {
|
|
857
|
+
project,
|
|
832
858
|
testPath,
|
|
833
859
|
name: '',
|
|
834
860
|
status: 'fail',
|
|
@@ -847,6 +873,7 @@ export const __webpack_modules__ = {
|
|
|
847
873
|
});
|
|
848
874
|
const snapshotResult = await snapshotClient.finish(testPath);
|
|
849
875
|
return {
|
|
876
|
+
project,
|
|
850
877
|
testPath,
|
|
851
878
|
name: '',
|
|
852
879
|
status: errors.length ? 'fail' : getTestStatus(results, defaultStatus),
|
|
@@ -894,8 +921,36 @@ export const __webpack_modules__ = {
|
|
|
894
921
|
return null != _expect;
|
|
895
922
|
}
|
|
896
923
|
});
|
|
924
|
+
Object.defineProperty(context, 'onTestFinished', {
|
|
925
|
+
get: ()=>(fn, timeout)=>{
|
|
926
|
+
this.onTestFinished(current, fn, timeout);
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
Object.defineProperty(context, 'onTestFailed', {
|
|
930
|
+
get: ()=>(fn, timeout)=>{
|
|
931
|
+
this.onTestFailed(current, fn, timeout);
|
|
932
|
+
}
|
|
933
|
+
});
|
|
897
934
|
return context;
|
|
898
935
|
}
|
|
936
|
+
onTestFinished(test, fn, timeout) {
|
|
937
|
+
if (!test) throw new Error('onTestFinished() can only be called inside a test');
|
|
938
|
+
test.onFinished.push(wrapTimeout({
|
|
939
|
+
name: 'onTestFinished hook',
|
|
940
|
+
fn,
|
|
941
|
+
timeout: timeout || this.workerState.runtimeConfig.hookTimeout,
|
|
942
|
+
stackTraceError: new Error('STACK_TRACE_ERROR')
|
|
943
|
+
}));
|
|
944
|
+
}
|
|
945
|
+
onTestFailed(test, fn, timeout) {
|
|
946
|
+
if (!test) throw new Error('onTestFailed() can only be called inside a test');
|
|
947
|
+
test.onFailed.push(wrapTimeout({
|
|
948
|
+
name: 'onTestFailed hook',
|
|
949
|
+
fn,
|
|
950
|
+
timeout: timeout || this.workerState.runtimeConfig.hookTimeout,
|
|
951
|
+
stackTraceError: new Error('STACK_TRACE_ERROR')
|
|
952
|
+
}));
|
|
953
|
+
}
|
|
899
954
|
async beforeRunTest(test, snapshotState) {
|
|
900
955
|
(0, dist.wb)({
|
|
901
956
|
assertionCalls: 0,
|
|
@@ -931,7 +986,9 @@ export const __webpack_modules__ = {
|
|
|
931
986
|
collectStatus = 'lazy';
|
|
932
987
|
currentCollectList = [];
|
|
933
988
|
runtimeConfig;
|
|
934
|
-
|
|
989
|
+
project;
|
|
990
|
+
constructor({ testPath, runtimeConfig, project }){
|
|
991
|
+
this.project = project;
|
|
935
992
|
this.testPath = testPath;
|
|
936
993
|
this.runtimeConfig = runtimeConfig;
|
|
937
994
|
}
|
|
@@ -982,6 +1039,7 @@ export const __webpack_modules__ = {
|
|
|
982
1039
|
}
|
|
983
1040
|
getDefaultRootSuite() {
|
|
984
1041
|
return {
|
|
1042
|
+
project: this.project,
|
|
985
1043
|
runMode: 'run',
|
|
986
1044
|
testPath: this.testPath,
|
|
987
1045
|
name: src_utils.q_,
|
|
@@ -992,6 +1050,7 @@ export const __webpack_modules__ = {
|
|
|
992
1050
|
describe({ name, fn, runMode = 'run', each = false, concurrent, sequential }) {
|
|
993
1051
|
this.checkStatus(name, 'suite');
|
|
994
1052
|
const currentSuite = {
|
|
1053
|
+
project: this.project,
|
|
995
1054
|
name,
|
|
996
1055
|
runMode,
|
|
997
1056
|
tests: [],
|
|
@@ -1067,6 +1126,7 @@ export const __webpack_modules__ = {
|
|
|
1067
1126
|
it({ name, fn, originalFn = fn, fixtures, timeout = this.runtimeConfig.testTimeout, runMode = 'run', fails = false, each = false, concurrent, sequential }) {
|
|
1068
1127
|
this.checkStatus(name, 'case');
|
|
1069
1128
|
this.addTestCase({
|
|
1129
|
+
project: this.project,
|
|
1070
1130
|
name,
|
|
1071
1131
|
originalFn,
|
|
1072
1132
|
fn: fn ? wrapTimeout({
|
|
@@ -1082,7 +1142,9 @@ export const __webpack_modules__ = {
|
|
|
1082
1142
|
concurrent,
|
|
1083
1143
|
sequential,
|
|
1084
1144
|
each,
|
|
1085
|
-
fails
|
|
1145
|
+
fails,
|
|
1146
|
+
onFinished: [],
|
|
1147
|
+
onFailed: []
|
|
1086
1148
|
});
|
|
1087
1149
|
}
|
|
1088
1150
|
describeEach({ cases, ...options }) {
|
|
@@ -1152,8 +1214,9 @@ export const __webpack_modules__ = {
|
|
|
1152
1214
|
throw new Error('Expect to find a suite, but got undefined');
|
|
1153
1215
|
}
|
|
1154
1216
|
}
|
|
1155
|
-
const createRuntimeAPI = ({ testPath, runtimeConfig })=>{
|
|
1217
|
+
const createRuntimeAPI = ({ testPath, runtimeConfig, project })=>{
|
|
1156
1218
|
const runtimeInstance = new RunnerRuntime({
|
|
1219
|
+
project,
|
|
1157
1220
|
testPath,
|
|
1158
1221
|
runtimeConfig
|
|
1159
1222
|
});
|
|
@@ -1303,14 +1366,23 @@ export const __webpack_modules__ = {
|
|
|
1303
1366
|
};
|
|
1304
1367
|
};
|
|
1305
1368
|
function createRunner({ workerState }) {
|
|
1306
|
-
const { testPath, runtimeConfig: { testNamePattern } } = workerState;
|
|
1369
|
+
const { testPath, project, runtimeConfig: { testNamePattern } } = workerState;
|
|
1307
1370
|
const runtime = createRuntimeAPI({
|
|
1371
|
+
project,
|
|
1308
1372
|
testPath,
|
|
1309
1373
|
runtimeConfig: workerState.runtimeConfig
|
|
1310
1374
|
});
|
|
1311
1375
|
const testRunner = new TestRunner();
|
|
1312
1376
|
return {
|
|
1313
|
-
api:
|
|
1377
|
+
api: {
|
|
1378
|
+
...runtime.api,
|
|
1379
|
+
onTestFinished: (fn, timeout)=>{
|
|
1380
|
+
testRunner.onTestFinished(testRunner.getCurrentTest(), fn, timeout);
|
|
1381
|
+
},
|
|
1382
|
+
onTestFailed: (fn, timeout)=>{
|
|
1383
|
+
testRunner.onTestFailed(testRunner.getCurrentTest(), fn, timeout);
|
|
1384
|
+
}
|
|
1385
|
+
},
|
|
1314
1386
|
runner: {
|
|
1315
1387
|
runTests: async (testPath, hooks, api)=>{
|
|
1316
1388
|
const tests = await runtime.instance.getTests();
|
package/dist/967.js
CHANGED
|
@@ -40,21 +40,22 @@ export const __webpack_modules__ = {
|
|
|
40
40
|
const clearConsole = ()=>{
|
|
41
41
|
if ((0, utils.Un)() && !process.env.DEBUG) process.stdout.write('\x1B[H\x1B[2J');
|
|
42
42
|
};
|
|
43
|
-
const beforeRestart = async ({ filePath, clear = true })=>{
|
|
43
|
+
const beforeRestart = async ({ filePath, root, clear = true })=>{
|
|
44
44
|
if (clear) clearConsole();
|
|
45
45
|
if (filePath) {
|
|
46
|
-
const filename = external_node_path_["default"].
|
|
46
|
+
const filename = external_node_path_["default"].relative(root, filePath);
|
|
47
47
|
utils.vF.info(`restarting Rstest as ${utils.yW.yellow(filename)} changed\n`);
|
|
48
48
|
} else utils.vF.info('restarting Rstest...\n');
|
|
49
49
|
for (const cleaner of cleaners)await cleaner();
|
|
50
50
|
cleaners = [];
|
|
51
51
|
};
|
|
52
|
-
const restart = async ({ filePath, clear = true, options, filters })=>{
|
|
52
|
+
const restart = async ({ filePath, clear = true, options, filters, root })=>{
|
|
53
53
|
await beforeRestart({
|
|
54
54
|
filePath,
|
|
55
|
+
root,
|
|
55
56
|
clear
|
|
56
57
|
});
|
|
57
|
-
await (0, commands.
|
|
58
|
+
await (0, commands.a)({
|
|
58
59
|
options,
|
|
59
60
|
filters,
|
|
60
61
|
command: 'watch'
|
|
@@ -62,11 +63,13 @@ export const __webpack_modules__ = {
|
|
|
62
63
|
return true;
|
|
63
64
|
};
|
|
64
65
|
async function watchFilesForRestart({ rstest, watchOptions, options, filters }) {
|
|
65
|
-
|
|
66
|
+
const configFilePaths = [
|
|
67
|
+
rstest.context.configFilePath,
|
|
68
|
+
...rstest.context.projects.map((project)=>project.configFilePath)
|
|
69
|
+
].filter(Boolean);
|
|
70
|
+
if (0 === configFilePaths.length) return;
|
|
66
71
|
const root = rstest.context.rootPath;
|
|
67
|
-
const watcher = await createChokidar(
|
|
68
|
-
rstest.context.configFilePath
|
|
69
|
-
], root, {
|
|
72
|
+
const watcher = await createChokidar(configFilePaths, root, {
|
|
70
73
|
ignoreInitial: true,
|
|
71
74
|
ignorePermissionErrors: true,
|
|
72
75
|
...watchOptions
|
|
@@ -77,6 +80,7 @@ export const __webpack_modules__ = {
|
|
|
77
80
|
restarting = true;
|
|
78
81
|
const restarted = await restart({
|
|
79
82
|
options,
|
|
83
|
+
root,
|
|
80
84
|
filters,
|
|
81
85
|
filePath
|
|
82
86
|
});
|
package/dist/971.js
CHANGED
|
@@ -15,50 +15,79 @@ export const __webpack_modules__ = {
|
|
|
15
15
|
var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./src/utils/index.ts");
|
|
16
16
|
var _rsbuild__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./src/core/rsbuild.ts");
|
|
17
17
|
async function listTests(context, { filesOnly, json }) {
|
|
18
|
-
const {
|
|
19
|
-
const testEntries =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
root
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
rootPath,
|
|
27
|
+
projectRoot: root,
|
|
28
|
+
fileFilters: context.fileFilters || [],
|
|
29
|
+
includeSource
|
|
30
|
+
});
|
|
31
|
+
testEntries[name] = entries;
|
|
32
|
+
return entries;
|
|
33
|
+
};
|
|
34
|
+
const setupFiles = Object.fromEntries(context.projects.map((project)=>{
|
|
35
|
+
const { environmentName, rootPath, normalizedConfig: { setupFiles } } = project;
|
|
36
|
+
return [
|
|
37
|
+
environmentName,
|
|
38
|
+
(0, _utils__WEBPACK_IMPORTED_MODULE_3__.pr)(setupFiles, rootPath)
|
|
39
|
+
];
|
|
40
|
+
}));
|
|
41
|
+
const rsbuildInstance = await (0, _rsbuild__WEBPACK_IMPORTED_MODULE_4__.zh)(context, globTestSourceEntries, setupFiles);
|
|
42
|
+
const { getRsbuildStats, closeServer } = await (0, _rsbuild__WEBPACK_IMPORTED_MODULE_4__.XD)({
|
|
31
43
|
globTestSourceEntries,
|
|
32
44
|
normalizedConfig: context.normalizedConfig,
|
|
33
45
|
setupFiles,
|
|
34
46
|
rsbuildInstance,
|
|
35
47
|
rootPath
|
|
36
48
|
});
|
|
37
|
-
const { entries, setupEntries, assetFiles, sourceMaps, getSourcemap } = await getRsbuildStats();
|
|
38
49
|
const pool = await (0, _pool__WEBPACK_IMPORTED_MODULE_2__.b)({
|
|
39
50
|
context
|
|
40
51
|
});
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
entries,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
const updateSnapshot = context.snapshotManager.options.updateSnapshot;
|
|
53
|
+
const returns = await Promise.all(context.projects.map(async (project)=>{
|
|
54
|
+
const { entries, setupEntries, assetFiles, sourceMaps } = await getRsbuildStats({
|
|
55
|
+
environmentName: project.environmentName
|
|
56
|
+
});
|
|
57
|
+
const list = await pool.collectTests({
|
|
58
|
+
entries,
|
|
59
|
+
sourceMaps,
|
|
60
|
+
setupEntries,
|
|
61
|
+
assetFiles,
|
|
62
|
+
project,
|
|
63
|
+
updateSnapshot
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
list,
|
|
67
|
+
sourceMaps
|
|
68
|
+
};
|
|
69
|
+
}));
|
|
70
|
+
const list = returns.flatMap((r)=>r.list);
|
|
71
|
+
const sourceMaps = Object.assign({}, ...returns.map((r)=>r.sourceMaps));
|
|
49
72
|
const tests = [];
|
|
50
73
|
const traverseTests = (test)=>{
|
|
51
74
|
if ([
|
|
52
75
|
'skip',
|
|
53
76
|
'todo'
|
|
54
77
|
].includes(test.runMode)) return;
|
|
55
|
-
if ('case' === test.type) tests.push({
|
|
78
|
+
if ('case' === test.type) if (showProject) tests.push({
|
|
79
|
+
file: test.testPath,
|
|
80
|
+
name: (0, _utils__WEBPACK_IMPORTED_MODULE_3__.fN)(test),
|
|
81
|
+
project: test.project
|
|
82
|
+
});
|
|
83
|
+
else tests.push({
|
|
56
84
|
file: test.testPath,
|
|
57
85
|
name: (0, _utils__WEBPACK_IMPORTED_MODULE_3__.fN)(test)
|
|
58
86
|
});
|
|
59
87
|
else for (const child of test.tests)traverseTests(child);
|
|
60
88
|
};
|
|
61
89
|
const hasError = list.some((file)=>file.errors?.length);
|
|
90
|
+
const showProject = context.projects.length > 1;
|
|
62
91
|
if (hasError) {
|
|
63
92
|
const { printError } = await Promise.all([
|
|
64
93
|
__webpack_require__.e("829"),
|
|
@@ -69,7 +98,7 @@ export const __webpack_modules__ = {
|
|
|
69
98
|
const relativePath = (0, node_path__WEBPACK_IMPORTED_MODULE_1__.relative)(rootPath, file.testPath);
|
|
70
99
|
if (file.errors?.length) {
|
|
71
100
|
_utils__WEBPACK_IMPORTED_MODULE_3__.vF.log(`${_utils__WEBPACK_IMPORTED_MODULE_3__.yW.bgRed(' FAIL ')} ${relativePath}`);
|
|
72
|
-
for (const error of file.errors)await printError(error,
|
|
101
|
+
for (const error of file.errors)await printError(error, (name)=>sourceMaps[name] || null, rootPath);
|
|
73
102
|
}
|
|
74
103
|
}
|
|
75
104
|
await closeServer();
|
|
@@ -78,7 +107,11 @@ export const __webpack_modules__ = {
|
|
|
78
107
|
}
|
|
79
108
|
for (const file of list){
|
|
80
109
|
if (filesOnly) {
|
|
81
|
-
tests.push({
|
|
110
|
+
if (showProject) tests.push({
|
|
111
|
+
file: file.testPath,
|
|
112
|
+
project: file.project
|
|
113
|
+
});
|
|
114
|
+
else tests.push({
|
|
82
115
|
file: file.testPath
|
|
83
116
|
});
|
|
84
117
|
continue;
|