@rspack/test-tools 1.4.10 → 1.5.0-beta.0

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.
@@ -5,13 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createBuiltinCase = createBuiltinCase;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
+ const helper_1 = require("../helper");
8
9
  const processor_1 = require("../processor");
9
10
  const creator_1 = require("../test/creator");
10
11
  const type_1 = require("../type");
11
12
  const FILTERS = {
12
13
  "plugin-css": (file) => file.endsWith(".css"),
13
- "plugin-css-modules": (file) => file.endsWith(".css") ||
14
- (file.endsWith(".js") && !file.includes("runtime")),
14
+ "plugin-css-modules": (file) => file.endsWith(".css") || ((0, helper_1.isJavaScript)(file) && !file.includes("runtime")),
15
15
  "plugin-html": (file) => file.endsWith(".html")
16
16
  };
17
17
  const creator = new creator_1.BasicCaseCreator({
@@ -11,7 +11,7 @@ export * from "./hook";
11
11
  export * from "./hot";
12
12
  export * from "./hot-step";
13
13
  export * from "./incremental";
14
- export * from "./nativeWatcher";
14
+ export * from "./native-watcher";
15
15
  export * from "./normal";
16
16
  export * from "./serial";
17
17
  export * from "./stats-api";
@@ -27,7 +27,7 @@ __exportStar(require("./hook"), exports);
27
27
  __exportStar(require("./hot"), exports);
28
28
  __exportStar(require("./hot-step"), exports);
29
29
  __exportStar(require("./incremental"), exports);
30
- __exportStar(require("./nativeWatcher"), exports);
30
+ __exportStar(require("./native-watcher"), exports);
31
31
  __exportStar(require("./normal"), exports);
32
32
  __exportStar(require("./serial"), exports);
33
33
  __exportStar(require("./stats-api"), exports);
@@ -44,11 +44,11 @@ const creator = new creator_1.BasicCaseCreator({
44
44
  tempDir: temp,
45
45
  runable: true,
46
46
  compilerType: type_1.ECompilerType.Rspack,
47
- configFiles: ["rspack.config.js", "webpack.config.js"]
47
+ configFiles: ["rspack.config.js", "webpack.config.js"],
48
+ nativeWatcher: true
48
49
  }, watchState));
49
50
  },
50
- // TODO: support more concurrency
51
- concurrent: 4
51
+ concurrent: true
52
52
  });
