@rspack-canary/test-tools 1.6.0-canary-beafb11e-20251019174144 → 1.6.0-canary-0eb13821-20251021173640

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.
Files changed (39) hide show
  1. package/dist/case/cache.js +3 -0
  2. package/dist/case/common.d.ts +1 -0
  3. package/dist/case/common.js +15 -12
  4. package/dist/case/config.js +4 -1
  5. package/dist/case/esm-output.js +28 -2
  6. package/dist/case/hot.d.ts +1 -1
  7. package/dist/case/hot.js +4 -3
  8. package/dist/case/incremental.d.ts +1 -1
  9. package/dist/case/incremental.js +1 -20
  10. package/dist/case/normal.js +3 -0
  11. package/dist/case/runner.d.ts +1 -1
  12. package/dist/case/runner.js +4 -3
  13. package/dist/case/watch.d.ts +3 -1
  14. package/dist/case/watch.js +5 -4
  15. package/dist/helper/hot-update/plugin.js +1 -1
  16. package/dist/helper/legacy/asModule.js +0 -2
  17. package/dist/helper/legacy/createLazyTestEnv.d.ts +1 -0
  18. package/dist/helper/legacy/createLazyTestEnv.js +3 -1
  19. package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
  20. package/dist/helper/legacy/supportsTextDecoder.js +9 -0
  21. package/dist/helper/setup-env.js +15 -0
  22. package/dist/runner/node/index.js +7 -3
  23. package/dist/runner/web/index.d.ts +20 -7
  24. package/dist/runner/web/index.js +293 -18
  25. package/dist/test/creator.js +13 -7
  26. package/dist/test/tester.d.ts +1 -0
  27. package/dist/test/tester.js +5 -0
  28. package/dist/type.d.ts +5 -5
  29. package/dist/type.js +1 -6
  30. package/jest.d.ts +2 -0
  31. package/package.json +3 -3
  32. package/dist/helper/legacy/FakeDocument.d.ts +0 -54
  33. package/dist/helper/legacy/FakeDocument.js +0 -280
  34. package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
  35. package/dist/helper/legacy/walkCssTokens.js +0 -761
  36. package/dist/runner/web/fake.d.ts +0 -15
  37. package/dist/runner/web/fake.js +0 -215
  38. package/dist/runner/web/jsdom.d.ts +0 -24
  39. package/dist/runner/web/jsdom.js +0 -241
