@rstest/core 0.7.0 → 0.7.2

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 CHANGED
@@ -943,7 +943,7 @@ Licensed under MIT license in the repository at https://github.com/chaijs/loupe.
943
943
 
944
944
  ### magic-string
945
945
 
946
- Licensed under MIT license in the repository at https://github.com/rich-harris/magic-string.git.
946
+ Licensed under MIT license in the repository at git+https://github.com/Rich-Harris/magic-string.git.
947
947
 
948
948
  > Copyright 2018 Rich Harris
949
949
  >
package/dist/0~122.js CHANGED
@@ -5,8 +5,8 @@ import node_events from "node:events";
5
5
  import { Tinypool } from "tinypool";
6
6
  import node_inspector from "node:inspector";
7
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 "./770.js";
9
- import { logger, createRsbuild } from "./155.js";
8
+ import { node_v8, fileURLToPath, createBirpc } from "./404.js";
9
+ import { core_logger, createRsbuild } from "./131.js";
10
10
  const DefaultMaxHeapSize = 1073741824;
11
11
  function memory_isMemorySufficient(options) {
12
12
  const { memoryThreshold = 0.7, maxHeapSize = DefaultMaxHeapSize } = options || {};
@@ -185,6 +185,12 @@ const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
185
185
  context.stateManager.onTestFileStart(test.testPath);
186
186
  await Promise.all(reporters.map((reporter)=>reporter.onTestFileStart?.(test)));
187
187
  },
