@rstest/core 0.7.2 → 0.7.4

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.
@@ -4,8 +4,11 @@ import { __webpack_require__ } from "./rslib-runtime.js";
4
4
  import node_events from "node:events";
5
5
  import { Tinypool } from "tinypool";
6
6
  import node_inspector from "node:inspector";
7
- import { basename, TEMP_RSTEST_OUTPUT_DIR, dirname, posix, resolve as pathe_M_eThtNZ_resolve, serializableConfig, node_process, isBuiltin, castArray, TEMP_RSTEST_OUTPUT_DIR_GLOB, isDebug, ADDITIONAL_NODE_BUILTINS, join, needFlagExperimentalDetectModule } from "./946.js";
8
- import { node_v8, fileURLToPath, createBirpc } from "./404.js";
7
+ import { isBuiltin } from "./664.js";
8
+ import { node_process, basename, isDebug, dirname, posix, resolve as pathe_M_eThtNZ_resolve, join } from "./278.js";
9
+ import { fileURLToPath } from "./198.js";
10
+ import { node_v8, createBirpc } from "./216.js";
11
+ import { serializableConfig, bgColor, TEMP_RSTEST_OUTPUT_DIR, TEMP_RSTEST_OUTPUT_DIR_GLOB, castArray, ADDITIONAL_NODE_BUILTINS, needFlagExperimentalDetectModule } from "./157.js";
9
12
  import { core_logger, createRsbuild } from "./131.js";
10
13
  const DefaultMaxHeapSize = 1073741824;
11
14
  function memory_isMemorySufficient(options) {
@@ -63,6 +66,8 @@ const createForksPool = (poolOptions)=>{
63
66
  isolateWorkers: isolate
64
67
  };
65
68
  const pool = new Tinypool(options);
69
+ const destroy = pool.destroy.bind(pool);
70
+ process.on('SIGTERM', destroy);
66
71
  return {
67
72
  name: 'forks',
68
73
  runTest: async ({ options, rpcMethods })=>{
@@ -85,7 +90,10 @@ const createForksPool = (poolOptions)=>{
85
90
  cleanup();
86
91
  }
87
92
  },
88
- close: ()=>pool.destroy()
93
+ close: ()=>{
94
+ process.off('SIGTERM', destroy);
95
+ return destroy();
96
+ }
89
97
  };
90
98
  };
91
99
  const external_node_os_ = __webpack_require__("node:os");
@@ -102,9 +110,12 @@ const parseWorkers = (maxWorkers)=>{
102
110
  return parsed > 0 ? parsed : 1;
103
111
  };
104
112
  const getRuntimeConfig = (context)=>{
105
- const { testNamePattern, testTimeout, passWithNoTests, retry, globals, clearMocks, resetMocks, restoreMocks, unstubEnvs, unstubGlobals, maxConcurrency, printConsoleTrace, disableConsoleIntercept, testEnvironment, hookTimeout, isolate, coverage, snapshotFormat, env, logHeapUsage, bail, chaiConfig } = context.normalizedConfig;
113
+ const { testNamePattern, testTimeout, passWithNoTests, retry, globals, clearMocks, resetMocks, restoreMocks, unstubEnvs, unstubGlobals, maxConcurrency, printConsoleTrace, disableConsoleIntercept, testEnvironment, hookTimeout, isolate, coverage, snapshotFormat, env, logHeapUsage, bail, chaiConfig, includeTaskLocation } = context.normalizedConfig;
106
114
  return {
107
- env,
115
+ env: {
116
+ ...process.env,
117
+ ...env
118
+ },
108
119
  testNamePattern,
109
120
  testTimeout,
110
121
  hookTimeout,
@@ -121,11 +132,15 @@ const getRuntimeConfig = (context)=>{
121
132
  disableConsoleIntercept,
122
133
  testEnvironment,
123
134
  isolate,
124
- coverage,
135
+ coverage: {
136
+ ...coverage,
137
+ reporters: []
138
+ },
125
139
  snapshotFormat,
126
140
  logHeapUsage,
127
141
  bail,
128
- chaiConfig
142
+ chaiConfig,
143
+ includeTaskLocation
129
144
  };
130
145
  };
131
146
  const filterAssetsByEntry = async (entryInfo, getAssetFiles, getSourceMaps, setupAssets)=>{
@@ -164,8 +179,7 @@ const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
164
179
  ].filter(Boolean),
165
180
  env: {
166
181
  NODE_ENV: 'test',
167
- FORCE_COLOR: '1' === process.env.NO_COLOR ? '0' : '1',
168
- ...process.env
182
+ FORCE_COLOR: '1' === process.env.NO_COLOR ? '0' : '1'
169
183
  }
170
184
  });
