@rspack-canary/test-tools 1.5.9-canary-bddc650e-20251012024608 → 1.5.9-canary-a915dabc-20251013174148

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.
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createBuiltinCase = createBuiltinCase;
7
7
  exports.defaultOptions = defaultOptions;
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
- const core_1 = require("@rspack/core");
10
9
  const fs_extra_1 = __importDefault(require("fs-extra"));
11
10
  const webpack_merge_1 = require("webpack-merge");
12
11
  const helper_1 = require("../helper");
@@ -164,27 +163,6 @@ function defaultOptions(context) {
164
163
  }
165
164
  defaultOptions = (0, webpack_merge_1.merge)(defaultOptions, caseOptions);
166
165
  }
167
- // TODO: remove builtin compatible code
168
- const defineOptions = defaultOptions.builtins?.define;
169
- if (defineOptions) {
170
- defaultOptions.plugins.push(new core_1.rspack.DefinePlugin(defineOptions));
171
- }
172
- const provideOptions = defaultOptions.builtins?.provide;
173
- if (provideOptions) {
174
- defaultOptions.plugins.push(new core_1.rspack.ProvidePlugin(provideOptions));
175
- }
176
- const htmlOptions = defaultOptions.builtins?.html;
177
- if (htmlOptions) {
178
- if (Array.isArray(htmlOptions)) {
179
- for (const item of htmlOptions) {
180
- defaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(item));
181
- }
182
- }
183
- else {
184
- defaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(htmlOptions));
185
- }
186
- }
187
- delete defaultOptions.builtins;
188
166
  if (!global.printLogger) {
189
167
  defaultOptions.infrastructureLogging = {
190
168
  level: "error"
@@ -81,7 +81,11 @@ async function run(env, context, name, findBundle) {
81
81
  const results = context.getValue(name, "modules") || [];
82
82
  await Promise.all(results);
83
83
  if (typeof testConfig.afterExecute === "function") {
84
- testConfig.afterExecute(compiler.getOptions());
84
+ let options = compiler.getOptions();
85
+ if (Array.isArray(options) && options.length === 1) {
86
+ options = options[0];
87
+ }
88
+ testConfig.afterExecute(options);
85
89
  }
86
90
  }
87
91
  async function check(env, context, name) {
@@ -71,7 +71,7 @@ function createErrorCase(name, src, dist, testConfig) {
71
71
  }
72
72
  function options(context, custom) {
73
73
  let options = {
74
- context: node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/fixtures/errors"),
74
+ context: node_path_1.default.resolve(__TEST_FIXTURES_PATH__, "errors"),
75
75
  mode: "none",
76
76
  devtool: false,
77
77
  optimization: {
package/dist/case/hook.js CHANGED
@@ -14,8 +14,8 @@ const webpack_merge_1 = __importDefault(require("webpack-merge"));
14
14
  const context_1 = require("../test/context");
15
15
  const creator_1 = require("../test/creator");
16
16
  const common_1 = require("./common");
17
- const srcDir = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/fixtures");
18
- const distDir = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/js/hook");
17
+ const srcDir = __TEST_FIXTURES_PATH__;
18
+ const distDir = node_path_1.default.resolve(__TEST_DIST_PATH__, "hook");
19
19
  const creator = new creator_1.BasicCaseCreator({
20
20
  clean: true,
21
21
  describe: true,
@@ -13,7 +13,7 @@ const core_1 = require("@rspack/core");
13
13
  const creator_1 = require("../test/creator");
14
14
  const common_1 = require("./common");
15
15
  const runner_1 = require("./runner");
16
- const NORMAL_CASES_ROOT = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/normalCases");
16
+ const NORMAL_CASES_ROOT = node_path_1.default.resolve(__TEST_PATH__, "normalCases");
17
17
  const createCaseOptions = (hot, mode) => {
18
18
  return {
19
19
  clean: true,
@@ -13,7 +13,6 @@ const helper_1 = require("../helper");
13
13
  const type_1 = require("../type");
14
14
  const format_code_1 = require("./format-code");
15
15
  const replace_runtime_module_name_1 = require("./replace-runtime-module-name");
16
- const WORKSPACE = node_path_1.default.resolve(__dirname, "../../../..");
17
16
  function compareFile(sourceFile, distFile, compareOptions) {
18
17
  const result = {
19
18
  type: type_1.ECompareResultType.Same,
@@ -49,7 +48,9 @@ function compareFile(sourceFile, distFile, compareOptions) {
49
48
  }
50
49
  return res;
51
50
  }
52
- const sourceContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default.readFileSync(sourceFile, "utf-8").replaceAll(WORKSPACE, "__WORKSPACE__"));
51
+ const sourceContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default
52
+ .readFileSync(sourceFile, "utf-8")
53
+ .replaceAll(__ROOT_PATH__, "__WORKSPACE__"));
53
54
  const sourceModules = (0, helper_1.parseModules)(sourceContent, {
54
55
  bootstrap: compareOptions.bootstrap,
55
56
  renameModule: compareOptions.renameModule
@@ -66,7 +67,9 @@ function compareFile(sourceFile, distFile, compareOptions) {
66
67
  distModules = JSON.parse(fs_extra_1.default.readFileSync(compareOptions.snapshot, "utf-8"));
67
68
  }
68
69
  else {
69
- const distContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default.readFileSync(distFile, "utf-8").replaceAll(WORKSPACE, "__WORKSPACE__"));
70
+ const distContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default
71
+ .readFileSync(distFile, "utf-8")
72
+ .replaceAll(__ROOT_PATH__, "__WORKSPACE__"));
70
73
  distModules = (0, helper_1.parseModules)(distContent, {
71
74
  bootstrap: compareOptions.bootstrap,
72
75
  renameModule: compareOptions.renameModule
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.normalizePlaceholder = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
4
  const path_serializer_1 = require("path-serializer");
9
5
  // 1. escapeEOL \r\n -> \n
10
6
  // 2. replace <RSPACK_ROOT> etc
@@ -13,14 +9,18 @@ const placeholderSerializer = (0, path_serializer_1.createSnapshotSerializer)({
13
9
  root: __dirname.includes("node_modules")
14
10
  ? // Use `process.cwd()` when using outside Rspack
15
11
  process.cwd()
16
- : node_path_1.default.resolve(__dirname, "../../../../../"),
12
+ : __ROOT_PATH__,
17
13
  replace: [
18
14
  {
19
- match: node_path_1.default.resolve(__dirname, "../../../../../tests/rspack-test"),
15
+ match: __RSPACK_TEST_TOOLS_PATH__,
20
16
  mark: "test_tools_root"
21
17
  },
22
18
  {
23
- match: node_path_1.default.resolve(__dirname, "../../../../rspack"),
19
+ match: __TEST_PATH__,
20
+ mark: "test_root"
21
+ },
22
+ {
23
+ match: __RSPACK_PATH__,
24
24
  mark: "rspack_root"
25
25
  },
26
26
  {
@@ -1,4 +1,3 @@
1
- import type { FileMatcherOptions } from "../../../jest";
2
1
  /**
3
2
  * Match given content against content of the specified file.
4
3
  *
@@ -0,0 +1,2 @@
1
+ declare function _exports(): boolean;
2
+ export = _exports;
@@ -0,0 +1,10 @@
1
+ // @ts-nocheck
2
+ "use strict";
3
+ module.exports = function supportsTextDecoder() {
4
+ try {
5
+ return typeof TextDecoder !== "undefined";
6
+ }
7
+ catch (_err) {
8
+ return false;
9
+ }
10
+ };
@@ -42,6 +42,7 @@ const node_path_1 = __importDefault(require("node:path"));
42
42
  const node_url_1 = require("node:url");
43
43
  const node_vm_1 = __importStar(require("node:vm"));
44
44
  const asModule_1 = __importDefault(require("../../helper/legacy/asModule"));
45
+ const createFakeWorker_1 = __importDefault(require("../../helper/legacy/createFakeWorker"));
45
46
  const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
46
47
  const type_1 = require("../../type");
47
48
  const isRelativePath = (p) => /^\.\.?\//.test(p);
@@ -165,6 +166,9 @@ class NodeRunner {
165
166
  setImmediate,
166
167
  __MODE__: this._options.compilerOptions.mode,
167
168
  __SNAPSHOT__: node_path_1.default.join(this._options.source, "__snapshot__"),
169
+ Worker: (0, createFakeWorker_1.default)(this._options.env, {
170
+ outputDirectory: this._options.dist
171
+ }),
168
172
  ...this._options.env
169
173
  };
170
174
  return baseModuleScope;
@@ -102,9 +102,6 @@ class FakeDocumentWebRunner extends node_1.NodeRunner {
102
102
  this.requirers.get("entry")(this._options.dist, (0, urlToRelativePath_1.default)(url));
103
103
  };
104
104
  globalContext.document = this.document;
105
- globalContext.Worker = (0, createFakeWorker_1.default)(this._options.env, {
106
- outputDirectory: this._options.dist
107
- });
108
105
  globalContext.EventSource = EventSourceForNode_1.default;
109
106
  globalContext.location = {
110
107
  href: "https://test.cases/path/index.html",
@@ -169,6 +166,12 @@ class FakeDocumentWebRunner extends node_1.NodeRunner {
169
166
  if (!file) {
170
167
  return this.requirers.get("miss")(currentDirectory, modulePath);
171
168
  }
169
+ if (file.content.includes("__STATS_I__")) {
170
+ const statsIndex = this._options.stats?.()?.__index__;
171
+ if (typeof statsIndex === "number") {
172
+ esmContext.__STATS_I__ = statsIndex;
173
+ }
174
+ }
172
175
  let esm = esmCache.get(file.path);
173
176
  if (!esm) {
174
177
  esm = new node_vm_1.SourceTextModule(file.content, {
@@ -8,7 +8,6 @@ const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const jsdom_1 = require("jsdom");
10
10
  const helper_1 = require("../../helper");
11
- const createFakeWorker_1 = __importDefault(require("../../helper/legacy/createFakeWorker"));
12
11
  const EventSourceForNode_1 = __importDefault(require("../../helper/legacy/EventSourceForNode"));
13
12
  const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
14
13
  const node_1 = require("../node");
@@ -110,9 +109,6 @@ class JSDOMWebRunner extends node_1.NodeRunner {
110
109
  createBaseModuleScope() {
111
110
  const moduleScope = super.createBaseModuleScope();
112
111
  moduleScope.EventSource = EventSourceForNode_1.default;
113
- moduleScope.Worker = (0, createFakeWorker_1.default)(this._options.env, {
114
- outputDirectory: this._options.dist
115
- });
116
112
  const urlToPath = (url) => {
117
113
  return node_path_1.default.resolve(this._webOptions.dist, `./${url.startsWith("https://test.cases/path/") ? url.slice(24) : url}`);
118
114
  };
package/dist/type.d.ts CHANGED
@@ -201,3 +201,11 @@ export type TTestRunnerCreator = {
201
201
  key: (context: ITestContext, name: string, file: string) => string;
202
202
  runner: (context: ITestContext, name: string, file: string, env: ITestEnv) => ITestRunner;
203
203
  };
204
+ declare global {
205
+ var __TEST_PATH__: string;
206
+ var __TEST_FIXTURES_PATH__: string;
207
+ var __TEST_DIST_PATH__: string;
208
+ var __ROOT_PATH__: string;
209
+ var __RSPACK_PATH__: string;
210
+ var __RSPACK_TEST_TOOLS_PATH__: string;
211
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack-canary/test-tools",
3
- "version": "1.5.9-canary-bddc650e-20251012024608",
3
+ "version": "1.5.9-canary-a915dabc-20251013174148",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -100,10 +100,10 @@
100
100
  "wast-loader": "^1.14.1",
101
101
  "worker-rspack-loader": "^3.1.2",
102
102
  "exports-loader": "^5.0.0",
103
- "@rspack/cli": "npm:@rspack-canary/cli@1.5.9-canary-bddc650e-20251012024608",
104
- "@rspack/binding-testing": "1.4.1",
105
- "@rspack/core": "npm:@rspack-canary/core@1.5.9-canary-bddc650e-20251012024608",
106
- "@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.9-canary-bddc650e-20251012024608"
103
+ "@rspack/cli": "npm:@rspack-canary/cli@1.5.9-canary-a915dabc-20251013174148",
104
+ "@rspack/core": "npm:@rspack-canary/core@1.5.9-canary-a915dabc-20251013174148",
105
+ "@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.9-canary-a915dabc-20251013174148",
106
+ "@rspack/binding-testing": "1.4.1"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "@rspack/core": ">=1.0.0"