@rspack/test-tools 1.0.0-beta.0 → 1.0.0-beta.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.
Files changed (41) hide show
  1. package/dist/case/config.js +11 -0
  2. package/dist/compiler.d.ts +1 -1
  3. package/dist/helper/directory.d.ts +1 -0
  4. package/dist/helper/directory.js +10 -0
  5. package/dist/helper/expect/to-be-typeof.js +2 -12
  6. package/dist/helper/expect/to-end-with.js +2 -12
  7. package/dist/helper/expect/to-match-file-snapshot.js +1 -3
  8. package/dist/helper/legacy/FakeDocument.d.ts +2 -0
  9. package/dist/helper/legacy/FakeDocument.js +34 -11
  10. package/dist/helper/legacy/checkArrayExpectation.js +13 -12
  11. package/dist/helper/legacy/copyDiff.js +1 -1
  12. package/dist/helper/legacy/walkCssTokens.d.ts +38 -0
  13. package/dist/helper/legacy/walkCssTokens.js +761 -0
  14. package/dist/helper/setup-env.js +1 -1
  15. package/dist/helper/util/checkSourceMap.js +1 -1
  16. package/dist/helper/util/identifier.js +5 -5
  17. package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -1
  18. package/dist/plugin/webpack-module-placeholder-plugin.js +2 -3
  19. package/dist/processor/config.d.ts +1 -1
  20. package/dist/processor/config.js +12 -2
  21. package/dist/processor/hook.js +2 -2
  22. package/dist/processor/hot.js +6 -0
  23. package/dist/processor/normal.js +1 -1
  24. package/dist/processor/stats.js +3 -5
  25. package/dist/processor/watch.js +2 -1
  26. package/dist/reporter/diff-stats.js +1 -1
  27. package/dist/runner/basic.js +1 -2
  28. package/dist/runner/hot-step.js +4 -4
  29. package/dist/runner/hot.js +4 -4
  30. package/dist/runner/runner/basic.js +1 -1
  31. package/dist/runner/runner/cjs.js +1 -1
  32. package/dist/runner/runner/esm.js +2 -2
  33. package/dist/runner/runner/watch.d.ts +4 -4
  34. package/dist/runner/runner/watch.js +5 -9
  35. package/dist/runner/runner/web/fake.js +1 -0
  36. package/dist/runner/runner/web/jsdom.js +10 -0
  37. package/dist/runner/watch.js +8 -2
  38. package/dist/test/creator.d.ts +1 -0
  39. package/dist/test/creator.js +3 -0
  40. package/dist/type.d.ts +2 -2
  41. package/package.json +3 -3
