@rstest/core 0.6.9 → 0.7.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/0~122.js CHANGED
@@ -202,6 +202,7 @@ const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
202
202
  options: {
203
203
  entryInfo,
204
204
  context: {
205
+ outputModule: project.outputModule,
205
206
  taskId: index + 1,
206
207
  project: projectName,
207
208
  rootPath: context.rootPath,
@@ -273,6 +274,7 @@ const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
273
274
  context: {
274
275
  taskId: index + 1,
275
276
  project: projectName,
277
+ outputModule: project.outputModule,
276
278
  rootPath: context.rootPath,
277
279
  projectRoot: project.rootPath,
278
280
  runtimeConfig: serializableConfig(runtimeConfig)
@@ -302,11 +304,15 @@ const createPool = async ({ context, recommendWorkerCount = 1 / 0 })=>{
302
304
  };
303
305
  };
304
306
  const RUNTIME_CHUNK_NAME = 'runtime';
307
+ const requireShim = `// Rstest ESM shims
308
+ import __rstest_shim_module__ from 'node:module';
309
+ const require = /*#__PURE__*/ __rstest_shim_module__.createRequire(import.meta.url);
310
+ `;
305
311
  const pluginBasic = (context)=>({
306
312
  name: 'rstest:basic',
307
313
  setup: (api)=>{
308
314
  api.modifyEnvironmentConfig(async (config, { mergeEnvironmentConfig, name })=>{
309
- const { normalizedConfig: { resolve, source, output, tools, performance, dev, testEnvironment }, rootPath } = context.projects.find((p)=>p.environmentName === name);
315
+ const { normalizedConfig: { resolve, source, output, tools, performance, dev, testEnvironment }, outputModule, rootPath } = context.projects.find((p)=>p.environmentName === name);
310
316
  return mergeEnvironmentConfig(config, {
311
317
  performance,
312
318
  tools,
@@ -326,6 +332,10 @@ const pluginBasic = (context)=>({
326
332
  sourceMap: {
327
333
  js: 'source-map'
328
334
  },
335
+ module: outputModule,
336
+ filename: outputModule ? {
337
+ js: '[name].mjs'
338
+ } : void 0,
329
339
  distPath: {
330
340
  root: context.projects.length > 1 ? `${TEMP_RSTEST_OUTPUT_DIR}/${name}` : TEMP_RSTEST_OUTPUT_DIR
331
341
  }
@@ -336,7 +346,7 @@ const pluginBasic = (context)=>({
336
346
  config.mode = isProd ? 'production' : 'development';
337
347
  config.output ??= {};
338
348
  config.output.iife = false;
339
- config.output.importFunctionName = '__rstest_dynamic_import__';
349
+ config.output.importFunctionName = outputModule ? 'import.meta.__rstest_dynamic_import__' : '__rstest_dynamic_import__';
340
350
  config.output.devtoolModuleFilenameTemplate = '[absolute-resource-path]';
341
351
  if (!config.devtool || !config.devtool.includes('inline')) config.devtool = 'nosources-source-map';
342
352
  config.plugins.push(new rspack.experiments.RstestPlugin({
@@ -345,6 +355,12 @@ const pluginBasic = (context)=>({
345
355
  hoistMockModule: true,
346
356
  manualMockRoot: posix.resolve(rootPath, '__mocks__')
347
357
  }));
358
+ if (outputModule) config.plugins.push(new rspack.BannerPlugin({
359
+ banner: requireShim,
360
+ stage: rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1,
361
+ raw: true,
362
+ include: /\.(js|mjs)$/
363
+ }));
348
364
  config.module.parser ??= {};
349
365
  config.module.parser.javascript = {
350
366
  importDynamic: false,
@@ -467,20 +483,20 @@ const pluginEntryWatch = ({ isWatch, globTestSourceEntries, setupFiles, context
467
483
  });
468
484
  }
469
485
  });
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');
486
+ const autoExternalNodeModules = (outputModule)=>({ context, request, dependencyType, getResolve }, callback)=>{
487
+ if (!request) return callback();
488
+ if (request.startsWith('@swc/helpers/') || request.endsWith('.wasm')) return callback();
489
+ const doExternal = (externalPath = request)=>{
490
+ callback(void 0, externalPath, 'commonjs' === dependencyType ? 'commonjs' : outputModule ? 'module-import' : 'import');
491
+ };
492
+ const resolver = getResolve?.();
493
+ if (!resolver) return callback();
494
+ resolver(context, request, (err, resolvePath)=>{
495
+ if (err) return callback(void 0, request, 'node-commonjs');
496
+ if (resolvePath && resolvePath.includes('node_modules') && !/\.(?:ts|tsx|jsx|mts|cts)$/.test(resolvePath)) return doExternal(resolvePath);
497
+ return callback();
498
+ });
475
499
  };
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
500
  function autoExternalNodeBuiltin({ request, dependencyType }, callback) {
485
501
  if (!request) return void callback();
486
502
  const isNodeBuiltin = isBuiltin(request) || ADDITIONAL_NODE_BUILTINS.some((builtin)=>{
@@ -494,11 +510,11 @@ const pluginExternal = (context)=>({
494
510
  name: 'rstest:external',
495
511
  setup: (api)=>{
496
512
  api.modifyEnvironmentConfig(async (config, { mergeEnvironmentConfig, name })=>{
497
- const { normalizedConfig: { testEnvironment } } = context.projects.find((p)=>p.environmentName === name);
513
+ const { normalizedConfig: { testEnvironment }, outputModule } = context.projects.find((p)=>p.environmentName === name);
498
514
  return mergeEnvironmentConfig(config, {
499
515
  output: {
500
516
  externals: 'node' === testEnvironment ? [
501
- autoExternalNodeModules
517
+ autoExternalNodeModules(outputModule)
502
518
  ] : void 0
503
519
  },
504
520
  tools: {
@@ -509,7 +525,7 @@ const pluginExternal = (context)=>({
509
525
  });
510
526
  config.externalsPresets ??= {};
511
527
  config.externalsPresets.node = false;
512
- config.externals.push(autoExternalNodeBuiltin);
528
+ config.externals.unshift(autoExternalNodeBuiltin);
513
529
  }
514
530
  }
515
531
  });
@@ -553,6 +569,10 @@ const pluginInspect = ()=>enable ? {
553
569
  const external_node_fs_ = __webpack_require__("node:fs");
554
570
  const mockRuntime_dirname = external_node_path_["default"].dirname(fileURLToPath(import.meta.url));
555
571
  class MockRuntimeRspackPlugin {
572
+ outputModule;
573
+ constructor(outputModule){
574
+ this.outputModule = outputModule;
575
+ }
556
576
  apply(compiler) {
557
577
  const { RuntimeModule } = compiler.webpack;
558
578
  class RetestImportRuntimeModule extends RuntimeModule {
@@ -570,12 +590,16 @@ class MockRuntimeRspackPlugin {
570
590
  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
591
  module.source.source = Buffer.from(finalSource);
572
592
  }
593
+ if ('module_chunk_loading' === module.name) {
594
+ 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;");
595
+ module.source.source = Buffer.from(finalSource);
596
+ }
573
597
  if ('define_property_getters' === module.name) {
574
598
  const finalSource = module.source.source.toString('utf-8').replace('enumerable: true, get:', 'enumerable: true, configurable: true, get:');
575
599
  module.source.source = Buffer.from(finalSource);
576
600
  }
577
601
  if ('async_wasm_loading' === module.name) {
578
- const finalSource = module.source.source.toString('utf-8').replace('readFile(', 'readWasmFile(');
602
+ const finalSource = module.source.source.toString('utf-8').replace('readFile(', this.outputModule ? 'import.meta.readWasmFile(' : 'readWasmFile(');
579
603
  module.source.source = Buffer.from(finalSource);
580
604
  }
581
605
  });
@@ -591,7 +615,7 @@ const pluginMockRuntime = {
591
615
  name: 'rstest:mock-runtime',
592
616
  setup: (api)=>{
593
617
  api.modifyRspackConfig(async (config)=>{
594
- config.plugins.push(new MockRuntimeRspackPlugin());
618
+ config.plugins.push(new MockRuntimeRspackPlugin(Boolean(config.output.module)));
595
619
  });
596
620
  }
597
621
  };
@@ -810,7 +834,8 @@ const createRsbuildServer = async ({ globTestSourceEntries, setupFiles, rsbuildI
810
834
  const readFile = async (fileName)=>new Promise((resolve, reject)=>{
811
835
  outputFileSystem.readFile(fileName, (err, data)=>{
812
836
  if (err) reject(err);
813
- resolve('string' == typeof data ? data : data.toString());
837
+ const content = 'string' == typeof data ? data : fileName.endsWith('.wasm') ? data.toString('base64') : data.toString('utf-8');
838
+ resolve(content);
814
839
  });
815
840
  });
816
841
  const buildData = {};
@@ -844,7 +869,8 @@ const createRsbuildServer = async ({ globTestSourceEntries, setupFiles, rsbuildI
844
869
  const sourceEntries = await globTestSourceEntries(environmentName);
845
870
  for (const entry of Object.keys(entrypoints)){
846
871
  const e = entrypoints[entry];
847
- const distPath = posix.join(outputPath, e.assets[e.assets.length - 1].name);
872
+ const filteredAssets = e.assets.filter((asset)=>!asset.name.endsWith('.wasm'));
873
+ const distPath = posix.join(outputPath, filteredAssets[filteredAssets.length - 1].name);
848
874
  if (setupFiles[environmentName][entry]) setupEntries.push({
849
875
  distPath,
850
876
  testPath: setupFiles[environmentName][entry],
package/dist/0~173.js CHANGED
@@ -379,12 +379,17 @@ async function runTests(context) {
379
379
  afterTestsWatchRun();
380
380
  });
381
381
  } else {
382
+ let isTeardown = false;
382
383
  const unExpectedExit = (code)=>{
383
- src_logger.log(picocolors_default().red(`Rstest exited unexpectedly with code ${code}, terminating test run.`));
384
- process.exitCode = 1;
384
+ if (isTeardown) src_logger.log(picocolors_default().yellow(`Rstest exited unexpectedly with code ${code}, this is likely caused by test environment teardown.`));
385
+ else {
386
+ src_logger.log(picocolors_default().red(`Rstest exited unexpectedly with code ${code}, terminating test run.`));
387
+ process.exitCode = 1;
388
+ }
385
389
  };
386
390
  process.on('exit', unExpectedExit);
387
391
  await run();
392
+ isTeardown = true;
388
393
  await pool.close();
389
394
  await closeServer();
390
395
  process.off('exit', unExpectedExit);
package/dist/0~346.js ADDED
@@ -0,0 +1,46 @@
1
+ import 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import node_vm from "node:vm";
4
+ const shouldInterop = ({ interopDefault = true, modulePath, mod })=>{
5
+ if (!interopDefault) return false;
6
+ return !modulePath.endsWith('.mjs') && 'default' in mod;
7
+ };
8
+ const isPrimitive = (v)=>v !== Object(v);
9
+ function interopModule(mod) {
10
+ if (isPrimitive(mod)) return {
11
+ mod: {
12
+ default: mod
13
+ },
14
+ defaultExport: mod
15
+ };
16
+ const defaultExport = 'default' in mod ? mod.default : mod;
17
+ if (!isPrimitive(defaultExport) && '__esModule' in defaultExport) return {
18
+ mod: defaultExport,
19
+ defaultExport: 'default' in defaultExport ? defaultExport.default : defaultExport
20
+ };
21
+ return {
22
+ mod,
23
+ defaultExport
24
+ };
25
+ }
26
+ const asModule = async (something, defaultExport, context, unlinked)=>{
27
+ const { Module, SyntheticModule } = await import("node:vm");
28
+ if (something instanceof Module) return something;
29
+ const exports = [
30
+ ...new Set([
31
+ 'default',
32
+ ...Object.keys(something)
33
+ ])
34
+ ];
35
+ const m = new SyntheticModule(exports, ()=>{
36
+ for (const name of exports)m.setExport(name, 'default' === name ? defaultExport : something[name]);
37
+ }, {
38
+ context
39
+ });
40
+ if (unlinked) return m;
41
+ await m.link(()=>{});
42
+ if (m.instantiate) m.instantiate();
43
+ await m.evaluate();
44
+ return m;
45
+ };
46
+ export { asModule, interopModule, node_vm, shouldInterop };
package/dist/0~835.js ADDED
@@ -0,0 +1,143 @@
1
+ import 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import { __webpack_require__ } from "./rslib-runtime.js";
4
+ import { posix, external_node_module_createRequire, src_logger } from "./946.js";
5
+ import { pathToFileURL } from "./770.js";
6
+ import { node_vm, asModule, shouldInterop, interopModule } from "./0~346.js";
7
+ const external_node_path_ = __webpack_require__("node:path");
8
+ const isRelativePath = (p)=>/^\.\.?\//.test(p);
9
+ const createRequire = (filename, distPath, rstestContext, assetFiles, interopDefault)=>{
10
+ const _require = (()=>{
11
+ try {
12
+ return external_node_module_createRequire(filename);
13
+ } catch (_err) {
14
+ return external_node_module_createRequire(distPath);
15
+ }
16
+ })();
17
+ const require = (id)=>{
18
+ const currentDirectory = posix.dirname(distPath);
19
+ const joinedPath = isRelativePath(id) ? posix.join(currentDirectory, id) : id;
20
+ const content = assetFiles[joinedPath];
21
+ if (content) try {
22
+ return cacheableLoadModule({
23
+ codeContent: content,
24
+ testPath: joinedPath,
25
+ distPath: joinedPath,
26
+ rstestContext,
27
+ assetFiles,
28
+ interopDefault
29
+ });
30
+ } catch (err) {
31
+ src_logger.error(`load file ${joinedPath} failed:\n`, err instanceof Error ? err.message : err);
32
+ }
33
+ const resolved = _require.resolve(id);
34
+ return _require(resolved);
35
+ };
36
+ require.resolve = _require.resolve;
37
+ require.main = _require.main;
38
+ return require;
39
+ };
40
+ const defineRstestDynamicImport = ({ testPath, interopDefault, returnModule = false })=>async (specifier, importAttributes)=>{
41
+ const resolvedPath = (0, external_node_path_.isAbsolute)(specifier) ? pathToFileURL(specifier) : import.meta.resolve(specifier, pathToFileURL(testPath));
42
+ const modulePath = 'string' == typeof resolvedPath ? resolvedPath : resolvedPath.pathname;
43
+ if (importAttributes?.with?.rstest) delete importAttributes.with.rstest;
44
+ if (modulePath.endsWith('.json')) {
45
+ const importedModule = await import(modulePath, {
46
+ with: {
47
+ type: 'json'
48
+ }
49
+ });
50
+ return returnModule ? asModule(importedModule.default, importedModule.default) : {
51
+ ...importedModule.default,
52
+ default: importedModule.default
53
+ };
54
+ }
55
+ const importedModule = await import(modulePath, importAttributes);
56
+ if (shouldInterop({
57
+ interopDefault,
58
+ modulePath,
59
+ mod: importedModule
60
+ })) {
61
+ const { mod, defaultExport } = interopModule(importedModule);
62
+ if (returnModule) return asModule(mod, defaultExport);
63
+ return new Proxy(mod, {
64
+ get (mod, prop) {
65
+ if ('default' === prop) return defaultExport;
66
+ return mod[prop] ?? defaultExport?.[prop];
67
+ },
68
+ has (mod, prop) {
69
+ if ('default' === prop) return void 0 !== defaultExport;
70
+ return prop in mod || defaultExport && prop in defaultExport;
71
+ },
72
+ getOwnPropertyDescriptor (mod, prop) {
73
+ const descriptor = Reflect.getOwnPropertyDescriptor(mod, prop);
74
+ if (descriptor) return descriptor;
75
+ if ('default' === prop && void 0 !== defaultExport) return {
76
+ value: defaultExport,
77
+ enumerable: true,
78
+ configurable: true
79
+ };
80
+ }
81
+ });
82
+ }
83
+ return importedModule;
84
+ };
85
+ const loadModule = ({ codeContent, distPath, testPath, rstestContext, assetFiles, interopDefault })=>{
86
+ const fileDir = posix.dirname(testPath);
87
+ const localModule = {
88
+ children: [],
89
+ exports: {},
90
+ filename: testPath,
91
+ id: testPath,
92
+ isPreloading: false,
93
+ loaded: false,
94
+ path: fileDir
95
+ };
96
+ const context = {
97
+ module: localModule,
98
+ exports: localModule.exports,
99
+ require: createRequire(testPath, distPath, rstestContext, assetFiles, interopDefault),
100
+ readWasmFile: (wasmPath, callback)=>{
101
+ const joinedPath = isRelativePath(wasmPath) ? posix.join(posix.dirname(distPath), wasmPath) : wasmPath;
102
+ const content = assetFiles[posix.normalize(joinedPath)];
103
+ if (content) callback(null, Buffer.from(content, 'base64'));
104
+ else callback(new Error(`WASM file ${joinedPath} not found in asset files.`));
105
+ },
106
+ __rstest_dynamic_import__: defineRstestDynamicImport({
107
+ testPath,
108
+ interopDefault
109
+ }),
110
+ __dirname: fileDir,
111
+ __filename: testPath,
112
+ ...rstestContext
113
+ };
114
+ const codeDefinition = `'use strict';(${Object.keys(context).join(',')})=>{`;
115
+ const code = `${codeDefinition}${codeContent}\n}`;
116
+ const fn = node_vm.runInThisContext(code, {
117
+ filename: distPath,
118
+ lineOffset: 0,
119
+ columnOffset: -codeDefinition.length,
120
+ importModuleDynamically: (specifier, _referencer, importAttributes)=>defineRstestDynamicImport({
121
+ testPath,
122
+ interopDefault,
123
+ returnModule: true
124
+ })(specifier, importAttributes)
125
+ });
126
+ fn(...Object.values(context));
127
+ return localModule.exports;
128
+ };
129
+ const moduleCache = new Map();
130
+ const cacheableLoadModule = ({ codeContent, distPath, testPath, rstestContext, assetFiles, interopDefault })=>{
131
+ if (moduleCache.has(testPath)) return moduleCache.get(testPath);
132
+ const mod = loadModule({
133
+ codeContent,
134
+ distPath,
135
+ testPath,
136
+ rstestContext,
137
+ assetFiles,
138
+ interopDefault
139
+ });
140
+ moduleCache.set(testPath, mod);
141
+ return mod;
142
+ };
143
+ export { cacheableLoadModule, loadModule };
package/dist/0~923.js ADDED
@@ -0,0 +1,149 @@
1
+ import 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import { __webpack_require__ } from "./rslib-runtime.js";
4
+ import { posix, src_logger } from "./946.js";
5
+ import { pathToFileURL } from "./770.js";
6
+ import { node_vm, interopModule, shouldInterop } from "./0~346.js";
7
+ const external_node_path_ = __webpack_require__("node:path");
8
+ var loadEsModule_EsmMode = /*#__PURE__*/ function(EsmMode) {
9
+ EsmMode[EsmMode["Unknown"] = 0] = "Unknown";
10
+ EsmMode[EsmMode["Evaluated"] = 1] = "Evaluated";
11
+ EsmMode[EsmMode["Unlinked"] = 2] = "Unlinked";
12
+ return EsmMode;
13
+ }({});
14
+ const isRelativePath = (p)=>/^\.\.?\//.test(p);
15
+ const defineRstestDynamicImport = ({ distPath, testPath, assetFiles, interopDefault, returnModule, esmMode })=>async (specifier, importAttributes)=>{
16
+ const currentDirectory = posix.dirname(distPath);
17
+ const joinedPath = isRelativePath(specifier) ? posix.join(currentDirectory, specifier) : specifier;
18
+ const content = assetFiles[joinedPath];
19
+ if (content) try {
20
+ return await loadModule({
21
+ codeContent: content,
22
+ testPath,
23
+ distPath: joinedPath,
24
+ rstestContext: {},
25
+ assetFiles,
26
+ interopDefault,
27
+ esmMode
28
+ });
29
+ } catch (err) {
30
+ src_logger.error(`load file ${joinedPath} failed:\n`, err instanceof Error ? err.message : err);
31
+ }
32
+ const resolvedPath = (0, external_node_path_.isAbsolute)(specifier) ? pathToFileURL(specifier) : import.meta.resolve(specifier, pathToFileURL(testPath));
33
+ const modulePath = 'string' == typeof resolvedPath ? resolvedPath : resolvedPath.pathname;
34
+ if (importAttributes?.with?.rstest) delete importAttributes.with.rstest;
35
+ if (modulePath.endsWith('.json')) {
36
+ const importedModule = await import(modulePath, {
37
+ with: {
38
+ type: 'json'
39
+ }
40
+ });
41
+ return returnModule ? asModule(importedModule.default) : {
42
+ ...importedModule.default,
43
+ default: importedModule.default
44
+ };
45
+ }
46
+ const importedModule = await import(modulePath, importAttributes);
47
+ if (shouldInterop({
48
+ interopDefault,
49
+ modulePath,
50
+ mod: importedModule
51
+ }) && !modulePath.startsWith('node:')) {
52
+ const { mod, defaultExport } = interopModule(importedModule);
53
+ if (returnModule) return asModule(mod);
54
+ return new Proxy(mod, {
55
+ get (mod, prop) {
56
+ if ('default' === prop) return defaultExport;
57
+ return mod[prop] ?? defaultExport?.[prop];
58
+ },
59
+ has (mod, prop) {
60
+ if ('default' === prop) return void 0 !== defaultExport;
61
+ return prop in mod || defaultExport && prop in defaultExport;
62
+ },
63
+ getOwnPropertyDescriptor (mod, prop) {
64
+ const descriptor = Reflect.getOwnPropertyDescriptor(mod, prop);
65
+ if (descriptor) return descriptor;
66
+ if ('default' === prop && void 0 !== defaultExport) return {
67
+ value: defaultExport,
68
+ enumerable: true,
69
+ configurable: true
70
+ };
71
+ }
72
+ });
73
+ }
74
+ return importedModule;
75
+ };
76
+ const asModule = async (something, context, unlinked)=>{
77
+ const { Module, SyntheticModule } = await import("node:vm");
78
+ if (something instanceof Module) return something;
79
+ const exports = [
80
+ ...new Set([
81
+ 'default',
82
+ ...Object.keys(something)
83
+ ])
84
+ ];
85
+ const syntheticModule = new SyntheticModule(exports, ()=>{
86
+ for (const name of exports)syntheticModule.setExport(name, 'default' === name ? something[name] ?? something : something[name]);
87
+ }, {
88
+ context
89
+ });
90
+ if (unlinked) return syntheticModule;
91
+ await syntheticModule.link(()=>{});
92
+ await syntheticModule.evaluate();
93
+ return syntheticModule;
94
+ };
95
+ const esmCache = new Map();
96
+ const loadModule = async ({ codeContent, distPath, testPath, assetFiles, interopDefault, esmMode = 0 })=>{
97
+ const code = codeContent;
98
+ let esm = esmCache.get(distPath);
99
+ if (!esm) {
100
+ esm = new node_vm.SourceTextModule(code, {
101
+ identifier: distPath,
102
+ lineOffset: 0,
103
+ columnOffset: 0,
104
+ initializeImportMeta: (meta)=>{
105
+ meta.url = pathToFileURL(distPath.endsWith('rstest-runtime.mjs') ? distPath : testPath).toString();
106
+ meta.__rstest_dynamic_import__ = defineRstestDynamicImport({
107
+ assetFiles,
108
+ testPath,
109
+ distPath: distPath || testPath,
110
+ interopDefault,
111
+ returnModule: false,
112
+ esmMode: 0
113
+ });
114
+ meta.readWasmFile = (wasmPath, callback)=>{
115
+ const joinedPath = isRelativePath(wasmPath.pathname) ? posix.join(posix.dirname(distPath), wasmPath.pathname) : wasmPath.pathname;
116
+ const content = assetFiles[posix.normalize(joinedPath)];
117
+ if (content) callback(null, Buffer.from(content, 'base64'));
118
+ else callback(new Error(`WASM file ${joinedPath} not found in asset files.`));
119
+ };
120
+ },
121
+ importModuleDynamically: (specifier, _referencer, importAttributes)=>defineRstestDynamicImport({
122
+ assetFiles,
123
+ testPath,
124
+ distPath: distPath || testPath,
125
+ interopDefault,
126
+ returnModule: true,
127
+ esmMode: 2
128
+ })(specifier, importAttributes)
129
+ });
130
+ distPath && esmCache.set(distPath, esm);
131
+ }
132
+ if (2 === esmMode) return esm;
133
+ if ('unlinked' === esm.status) await esm.link(async (specifier, referencingModule)=>{
134
+ const result = await defineRstestDynamicImport({
135
+ assetFiles,
136
+ testPath,
137
+ distPath: distPath || testPath,
138
+ interopDefault,
139
+ returnModule: true,
140
+ esmMode: 2
141
+ })(specifier, referencingModule);
142
+ const linkedModule = await asModule(result, referencingModule.context, true);
143
+ return linkedModule;
144
+ });
145
+ 'evaluated' !== esm.status && 'evaluating' !== esm.status && await esm.evaluate();
146
+ const ns = esm.namespace;
147
+ return ns.default && ns.default instanceof Promise ? ns.default : ns;
148
+ };
149
+ export { asModule, loadEsModule_EsmMode, loadModule };
package/dist/155.js CHANGED
@@ -500,7 +500,7 @@ function prepareCli() {
500
500
  if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
501
501
  }
502
502
  function showRstest() {
503
- src_logger.greet(" Rstest v0.6.9");
503
+ src_logger.greet(" Rstest v0.7.1");
504
504
  src_logger.log('');
505
505
  }
506
506
  const applyCommonOptions = (cli)=>{
@@ -544,7 +544,7 @@ const runRest = async ({ options, filters, command })=>{
544
544
  function setupCommands() {
545
545
  const cli = dist('rstest');
546
546
  cli.help();
547
- cli.version("0.6.9");
547
+ cli.version("0.7.1");
548
548
  applyCommonOptions(cli);
549
549
  cli.command('[...filters]', 'run tests').option('-w, --watch', 'Run tests in watch mode').action(async (filters, options)=>{
550
550
  showRstest();
@@ -2169,6 +2169,7 @@ const stackIgnores = [
2169
2169
  /node_modules\/@vitest\/snapshot/,
2170
2170
  /node:\w+/,
2171
2171
  /webpack\/runtime/,
2172
+ /rstest runtime/,
2172
2173
  /webpack\\runtime/,
2173
2174
  '<anonymous>'
2174
2175
  ];
@@ -2427,7 +2428,7 @@ class Rstest {
2427
2428
  });
2428
2429
  this.reporters = reporters;
2429
2430
  this.snapshotManager = snapshotManager;
2430
- this.version = "0.6.9";
2431
+ this.version = "0.7.1";
2431
2432
  this.rootPath = rootPath;
2432
2433
  this.originalConfig = userConfig;
2433
2434
  this.normalizedConfig = rstestConfig;
@@ -2447,6 +2448,7 @@ class Rstest {
2447
2448
  configFilePath: project.configFilePath,
2448
2449
  rootPath: config.root,
2449
2450
  name: config.name,
2451
+ outputModule: config.output?.module ?? 'true' === process.env.RSTEST_OUTPUT_MODULE,
2450
2452
  environmentName: formatEnvironmentName(config.name),
2451
2453
  normalizedConfig: config
2452
2454
  };
@@ -2455,6 +2457,7 @@ class Rstest {
2455
2457
  configFilePath,
2456
2458
  rootPath,
2457
2459
  name: rstestConfig.name,
2460
+ outputModule: rstestConfig.output?.module ?? 'true' === process.env.RSTEST_OUTPUT_MODULE,
2458
2461
  environmentName: formatEnvironmentName(rstestConfig.name),
2459
2462
  normalizedConfig: rstestConfig
2460
2463
  }
package/dist/362.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /*! For license information please see 362.js.LICENSE.txt */
2
2
  import __rslib_shim_module__ from 'module';
3
3
  const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
4
+ "use strict";
4
5
  import { __webpack_require__ } from "./rslib-runtime.js";
5
- import node_vm from "node:vm";
6
- import { basename, globalApis, posix, external_node_module_createRequire, dirname, resolve as pathe_M_eThtNZ_resolve, undoSerializableConfig, src_logger, isAbsolute, join } from "./946.js";
7
- import { node_v8, pathToFileURL, createBirpc } from "./770.js";
6
+ import { basename, globalApis, dirname, external_node_module_createRequire, resolve as pathe_M_eThtNZ_resolve, undoSerializableConfig, isAbsolute, join } from "./946.js";
7
+ import { node_v8, createBirpc } from "./770.js";
8
8
  import { createCoverageProvider } from "./734.js";
9
9
  __webpack_require__.add({
10
10
  "../../node_modules/.pnpm/@jest+diff-sequences@30.0.1/node_modules/@jest/diff-sequences/build/index.js": function(module) {
@@ -6710,184 +6710,6 @@ function checkPkgInstalled(name) {
6710
6710
  throw error;
6711
6711
  }
6712
6712
  }
6713
- const shouldInterop = ({ interopDefault = true, modulePath, mod })=>{
6714
- if (!interopDefault) return false;
6715
- return !modulePath.endsWith('.mjs') && 'default' in mod;
6716
- };
6717
- const isPrimitive = (v)=>v !== Object(v);
6718
- function interopModule(mod) {
6719
- if (isPrimitive(mod)) return {
6720
- mod: {
6721
- default: mod
6722
- },
6723
- defaultExport: mod
6724
- };
6725
- const defaultExport = 'default' in mod ? mod.default : mod;
6726
- if (!isPrimitive(defaultExport) && '__esModule' in defaultExport) return {
6727
- mod: defaultExport,
6728
- defaultExport: 'default' in defaultExport ? defaultExport.default : defaultExport
6729
- };
6730
- return {
6731
- mod,
6732
- defaultExport
6733
- };
6734
- }
6735
- const asModule = async (something, defaultExport, context, unlinked)=>{
6736
- const { Module, SyntheticModule } = await import("node:vm");
6737
- if (something instanceof Module) return something;
6738
- const exports = [
6739
- ...new Set([
6740
- 'default',
6741
- ...Object.keys(something)
6742
- ])
6743
- ];
6744
- const m = new SyntheticModule(exports, ()=>{
6745
- for (const name of exports)m.setExport(name, 'default' === name ? defaultExport : something[name]);
6746
- }, {
6747
- context
6748
- });
6749
- if (unlinked) return m;
6750
- await m.link(()=>{});
6751
- if (m.instantiate) m.instantiate();
6752
- await m.evaluate();
6753
- return m;
6754
- };
6755
- const external_node_path_ = __webpack_require__("node:path");
6756
- const isRelativePath = (p)=>/^\.\.?\//.test(p);
6757
- const createRequire = (filename, distPath, rstestContext, assetFiles, interopDefault)=>{
6758
- const _require = (()=>{
6759
- try {
6760
- return external_node_module_createRequire(filename);
6761
- } catch (_err) {
6762
- return external_node_module_createRequire(distPath);
6763
- }
6764
- })();
6765
- const require = (id)=>{
6766
- const currentDirectory = posix.dirname(distPath);
6767
- const joinedPath = isRelativePath(id) ? posix.join(currentDirectory, id) : id;
6768
- const content = assetFiles[joinedPath];
6769
- if (content) try {
6770
- return cacheableLoadModule({
6771
- codeContent: content,
6772
- testPath: joinedPath,
6773
- distPath: joinedPath,
6774
- rstestContext,
6775
- assetFiles,
6776
- interopDefault
6777
- });
6778
- } catch (err) {
6779
- src_logger.error(`load file ${joinedPath} failed:\n`, err instanceof Error ? err.message : err);
6780
- }
6781
- const resolved = _require.resolve(id);
6782
- return _require(resolved);
6783
- };
6784
- require.resolve = _require.resolve;
6785
- require.main = _require.main;
6786
- return require;
6787
- };
6788
- const defineRstestDynamicImport = ({ testPath, interopDefault, returnModule = false })=>async (specifier, importAttributes)=>{
6789
- const resolvedPath = (0, external_node_path_.isAbsolute)(specifier) ? pathToFileURL(specifier) : import.meta.resolve(specifier, pathToFileURL(testPath));
6790
- const modulePath = 'string' == typeof resolvedPath ? resolvedPath : resolvedPath.pathname;
6791
- if (importAttributes?.with?.rstest) delete importAttributes.with.rstest;
6792
- if (modulePath.endsWith('.json')) {
6793
- const importedModule = await import(modulePath, {
6794
- with: {
6795
- type: 'json'
6796
- }
6797
- });
6798
- return returnModule ? asModule(importedModule.default, importedModule.default) : {
6799
- ...importedModule.default,
6800
- default: importedModule.default
6801
- };
6802
- }
6803
- const importedModule = await import(modulePath, importAttributes);
6804
- if (shouldInterop({
6805
- interopDefault,
6806
- modulePath,
6807
- mod: importedModule
6808
- })) {
6809
- const { mod, defaultExport } = interopModule(importedModule);
6810
- if (returnModule) return asModule(mod, defaultExport);
6811
- return new Proxy(mod, {
6812
- get (mod, prop) {
6813
- if ('default' === prop) return defaultExport;
6814
- return mod[prop] ?? defaultExport?.[prop];
6815
- },
6816
- has (mod, prop) {
6817
- if ('default' === prop) return void 0 !== defaultExport;
6818
- return prop in mod || defaultExport && prop in defaultExport;
6819
- },
6820
- getOwnPropertyDescriptor (mod, prop) {
6821
- const descriptor = Reflect.getOwnPropertyDescriptor(mod, prop);
6822
- if (descriptor) return descriptor;
6823
- if ('default' === prop && void 0 !== defaultExport) return {
6824
- value: defaultExport,
6825
- enumerable: true,
6826
- configurable: true
6827
- };
6828
- }
6829
- });
6830
- }
6831
- return importedModule;
6832
- };
6833
- const loadModule = ({ codeContent, distPath, testPath, rstestContext, assetFiles, interopDefault })=>{
6834
- const fileDir = posix.dirname(testPath);
6835
- const localModule = {
6836
- children: [],
6837
- exports: {},
6838
- filename: testPath,
6839
- id: testPath,
6840
- isPreloading: false,
6841
- loaded: false,
6842
- path: fileDir
6843
- };
6844
- const context = {
6845
- module: localModule,
6846
- exports: localModule.exports,
6847
- require: createRequire(testPath, distPath, rstestContext, assetFiles, interopDefault),
6848
- readWasmFile: (wasmPath, callback)=>{
6849
- const joinedPath = isRelativePath(wasmPath) ? posix.join(posix.dirname(distPath), wasmPath) : wasmPath;
6850
- const content = assetFiles[posix.normalize(joinedPath)];
6851
- if (content) callback(null, Buffer.from(content, 'utf-8'));
6852
- else callback(new Error(`WASM file ${joinedPath} not found in asset files.`));
6853
- },
6854
- __rstest_dynamic_import__: defineRstestDynamicImport({
6855
- testPath,
6856
- interopDefault
6857
- }),
6858
- __dirname: fileDir,
6859
- __filename: testPath,
6860
- ...rstestContext
6861
- };
6862
- const codeDefinition = `'use strict';(${Object.keys(context).join(',')})=>{`;
6863
- const code = `${codeDefinition}${codeContent}\n}`;
6864
- const fn = node_vm.runInThisContext(code, {
6865
- filename: distPath,
6866
- lineOffset: 0,
6867
- columnOffset: -codeDefinition.length,
6868
- importModuleDynamically: (specifier, _referencer, importAttributes)=>defineRstestDynamicImport({
6869
- testPath,
6870
- interopDefault,
6871
- returnModule: true
6872
- })(specifier, importAttributes)
6873
- });
6874
- fn(...Object.values(context));
6875
- return localModule.exports;
6876
- };
6877
- const moduleCache = new Map();
6878
- const cacheableLoadModule = ({ codeContent, distPath, testPath, rstestContext, assetFiles, interopDefault })=>{
6879
- if (moduleCache.has(testPath)) return moduleCache.get(testPath);
6880
- const mod = loadModule({
6881
- codeContent,
6882
- distPath,
6883
- testPath,
6884
- rstestContext,
6885
- assetFiles,
6886
- interopDefault
6887
- });
6888
- moduleCache.set(testPath, mod);
6889
- return mod;
6890
- };
6891
6713
  const processSend = process.send.bind(process);
6892
6714
  const processOn = process.on.bind(process);
6893
6715
  const processOff = process.off.bind(process);
@@ -6992,6 +6814,8 @@ const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.
6992
6814
  var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
6993
6815
  let sourceMaps = {};
6994
6816
  (0, source_map_support.install)({
6817
+ environment: 'node',
6818
+ handleUncaughtExceptions: false,
6995
6819
  retrieveSourceMap: (source)=>{
6996
6820
  if (sourceMaps[source]) return {
6997
6821
  url: source,
@@ -7115,12 +6939,20 @@ const preparePool = async ({ entryInfo: { distPath, testPath }, updateSnapshot,
7115
6939
  }
7116
6940
  };
7117
6941
  };
7118
- const loadFiles = async ({ setupEntries, assetFiles, rstestContext, distPath, testPath, interopDefault, isolate })=>{
6942
+ const loadFiles = async ({ setupEntries, assetFiles, rstestContext, distPath, testPath, interopDefault, isolate, outputModule })=>{
6943
+ const { loadModule } = outputModule ? await import("./0~923.js").then((mod)=>({
6944
+ EsmMode: mod.loadEsModule_EsmMode,
6945
+ asModule: mod.asModule,
6946
+ loadModule: mod.loadModule
6947
+ })) : await import("./0~835.js").then((mod)=>({
6948
+ cacheableLoadModule: mod.cacheableLoadModule,
6949
+ loadModule: mod.loadModule
6950
+ }));
7119
6951
  if (!isolate) await loadModule({
7120
6952
  codeContent: `if (global && typeof global.__rstest_clean_core_cache__ === 'function') {
7121
6953
  global.__rstest_clean_core_cache__();
7122
6954
  }`,
7123
- distPath,
6955
+ distPath: '',
7124
6956
  testPath,
7125
6957
  rstestContext,
7126
6958
  assetFiles,
@@ -7180,7 +7012,8 @@ const runInPool = async (options)=>{
7180
7012
  assetFiles,
7181
7013
  setupEntries,
7182
7014
  interopDefault,
7183
- isolate
7015
+ isolate,
7016
+ outputModule: options.context.outputModule
7184
7017
  });
7185
7018
  const tests = await runner.collectTests();
7186
7019
  return {
@@ -7224,7 +7057,8 @@ const runInPool = async (options)=>{
7224
7057
  assetFiles,
7225
7058
  setupEntries,
7226
7059
  interopDefault,
7227
- isolate
7060
+ isolate,
7061
+ outputModule: options.context.outputModule
7228
7062
  });
7229
7063
  const results = await runner.runTests(testPath, {
7230
7064
  onTestCaseStart: async (test)=>{
package/dist/index.d.ts CHANGED
@@ -2042,6 +2042,8 @@ declare type ProjectContext = {
2042
2042
  environmentName: string;
2043
2043
  /** The root path of current project. */
2044
2044
  rootPath: string;
2045
+ /** Whether to output es module. */
2046
+ outputModule: boolean;
2045
2047
  configFilePath?: string;
2046
2048
  normalizedConfig: NormalizedProjectConfig;
2047
2049
  };
@@ -2363,7 +2365,7 @@ export declare interface RstestConfig {
2363
2365
  source?: Pick<NonNullable<RsbuildConfig['source']>, 'define' | 'tsconfigPath' | 'decorators' | 'include' | 'exclude'>;
2364
2366
  performance?: Pick<NonNullable<RsbuildConfig['performance']>, 'bundleAnalyze'>;
2365
2367
  dev?: Pick<NonNullable<RsbuildConfig['dev']>, 'writeToDisk'>;
2366
- output?: Pick<NonNullable<RsbuildConfig['output']>, 'cssModules' | 'externals' | 'cleanDistPath'>;
2368
+ output?: Pick<NonNullable<RsbuildConfig['output']>, 'cssModules' | 'externals' | 'cleanDistPath' | 'module'>;
2367
2369
  resolve?: RsbuildConfig['resolve'];
2368
2370
  tools?: Pick<NonNullable<RsbuildConfig['tools']>, 'rspack' | 'swc' | 'bundlerChain'>;
2369
2371
  }
package/dist/worker.d.ts CHANGED
@@ -1688,6 +1688,8 @@ declare type ProjectContext = {
1688
1688
  environmentName: string;
1689
1689
  /** The root path of current project. */
1690
1690
  rootPath: string;
1691
+ /** Whether to output es module. */
1692
+ outputModule: boolean;
1691
1693
  configFilePath?: string;
1692
1694
  normalizedConfig: NormalizedProjectConfig;
1693
1695
  };
@@ -1996,7 +1998,7 @@ declare interface RstestConfig {
1996
1998
  source?: Pick<NonNullable<RsbuildConfig['source']>, 'define' | 'tsconfigPath' | 'decorators' | 'include' | 'exclude'>;
1997
1999
  performance?: Pick<NonNullable<RsbuildConfig['performance']>, 'bundleAnalyze'>;
1998
2000
  dev?: Pick<NonNullable<RsbuildConfig['dev']>, 'writeToDisk'>;
1999
- output?: Pick<NonNullable<RsbuildConfig['output']>, 'cssModules' | 'externals' | 'cleanDistPath'>;
2001
+ output?: Pick<NonNullable<RsbuildConfig['output']>, 'cssModules' | 'externals' | 'cleanDistPath' | 'module'>;
2000
2002
  resolve?: RsbuildConfig['resolve'];
2001
2003
  tools?: Pick<NonNullable<RsbuildConfig['tools']>, 'rspack' | 'swc' | 'bundlerChain'>;
2002
2004
  }
@@ -2553,6 +2555,7 @@ declare type WorkerContext = {
2553
2555
  project: string;
2554
2556
  runtimeConfig: RuntimeConfig;
2555
2557
  taskId: number;
2558
+ outputModule: boolean;
2556
2559
  };
2557
2560
 
2558
2561
  declare type XInput = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstest/core",
3
- "version": "0.6.9",
3
+ "version": "0.7.1",
4
4
  "description": "The Rsbuild-based test tool.",
5
5
  "bugs": {
6
6
  "url": "https://github.com/web-infra-dev/rstest/issues"
@@ -47,7 +47,7 @@
47
47
  ],
48
48
  "dependencies": {
49
49
  "@types/chai": "^5.2.3",
50
- "@rsbuild/core": "1.6.0-beta.1",
50
+ "@rsbuild/core": "1.6.12-canary-20251204065915",
51
51
  "tinypool": "^1.1.1"
52
52
  },
53
53
  "devDependencies": {