188
+ onTestSuiteStart: async (test)=>{
189
+ await Promise.all(reporters.map((reporter)=>reporter.onTestSuiteStart?.(test)));
190
+ },
191
+ onTestSuiteResult: async (result)=>{
192
+ await Promise.all(reporters.map((reporter)=>reporter.onTestSuiteResult?.(result)));
193
+ },
188
194
  resolveSnapshotPath: (testPath)=>{
189
195
  const snapExtension = '.snap';
190
196
  const resolver = context.normalizedConfig.resolveSnapshotPath || (()=>join(dirname(testPath), '__snapshots__', `${basename(testPath)}${snapExtension}`));
@@ -202,6 +208,7 @@ const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
202
208
  options: {
203
209
  entryInfo,
204
210
  context: {
211
+ outputModule: project.outputModule,
205
212
  taskId: index + 1,
206
213
  project: projectName,
207
214
  rootPath: context.rootPath,
@@ -273,6 +280,7 @@ const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
273
280
  context: {
274
281
  taskId: index + 1,
275
282
  project: projectName,
283
+ outputModule: project.outputModule,
276
284
  rootPath: context.rootPath,
277
285
  projectRoot: project.rootPath,
278
286
  runtimeConfig: serializableConfig(runtimeConfig)
@@ -302,11 +310,15 @@ const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
302
310
  };
303
311
  };
304
312
  const RUNTIME_CHUNK_NAME = 'runtime';
313
+ const requireShim = `// Rstest ESM shims
314
+ import __rstest_shim_module__ from 'node:module';
315
+ const require = /*#__PURE__*/ __rstest_shim_module__.createRequire(import.meta.url);
316
+ `;
305
317
  const pluginBasic = (context)=>({
306
318
  name: 'rstest:basic',
307
319
  setup: (api)=>{
308
320
  api.modifyEnvironmentConfig(async (config, { mergeEnvironmentConfig, name })=>{
309
- const { normalizedConfig: { resolve, source, output, tools, performance, dev, testEnvironment }, rootPath } = context.projects.find((p)=>p.environmentName === name);
321
+ const { normalizedConfig: { resolve, source, output, tools, performance, dev, testEnvironment }, outputModule, rootPath } = context.projects.find((p)=>p.environmentName === name);
310
322
  return mergeEnvironmentConfig(config, {
311
323
  performance,
312
324
  tools,
@@ -326,6 +338,10 @@ const pluginBasic = (context)=>({
326
338
  sourceMap: {
327
339
  js: 'source-map'
328
340
  },
341
+ module: outputModule,
342
+ filename: outputModule ? {
343
+ js: '[name].mjs'
344
+ } : void 0,
329
345
  distPath: {
330
346
  root: context.projects.length > 1 ? `${TEMP_RSTEST_OUTPUT_DIR}/${name}` : TEMP_RSTEST_OUTPUT_DIR
331
347
  }
@@ -336,7 +352,7 @@ const pluginBasic = (context)=>({
336
352
  config.mode = isProd ? 'production' : 'development';
337
353
  config.output ??= {};
338
354
  config.output.iife = false;
339
- config.output.importFunctionName = '__rstest_dynamic_import__';
355
+ config.output.importFunctionName = outputModule ? 'import.meta.__rstest_dynamic_import__' : '__rstest_dynamic_import__';
340
356
  config.output.devtoolModuleFilenameTemplate = '[absolute-resource-path]';
341
357
  if (!config.devtool || !config.devtool.includes('inline')) config.devtool = 'nosources-source-map';
342
358
  config.plugins.push(new rspack.experiments.RstestPlugin({
@@ -345,6 +361,12 @@ const pluginBasic = (context)=>({
345
361
  hoistMockModule: true,
346
362
  manualMockRoot: posix.resolve(rootPath, '__mocks__')
347
363
  }));
364
+ if (outputModule) config.plugins.push(new rspack.BannerPlugin({
365
+ banner: requireShim,
366
+ stage: rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1,
367
+ raw: true,
368
+ include: /\.(js|mjs)$/
369
+ }));
348
370
  config.module.parser ??= {};
349
371
  config.module.parser.javascript = {
350
372
  importDynamic: false,
@@ -467,20 +489,20 @@ const pluginEntryWatch = ({ isWatch, globTestSourceEntries, setupFiles, context
467
489
  });
468
490
  }
469
491
  });
470
- const autoExternalNodeModules = ({ context, request, dependencyType, getResolve }, callback)=>{
471
- if (!request) return callback();
472
- if (request.startsWith('@swc/helpers/') || request.endsWith('.wasm')) return callback();
473
- const doExternal = (externalPath = request)=>{
474
- callback(void 0, externalPath, 'commonjs' === dependencyType ? 'commonjs' : 'import');
492
+ const autoExternalNodeModules = (outputModule)=>({ context, request, dependencyType, getResolve }, callback)=>{
493
+ if (!request) return callback();
494
+ if (request.startsWith('@swc/helpers/') || request.endsWith('.wasm')) return callback();
495
+ const doExternal = (externalPath = request)=>{
496
+ callback(void 0, externalPath, 'commonjs' === dependencyType ? 'commonjs' : outputModule ? 'module-import' : 'import');
497
+ };
498
+ const resolver = getResolve?.();
499
+ if (!resolver) return callback();
500
+ resolver(context, request, (err, resolvePath)=>{
501
+ if (err) return callback(void 0, request, 'node-commonjs');
502
+ if (resolvePath && resolvePath.includes('node_modules') && !/\.(?:ts|tsx|jsx|mts|cts)$/.test(resolvePath)) return doExternal(resolvePath);
503
+ return callback();
504
+ });
475
505
  };
476
- const resolver = getResolve?.();
477
- if (!resolver) return callback();
478
- resolver(context, request, (err, resolvePath)=>{
479
- if (err) return callback();
480
- if (resolvePath && resolvePath.includes('node_modules') && !/\.(?:ts|tsx|jsx|mts|cts)$/.test(resolvePath)) return doExternal(resolvePath);
481
- return callback();
482
- });
483
- };
484
506
  function autoExternalNodeBuiltin({ request, dependencyType }, callback) {
485
507
  if (!request) return void callback();
486
508
  const isNodeBuiltin = isBuiltin(request) || ADDITIONAL_NODE_BUILTINS.some((builtin)=>{
@@ -494,11 +516,11 @@ const pluginExternal = (context)=>({
494
516
  name: 'rstest:external',
495
517
  setup: (api)=>{
496
518
  api.modifyEnvironmentConfig(async (config, { mergeEnvironmentConfig, name })=>{
497
- const { normalizedConfig: { testEnvironment } } = context.projects.find((p)=>p.environmentName === name);
519
+ const { normalizedConfig: { testEnvironment }, outputModule } = context.projects.find((p)=>p.environmentName === name);
498
520
  return mergeEnvironmentConfig(config, {
499
521
  output: {
500
522
  externals: 'node' === testEnvironment ? [
501
- autoExternalNodeModules
523
+ autoExternalNodeModules(outputModule)
502
524
  ] : void 0
503
525
  },
504
526
  tools: {
@@ -509,7 +531,7 @@ const pluginExternal = (context)=>({
509
531
  });
510
532
  config.externalsPresets ??= {};
511
533
  config.externalsPresets.node = false;
512
- config.externals.push(autoExternalNodeBuiltin);
534
+ config.externals.unshift(autoExternalNodeBuiltin);
513
535
  }
514
536
  }
515
537
  });
@@ -553,6 +575,10 @@ const pluginInspect = ()=>enable ? {
553
575
  const external_node_fs_ = __webpack_require__("node:fs");
554
576
  const mockRuntime_dirname = external_node_path_["default"].dirname(fileURLToPath(import.meta.url));
555
577
  class MockRuntimeRspackPlugin {
578
+ outputModule;
579
+ constructor(outputModule){
580
+ this.outputModule = outputModule;
581
+ }
556
582
  apply(compiler) {
557
583
  const { RuntimeModule } = compiler.webpack;
558
584
  class RetestImportRuntimeModule extends RuntimeModule {
@@ -570,12 +596,16 @@ class MockRuntimeRspackPlugin {
570
596
  const finalSource = module.source.source.toString('utf-8').replace('for (var moduleId in moreModules) {', "for (var moduleId in moreModules) {\n if (Object.keys(__webpack_require__.rstest_original_modules).includes(moduleId)) continue;");
571
597
  module.source.source = Buffer.from(finalSource);
572
598
  }
599
+ if ('module_chunk_loading' === module.name) {
600
+ const finalSource = module.source.source.toString('utf-8').replace('for (moduleId in __webpack_modules__) {', "for (moduleId in __webpack_modules__) {\n if (Object.keys(__webpack_require__.rstest_original_modules).includes(moduleId)) continue;");
601
+ module.source.source = Buffer.from(finalSource);
602
+ }
573
603
  if ('define_property_getters' === module.name) {
574
604
  const finalSource = module.source.source.toString('utf-8').replace('enumerable: true, get:', 'enumerable: true, configurable: true, get:');
575
605
  module.source.source = Buffer.from(finalSource);
576
606
  }
577
607
  if ('async_wasm_loading' === module.name) {
578
- const finalSource = module.source.source.toString('utf-8').replace('readFile(', 'readWasmFile(');
608
+ const finalSource = module.source.source.toString('utf-8').replace('readFile(', this.outputModule ? 'import.meta.readWasmFile(' : 'readWasmFile(');
579
609
  module.source.source = Buffer.from(finalSource);
580
610
  }
581
611
  });
@@ -591,7 +621,7 @@ const pluginMockRuntime = {
591
621
  name: 'rstest:mock-runtime',
592
622
  setup: (api)=>{
593
623
  api.modifyRspackConfig(async (config)=>{
594
- config.plugins.push(new MockRuntimeRspackPlugin());
624
+ config.plugins.push(new MockRuntimeRspackPlugin(Boolean(config.output.module)));
595
625
  });
596
626
  }
597
627
  };
@@ -663,7 +693,7 @@ const isMultiCompiler = (compiler)=>'compilers' in compiler && Array.isArray(com
663
693
  const prepareRsbuild = async (context, globTestSourceEntries, setupFiles)=>{
664
694
  const { command, normalizedConfig: { isolate, dev = {}, coverage } } = context;
665
695
  const debugMode = isDebug();
666
- logger.level = debugMode ? 'verbose' : 'error';
696
+ core_logger.level = debugMode ? 'verbose' : 'error';
667
697
  const writeToDisk = dev.writeToDisk || debugMode;
668
698
  const rsbuildInstance = await createRsbuild({
669
699
  callerName: 'rstest',