@@ -40,6 +40,9 @@ function createCacheProcessor(name, src, temp, target) {
40
40
  check: async (env, context) => {
41
41
  await (0, common_1.check)(env, context, name);
42
42
  },
43
+ after: async (context) => {
44
+ await (0, common_1.afterExecute)(context, name);
45
+ },
43
46
  afterAll: async (context) => {
44
47
  const updateIndex = updatePlugin.getUpdateIndex();
45
48
  const totalUpdates = updatePlugin.getTotalUpdates();
@@ -6,5 +6,6 @@ export declare function build<T extends ECompilerType = ECompilerType.Rspack>(co
6
6
  export declare function run<T extends ECompilerType = ECompilerType.Rspack>(env: ITestEnv, context: ITestContext, name: string, findBundle: (context: ITestContext, options: TCompilerOptions<T>) => string[] | string | void): Promise<void>;
7
7
  export declare function check<T extends ECompilerType = ECompilerType.Rspack>(env: ITestEnv, context: ITestContext, name: string): Promise<void>;
8
8
  export declare function checkSnapshot<T extends ECompilerType = ECompilerType.Rspack>(env: ITestEnv, context: ITestContext, name: string, snapshot: string, filter?: (file: string) => boolean): Promise<void>;
9
+ export declare function afterExecute(context: ITestContext, name: string): Promise<void>;
9
10
  export declare function findMultiCompilerBundle<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, multiFindBundle: (index: number, context: ITestContext, options: TCompilerOptions<T>) => string[] | string | void): string[];
10
11
  export declare function configMultiCompiler<T extends ECompilerType = ECompilerType.Rspack>(context: ITestContext, name: string, configFiles: string[], defaultOptions: (index: number, context: ITestContext) => TCompilerOptions<T>, overrideOptions: (index: number, context: ITestContext, options: TCompilerOptions<T>) => void): void;
@@ -10,6 +10,7 @@ exports.build = build;
10
10
  exports.run = run;
11
11
  exports.check = check;
12
12
  exports.checkSnapshot = checkSnapshot;
13
+ exports.afterExecute = afterExecute;
13
14
  exports.findMultiCompilerBundle = findMultiCompilerBundle;
14
15
  exports.configMultiCompiler = configMultiCompiler;
15
16
  const fs_extra_1 = __importDefault(require("fs-extra"));
@@ -45,9 +46,6 @@ async function run(env, context, name, findBundle) {
45
46
  const testConfig = context.getTestConfig();
46
47
  if (testConfig.noTests)
47
48
  return;
48
- if (testConfig.documentType) {
49
- context.setValue(name, "documentType", testConfig.documentType);
50
- }
51
49
  const compiler = getCompiler(context, name);
52
50
  if (typeof testConfig.beforeExecute === "function") {
53
51
  testConfig.beforeExecute(compiler.getOptions());
@@ -80,13 +78,6 @@ async function run(env, context, name, findBundle) {
80
78
  }
81
79
  const results = context.getValue(name, "modules") || [];
82
80
  await Promise.all(results);
83
- if (typeof testConfig.afterExecute === "function") {
84
- let options = compiler.getOptions();
85
- if (Array.isArray(options) && options.length === 1) {
86
- options = options[0];
87
- }
88
- testConfig.afterExecute(options);
89
- }
90
81
  }
91
82
  async function check(env, context, name) {
92
83
  const testConfig = context.getTestConfig();
@@ -175,16 +166,28 @@ async function checkSnapshot(env, context, name, snapshot, filter) {
175
166
  if (testConfig.snapshotContent) {
176
167
  content = testConfig.snapshotContent(content);
177
168
  }
178
- return `\`\`\`${tag} title=${file}\n${content}\n\`\`\``;
169
+ const filePath = file.replaceAll(path_1.default.sep, "/");
170
+ return `\`\`\`${tag} title=${filePath}\n${content}\n\`\`\``;
179
171
  });
180
172
  fileContents.sort();
181
173
  const content = fileContents.join("\n\n");
182
174
  const snapshotPath = path_1.default.isAbsolute(snapshot)
183
175
  ? snapshot
184
- : path_1.default.resolve(context.getSource(), `./__snapshots__/${snapshot}${total > 1 ? `-${i}` : ""}`);
176
+ : path_1.default.resolve(context.getSource(), path_1.default.join("__snapshots__", `${snapshot}${total > 1 ? `-${i}` : ""}`));
185
177
  env.expect(content).toMatchFileSnapshot(snapshotPath);
186
178
  }
187
179
  }
180
+ async function afterExecute(context, name) {
181
+ const compiler = getCompiler(context, name);
182
+ const testConfig = context.getTestConfig();
183
+ if (typeof testConfig.afterExecute === "function") {
184
+ let options = compiler.getOptions();
185
+ if (Array.isArray(options) && options.length === 1) {
186
+ options = options[0];
187
+ }
188
+ testConfig.afterExecute(options);
189
+ }
190
+ }
188
191
  function findMultiCompilerBundle(context, name, multiFindBundle) {
189
192
  if (typeof multiFindBundle !== "function") {
190
193
  return [];
@@ -30,6 +30,9 @@ function createConfigProcessor(name) {
30
30
  },
31
31
  check: async (env, context) => {
32
32
  await (0, common_1.check)(env, context, name);
33
+ },
34
+ after: async (context) => {
35
+ await (0, common_1.afterExecute)(context, name);
33
36
  }
34
37
  };
35
38
  }
@@ -115,7 +118,7 @@ function findBundle(index, context, options) {
115
118
  options.output?.cssFilename) ||
116
119
  `bundle${index}.css`);
117
120
  if (fs_extra_1.default.existsSync(cssOutputPath)) {
118
- bundlePath.push(`./bundle${index}.css`);
121
+ bundlePath.push(path_1.default.relative(options.output.path, cssOutputPath));
119
122
  }
