@rstest/core 0.2.2 → 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/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
- constructor({ testPath, runtimeConfig }){
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: runtime.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"].basename(filePath);
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.a8)({
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
- if (!rstest.context.configFilePath) return;
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,78 @@ 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 { normalizedConfig: { include, exclude, root, name, setupFiles: setups, includeSource }, rootPath } = context;
19
- const testEntries = await (0, _utils__WEBPACK_IMPORTED_MODULE_3__.tG)({
20
- include,
21
- exclude,
22
- root,
23
- fileFilters: context.fileFilters || [],
24
- includeSource
25
- });
26
- const globTestSourceEntries = async ()=>testEntries;
27
- const setupFiles = (0, _utils__WEBPACK_IMPORTED_MODULE_3__.pr)(setups, rootPath);
28
- const rsbuildInstance = await (0, _rsbuild__WEBPACK_IMPORTED_MODULE_4__.z)(context, globTestSourceEntries, setupFiles);
29
- const { getRsbuildStats, closeServer } = await (0, _rsbuild__WEBPACK_IMPORTED_MODULE_4__.X)({
30
- 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)({
31
42
  globTestSourceEntries,
32
43
  normalizedConfig: context.normalizedConfig,
33
44
  setupFiles,
34
45
  rsbuildInstance,
35
46
  rootPath
36
47
  });
37
- const { entries, setupEntries, assetFiles, sourceMaps, getSourcemap } = await getRsbuildStats();
38
48
  const pool = await (0, _pool__WEBPACK_IMPORTED_MODULE_2__.b)({
39
49
  context
40
50
  });
41
- const list = await pool.collectTests({
42
- context,
43
- entries,
44
- sourceMaps,
45
- setupEntries,
46
- assetFiles,
47
- updateSnapshot: context.snapshotManager.options.updateSnapshot
48
- });
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));
49
71
  const tests = [];
50
72
  const traverseTests = (test)=>{
51
73
  if ([
52
74
  'skip',
53
75
  'todo'
54
76
  ].includes(test.runMode)) return;
55
- 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({
56
83
  file: test.testPath,
57
84
  name: (0, _utils__WEBPACK_IMPORTED_MODULE_3__.fN)(test)
58
85
  });
59
86
  else for (const child of test.tests)traverseTests(child);
60
87
  };
61
88
  const hasError = list.some((file)=>file.errors?.length);
89
+ const showProject = context.projects.length > 1;
62
90
  if (hasError) {
63
91
  const { printError } = await Promise.all([
64
92
  __webpack_require__.e("829"),
@@ -69,7 +97,7 @@ export const __webpack_modules__ = {
69
97
  const relativePath = (0, node_path__WEBPACK_IMPORTED_MODULE_1__.relative)(rootPath, file.testPath);
70
98
  if (file.errors?.length) {
71
99
  _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, getSourcemap, rootPath);
100
+ for (const error of file.errors)await printError(error, (name)=>sourceMaps[name] || null, rootPath);
73
101
  }
74
102
  }
75
103
  await closeServer();
@@ -78,7 +106,11 @@ export const __webpack_modules__ = {
78
106
  }
79
107
  for (const file of list){
80
108
  if (filesOnly) {
81
- tests.push({
109
+ if (showProject) tests.push({
110
+ file: file.testPath,
111
+ project: file.project
112
+ });
113
+ else tests.push({
82
114
  file: file.testPath
83
115
  });
84
116
  continue;