171
185
  const rpcMethods = {
@@ -185,6 +199,9 @@ const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
185
199
  context.stateManager.onTestFileStart(test.testPath);
186
200
  await Promise.all(reporters.map((reporter)=>reporter.onTestFileStart?.(test)));
187
201
  },
202
+ onTestFileReady: async (test)=>{
203
+ await Promise.all(reporters.map((reporter)=>reporter.onTestFileReady?.(test)));
204
+ },
188
205
  onTestSuiteStart: async (test)=>{
189
206
  await Promise.all(reporters.map((reporter)=>reporter.onTestSuiteStart?.(test)));
190
207
  },
@@ -309,6 +326,78 @@ const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
309
326
  close: ()=>pool.close()
310
327
  };
311
328
  };
329
+ let globalTeardownCallbacks = [];
330
+ function applyEnvChanges(changes) {
331
+ for(const key in changes)if (void 0 === changes[key]) delete process.env[key];
332
+ else process.env[key] = changes[key];
333
+ }
334
+ const globalSetup_filename = fileURLToPath(import.meta.url);
335
+ const globalSetup_dirname = dirname(globalSetup_filename);
336
+ async function createSetupPool() {
337
+ const options = {
338
+ runtime: 'child_process',
339
+ filename: pathe_M_eThtNZ_resolve(globalSetup_dirname, './globalSetupWorker.js'),
340
+ execArgv: [
341
+ ...process.execArgv,
342
+ '--experimental-vm-modules',
343
+ '--experimental-import-meta-resolve',
344
+ '--no-warnings'
345
+ ],
346
+ maxThreads: 1,
347
+ minThreads: 1,
348
+ concurrentTasksPerWorker: 1,
349
+ isolateWorkers: false,
350
+ env: {
351
+ NODE_ENV: 'test',
352
+ FORCE_COLOR: '1' === process.env.NO_COLOR ? '0' : '1',
353
+ ...process.env
354
+ }
355
+ };
356
+ const pool = new Tinypool(options);
357
+ const destroy = pool.destroy.bind(pool);
358
+ process.on('SIGTERM', destroy);
359
+ return pool;
360
+ }
361
+ async function runGlobalSetup({ globalSetupEntries, assetFiles, sourceMaps, interopDefault, outputModule }) {
362
+ const pool = await createSetupPool();
363
+ const result = await pool.run({
364
+ type: 'setup',
365
+ entries: globalSetupEntries,
366
+ assetFiles,
367
+ interopDefault,
368
+ outputModule,
369
+ sourceMaps
370
+ });
371
+ if (result.success) {
372
+ if (result.envChanges) applyEnvChanges(result.envChanges);
373
+ if (result.hasTeardown) globalTeardownCallbacks.push(()=>runWorkerTeardown(pool));
374
+ }
375
+ return {
376
+ success: result.success,
377
+ errors: result.errors
378
+ };
379
+ }
380
+ async function runWorkerTeardown(pool) {
381
+ const result = await pool.run({
382
+ type: 'teardown'
383
+ });
384
+ if (!result.success) process.exitCode = 1;
385
+ await pool.destroy();
386
+ }
387
+ async function runGlobalTeardown() {
388
+ const teardownCallbacks = [
389
+ ...globalTeardownCallbacks
390
+ ];
391
+ globalTeardownCallbacks = [];
392
+ for (const teardown of teardownCallbacks.reverse())try {
393
+ await teardown();
394
+ } catch (error) {
395
+ console.error(bgColor('bgRed', 'Error during global teardown'));
396
+ if (error instanceof Error) error.stack ? console.error(picocolors_default().red(error.stack)) : console.error(picocolors_default().red(error.message));
397
+ else console.error(picocolors_default().red(String(error)));
398
+ process.exitCode = 1;
399
+ }
400
+ }
312
401
  const RUNTIME_CHUNK_NAME = 'runtime';