120
123
  }
121
124
  bundlePath.push(`./bundle${index}${ext}`);
@@ -25,7 +25,26 @@ const creator = new creator_1.BasicCaseCreator({
25
25
  steps: ({ name }) => [
26
26
  {
27
27
  config: async (context) => {
28
- (0, common_1.configMultiCompiler)(context, name, ["rspack.config.cjs", "rspack.config.js", "webpack.config.js"], defaultOptions, () => { });
28
+ (0, common_1.configMultiCompiler)(context, name, ["rspack.config.cjs", "rspack.config.js", "webpack.config.js"], defaultOptions, (_index, context, options) => {
29
+ const testConfig = context.getTestConfig();
30
+ if (testConfig.esmLibPluginOptions) {
31
+ let target;
32
+ const otherPlugins = options.plugins?.filter(plugin => {
33
+ const isTarget = plugin instanceof core_1.default.experiments.EsmLibraryPlugin;
34
+ if (isTarget) {
35
+ target = plugin;
36
+ }
37
+ return !isTarget;
38
+ });
39
+ options.plugins = [
40
+ ...otherPlugins,
41
+ new core_1.default.experiments.EsmLibraryPlugin({
42
+ ...target.options,
43
+ ...testConfig.esmLibPluginOptions
44
+ })
45
+ ];
46
+ }
47
+ });
29
48
  },
30
49
  compiler: async (context) => {
31
50
  await (0, common_1.compiler)(context, name);
@@ -34,7 +53,11 @@ const creator = new creator_1.BasicCaseCreator({
34
53
  await (0, common_1.build)(context, name);
35
54
  },
36
55
  run: async (env, context) => {
37
- await (0, common_1.run)(env, context, name, (context) => (0, common_1.findMultiCompilerBundle)(context, name, (_index, _context, options) => {
56
+ await (0, common_1.run)(env, context, name, (context) => (0, common_1.findMultiCompilerBundle)(context, name, (_index, context, options) => {
57
+ const testConfig = context.getTestConfig();
58
+ if (typeof testConfig.findBundle === "function") {
59
+ return testConfig.findBundle(_index, options);
60
+ }
38
61
  if (options.output?.filename === "[name].mjs") {
39
62
  return ["main.mjs"];
40
63
  }
@@ -46,6 +69,9 @@ const creator = new creator_1.BasicCaseCreator({
46
69
  check: async (env, context) => {
47
70
  await (0, common_1.check)(env, context, name);
48
71
  await (0, common_1.checkSnapshot)(env, context, name, "esm.snap.txt");
72
+ },
73
+ after: async (context) => {
74
+ await (0, common_1.afterExecute)(context, name);
49
75
  }
50
76
  }
51
77
  ],
@@ -1,5 +1,5 @@
1
1
  import { HotUpdatePlugin } from "../helper/hot-update/plugin";
2
- import { type ECompilerType, type ITestContext, type ITestEnv, type ITestProcessor, type ITestRunner, type TCompilerOptions } from "../type";
2
+ import type { ECompilerType, ITestContext, ITestEnv, ITestProcessor, ITestRunner, TCompilerOptions } from "../type";
3
3
  type TTarget = TCompilerOptions<ECompilerType.Rspack>["target"];
4
4
  export declare function createHotProcessor(name: string, src: string, temp: string, target: TTarget, incremental?: boolean): THotProcessor;
5
5
  export declare function createHotCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
package/dist/case/hot.js CHANGED
@@ -14,7 +14,6 @@ const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkA
14
14
  const plugin_2 = require("../plugin");
15
15
  const runner_1 = require("../runner");
16
16
  const creator_1 = require("../test/creator");
17
- const type_1 = require("../type");
18
17
  const common_1 = require("./common");
19
18
  const runner_2 = require("./runner");
20
19
  const creators = new Map();
@@ -48,6 +47,9 @@ function createHotProcessor(name, src, temp, target, incremental = false) {
48
47
  check: async (env, context) => {
49
48
  await (0, common_1.check)(env, context, name);
50
49
  },
50
+ after: async (context) => {
51
+ await (0, common_1.afterExecute)(context, name);
52
+ },
51
53
  afterAll: async (context) => {
52
54
  if (context.getTestConfig().checkSteps === false) {
53
55
  return;
@@ -205,7 +207,6 @@ function createHotRunner(context, name, file, env) {
205
207
  name: name,
206
208
  runInNewContext: false,
207
209
  testConfig: {
208
- documentType: testConfig.documentType || type_1.EDocumentType.JSDOM,
209
210
  ...testConfig,
210
211
  moduleScope(ms, stats, options) {
211
212
  const moduleScope = ms;
@@ -225,7 +226,7 @@ function createHotRunner(context, name, file, env) {
225
226
  if (compilerOptions.target === "web" ||
226
227
  compilerOptions.target === "webworker") {
227
228
  runner = new runner_1.WebRunner({
228
- dom: context.getValue(name, "documentType") || type_1.EDocumentType.JSDOM,
229
+ location: testConfig.location || "https://test.cases/path/index.html",
229
230
  ...commonOptions
230
231
  });
231
232
  }
@@ -1,4 +1,4 @@
1
- import { type ECompilerType, type TCompilerOptions } from "../type";
1
+ import type { ECompilerType, TCompilerOptions } from "../type";
2
2
  export declare function createHotIncrementalCase(name: string, src: string, dist: string, temp: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], webpackCases: boolean): void;
3
3
  export type WatchIncrementalOptions = {
4
4
  ignoreNotFriendlyForIncrementalWarnings?: boolean;
@@ -8,30 +8,11 @@ exports.createWatchIncrementalCase = createWatchIncrementalCase;
8
8
  const node_fs_1 = __importDefault(require("node:fs"));
9
9
  const node_path_1 = __importDefault(require("node:path"));
10
10
  const creator_1 = require("../test/creator");
11
- const type_1 = require("../type");
12
11
  const hot_1 = require("./hot");
13
12
  const watch_1 = require("./watch");
14
13
  const hotCreators = new Map();
15
14
  function createHotIncrementalProcessor(name, src, temp, target, webpackCases) {
16
- const processor = (0, hot_1.createHotProcessor)(name, src, temp, target, true);
17
- const originalBefore = processor.before;
18
- processor.before = async (context) => {
19
- await originalBefore?.(context);
20
- context.setValue(name, "documentType", webpackCases ? type_1.EDocumentType.JSDOM : type_1.EDocumentType.JSDOM);
21
- };
22
- const originalAfterAll = processor.afterAll;
23
- processor.afterAll = async function (context) {
24
- try {
25
- await originalAfterAll?.(context);
26
- }
27
- catch (e) {
28
- const isFake = context.getValue(name, "documentType") === type_1.EDocumentType.Fake;
29
- if (isFake && /Should run all hot steps/.test(e.message))
30
- return;
31
- throw e;
32
- }
33
- };
34
- return processor;
15
+ return (0, hot_1.createHotProcessor)(name, src, temp, target, true);
35
16
  }
36
17
  function getHotCreator(target, webpackCases) {
37
18
  const key = JSON.stringify({ target, webpackCases });
@@ -40,6 +40,9 @@ const createCaseOptions = (hot, mode) => {
40
40
  },
41
41
  check: async (env, context) => {
42
42
  await (0, common_1.check)(env, context, name);
43
+ },
44
+ after: async (context) => {
45
+ await (0, common_1.afterExecute)(context, name);
43
46
  }
44
47
  }
45
48
  ],
@@ -1,4 +1,4 @@
1
- import { type ECompilerType, type ITestContext, type ITestEnv, type ITestRunner, type TCompilerStatsCompilation } from "../type";
1
+ import type { ECompilerType, ITestContext, ITestEnv, ITestRunner, TCompilerStatsCompilation } from "../type";
2
2
  export type THotStepRuntimeLangData = {
3
3
  outdatedModules: string[];
4
4
  outdatedDependencies: Record<string, string[]>;
@@ -5,7 +5,6 @@ exports.createRunner = createRunner;
5
5
  exports.getMultiCompilerRunnerKey = getMultiCompilerRunnerKey;
6
6
  exports.createMultiCompilerRunner = createMultiCompilerRunner;
7
7
  const runner_1 = require("../runner");
8
- const type_1 = require("../type");
9
8
  const common_1 = require("./common");
10
9
  function cachedStats(context, name) {
11
10
  const compiler = context.getCompiler(name);
@@ -25,6 +24,7 @@ function cachedStats(context, name) {
25
24
  }
26
25
  function createRunner(context, name, file, env) {
27
26
  const compiler = (0, common_1.getCompiler)(context, name);
27
+ const testConfig = context.getTestConfig();
28
28
  const compilerOptions = compiler.getOptions();
29
29
  const runnerOptions = {
30
30
  runInNewContext: false,
@@ -42,7 +42,7 @@ function createRunner(context, name, file, env) {
42
42
  return new runner_1.WebRunner({
43
43
  ...runnerOptions,
44
44
  runInNewContext: true,
45
- dom: context.getValue(name, "documentType") || type_1.EDocumentType.JSDOM
45
+ location: testConfig.location || "https://test.cases/path/index.html"
46
46
  });
47
47
  }
48
48
  return new runner_1.NodeRunner(runnerOptions);
@@ -69,6 +69,7 @@ function getMultiCompilerRunnerKey(context, name, file) {
69
69
  return `${name}-${index}[${seq}]`;
70
70
  }
71
71
  function createMultiCompilerRunner(context, name, file, env) {
72
+ const testConfig = context.getTestConfig();
72
73
  const { getIndex, flagIndex } = getFileIndexHandler(context, name, file);
73
74
  const multiCompilerOptions = context.getValue(name, "multiCompilerOptions") || [];
74
75
  const [index] = getIndex();
@@ -97,7 +98,7 @@ function createMultiCompilerRunner(context, name, file, env) {
97
98
  runner = new runner_1.WebRunner({
98
99
  ...runnerOptions,
99
100
  runInNewContext: true,
100
- dom: context.getValue(name, "documentType") || type_1.EDocumentType.Fake
101
+ location: testConfig.location || "https://test.cases/path/index.html"
101
102
  });
102
103
  }
103
104
  else {
@@ -1,4 +1,4 @@
1
- import { type ECompilerType, type ITestContext, type ITestEnv, type ITestRunner } from "../type";
1
+ import type { ECompilerType, ITestContext, ITestEnv, ITestRunner } from "../type";
2
2
  export declare function createWatchInitialProcessor(name: string, tempDir: string, step: string, watchState: Record<string, any>, { incremental, nativeWatcher }?: {
3
3
  incremental?: boolean | undefined;
4
4
  nativeWatcher?: boolean | undefined;
@@ -9,6 +9,7 @@ export declare function createWatchInitialProcessor(name: string, tempDir: strin
9
9
  build: (context: ITestContext) => Promise<void>;
10
10
  run: (env: ITestEnv, context: ITestContext) => Promise<void>;
11
11
  check: <T extends ECompilerType.Rspack>(env: ITestEnv, context: ITestContext) => Promise<void>;
12
+ after: (context: ITestContext) => Promise<void>;
12
13
  };
13
14
  export declare function createWatchStepProcessor(name: string, tempDir: string, step: string, watchState: Record<string, any>, { incremental, nativeWatcher }?: {
14
15
  incremental?: boolean | undefined;
@@ -20,6 +21,7 @@ export declare function createWatchStepProcessor(name: string, tempDir: string,
20
21
  build: (context: ITestContext) => Promise<void>;
21
22
  run: (env: ITestEnv, context: ITestContext) => Promise<void>;
22
23
  check: <T extends ECompilerType.Rspack>(env: ITestEnv, context: ITestContext) => Promise<void>;
24
+ after: (context: ITestContext) => Promise<void>;
23
25
  };
24
26
  export declare function createWatchCase(name: string, src: string, dist: string, temp: string): void;
25
27
  export declare function getWatchRunnerKey(context: ITestContext, name: string, file: string): string;
@@ -17,7 +17,6 @@ const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkA
17
17
  const copyDiff_1 = __importDefault(require("../helper/legacy/copyDiff"));
18
18
  const runner_1 = require("../runner");
19
19
  const creator_1 = require("../test/creator");
20
- const type_1 = require("../type");
21
20
  const common_1 = require("./common");
22
21
  function createWatchInitialProcessor(name, tempDir, step, watchState, { incremental = false, nativeWatcher = false } = {}) {
23
22
  const watchContext = {
@@ -158,6 +157,9 @@ function createWatchInitialProcessor(name, tempDir, step, watchState, { incremen
158
157
  if (testConfig.writeStatsJson) {
159
158
  node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.json"), node_path_1.default.join(context.getDist(), `stats.${watchContext.step}.json`));
160
159
  }
160
+ },
161
+ after: async (context) => {
162
+ await (0, common_1.afterExecute)(context, name);
161
163
  }
162
164
  };
163
165
  }
@@ -321,9 +323,7 @@ function createWatchRunner(context, name, file, env) {
321
323
  : compilerOptions.target === "web" ||
322
324
  compilerOptions.target === "webworker";
323
325
  const testConfig = context.getTestConfig();
324
- const documentType = context.getValue(name, "documentType") || type_1.EDocumentType.JSDOM;
325
326
  return new runner_1.WebRunner({
326
- dom: documentType,
327
327
  env,
328
328
  stats: cachedWatchStats(context, name),
329
329
  name: name,
@@ -342,6 +342,7 @@ function createWatchRunner(context, name, file, env) {
342
342
  },
343
343
  source: context.getSource(),
344
344
  dist: context.getDist(),
345
- compilerOptions
345
+ compilerOptions,
346
+ location: testConfig.location || "https://test.cases/path/index.html"
346
347
  });
347
348
  }
@@ -49,7 +49,7 @@ class HotUpdatePlugin {
49
49
  const { content, command } = this.getContent(filePath, this.updateIndex);
50
50
  // match command
51
51
  if (command === "delete") {
52
- await fs_extra_1.default.unlink(filePath);
52
+ await fs_extra_1.default.remove(filePath);
53
53
  return;
54
54
  }
55
55
  if (command === "force_write") {
@@ -18,8 +18,6 @@ module.exports = async (something, context, unlinked) => {
18
18
  if (unlinked)
19
19
  return m;
20
20
  await m.link(() => { });
21
- if (m.instantiate)
22
- m.instantiate();
23
21
  await m.evaluate();
24
22
  return m;
25
23
  };
@@ -6,5 +6,6 @@ declare function _exports(globalTimeout?: number, nameSuffix?: string): {
6
6
  afterEach(...args: any[]): void;
7
7
  expect: jest.Expect;
8
8
  jest: typeof jest;
9
+ rstest: typeof jest;
9
10
  };
10
11
  export = _exports;
@@ -110,6 +110,8 @@ module.exports = (globalTimeout = 2000, nameSuffix = "") => {
110
110
  });
111
111
  },
112
112
  expect,
113
- jest
113
+ jest,
114
+ // Compatible with rstest
115
+ rstest: global.rstest || global.jest
114
116
  };
115
117
  };
@@ -0,0 +1,2 @@
1
+ declare function _exports(): boolean;
2
+ export = _exports;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ module.exports = function supportsTextDecoder() {
3
+ try {
4
+ return typeof TextDecoder !== "undefined";
5
+ }
6
+ catch (_err) {
7
+ return false;
8
+ }
9
+ };
@@ -6,6 +6,21 @@ const path = require("node:path");
6
6
  if (process.env.RSPACK_BINDING_BUILDER_TESTING) {
7
7
  process.env.RSPACK_BINDING = path.resolve(__dirname, "../../node_modules/@rspack/binding-testing");
8
8
  }
9
+ if (process.env.RSTEST) {
10
+ global.printLogger ??= process.env.printLogger === "true";
11
+ global.__TEST_FIXTURES_PATH__ ??= process.env.__TEST_FIXTURES_PATH__;
12
+ global.updateSnapshot ??= process.env.updateSnapshot === "true";
13
+ global.testFilter ??= process.env.testFilter;
14
+ global.__TEST_PATH__ ??= process.env.__TEST_PATH__;
15
+ global.__TEST_DIST_PATH__ ??= process.env.__TEST_DIST_PATH__;
16
+ global.__ROOT_PATH__ ??= process.env.__ROOT_PATH__;
17
+ global.__RSPACK_PATH__ ??= process.env.__RSPACK_PATH__;
18
+ global.__RSPACK_TEST_TOOLS_PATH__ ??= process.env.__RSPACK_TEST_TOOLS_PATH__;
19
+ }
20
+ else {
21
+ // Compatible with wasm tests (lazyTestEnv)
22
+ global.rstest = jest;
23
+ }
9
24
  if (process.env.ALTERNATIVE_SORT) {
10
25
  const oldSort = Array.prototype.sort;
11
26
  Array.prototype.sort = function (cmp) {
@@ -308,7 +308,7 @@ class NodeRunner {
308
308
  };
309
309
  this.requireCache[file.path] = m;
310
310
  if (!this._options.runInNewContext) {
311
- file.content = `Object.assign(global, _globalAssign);\n ${file.content}`;
311
+ file.content = `Object.assign(global, _globalAssign);${file.content}`;
312
312
  }
313
313
  const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
314
314
  if (this._options.testConfig.moduleScope) {
@@ -357,6 +357,12 @@ class NodeRunner {
357
357
  if (file.content.includes("__STATS__")) {
358
358
  esmContext.__STATS__ = this._options.stats?.();
359
359
  }
360
+ if (file.content.includes("__STATS_I__")) {
361
+ const statsIndex = this._options.stats?.()?.__index__;
362
+ if (typeof statsIndex === "number") {
363
+ esmContext.__STATS_I__ = statsIndex;
364
+ }
365
+ }
360
366
  let esm = esmCache.get(file.path);
361
367
  if (!esm) {
362
368
  esm = new node_vm_1.SourceTextModule(file.content, {
@@ -390,8 +396,6 @@ class NodeRunner {
390
396
  }), referencingModule.context, true);
391
397
  });
392
398
  }
393
- if (esm.instantiate)
394
- esm.instantiate();
395
399
  await esm.evaluate();
396
400
  if (context.esmMode === type_1.EEsmMode.Evaluated) {
397
401
  return esm;
@@ -1,14 +1,27 @@
1
- import { type ECompilerType, EDocumentType, type ITestRunner } from "../../type";
2
- import type { INodeRunnerOptions, NodeRunner } from "../node";
1
+ import type { ECompilerType, TRunnerFile, TRunnerRequirer } from "../../type";
2
+ import { type INodeRunnerOptions, NodeRunner } from "../node";
3
3
  export interface IWebRunnerOptions<T extends ECompilerType = ECompilerType.Rspack> extends INodeRunnerOptions<T> {
4
- dom: EDocumentType;
4
+ location: string;
5
5
  }
6
- export declare class WebRunner<T extends ECompilerType = ECompilerType.Rspack> implements ITestRunner {
6
+ export declare class WebRunner<T extends ECompilerType = ECompilerType.Rspack> extends NodeRunner<T> {
7
7
  protected _webOptions: IWebRunnerOptions<T>;
8
- protected originMethods: Partial<NodeRunner<T>>;
9
- private implement;
8
+ private dom;
10
9
  constructor(_webOptions: IWebRunnerOptions<T>);
11
10
  run(file: string): Promise<unknown>;
12
- getRequire(): import("../../type").TRunnerRequirer;
13
11
  getGlobal(name: string): unknown;
12
+ protected createResourceLoader(): {
13
+ fetch(url: string, _: {
14
+ element: HTMLScriptElement;
15
+ }): any;
16
+ };
17
+ private urlToPath;
18
+ protected createBaseModuleScope(): import("../../type").IModuleScope;
19
+ protected getModuleContent(file: TRunnerFile): [
20
+ {
21
+ exports: Record<string, unknown>;
22
+ },
23
+ string
24
+ ];
25
+ protected createJSDOMRequirer(): TRunnerRequirer;
26
+ protected createRunner(): void;
14
27
  }