53
53
  function createNativeWatcher(name, src, dist, temp) {
54
54
  creator.create(name, src, dist, temp);
@@ -60,7 +60,7 @@ class HotUpdatePlugin {
60
60
  }
61
61
  // default
62
62
  const { content: oldContent } = this.getContent(filePath, this.updateIndex - 1);
63
- if (content === oldContent) {
63
+ if (this.updateIndex !== 0 && content === oldContent) {
64
64
  return;
65
65
  }
66
66
  await promises_1.default.writeFile(filePath, content);
@@ -1,4 +1,5 @@
1
1
  export * from "./directory";
2
+ export * from "./is";
2
3
  export * from "./legacy/supportsImportFn";
3
4
  export * from "./parse-modules";
4
5
  export * from "./read-config-file";
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./directory"), exports);
18
+ __exportStar(require("./is"), exports);
18
19
  __exportStar(require("./legacy/supportsImportFn"), exports);
19
20
  __exportStar(require("./parse-modules"), exports);
20
21
  __exportStar(require("./read-config-file"), exports);
@@ -0,0 +1,2 @@
1
+ export declare function isJavaScript(filePath: string): boolean;
2
+ export declare function isCss(filePath: string): boolean;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isJavaScript = isJavaScript;
7
+ exports.isCss = isCss;
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ function isJavaScript(filePath) {
10
+ const ext = node_path_1.default.extname(filePath).toLowerCase();
11
+ return ext === ".js" || ext === ".mjs";
12
+ }
13
+ function isCss(filePath) {
14
+ return node_path_1.default.extname(filePath).toLowerCase() === ".css";
15
+ }
@@ -5,7 +5,7 @@ declare function _exports(env: any, { outputDirectory }: {
5
5
  url: any;
6
6
  worker: import("worker_threads").Worker;
7
7
  _onmessage: ((data: any) => void) | undefined;
8
- onmessage: any;
8
+ set onmessage(value: any);
9
9
  postMessage(data: any): void;
10
10
  terminate(): Promise<number>;
11
11
  };
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.CacheProcessor = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
8
  const core_1 = require("@rspack/core");
9
+ const helper_1 = require("../helper");
9
10
  const hot_update_1 = require("../helper/hot-update");
10
11
  const type_1 = require("../type");
11
12
  const basic_1 = require("./basic");
@@ -46,7 +47,7 @@ class CacheProcessor extends basic_1.BasicProcessor {
46
47
  if (this._cacheOptions.target === "web" ||
47
48
  this._cacheOptions.target === "webworker") {
48
49
  for (const file of info.entrypoints.main.assets) {
49
- if (file.name.endsWith(".js")) {
50
+ if ((0, helper_1.isJavaScript)(file.name)) {
50
51
  files.push(file.name);
51
52
  }
52
53
  else {
@@ -55,7 +56,7 @@ class CacheProcessor extends basic_1.BasicProcessor {
55
56
  }
56
57
  }
57
58
  else {
58
- const assets = info.entrypoints.main.assets.filter(s => s.name.endsWith(".js"));
59
+ const assets = info.entrypoints.main.assets.filter(s => (0, helper_1.isJavaScript)(s.name));
59
60
  files.push(assets[assets.length - 1].name);
60
61
  }
61
62
  return [...prefiles, ...files];
@@ -82,7 +83,8 @@ class CacheProcessor extends basic_1.BasicProcessor {
82
83
  library: { type: "commonjs2" }
83
84
  },
84
85
  optimization: {
85
- moduleIds: "named"
86
+ moduleIds: "named",
87
+ emitOnErrors: true
86
88
  },
87
89
  target: this._cacheOptions.target,
88
90
  experiments: {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.HotProcessor = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
8
  const core_1 = require("@rspack/core");
9
+ const helper_1 = require("../helper");
9
10
  const plugins_1 = require("../helper/plugins");
10
11
  const plugin_1 = require("../plugin");
11
12
  const type_1 = require("../type");
@@ -45,7 +46,7 @@ class HotProcessor extends basic_1.BasicProcessor {
45
46
  if (this._hotOptions.target === "web" ||
46
47
  this._hotOptions.target === "webworker") {
47
48
  for (const file of info.entrypoints.main.assets) {
48
- if (file.name.endsWith(".js")) {
49
+ if ((0, helper_1.isJavaScript)(file.name)) {
49
50
  files.push(file.name);
50
51
  }
51
52
  else {
@@ -54,7 +55,7 @@ class HotProcessor extends basic_1.BasicProcessor {
54
55
  }
55
56
  }
56
57
  else {
57
- const assets = info.entrypoints.main.assets.filter(s => s.name.endsWith(".js"));
58
+ const assets = info.entrypoints.main.assets.filter(s => (0, helper_1.isJavaScript)(s.name));
58
59
  files.push(assets[assets.length - 1].name);
59
60
  }
60
61
  return [...prefiles, ...files];
@@ -233,10 +233,16 @@ class WatchStepProcessor extends WatchProcessor {
233
233
  });
234
234
  });
235
235
  // wait compiler to ready watch the files and diretories
236
- // TODO: native watcher will call ignored js function in rust
237
- // but it will block the watch step processor. Then, native watcher maybe spend more time.
238
- // So we need to wait a while to ensure the files and directories are ready.
239
- const timeout = this._watchOptions.nativeWatcher ? 500 : 100;
236
+ // Native Watcher using [notify](https://github.com/notify-rs/notify) to watch files.
237
+ // After tests, notify will cost many milliseconds to watch in windows OS when jest run concurrently.
238
+ // So we need to wait a while to ensure the watcher is ready.
239
+ // If we don't wait, copyDiff will happen before the watcher is ready,
240
+ // which will cause the compiler not rebuild when the files change.
241
+ // The timeout is set to 400ms for windows OS and 100ms for other OS.
242
+ // TODO: This is a workaround, we can remove it when notify support windows better.
243
+ const timeout = this._watchOptions.nativeWatcher && process.platform === "win32"
244
+ ? 400
245
+ : 100;
240
246
  await new Promise(resolve => setTimeout(resolve, timeout));
241
247
  (0, copyDiff_1.default)(node_path_1.default.join(context.getSource(), this._watchOptions.stepName), this._watchOptions.tempDir, false);
242
248
  await task;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BasicRunner = void 0;
7
7
  const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
+ const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
9
10
  const isRelativePath = (p) => /^\.\.?\//.test(p);
10
11
  const getSubPath = (p) => {
11
12
  const lastSlash = p.lastIndexOf("/");
@@ -91,6 +92,15 @@ class BasicRunner {
91
92
  subPath: "absolute_path"
92
93
  };
93
94
  }
95
+ else if (modulePath.startsWith("https://test.cases/path/")) {
96
+ const relativePath = (0, urlToRelativePath_1.default)(modulePath);
97
+ const absPath = node_path_1.default.join(currentDirectory, relativePath);
98
+ res = {
99
+ path: absPath,
100
+ content: node_fs_1.default.readFileSync(absPath, "utf-8"),
101
+ subPath: ""
102
+ };
103
+ }
94
104
  if (this._options.cachable && res) {
95
105
  cached.set(cacheKey, res);
96
106
  }
@@ -1,5 +1,5 @@
1
1
  import type { ECompilerType } from "../../../type";
2
- import type { TBasicRunnerFile, TRunnerRequirer } from "../../type";
2
+ import { type TBasicRunnerFile, type TRunnerRequirer } from "../../type";
3
3
  import type { IBasicRunnerOptions } from "../basic";
4
4
  import { CommonJsRunner } from "../cjs";
5
5
  export declare class FakeDocumentWebRunner<T extends ECompilerType = ECompilerType.Rspack> extends CommonJsRunner<T> {
@@ -15,4 +15,5 @@ export declare class FakeDocumentWebRunner<T extends ECompilerType = ECompilerTy
15
15
  protected createRunner(): void;
16
16
  protected preExecute(_: string, file: TBasicRunnerFile): void;
17
17
  protected postExecute(_: Object, file: TBasicRunnerFile): void;
18
+ private createESMRequirer;
18
19
  }
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
@@ -6,11 +39,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
39
  exports.FakeDocumentWebRunner = void 0;
7
40
  const node_fs_1 = __importDefault(require("node:fs"));
8
41
  const node_path_1 = __importDefault(require("node:path"));
42
+ const node_url_1 = require("node:url");
43
+ const node_vm_1 = __importStar(require("node:vm"));
44
+ const helper_1 = require("../../../helper");
45
+ const asModule_1 = __importDefault(require("../../../helper/legacy/asModule"));
9
46
  const createFakeWorker_1 = __importDefault(require("../../../helper/legacy/createFakeWorker"));
10
47
  const currentScript_1 = __importDefault(require("../../../helper/legacy/currentScript"));
11
48
  const EventSourceForNode_1 = __importDefault(require("../../../helper/legacy/EventSourceForNode"));
12
49
  const FakeDocument_1 = __importDefault(require("../../../helper/legacy/FakeDocument"));
13
50
  const urlToRelativePath_1 = __importDefault(require("../../../helper/legacy/urlToRelativePath"));
51
+ const type_1 = require("../../type");
14
52
  const cjs_1 = require("../cjs");
15
53
  class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
16
54
  constructor(_webOptions) {
@@ -24,7 +62,7 @@ class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
24
62
  });
25
63
  }
26
64
  run(file) {
27
- if (!file.endsWith(".js")) {
65
+ if ((0, helper_1.isCss)(file)) {
28
66
  const cssElement = this.document.createElement("link");
29
67
  cssElement.href = file;
30
68
  cssElement.rel = "stylesheet";
@@ -118,6 +156,7 @@ class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
118
156
  createRunner() {
119
157
  super.createRunner();
120
158
  this.requirers.set("cjs", this.getRequire());
159
+ this.requirers.set("mjs", this.createESMRequirer());
121
160
  this.requirers.set("json", this.createJsonRequirer());
122
161
  this.requirers.set("entry", (_, modulePath, context) => {
123
162
  if (Array.isArray(modulePath)) {
@@ -126,6 +165,9 @@ class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
126
165
  if (modulePath.endsWith(".json")) {
127
166
  return this.requirers.get("json")(this._options.dist, modulePath, context);
128
167
  }
168
+ else if (modulePath.endsWith(".mjs")) {
169
+ return this.requirers.get("mjs")(this._options.dist, modulePath, context);
170
+ }
129
171
  return this.requirers.get("cjs")(this._options.dist, modulePath, context);
130
172
  });
131
173
  }
@@ -139,5 +181,63 @@ class FakeDocumentWebRunner extends cjs_1.CommonJsRunner {
139
181
  this.document.currentScript = this.oldCurrentScript;
140
182
  this.oldCurrentScript = null;
141
183
  }
184
+ createESMRequirer() {
185
+ const esmContext = node_vm_1.default.createContext({
186
+ ...this.baseModuleScope,
187
+ ...this.globalContext
188
+ }, {
189
+ name: "context for esm"
190
+ });
191
+ const esmCache = new Map();
192
+ return (currentDirectory, modulePath, context = {}) => {
193
+ const esmIdentifier = `esm-${currentDirectory}-${modulePath}`;
194
+ if (!node_vm_1.SourceTextModule) {
195
+ throw new Error("Running this test requires '--experimental-vm-modules'.\nRun with 'node --experimental-vm-modules node_modules/jest-cli/bin/jest'.");
196
+ }
197
+ const _require = this.getRequire();
198
+ const file = context.file || this.getFile(modulePath, currentDirectory);
199
+ if (!file) {
200
+ return this.requirers.get("miss")(currentDirectory, modulePath);
201
+ }
202
+ let esm = esmCache.get(file.path);
203
+ if (!esm) {
204
+ esm = new node_vm_1.SourceTextModule(file.content, {
205
+ identifier: `${esmIdentifier}-${file.path}`,
206
+ // no attribute
207
+ url: `${(0, node_url_1.pathToFileURL)(file.path).href}?${esmIdentifier}`,
208
+ context: esmContext,
209
+ initializeImportMeta: (meta, _) => {
210
+ meta.url = (0, node_url_1.pathToFileURL)(file.path).href;
211
+ },
212
+ importModuleDynamically: async (specifier, module) => {
213
+ const result = await _require(node_path_1.default.dirname(file.path), specifier, {
214
+ esmMode: type_1.EEsmMode.Evaluated
215
+ });
216
+ return await (0, asModule_1.default)(result, module.context);
217
+ }
218
+ });
219
+ esmCache.set(file.path, esm);
220
+ }
221
+ if (context.esmMode === type_1.EEsmMode.Unlinked)
222
+ return esm;
223
+ return (async () => {
224
+ await esm.link(async (specifier, referencingModule) => {
225
+ return await (0, asModule_1.default)(await _require(node_path_1.default.dirname(referencingModule.identifier
226
+ ? referencingModule.identifier.slice(esmIdentifier.length + 1)
227
+ : (0, node_url_1.fileURLToPath)(referencingModule.url)), specifier, {
228
+ esmMode: type_1.EEsmMode.Unlinked
229
+ }), referencingModule.context, true);
230
+ });
231
+ if (esm.instantiate)
232
+ esm.instantiate();
233
+ await esm.evaluate();
234
+ if (context.esmMode === type_1.EEsmMode.Evaluated) {
235
+ return esm;
236
+ }
237
+ const ns = esm.namespace;
238
+ return ns.default && ns.default instanceof Promise ? ns.default : ns;
239
+ })();
240
+ };
241
+ }
142
242
  }
143
243
  exports.FakeDocumentWebRunner = FakeDocumentWebRunner;
@@ -59,7 +59,7 @@ class JSDOMWebRunner extends cjs_1.CommonJsRunner {
59
59
  vmContext.global = {};
60
60
  }
61
61
  run(file) {
62
- if (!file.endsWith(".js")) {
62
+ if (!file.endsWith(".js") && !file.endsWith(".mjs")) {
63
63
  const cssElement = this.dom.window.document.createElement("link");
64
64
  cssElement.href = file;
65
65
  cssElement.rel = "stylesheet";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/test-tools",
3
- "version": "1.4.10",
3
+ "version": "1.5.0-beta.0",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -35,7 +35,7 @@
35
35
  "@babel/generator": "7.28.0",
36
36
  "@babel/parser": "7.28.0",
37
37
  "@babel/traverse": "7.28.0",
38
- "@babel/types": "7.28.1",
38
+ "@babel/types": "7.28.2",
39
39
  "cross-env": "^7.0.3",
40
40
  "csv-to-markdown-table": "^1.5.0",
41
41
  "deepmerge": "^4.3.1",
@@ -47,12 +47,12 @@
47
47
  "jest-diff": "^29.7.0",
48
48
  "jest-snapshot": "29.7.0",
49
49
  "jsdom": "^26.1.0",
50
- "memfs": "4.17.2",
50
+ "memfs": "4.36.0",
51
51
  "loader-utils": "^2.0.4",
52
52
  "path-serializer": "0.5.0",
53
53
  "pretty-format": "29.7.0",
54
54
  "rimraf": "^5.0.10",
55
- "source-map": "^0.7.4",
55
+ "source-map": "^0.7.6",
56
56
  "terser-webpack-plugin": "^5.3.14",
57
57
  "webpack": "5.99.9",
58
58
  "webpack-merge": "6.0.1",
@@ -62,7 +62,7 @@
62
62
  "@rspack/plugin-preact-refresh": "1.1.2",
63
63
  "@rspack/plugin-react-refresh": "^1.4.3",
64
64
  "@swc/helpers": "0.5.17",
65
- "@swc/plugin-remove-console": "^7.0.4",
65
+ "@swc/plugin-remove-console": "^9.0.0",
66
66
  "@types/babel__generator": "7.27.0",
67
67
  "@types/babel__traverse": "7.20.7",
68
68
  "@types/fs-extra": "11.0.4",
@@ -89,17 +89,17 @@
89
89
  "react-dom": "^19.1.0",
90
90
  "react-refresh": "^0.17.0",
91
91
  "sass-loader": "^16.0.5",
92
- "source-map": "^0.7.4",
92
+ "source-map": "^0.7.6",
93
93
  "source-map-loader": "^5.0.0",
94
94
  "style-loader": "^4.0.0",
95
95
  "terser": "5.43.1",
96
- "typescript": "^5.8.3",
96
+ "typescript": "^5.9.2",
97
97
  "wast-loader": "^1.14.1",
98
98
  "worker-rspack-loader": "^3.1.2",
99
- "@rspack/cli": "1.4.10",
100
- "@rspack/binding-testing": "1.4.1",
101
- "@rspack/test-tools": "1.4.10",
102
- "@rspack/core": "1.4.10"
99
+ "@rspack/cli": "1.5.0-beta.0",
100
+ "@rspack/core": "1.5.0-beta.0",
101
+ "@rspack/test-tools": "1.5.0-beta.0",
102
+ "@rspack/binding-testing": "1.4.1"
103
103
  },
104
104
  "peerDependencies": {
105
105
  "@rspack/core": ">=1.0.0"