313
402
  const requireShim = `// Rstest ESM shims
314
403
  import __rstest_shim_module__ from 'node:module';
@@ -457,7 +546,7 @@ class TestFileWatchPlugin {
457
546
  });
458
547
  }
459
548
  }
460
- const pluginEntryWatch = ({ isWatch, globTestSourceEntries, setupFiles, context })=>({
549
+ const pluginEntryWatch = ({ isWatch, globTestSourceEntries, setupFiles, globalSetupFiles, context })=>({
461
550
  name: 'rstest:entry-watch',
462
551
  setup: (api)=>{
463
552
  api.modifyRspackConfig(async (config, { environment })=>{
@@ -467,13 +556,14 @@ const pluginEntryWatch = ({ isWatch, globTestSourceEntries, setupFiles, context
467
556
  const sourceEntries = await globTestSourceEntries(environment.name);
468
557
  return {
469
558
  ...sourceEntries,
470
- ...setupFiles[environment.name]
559
+ ...setupFiles[environment.name],
560
+ ...globalSetupFiles?.[environment.name] || {}
471
561
  };
472
562
  };
473
563
  config.watchOptions ??= {};
474
564
  config.watchOptions.ignored = castArray(config.watchOptions.ignored || []);
475
565
  if (0 === config.watchOptions.ignored.length) config.watchOptions.ignored.push('**/.git', '**/node_modules');
476
- config.watchOptions.ignored.push(TEMP_RSTEST_OUTPUT_DIR_GLOB, context.normalizedConfig.coverage.reportsDirectory, '**/*.snap');
566
+ config.watchOptions.ignored.push(TEMP_RSTEST_OUTPUT_DIR_GLOB, context.normalizedConfig.coverage.reportsDirectory, ...Object.values(globalSetupFiles?.[environment.name] || {}), '**/*.snap');
477
567
  const configFilePath = context.projects.find((project)=>project.environmentName === environment.name)?.configFilePath;
478
568
  if (configFilePath) config.watchOptions.ignored.push(configFilePath);
479
569
  } else {
@@ -483,6 +573,7 @@ const pluginEntryWatch = ({ isWatch, globTestSourceEntries, setupFiles, context
483
573
  const sourceEntries = await globTestSourceEntries(environment.name);
484
574
  config.entry = {
485
575
  ...setupFiles[environment.name],
576
+ ...globalSetupFiles?.[environment.name] || {},
486
577
  ...sourceEntries
487
578
  };
488
579
  }
@@ -572,7 +663,7 @@ const pluginInspect = ()=>enable ? {
572
663
  });
573
664
  }
574
665
  } : null;
575
- const external_node_fs_ = __webpack_require__("node:fs");
666
+ const external_node_fs_ = __webpack_require__("fs");
576
667
  const mockRuntime_dirname = external_node_path_["default"].dirname(fileURLToPath(import.meta.url));
577
668
  class MockRuntimeRspackPlugin {
578
669
  outputModule;
@@ -690,7 +781,7 @@ function parseInlineSourceMapStr(code) {
690
781
  }
691
782
  }
692
783
  const isMultiCompiler = (compiler)=>'compilers' in compiler && Array.isArray(compiler.compilers);
693
- const prepareRsbuild = async (context, globTestSourceEntries, setupFiles)=>{
784
+ const prepareRsbuild = async (context, globTestSourceEntries, setupFiles, globalSetupFiles)=>{
694
785
  const { command, normalizedConfig: { isolate, dev = {}, coverage } } = context;
695
786
  const debugMode = isDebug();
696
787
  core_logger.level = debugMode ? 'verbose' : 'error';
@@ -729,11 +820,15 @@ const prepareRsbuild = async (context, globTestSourceEntries, setupFiles)=>{
729
820
  pluginEntryWatch({
730
821
  globTestSourceEntries,
731
822
  setupFiles,
823
+ globalSetupFiles,
732
824
  context,
733
825
  isWatch: 'watch' === command
734
826
  }),
735
827
  pluginExternal(context),
736
- !isolate ? pluginCacheControl(Object.values(setupFiles).flatMap((files)=>Object.values(files))) : null,
828
+ !isolate ? pluginCacheControl(Object.values({
829
+ ...setupFiles,
830
+ ...globalSetupFiles
831
+ }).flatMap((files)=>Object.values(files))) : null,
737
832
  pluginInspect()
738
833
  ].filter(Boolean)
739
834
  }
@@ -746,7 +841,7 @@ const prepareRsbuild = async (context, globTestSourceEntries, setupFiles)=>{
746
841
  pluginCoverageCore: mod.pluginCoverageCore
747
842
  }));
748
843
  const { pluginCoverage } = await loadCoverageProvider(coverage, context.rootPath);
749
- coverage.exclude.push(...Object.values(setupFiles).flatMap((files)=>Object.values(files)));
844
+ coverage.exclude.push(...Object.values(setupFiles).flatMap((files)=>Object.values(files)), ...Object.values(globalSetupFiles || {}).flatMap((files)=>Object.values(files)));
750
845
  rsbuildInstance.addPlugins([
751
846
  pluginCoverage(coverage),
752
847
  pluginCoverageCore(coverage)
@@ -807,7 +902,7 @@ class AssetsMemorySafeMap extends Map {
807
902
  return super.set(key, value);
808
903
  }
809
904
  }
810
- const createRsbuildServer = async ({ globTestSourceEntries, setupFiles, rsbuildInstance, inspectedConfig })=>{
905
+ const createRsbuildServer = async ({ globTestSourceEntries, setupFiles, globalSetupFiles, rsbuildInstance, inspectedConfig })=>{
811
906
  let rspackCompiler;
812
907
  const rstestCompilerPlugin = {
813
908
  name: 'rstest:compiler',
@@ -872,12 +967,13 @@ const createRsbuildServer = async ({ globTestSourceEntries, setupFiles, rsbuildI
872
967
  const entryFiles = await getEntryFiles(manifest, outputPath);
873
968
  const entries = [];
874
969
  const setupEntries = [];
970
+ const globalSetupEntries = [];
875
971
  const sourceEntries = await globTestSourceEntries(environmentName);
876
972
  for (const entry of Object.keys(entrypoints)){
877
973
  const e = entrypoints[entry];
878
974
  const filteredAssets = e.assets.filter((asset)=>!asset.name.endsWith('.wasm'));
879
975
  const distPath = posix.join(outputPath, filteredAssets[filteredAssets.length - 1].name);
880
- if (setupFiles[environmentName][entry]) setupEntries.push({
976
+ if (setupFiles[environmentName]?.[entry]) setupEntries.push({
881
977
  distPath,
882
978
  testPath: setupFiles[environmentName][entry],
883
979
  files: entryFiles[entry],
@@ -891,7 +987,12 @@ const createRsbuildServer = async ({ globTestSourceEntries, setupFiles, rsbuildI
891
987
  files: entryFiles[entry],
892
988
  chunks: e.chunks || []
893
989
  });
894
- }
990
+ } else if (globalSetupFiles?.[environmentName]?.[entry]) globalSetupEntries.push({
991
+ distPath,
992
+ testPath: globalSetupFiles[environmentName][entry],
993
+ files: entryFiles[entry],
994
+ chunks: e.chunks || []
995
+ });
895
996
  }
896
997
  const inlineSourceMap = 'inline-source-map' === stats.compilation.options.devtool;
897
998
  const sourceMapPaths = Object.fromEntries(assets.map((asset)=>{
@@ -945,6 +1046,7 @@ const createRsbuildServer = async ({ globTestSourceEntries, setupFiles, rsbuildI
945
1046
  hash,
946
1047
  entries,
947
1048
  setupEntries,
1049
+ globalSetupEntries,
948
1050
  assetNames,
949
1051
  getAssetFiles: async (names)=>Object.fromEntries(await Promise.all(names.map(async (name)=>{
950
1052
  const content = await readFileWithCache(name);
@@ -967,4 +1069,4 @@ const createRsbuildServer = async ({ globTestSourceEntries, setupFiles, rsbuildI
967
1069
  getRsbuildStats
968
1070
  };
969
1071
  };
970
- export { createPool, createRsbuildServer, prepareRsbuild };
1072
+ export { createPool, createRsbuildServer, prepareRsbuild, runGlobalSetup, runGlobalTeardown };
package/dist/0~919.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import 'module';
2
2
  /*#__PURE__*/ import.meta.url;
3
3
  import { __webpack_require__ } from "./rslib-runtime.js";
4
- import "./946.js";
4
+ import "./664.js";
5
5
  __webpack_require__.add({
6
- "../../node_modules/.pnpm/js-tokens@4.0.0/node_modules/js-tokens/index.js" (__unused_webpack_module, exports) {
6
+ "../../node_modules/.pnpm/js-tokens@4.0.0/node_modules/js-tokens/index.js" (__unused_rspack_module, exports) {
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
@@ -25,7 +25,7 @@ __webpack_require__.add({
25
25
  return token;
26
26
  };
27
27
  },
28
- "../../node_modules/.pnpm/@babel+code-frame@7.27.1/node_modules/@babel/code-frame/lib/index.js" (__unused_webpack_module, exports, __webpack_require__) {
28
+ "../../node_modules/.pnpm/@babel+code-frame@7.27.1/node_modules/@babel/code-frame/lib/index.js" (__unused_rspack_module, exports, __webpack_require__) {
29
29
  var picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
30
30
  var jsTokens = __webpack_require__("../../node_modules/.pnpm/js-tokens@4.0.0/node_modules/js-tokens/index.js");
31
31
  var helperValidatorIdentifier = __webpack_require__("../../node_modules/.pnpm/@babel+helper-validator-identifier@7.28.5/node_modules/@babel/helper-validator-identifier/lib/index.js");
@@ -194,7 +194,7 @@ __webpack_require__.add({
194
194
  }
195
195
  exports.codeFrameColumns = codeFrameColumns;
196
196
  },
197
- "../../node_modules/.pnpm/@babel+helper-validator-identifier@7.28.5/node_modules/@babel/helper-validator-identifier/lib/identifier.js" (__unused_webpack_module, exports) {
197
+ "../../node_modules/.pnpm/@babel+helper-validator-identifier@7.28.5/node_modules/@babel/helper-validator-identifier/lib/identifier.js" (__unused_rspack_module, exports) {
198
198
  Object.defineProperty(exports, "__esModule", {
199
199
  value: true
200
200
  });
@@ -1202,7 +1202,7 @@ __webpack_require__.add({
1202
1202
  return !isFirst;
1203
1203
  }
1204
1204
  },
1205
- "../../node_modules/.pnpm/@babel+helper-validator-identifier@7.28.5/node_modules/@babel/helper-validator-identifier/lib/index.js" (__unused_webpack_module, exports, __webpack_require__) {
1205
+ "../../node_modules/.pnpm/@babel+helper-validator-identifier@7.28.5/node_modules/@babel/helper-validator-identifier/lib/index.js" (__unused_rspack_module, exports, __webpack_require__) {
1206
1206
  Object.defineProperty(exports, "__esModule", {
1207
1207
  value: true
1208
1208
  });
@@ -1257,7 +1257,7 @@ __webpack_require__.add({
1257
1257
  var _identifier = __webpack_require__("../../node_modules/.pnpm/@babel+helper-validator-identifier@7.28.5/node_modules/@babel/helper-validator-identifier/lib/identifier.js");
1258
1258
  var _keyword = __webpack_require__("../../node_modules/.pnpm/@babel+helper-validator-identifier@7.28.5/node_modules/@babel/helper-validator-identifier/lib/keyword.js");
1259
1259
  },
1260
- "../../node_modules/.pnpm/@babel+helper-validator-identifier@7.28.5/node_modules/@babel/helper-validator-identifier/lib/keyword.js" (__unused_webpack_module, exports) {
1260
+ "../../node_modules/.pnpm/@babel+helper-validator-identifier@7.28.5/node_modules/@babel/helper-validator-identifier/lib/keyword.js" (__unused_rspack_module, exports) {
1261
1261
  Object.defineProperty(exports, "__esModule", {
1262
1262
  value: true
1263
1263
  });
package/dist/0~923.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import 'module';
2
2
  /*#__PURE__*/ import.meta.url;
3
3
  import { __webpack_require__ } from "./rslib-runtime.js";
4
- import { posix, src_logger } from "./946.js";
5
- import { pathToFileURL } from "./404.js";
4
+ import "./664.js";
5
+ import { pathToFileURL } from "./198.js";
6
6
  import { node_vm, interopModule, shouldInterop } from "./0~346.js";
7
+ import { posix, logger_logger } from "./278.js";
7
8
  const external_node_path_ = __webpack_require__("node:path");
8
9
  var loadEsModule_EsmMode = /*#__PURE__*/ function(EsmMode) {
9
10
  EsmMode[EsmMode["Unknown"] = 0] = "Unknown";
@@ -27,7 +28,7 @@ const defineRstestDynamicImport = ({ distPath, testPath, assetFiles, interopDefa
27
28
  esmMode
28
29
  });
29
30
  } catch (err) {
30
- src_logger.error(`load file ${joinedPath} failed:\n`, err instanceof Error ? err.message : err);
31
+ logger_logger.error(`load file ${joinedPath} failed:\n`, err instanceof Error ? err.message : err);
31
32
  }
32
33
  const resolvedPath = (0, external_node_path_.isAbsolute)(specifier) ? pathToFileURL(specifier) : import.meta.resolve(specifier, pathToFileURL(testPath));
33
34
  const modulePath = 'string' == typeof resolvedPath ? resolvedPath : resolvedPath.pathname;