@@ -34,7 +34,7 @@ if (process.env.DEBUG_INFO) {
34
34
  process.stdout.write(`START1 ${name}\n`);
35
35
  try {
36
36
  const promise = fn();
37
- if (promise && promise.then) {
37
+ if (promise?.then) {
38
38
  return promise.then(r => {
39
39
  process.stdout.write(`DONE OK ${name}\n`);
40
40
  return r;
@@ -63,7 +63,7 @@ async function checkSourceMap(out, outCodeMap, toSearch, _checkColumn = true //
63
63
  column: checkColumn ? inColumn : 0
64
64
  });
65
65
  const observed = JSON.stringify({ source, line, column });
66
- recordCheck(expected === observed, `expected original position: ${expected}, observed original position: ${observed}, out: ${outLine + "," + outColumn + "," + outIndex + ":" + outId}, ${checkColumn ? "" : "(column ignored)"}`);
66
+ recordCheck(expected === observed, `expected original position: ${expected}, observed original position: ${observed}, out: ${`${outLine},${outColumn},${outIndex}:${outId}`}, ${checkColumn ? "" : "(column ignored)"}`);
67
67
  // Also check the reverse mapping
68
68
  const positions = map.allGeneratedPositionsFor({
69
69
  source,
@@ -1,8 +1,8 @@
1
+ "use strict";
1
2
  // @ts-nocheck
2
3
  /*
3
- MIT License http://www.opensource.org/licenses/mit-license.php
4
- */
5
- "use strict";
4
+ * MIT License http://www.opensource.org/licenses/mit-license.php
5
+ */
6
6
  const path = require("node:path");
7
7
  const WINDOWS_ABS_PATH_REGEXP = /^[a-zA-Z]:[\\/]/;
8
8
  const SEGMENTS_SPLIT_REGEXP = /([|!])/;
@@ -322,8 +322,8 @@ exports.getUndoPath = (filename, outputPath, enforceRelative) => {
322
322
  const j = outputPath.lastIndexOf("\\");
323
323
  const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j);
324
324
  if (pos < 0)
325
- return outputPath + "/";
326
- append = outputPath.slice(pos + 1) + "/" + append;
325
+ return `${outputPath}/`;
326
+ append = `${outputPath.slice(pos + 1)}/${append}`;
327
327
  outputPath = outputPath.slice(0, pos);
328
328
  }
329
329
  }
@@ -1,4 +1,3 @@
1
1
  export declare class WebpackModulePlaceholderPlugin {
2
- constructor();
3
2
  apply(compiler: any): void;
4
3
  }
@@ -28,7 +28,7 @@ function createRenderRuntimeModulesFn(Template) {
28
28
  }
29
29
  if (runtimeSource) {
30
30
  const identifier = module.identifier();
31
- source.add(Template.toNormalComment(`start::${identifier}`) + "\n");
31
+ source.add(`${Template.toNormalComment(`start::${identifier}`)}\n`);
32
32
  if (!module.shouldIsolate()) {
33
33
  source.add(runtimeSource);
34
34
  source.add("\n\n");
@@ -43,7 +43,7 @@ function createRenderRuntimeModulesFn(Template) {
43
43
  source.add(new PrefixSource("\t", runtimeSource));
44
44
  source.add("\n}();\n\n");
45
45
  }
46
- source.add(Template.toNormalComment(`end::${identifier}`) + "\n");
46
+ source.add(`${Template.toNormalComment(`end::${identifier}`)}\n`);
47
47
  }
48
48
  }
49
49
  return source;
@@ -51,7 +51,6 @@ function createRenderRuntimeModulesFn(Template) {
51
51
  }
52
52
  const caches = new WeakMap();
53
53
  class WebpackModulePlaceholderPlugin {
54
- constructor() { }
55
54
  apply(compiler) {
56
55
  const { webpack } = compiler;
57
56
  const { Template, javascript: { JavascriptModulesPlugin } } = webpack;
@@ -5,7 +5,7 @@ export interface IConfigProcessorOptions<T extends ECompilerType> extends IMulti
5
5
  export declare class ConfigProcessor<T extends ECompilerType> extends MultiTaskProcessor<T> {
6
6
  protected _configOptions: IConfigProcessorOptions<T>;
7
7
  constructor(_configOptions: IConfigProcessorOptions<T>);
8
- static findBundle<T extends ECompilerType>(index: number, context: ITestContext, options: TCompilerOptions<T>): string | string[] | undefined;
8
+ static findBundle<T extends ECompilerType>(index: number, context: ITestContext, options: TCompilerOptions<T>): string | string[];
9
9
  static defaultOptions<T extends ECompilerType>(index: number, context: ITestContext): TCompilerOptions<T>;
10
10
  static overrideOptions<T extends ECompilerType>(index: number, context: ITestContext, options: TCompilerOptions<T>): void;
11
11
  }
@@ -24,10 +24,20 @@ class ConfigProcessor extends multi_1.MultiTaskProcessor {
24
24
  return testConfig.findBundle(index, options);
25
25
  }
26
26
  const ext = node_path_1.default.extname((0, parseResource_1.parseResource)(options.output?.filename).path);
27
+ const bundlePath = [];
27
28
  if (options.output?.path &&
28
- node_fs_1.default.existsSync(node_path_1.default.join(options.output.path, "bundle" + index + ext))) {
29
- return "./bundle" + index + ext;
29
+ node_fs_1.default.existsSync(node_path_1.default.join(options.output.path, `bundle${index}${ext}`))) {
30
+ if (options.experiments?.css) {
31
+ const cssOutputPath = node_path_1.default.join(options.output.path, (typeof options.output?.cssFilename === "string" &&
32
+ options.output?.cssFilename) ||
33
+ `bundle${index}.css`);
34
+ if (node_fs_1.default.existsSync(cssOutputPath)) {
35
+ bundlePath.push(`./bundle${index}.css`);
36
+ }
37
+ }
38
+ bundlePath.push(`./bundle${index}${ext}`);
30
39
  }
40
+ return bundlePath;
31
41
  }
32
42
  static defaultOptions(index, context) {
33
43
  return {
@@ -132,8 +132,8 @@ class HookCasesContext extends context_1.TestContext {
132
132
  const snapshots = this.snapshotsList.reduce((acc, group, index) => {
133
133
  const block = this.snapshots[group || index].reduce((acc, [content, name]) => {
134
134
  name = `## ${name || `test: ${index}`}\n\n`;
135
- const block = "```javascript\n" + content + "\n```\n";
136
- return (acc += name + block + "\n");
135
+ const block = `\`\`\`javascript\n${content}\n\`\`\`\n`;
136
+ return (acc += `${name + block}\n`);
137
137
  }, "");
138
138
  group = Number.isInteger(group) ? `Group: ${index}` : group;
139
139
  group = `# ${group}\n\n`;
@@ -100,6 +100,12 @@ class HotProcessor extends basic_1.BasicProcessor {
100
100
  options.entry = "./index.js";
101
101
  }
102
102
  options.module ??= {};
103
+ for (const cssModuleType of ["css/auto", "css/module", "css"]) {
104
+ options.module.generator ??= {};
105
+ options.module.generator[cssModuleType] ??= {};
106
+ options.module.generator[cssModuleType].exportsOnly ??=
107
+ this._hotOptions.target === "async-node";
108
+ }
103
109
  options.module.rules ??= [];
104
110
  options.module.rules.push({
105
111
  test: /\.(js|css|json)/,
@@ -32,7 +32,7 @@ class NormalProcessor extends basic_1.BasicProcessor {
32
32
  const { root, compilerOptions } = this._normalOptions;
33
33
  return {
34
34
  context: root,
35
- entry: "./" + node_path_1.default.relative(root, context.getSource()) + "/",
35
+ entry: `./${node_path_1.default.relative(root, context.getSource())}/`,
36
36
  target: compilerOptions?.target || "async-node",
37
37
  devtool: compilerOptions?.devtool,
38
38
  mode: compilerOptions?.mode || "none",
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable no-control-regex */
3
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
4
  };
@@ -38,8 +37,7 @@ class StatsProcessor extends multi_1.MultiTaskProcessor {
38
37
  for (const compiler of compilers) {
39
38
  const ifs = compiler.inputFileSystem;
40
39
  compiler.inputFileSystem = Object.create(ifs);
41
- compiler.inputFileSystem.readFile = () => {
42
- const args = Array.prototype.slice.call(arguments);
40
+ compiler.inputFileSystem.readFile = (...args) => {
43
41
  const callback = args.pop();
44
42
  ifs.readFile.apply(ifs, args.concat([
45
43
  (err, result) => {
@@ -145,10 +143,10 @@ class StatsProcessor extends multi_1.MultiTaskProcessor {
145
143
  actual = actual
146
144
  .replace(/\r\n?/g, "\n")
147
145
  // CHANGE: Remove potential line break and "|" caused by long text
148
- .replace(/((ERROR|WARNING)([\s\S](?!╭|├))*?)(\n │ )/g, "$1")
146
+ .replace(/((ERROR|WARNING)([\s\S](?!╭|├))*?)(\n {2}│ )/g, "$1")
149
147
  // CHANGE: Update the regular expression to replace the 'Rspack' version string
150
148
  .replace(/Rspack [^ )]+(\)?) compiled/g, "Rspack x.x.x$1 compiled")
151
- .replace(new RegExp(quoteMeta(testPath), "g"), "Xdir/" + node_path_1.default.basename(this._options.name))
149
+ .replace(new RegExp(quoteMeta(testPath), "g"), `Xdir/${node_path_1.default.basename(this._options.name)}`)
152
150
  .replace(/(\w)\\(\w)/g, "$1/$2")
153
151
  .replace(/, additional resolving: X ms/g, "")
154
152
  .replace(/Unexpected identifier '.+?'/g, "Unexpected identifier");
@@ -8,6 +8,7 @@ const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const compiler_1 = require("../compiler");
10
10
  const copyDiff_1 = __importDefault(require("../helper/legacy/copyDiff"));
11
+ const config_1 = require("./config");
11
12
  const multi_1 = require("./multi");
12
13
  // This file is used to port step number to rspack.config.js/webpack.config.js
13
14
  const currentWatchStepModulePath = node_path_1.default.resolve(__dirname, "../helper/util/currentWatchStep");
@@ -15,7 +16,7 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
15
16
  constructor(_watchOptions) {
16
17
  super({
17
18
  overrideOptions: WatchProcessor.overrideOptions(_watchOptions),
18
- findBundle: () => "bundle.js",
19
+ findBundle: (config_1.ConfigProcessor.findBundle),
19
20
  ..._watchOptions
20
21
  });
21
22
  this._watchOptions = _watchOptions;
@@ -7,7 +7,7 @@ exports.DiffStatsReporter = void 0;
7
7
  const csv_to_markdown_table_1 = __importDefault(require("csv-to-markdown-table"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const type_1 = require("../type");
10
- const toPercent = (d) => (d * 100).toFixed(2) + "%";
10
+ const toPercent = (d) => `${(d * 100).toFixed(2)}%`;
11
11
  const toFirstLetterUpperCase = (s) => (s.charAt(0).toUpperCase() + s.slice(1)).split("-").join(" ");
12
12
  const GITHUB_RUN_ID = process.env.GITHUB_RUN_ID;
13
13
  class DiffStatsReporter {
@@ -41,8 +41,7 @@ class BasicRunnerFactory {
41
41
  return new web_1.WebRunner({
42
42
  ...runnerOptions,
43
43
  runInNewContext: true,
44
- dom: this.context.getValue(this.name, "documentType") ||
45
- type_1.EDocumentType.JSDOM
44
+ dom: this.context.getValue(this.name, "documentType") || type_1.EDocumentType.Fake
46
45
  });
47
46
  }
48
47
  return new esm_1.EsmRunner(runnerOptions);
@@ -35,10 +35,10 @@ class HotStepRunnerFactory extends hot_1.HotRunnerFactory {
35
35
  ? "hotUpdateStepErrorChecker"
36
36
  : "hotUpdateStepChecker");
37
37
  checker(hotUpdateContext, stats, runner.getGlobal("__HMR_UPDATED_RUNTIME__"));
38
- if ((0, checkArrayExpectation_1.default)(source, jsonStats, "error", "errors" + hotUpdateContext.updateIndex, "Error", callback)) {
38
+ if ((0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${hotUpdateContext.updateIndex}`, "Error", callback)) {
39
39
  return;
40
40
  }
41
- if ((0, checkArrayExpectation_1.default)(source, jsonStats, "warning", "warnings" + hotUpdateContext.updateIndex, "Warning", callback)) {
41
+ if ((0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${hotUpdateContext.updateIndex}`, "Warning", callback)) {
42
42
  return;
43
43
  }
44
44
  callback(null, jsonStats);
@@ -57,9 +57,9 @@ class HotStepRunnerFactory extends hot_1.HotRunnerFactory {
57
57
  runInNewContext: false,
58
58
  testConfig: {
59
59
  ...testConfig,
60
- moduleScope(ms) {
60
+ moduleScope(ms, stats) {
61
61
  if (typeof testConfig.moduleScope === "function") {
62
- ms = testConfig.moduleScope(ms);
62
+ ms = testConfig.moduleScope(ms, stats);
63
63
  }
64
64
  ms.NEXT = next;
65
65
  return ms;
@@ -30,10 +30,10 @@ class HotRunnerFactory extends basic_1.BasicRunnerFactory {
30
30
  });
31
31
  hotUpdateContext.totalUpdates = Math.max(hotUpdateContext.totalUpdates, ...changedFiles.values());
32
32
  hotUpdateContext.changedFiles = [...changedFiles.keys()];
33
- if ((0, checkArrayExpectation_1.default)(source, jsonStats, "error", "errors" + hotUpdateContext.updateIndex, "Error", callback)) {
33
+ if ((0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${hotUpdateContext.updateIndex}`, "Error", callback)) {
34
34
  return;
35
35
  }
36
- if ((0, checkArrayExpectation_1.default)(source, jsonStats, "warning", "warnings" + hotUpdateContext.updateIndex, "Warning", callback)) {
36
+ if ((0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${hotUpdateContext.updateIndex}`, "Warning", callback)) {
37
37
  return;
38
38
  }
39
39
  callback(null, jsonStats);
@@ -48,9 +48,9 @@ class HotRunnerFactory extends basic_1.BasicRunnerFactory {
48
48
  runInNewContext: false,
49
49
  testConfig: {
50
50
  ...testConfig,
51
- moduleScope(ms) {
51
+ moduleScope(ms, stats) {
52
52
  if (typeof testConfig.moduleScope === "function") {
53
- ms = testConfig.moduleScope(ms);
53
+ ms = testConfig.moduleScope(ms, stats);
54
54
  }
55
55
  ms.NEXT = next;
56
56
  return ms;
@@ -37,7 +37,7 @@ class BasicRunner {
37
37
  }
38
38
  this.baseModuleScope = this.createBaseModuleScope();
39
39
  if (typeof this._options.testConfig.moduleScope === "function") {
40
- this._options.testConfig.moduleScope(this.baseModuleScope);
40
+ this._options.testConfig.moduleScope(this.baseModuleScope, this._options.stats);
41
41
  }
42
42
  this.createRunner();
43
43
  const res = this.getRequire()(this._options.dist, file.startsWith("./") ? file : `./${file}`);
@@ -87,7 +87,7 @@ class CommonJsRunner extends basic_1.BasicRunner {
87
87
  requireCache[file.path] = m;
88
88
  const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
89
89
  if (this._options.testConfig.moduleScope) {
90
- this._options.testConfig.moduleScope(currentModuleScope);
90
+ this._options.testConfig.moduleScope(currentModuleScope, this._options.stats);
91
91
  }
92
92
  if (!this._options.runInNewContext) {
93
93
  file.content = `Object.assign(global, _globalAssign);\n ${file.content}`;
@@ -74,9 +74,9 @@ class EsmRunner extends cjs_1.CommonJsRunner {
74
74
  let esm = esmCache.get(file.path);
75
75
  if (!esm) {
76
76
  esm = new node_vm_1.SourceTextModule(file.content, {
77
- identifier: esmIdentifier + "-" + file.path,
77
+ identifier: `${esmIdentifier}-${file.path}`,
78
78
  // no attribute
79
- url: (0, node_url_1.pathToFileURL)(file.path).href + "?" + esmIdentifier,
79
+ url: `${(0, node_url_1.pathToFileURL)(file.path).href}?${esmIdentifier}`,
80
80
  context: esmContext,
81
81
  initializeImportMeta: (meta, _) => {
82
82
  meta.url = (0, node_url_1.pathToFileURL)(file.path).href;
@@ -1,16 +1,16 @@
1
1
  import type { ECompilerType } from "../../type";
2
2
  import type { IBasicModuleScope, TBasicRunnerFile, TRunnerRequirer } from "../type";
3
3
  import type { IBasicRunnerOptions } from "./basic";
4
- import { CommonJsRunner } from "./cjs";
4
+ import { FakeDocumentWebRunner } from "./web/fake";
5
5
  interface IWatchRunnerOptions<T extends ECompilerType = ECompilerType.Rspack> extends IBasicRunnerOptions<T> {
6
6
  stepName: string;
7
+ isWeb: boolean;
7
8
  }
8
- export declare class WatchRunner<T extends ECompilerType = ECompilerType.Rspack> extends CommonJsRunner<T> {
9
+ export declare class WatchRunner<T extends ECompilerType = ECompilerType.Rspack> extends FakeDocumentWebRunner<T> {
9
10
  protected _watchOptions: IWatchRunnerOptions<T>;
10
- private document;
11
11
  private state;
12
12
  constructor(_watchOptions: IWatchRunnerOptions<T>);
13
- protected createGlobalContext(): import("../type").IBasicGlobalContext;
14
13
  protected createModuleScope(requireFn: TRunnerRequirer, m: any, file: TBasicRunnerFile): IBasicModuleScope;
14
+ run(file: string): Promise<unknown>;
15
15
  }
16
16
  export {};
@@ -5,19 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.WatchRunner = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
- const FakeDocument_1 = __importDefault(require("../../helper/legacy/FakeDocument"));
9
- const cjs_1 = require("./cjs");
10
- class WatchRunner extends cjs_1.CommonJsRunner {
8
+ const fake_1 = require("./web/fake");
9
+ class WatchRunner extends fake_1.FakeDocumentWebRunner {
11
10
  constructor(_watchOptions) {
12
11
  super(_watchOptions);
13
12
  this._watchOptions = _watchOptions;
14
13
  this.state = {};
15
- this.document = new FakeDocument_1.default(_watchOptions.dist);
16
- }
17
- createGlobalContext() {
18
- const globalContext = super.createGlobalContext();
19
- globalContext.document = this.document;
20
- return globalContext;
21
14
  }
22
15
  createModuleScope(requireFn, m, file) {
23
16
  const moduleScope = super.createModuleScope(requireFn, m, file);
@@ -27,5 +20,8 @@ class WatchRunner extends cjs_1.CommonJsRunner {
27
20
  moduleScope.WATCH_STEP = this._watchOptions.stepName;
28
21
  return moduleScope;
29
22
  }
23
+ run(file) {
24
+ return super.run(file);
25
+ }
30
26
  }
31
27
  exports.WatchRunner = WatchRunner;
@@ -93,6 +93,7 @@ class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
93
93
  moduleScope.self = this.globalContext;
94
94
  moduleScope.globalThis = this.globalContext;
95
95
  moduleScope.document = this.globalContext.document;
96
+ moduleScope.getComputedStyle = this.globalContext.getComputedStyle.bind(this.globalContext);
96
97
  moduleScope.fetch = this.globalContext.fetch;
97
98
  moduleScope.importScripts = this.globalContext.importScripts;
98
99
  moduleScope.Worker = this.globalContext.Worker;
@@ -125,6 +125,16 @@ class JSDOMWebRunner extends cjs_1.CommonJsRunner {
125
125
  this._options.env.expect(url).toMatch(/^https:\/\/test\.cases\/path\//);
126
126
  this.requirers.get("entry")(this._options.dist, (0, urlToRelativePath_1.default)(url));
127
127
  };
128
+ moduleScope.getComputedStyle = function () {
129
+ const computedStyle = this.dom.window.getComputedStyle(this.dom.window);
130
+ const getPropertyValue = computedStyle.getPropertyValue.bind(computedStyle);
131
+ return {
132
+ ...computedStyle,
133
+ getPropertyValue(v) {
134
+ return getPropertyValue(v);
135
+ }
136
+ };
137
+ };
128
138
  moduleScope.STATS = moduleScope.__STATS__;
129
139
  return moduleScope;
130
140
  }
@@ -14,13 +14,19 @@ class WatchRunnerFactory extends basic_1.BasicRunnerFactory {
14
14
  if (!stepName) {
15
15
  throw new Error("Can not get watch step name from context");
16
16
  }
17
+ const isWeb = Array.isArray(compilerOptions)
18
+ ? compilerOptions.some(option => {
19
+ return option.target === "web" || option.target === "webworker";
20
+ })
21
+ : compilerOptions.target === "web" ||
22
+ compilerOptions.target === "webworker";
17
23
  return new watch_1.WatchRunner({
18
24
  env,
19
25
  stats,
20
26
  name: this.name,
21
27
  stepName,
22
- runInNewContext: compilerOptions.target === "web" ||
23
- compilerOptions.target === "webworker",
28
+ runInNewContext: isWeb,
29
+ isWeb,
24
30
  testConfig: this.context.getTestConfig(),
25
31
  source: this.context.getSource(),
26
32
  dist: this.context.getDist(),
@@ -10,6 +10,7 @@ export interface IBasicCaseCreatorOptions<T extends ECompilerType> {
10
10
  dist: string;
11
11
  temp: string | void;
12
12
  }) => ITestProcessor[];
13
+ testConfig?: (testConfig: TTestConfig<T>) => void;
13
14
  description?: (name: string, step: number) => string;
14
15
  runner?: new (name: string, context: ITestContext) => TRunnerFactory<ECompilerType>;
15
16
  [key: string]: unknown;
@@ -15,6 +15,9 @@ class BasicCaseCreator {
15
15
  }
16
16
  create(name, src, dist, temp) {
17
17
  const testConfig = this.readTestConfig(src);
18
+ if (typeof this._options.testConfig === "function") {
19
+ this._options.testConfig(testConfig);
20
+ }
18
21
  const skipped = this.checkSkipped(src, testConfig);
19
22
  if (skipped) {
20
23
  this.skip(name, skipped);
package/dist/type.d.ts CHANGED
@@ -130,7 +130,7 @@ export interface ITestEnv {
130
130
  afterEach: (...args: any[]) => void;
131
131
  [key: string]: unknown;
132
132
  }
133
- export declare const enum EDocumentType {
133
+ export declare enum EDocumentType {
134
134
  Fake = "fake",
135
135
  JSDOM = "jsdom"
136
136
  }
@@ -140,7 +140,7 @@ export type TTestConfig<T extends ECompilerType> = {
140
140
  noTest?: boolean;
141
141
  beforeExecute?: () => void;
142
142
  afterExecute?: () => void;
143
- moduleScope?: (ms: IBasicModuleScope) => IBasicModuleScope;
143
+ moduleScope?: (ms: IBasicModuleScope, stats?: TCompilerStatsCompilation<T>) => IBasicModuleScope;
144
144
  findBundle?: (index: number, options: TCompilerOptions<T>) => string | string[];
145
145
  bundlePath?: string[];
146
146
  nonEsmThis?: (p: string | string[]) => Object;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/test-tools",
3
- "version": "1.0.0-beta.0",
3
+ "version": "1.0.0-beta.2",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -99,8 +99,8 @@
99
99
  "terser": "5.27.2",
100
100
  "typescript": "5.0.2",
101
101
  "wast-loader": "^1.12.1",
102
- "@rspack/core": "1.0.0-beta.0",
103
- "@rspack/cli": "1.0.0-beta.0"
102
+ "@rspack/core": "1.0.0-beta.2",
103
+ "@rspack/cli": "1.0.0-beta.2"
104
104
  },
105
105
  "peerDependencies": {
106
106
  "@rspack/core": ">=0.7.0"