@rspack/test-tools 2.0.1 → 2.0.3

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 (118) hide show
  1. package/dist/case/builtin.js +106 -66
  2. package/dist/case/cache.js +152 -132
  3. package/dist/case/common.d.ts +4 -4
  4. package/dist/case/common.js +162 -157
  5. package/dist/case/compiler.d.ts +4 -4
  6. package/dist/case/compiler.js +75 -64
  7. package/dist/case/config.js +112 -74
  8. package/dist/case/defaults.js +136 -83
  9. package/dist/case/diagnostic.js +112 -84
  10. package/dist/case/error.d.ts +4 -4
  11. package/dist/case/error.js +105 -89
  12. package/dist/case/esm-output.js +118 -87
  13. package/dist/case/example.js +73 -35
  14. package/dist/case/hash.js +74 -59
  15. package/dist/case/hook.js +151 -138
  16. package/dist/case/hot-step.js +130 -161
  17. package/dist/case/hot.js +148 -134
  18. package/dist/case/incremental.js +91 -58
  19. package/dist/case/index.js +134 -51
  20. package/dist/case/multi-compiler.d.ts +4 -4
  21. package/dist/case/multi-compiler.js +81 -56
  22. package/dist/case/native-watcher.js +62 -30
  23. package/dist/case/normal.js +253 -185
  24. package/dist/case/runner.js +80 -51
  25. package/dist/case/serial.js +47 -16
  26. package/dist/case/stats-api.d.ts +4 -4
  27. package/dist/case/stats-api.js +63 -43
  28. package/dist/case/stats-output.d.ts +3 -3
  29. package/dist/case/stats-output.js +147 -152
  30. package/dist/case/treeshaking.js +66 -35
  31. package/dist/case/watch.d.ts +3 -19
  32. package/dist/case/watch.js +204 -224
  33. package/dist/compiler.js +222 -195
  34. package/dist/helper/directory.js +83 -71
  35. package/dist/helper/disable-iconv-lite-warning.js +35 -9
  36. package/dist/helper/expect/diff.js +39 -10
  37. package/dist/helper/expect/error.js +62 -30
  38. package/dist/helper/expect/placeholder.js +47 -21
  39. package/dist/helper/expect/rspack.js +35 -13
  40. package/dist/helper/expect/to-be-typeof.js +39 -7
  41. package/dist/helper/expect/to-end-with.js +40 -8
  42. package/dist/helper/expect/to-match-file-snapshot.js +103 -80
  43. package/dist/helper/hot-update/index.js +35 -4
  44. package/dist/helper/hot-update/loader.d.ts +1 -0
  45. package/dist/helper/hot-update/loader.js +39 -4
  46. package/dist/helper/hot-update/plugin.d.ts +1 -1
  47. package/dist/helper/hot-update/plugin.js +87 -74
  48. package/dist/helper/index.js +138 -24
  49. package/dist/helper/is.js +51 -10
  50. package/dist/helper/legacy/EventSourceForNode.d.ts +11 -3
  51. package/dist/helper/legacy/EventSourceForNode.js +83 -37
  52. package/dist/helper/legacy/LogTestPlugin.d.ts +2 -3
  53. package/dist/helper/legacy/LogTestPlugin.js +39 -6
  54. package/dist/helper/legacy/asModule.d.ts +3 -3
  55. package/dist/helper/legacy/asModule.js +68 -19
  56. package/dist/helper/legacy/captureStdio.d.ts +1 -2
  57. package/dist/helper/legacy/captureStdio.js +69 -29
  58. package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -2
  59. package/dist/helper/legacy/checkArrayExpectation.js +132 -121
  60. package/dist/helper/legacy/copyDiff.d.ts +1 -2
  61. package/dist/helper/legacy/copyDiff.js +86 -42
  62. package/dist/helper/legacy/createFakeWorker.d.ts +2 -3
  63. package/dist/helper/legacy/createFakeWorker.js +90 -47
  64. package/dist/helper/legacy/createLazyTestEnv.d.ts +2 -3
  65. package/dist/helper/legacy/createLazyTestEnv.js +70 -59
  66. package/dist/helper/legacy/currentScript.d.ts +2 -2
  67. package/dist/helper/legacy/currentScript.js +35 -2
  68. package/dist/helper/legacy/deprecationTracking.d.ts +1 -1
  69. package/dist/helper/legacy/deprecationTracking.js +53 -28
  70. package/dist/helper/legacy/expectSource.d.ts +3 -2
  71. package/dist/helper/legacy/expectSource.js +42 -18
  72. package/dist/helper/legacy/fakeSystem.d.ts +12 -9
  73. package/dist/helper/legacy/fakeSystem.js +68 -58
  74. package/dist/helper/legacy/findOutputFiles.d.ts +7 -2
  75. package/dist/helper/legacy/findOutputFiles.js +60 -13
  76. package/dist/helper/legacy/parseResource.d.ts +1 -1
  77. package/dist/helper/legacy/parseResource.js +36 -6
  78. package/dist/helper/legacy/regexEscape.d.ts +1 -2
  79. package/dist/helper/legacy/regexEscape.js +39 -5
  80. package/dist/helper/legacy/supportDefaultAssignment.d.ts +1 -2
  81. package/dist/helper/legacy/supportDefaultAssignment.js +40 -7
  82. package/dist/helper/legacy/supportsTextDecoder.d.ts +1 -2
  83. package/dist/helper/legacy/supportsTextDecoder.js +40 -6
  84. package/dist/helper/legacy/supportsUsing.d.ts +1 -2
  85. package/dist/helper/legacy/supportsUsing.js +40 -7
  86. package/dist/helper/legacy/urlToRelativePath.d.ts +2 -2
  87. package/dist/helper/legacy/urlToRelativePath.js +56 -7
  88. package/dist/helper/parse-modules.js +52 -42
  89. package/dist/helper/read-config-file.js +60 -18
  90. package/dist/helper/serializers.js +62 -33
  91. package/dist/helper/setup-env.js +81 -91
  92. package/dist/helper/setup-expect.js +13 -13
  93. package/dist/helper/setup-wasm.js +18 -9
  94. package/dist/helper/stringify-config.js +44 -26
  95. package/dist/helper/update-snapshot.js +35 -3
  96. package/dist/helper/util/checkSourceMap.js +119 -80
  97. package/dist/helper/util/checkStats.d.ts +1 -1
  98. package/dist/helper/util/checkStats.js +42 -17
  99. package/dist/helper/util/expectWarningFactory.d.ts +1 -2
  100. package/dist/helper/util/expectWarningFactory.js +41 -8
  101. package/dist/helper/util/filterUtil.d.ts +9 -8
  102. package/dist/helper/util/filterUtil.js +63 -23
  103. package/dist/helper/win.js +46 -7
  104. package/dist/index.js +115 -23
  105. package/dist/plugin/index.js +55 -14
  106. package/dist/plugin/lazy-compilation-test-plugin.js +55 -41
  107. package/dist/reporter/index.js +55 -14
  108. package/dist/reporter/streamed-events-reporter.js +51 -77
  109. package/dist/runner/index.js +62 -15
  110. package/dist/runner/node/index.js +365 -431
  111. package/dist/runner/web/index.js +278 -263
  112. package/dist/test/context.js +67 -41
  113. package/dist/test/creator.js +135 -167
  114. package/dist/test/debug.js +89 -58
  115. package/dist/test/tester.js +94 -74
  116. package/dist/type.d.ts +10 -9
  117. package/dist/type.js +43 -9
  118. package/package.json +24 -23
@@ -1,471 +1,405 @@
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]; } };
2
+ var __webpack_modules__ = {
3
+ "@rspack/test-tools" (module) {
4
+ module.exports = require("@rspack/test-tools");
7
5
  }
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);
6
+ };
7
+ var __webpack_module_cache__ = {};
8
+ function __webpack_require__(moduleId) {
9
+ var cachedModule = __webpack_module_cache__[moduleId];
10
+ if (void 0 !== cachedModule) return cachedModule.exports;
11
+ var module = __webpack_module_cache__[moduleId] = {
12
+ exports: {}
26
13
  };
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;
14
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
15
+ return module.exports;
16
+ }
17
+ (()=>{
18
+ __webpack_require__.n = (module)=>{
19
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
20
+ __webpack_require__.d(getter, {
21
+ a: getter
22
+ });
23
+ return getter;
33
24
  };
34
25
  })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.NodeRunner = void 0;
40
- const node_fs_1 = __importDefault(require("node:fs"));
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 config_1 = require("../../case/config");
45
- const asModule_1 = __importDefault(require("../../helper/legacy/asModule"));
46
- const createFakeWorker_1 = __importDefault(require("../../helper/legacy/createFakeWorker"));
47
- const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
48
- const type_1 = require("../../type");
49
- const isRelativePath = (p) => /^\.\.?\//.test(p);
50
- const getSubPath = (p) => {
51
- const lastSlash = p.lastIndexOf('/');
52
- let firstSlash = p.indexOf('/');
53
- if (lastSlash !== -1 && firstSlash !== lastSlash) {
54
- if (firstSlash !== -1) {
55
- let next = p.indexOf('/', firstSlash + 1);
56
- let dir = p.slice(firstSlash + 1, next);
57
- while (dir === '.') {
58
- firstSlash = next;
59
- next = p.indexOf('/', firstSlash + 1);
60
- dir = p.slice(firstSlash + 1, next);
26
+ (()=>{
27
+ __webpack_require__.d = (exports1, definition)=>{
28
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
29
+ enumerable: true,
30
+ get: definition[key]
31
+ });
32
+ };
33
+ })();
34
+ (()=>{
35
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
36
+ })();
37
+ (()=>{
38
+ __webpack_require__.r = (exports1)=>{
39
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
40
+ value: 'Module'
41
+ });
42
+ Object.defineProperty(exports1, '__esModule', {
43
+ value: true
44
+ });
45
+ };
46
+ })();
47
+ var __webpack_exports__ = {};
48
+ (()=>{
49
+ __webpack_require__.r(__webpack_exports__);
50
+ __webpack_require__.d(__webpack_exports__, {
51
+ NodeRunner: ()=>NodeRunner
52
+ });
53
+ const external_node_fs_namespaceObject = require("node:fs");
54
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
55
+ const external_node_path_namespaceObject = require("node:path");
56
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
57
+ const external_node_url_namespaceObject = require("node:url");
58
+ const external_node_vm_namespaceObject = require("node:vm");
59
+ var external_node_vm_default = /*#__PURE__*/ __webpack_require__.n(external_node_vm_namespaceObject);
60
+ const config_js_namespaceObject = require("../../case/config.js");
61
+ const asModule_js_namespaceObject = require("../../helper/legacy/asModule.js");
62
+ const createFakeWorker_js_namespaceObject = require("../../helper/legacy/createFakeWorker.js");
63
+ const urlToRelativePath_js_namespaceObject = require("../../helper/legacy/urlToRelativePath.js");
64
+ const external_type_js_namespaceObject = require("../../type.js");
65
+ const isRelativePath = (p)=>/^\.\.?\//.test(p);
66
+ const getSubPath = (p)=>{
67
+ const lastSlash = p.lastIndexOf('/');
68
+ let firstSlash = p.indexOf('/');
69
+ if (-1 !== lastSlash && firstSlash !== lastSlash) {
70
+ if (-1 !== firstSlash) {
71
+ let next = p.indexOf('/', firstSlash + 1);
72
+ let dir = p.slice(firstSlash + 1, next);
73
+ while('.' === dir){
74
+ firstSlash = next;
75
+ next = p.indexOf('/', firstSlash + 1);
76
+ dir = p.slice(firstSlash + 1, next);
77
+ }
61
78
  }
79
+ return p.slice(firstSlash + 1, lastSlash + 1);
62
80
  }
63
- return p.slice(firstSlash + 1, lastSlash + 1);
64
- }
65
- return '';
66
- };
67
- const cached = new Map();
68
- class NodeRunner {
69
- constructor(_options) {
70
- this._options = _options;
71
- this.requireCache = Object.create(null);
72
- this.globalContext = null;
73
- this.baseModuleScope = null;
74
- this.requirers = new Map();
75
- }
76
- log(message) {
77
- this._options.logs?.push(`[NodeRunner] ${message}`);
78
- }
79
- run(file) {
80
- if (!this.globalContext) {
81
- this.globalContext = this.createGlobalContext();
81
+ return '';
82
+ };
83
+ const cached = new Map();
84
+ class NodeRunner {
85
+ _options;
86
+ requireCache = Object.create(null);
87
+ globalContext = null;
88
+ baseModuleScope = null;
89
+ requirers = new Map();
90
+ constructor(_options){
91
+ this._options = _options;
82
92
  }
83
- this.baseModuleScope = this.createBaseModuleScope();
84
- if (typeof this._options.testConfig.moduleScope === 'function') {
85
- this._options.testConfig.moduleScope(this.baseModuleScope, this._options.stats, this._options.compilerOptions);
93
+ log(message) {
94
+ this._options.logs?.push(`[NodeRunner] ${message}`);
86
95
  }
87
- this.createRunner();
88
- const res = this.getRequire()(node_path_1.default.isAbsolute(file) ? node_path_1.default.dirname(file) : this._options.dist, file.startsWith('./') ||
89
- file.startsWith('https://test.cases/') ||
90
- node_path_1.default.isAbsolute(file)
91
- ? file
92
- : `./${file}`);
93
- if (this.globalContext.WAITING.length) {
94
- return Promise.all(this.globalContext.WAITING).then(() => res);
96
+ run(file) {
97
+ if (!this.globalContext) this.globalContext = this.createGlobalContext();
98
+ this.baseModuleScope = this.createBaseModuleScope();
99
+ if ('function' == typeof this._options.testConfig.moduleScope) this._options.testConfig.moduleScope(this.baseModuleScope, this._options.stats, this._options.compilerOptions);
100
+ this.createRunner();
101
+ const res = this.getRequire()(external_node_path_default().isAbsolute(file) ? external_node_path_default().dirname(file) : this._options.dist, file.startsWith('./') || file.startsWith('https://test.cases/') || external_node_path_default().isAbsolute(file) ? file : `./${file}`);
102
+ if (this.globalContext.WAITING.length) return Promise.all(this.globalContext.WAITING).then(()=>res);
103
+ if ('object' == typeof res && 'then' in res) return res;
104
+ return Promise.resolve(res);
95
105
  }
96
- if (typeof res === 'object' && 'then' in res) {
97
- return res;
106
+ getRequire() {
107
+ const entryRequire = this.requirers.get('entry');
108
+ const runner = this;
109
+ return function(currentDirectory, modulePath, context = {}) {
110
+ const from = this?.from;
111
+ if (from) runner.log(`require: ${modulePath} from ${from}`);
112
+ else runner.log(`require: ${modulePath}`);
113
+ const p = Array.isArray(modulePath) ? modulePath : modulePath.split('?')[0];
114
+ return entryRequire(currentDirectory, p, context);
115
+ };
98
116
  }
99
- return Promise.resolve(res);
100
- }
101
- getRequire() {
102
- const entryRequire = this.requirers.get('entry');
103
- const runner = this;
104
- return function (currentDirectory, modulePath, context = {}) {
105
- const from = this?.from;
106
- if (from) {
107
- runner.log(`require: ${modulePath} from ${from}`);
108
- }
109
- else {
110
- runner.log(`require: ${modulePath}`);
111
- }
112
- const p = Array.isArray(modulePath)
113
- ? modulePath
114
- : modulePath.split('?')[0];
115
- return entryRequire(currentDirectory, p, context);
116
- };
117
- }
118
- getGlobal(name) {
119
- return (this.globalContext || {})[name];
120
- }
121
- createGlobalContext() {
122
- return {
123
- console: {
124
- log: (...args) => {
125
- if (printLogger) {
126
- console.log(...args);
127
- }
128
- },
129
- warn: (...args) => {
130
- if (printLogger) {
131
- console.warn(...args);
132
- }
133
- },
134
- error: (...args) => {
135
- console.error(...args);
136
- },
137
- info: (...args) => {
138
- if (printLogger) {
139
- console.info(...args);
140
- }
141
- },
142
- debug: (...args) => {
143
- if (printLogger) {
144
- console.info(...args);
145
- }
146
- },
147
- trace: (...args) => {
148
- if (printLogger) {
149
- console.info(...args);
117
+ getGlobal(name) {
118
+ return (this.globalContext || {})[name];
119
+ }
120
+ createGlobalContext() {
121
+ return {
122
+ console: {
123
+ log: (...args)=>{
124
+ if (printLogger) console.log(...args);
125
+ },
126
+ warn: (...args)=>{
127
+ if (printLogger) console.warn(...args);
128
+ },
129
+ error: (...args)=>{
130
+ console.error(...args);
131
+ },
132
+ info: (...args)=>{
133
+ if (printLogger) console.info(...args);
134
+ },
135
+ debug: (...args)=>{
136
+ if (printLogger) console.info(...args);
137
+ },
138
+ trace: (...args)=>{
139
+ if (printLogger) console.info(...args);
140
+ },
141
+ assert: (...args)=>{
142
+ console.assert(...args);
143
+ },
144
+ clear: ()=>{
145
+ console.clear();
150
146
  }
151
147
  },
152
- assert: (...args) => {
153
- console.assert(...args);
154
- },
155
- clear: () => {
156
- console.clear();
148
+ WAITING: [],
149
+ setTimeout: (cb, ms, ...args)=>{
150
+ const timeout = setTimeout(cb, ms, ...args);
151
+ timeout.unref();
152
+ return timeout;
157
153
  },
158
- },
159
- WAITING: [],
160
- setTimeout: ((cb, ms, ...args) => {
161
- const timeout = setTimeout(cb, ms, ...args);
162
- timeout.unref();
163
- return timeout;
164
- }),
165
- clearTimeout: clearTimeout,
166
- };
167
- }
168
- createBaseModuleScope() {
169
- const baseModuleScope = {
170
- console: this.globalContext.console,
171
- setTimeout: this.globalContext.setTimeout,
172
- clearTimeout: this.globalContext.clearTimeout,
173
- nsObj: (m) => {
174
- Object.defineProperty(m, Symbol.toStringTag, {
175
- value: 'Module',
176
- });
177
- return m;
178
- },
179
- WAITING: this.globalContext.WAITING,
180
- process,
181
- TextDecoder,
182
- URL,
183
- Blob,
184
- Symbol,
185
- Buffer,
186
- setImmediate,
187
- self: this.globalContext,
188
- __TEST_PATH__: __TEST_PATH__,
189
- __TEST_SOURCE_PATH__: this._options.source,
190
- __TEST_DIST_PATH__: this._options.dist,
191
- __MODE__: this._options.compilerOptions.mode,
192
- __SNAPSHOT__: node_path_1.default.join(this._options.source, '__snapshot__'),
193
- Worker: (0, createFakeWorker_1.default)(this._options.env, {
194
- outputDirectory: this._options.dist,
195
- }),
196
- ...this._options.env,
197
- };
198
- return baseModuleScope;
199
- }
200
- createModuleScope(requireFn, m, file) {
201
- const requirer = requireFn.bind({
202
- from: file.path,
203
- module: m,
204
- }, node_path_1.default.dirname(file.path));
205
- requirer.webpackTestSuiteRequire = true;
206
- return {
207
- ...this.baseModuleScope,
208
- require: requirer,
209
- module: m,
210
- exports: m.exports,
211
- __dirname: node_path_1.default.dirname(file.path),
212
- __filename: file.path,
213
- _globalAssign: {
214
- expect: this._options.env.expect,
215
- },
216
- };
217
- }
218
- getFile(modulePath, currentDirectory) {
219
- const cacheKey = `${currentDirectory}|${modulePath}`;
220
- if (this._options.cachable && cached.has(cacheKey)) {
221
- return cached.get(cacheKey);
222
- }
223
- let res = null;
224
- if (Array.isArray(modulePath)) {
225
- res = {
226
- path: node_path_1.default.join(currentDirectory, '.array-require.js'),
227
- content: `module.exports = (${modulePath
228
- .map((arg) => {
229
- return `require(${JSON.stringify(`./${arg}`)})`;
230
- })
231
- .join(', ')});`,
232
- subPath: '',
154
+ clearTimeout: clearTimeout
233
155
  };
234
156
  }
235
- else if (modulePath.startsWith('https://test.cases/')) {
236
- const relativePath = (0, urlToRelativePath_1.default)(modulePath);
237
- const absPath = node_path_1.default.join(currentDirectory, relativePath);
238
- res = {
239
- path: absPath,
240
- content: node_fs_1.default.readFileSync(absPath, 'utf-8'),
241
- subPath: '',
157
+ createBaseModuleScope() {
158
+ const baseModuleScope = {
159
+ console: this.globalContext.console,
160
+ setTimeout: this.globalContext.setTimeout,
161
+ clearTimeout: this.globalContext.clearTimeout,
162
+ nsObj: (m)=>{
163
+ Object.defineProperty(m, Symbol.toStringTag, {
164
+ value: 'Module'
165
+ });
166
+ return m;
167
+ },
168
+ WAITING: this.globalContext.WAITING,
169
+ process,
170
+ TextDecoder,
171
+ URL,
172
+ Blob,
173
+ Symbol,
174
+ Buffer,
175
+ setImmediate,
176
+ self: this.globalContext,
177
+ __TEST_PATH__: __TEST_PATH__,
178
+ __TEST_SOURCE_PATH__: this._options.source,
179
+ __TEST_DIST_PATH__: this._options.dist,
180
+ __MODE__: this._options.compilerOptions.mode,
181
+ __SNAPSHOT__: external_node_path_default().join(this._options.source, '__snapshot__'),
182
+ Worker: (0, createFakeWorker_js_namespaceObject.createFakeWorker)(this._options.env, {
183
+ outputDirectory: this._options.dist
184
+ }),
185
+ ...this._options.env
242
186
  };
187
+ return baseModuleScope;
243
188
  }
244
- else if (isRelativePath(modulePath)) {
245
- const p = node_path_1.default.join(currentDirectory, modulePath);
246
- res = {
247
- path: p,
248
- content: node_fs_1.default.readFileSync(p, 'utf-8'),
249
- subPath: getSubPath(modulePath),
189
+ createModuleScope(requireFn, m, file) {
190
+ const requirer = requireFn.bind({
191
+ from: file.path,
192
+ module: m
193
+ }, external_node_path_default().dirname(file.path));
194
+ requirer.webpackTestSuiteRequire = true;
195
+ return {
196
+ ...this.baseModuleScope,
197
+ require: requirer,
198
+ module: m,
199
+ exports: m.exports,
200
+ __dirname: external_node_path_default().dirname(file.path),
201
+ __filename: file.path,
202
+ _globalAssign: {
203
+ expect: this._options.env.expect
204
+ }
250
205
  };
251
206
  }
252
- else if (node_path_1.default.isAbsolute(modulePath)) {
253
- res = {
207
+ getFile(modulePath, currentDirectory) {
208
+ const cacheKey = `${currentDirectory}|${modulePath}`;
209
+ if (this._options.cachable && cached.has(cacheKey)) return cached.get(cacheKey);
210
+ let res = null;
211
+ if (Array.isArray(modulePath)) res = {
212
+ path: external_node_path_default().join(currentDirectory, '.array-require.js'),
213
+ content: `module.exports = (${modulePath.map((arg)=>`require(${JSON.stringify(`./${arg}`)})`).join(', ')});`,
214
+ subPath: ''
215
+ };
216
+ else if (modulePath.startsWith('https://test.cases/')) {
217
+ const relativePath = (0, urlToRelativePath_js_namespaceObject.urlToRelativePath)(modulePath);
218
+ const absPath = external_node_path_default().join(currentDirectory, relativePath);
219
+ res = {
220
+ path: absPath,
221
+ content: external_node_fs_default().readFileSync(absPath, 'utf-8'),
222
+ subPath: ''
223
+ };
224
+ } else if (isRelativePath(modulePath)) {
225
+ const p = external_node_path_default().join(currentDirectory, modulePath);
226
+ res = {
227
+ path: p,
228
+ content: external_node_fs_default().readFileSync(p, 'utf-8'),
229
+ subPath: getSubPath(modulePath)
230
+ };
231
+ } else if (external_node_path_default().isAbsolute(modulePath)) res = {
254
232
  path: modulePath,
255
- content: node_fs_1.default.readFileSync(modulePath, 'utf-8'),
256
- subPath: 'absolute_path',
233
+ content: external_node_fs_default().readFileSync(modulePath, 'utf-8'),
234
+ subPath: 'absolute_path'
257
235
  };
236
+ if (this._options.cachable && res) cached.set(cacheKey, res);
237
+ return res;
258
238
  }
259
- if (this._options.cachable && res) {
260
- cached.set(cacheKey, res);
261
- }
262
- return res;
263
- }
264
- preExecute(code, file) { }
265
- postExecute(m, file) { }
266
- createRunner() {
267
- this.requirers.set('cjs', this.createCjsRequirer());
268
- this.requirers.set('esm', this.createEsmRequirer());
269
- this.requirers.set('miss', this.createMissRequirer());
270
- this.requirers.set('json', this.createJsonRequirer());
271
- this.requirers.set('entry', (currentDirectory, modulePath, context) => {
272
- const file = this.getFile(modulePath, currentDirectory);
273
- this.log(`entry: ${modulePath} -> ${file?.path}`);
274
- if (!file) {
275
- return this.requirers.get('miss')(currentDirectory, modulePath);
276
- }
277
- if (file.path.endsWith('.json')) {
278
- return this.requirers.get('json')(currentDirectory, modulePath, {
239
+ preExecute(code, file) {}
240
+ postExecute(m, file) {}
241
+ createRunner() {
242
+ this.requirers.set('cjs', this.createCjsRequirer());
243
+ this.requirers.set('esm', this.createEsmRequirer());
244
+ this.requirers.set('miss', this.createMissRequirer());
245
+ this.requirers.set('json', this.createJsonRequirer());
246
+ this.requirers.set('entry', (currentDirectory, modulePath, context)=>{
247
+ const file = this.getFile(modulePath, currentDirectory);
248
+ this.log(`entry: ${modulePath} -> ${file?.path}`);
249
+ if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
250
+ if (file.path.endsWith('.json')) return this.requirers.get('json')(currentDirectory, modulePath, {
279
251
  ...context,
280
- file,
252
+ file
281
253
  });
282
- }
283
- if (file.path.endsWith('.mjs') ||
284
- (0, config_1.enableEsmLibraryPlugin)(this._options.compilerOptions)) {
285
- return this.requirers.get('esm')(currentDirectory, modulePath, {
254
+ if (file.path.endsWith('.mjs') || (0, config_js_namespaceObject.enableEsmLibraryPlugin)(this._options.compilerOptions)) return this.requirers.get('esm')(currentDirectory, modulePath, {
286
255
  ...context,
287
- file,
256
+ file
257
+ });
258
+ return this.requirers.get('cjs')(currentDirectory, modulePath, {
259
+ ...context,
260
+ file
288
261
  });
289
- }
290
- return this.requirers.get('cjs')(currentDirectory, modulePath, {
291
- ...context,
292
- file,
293
262
  });
294
- });
295
- }
296
- createMissRequirer() {
297
- return (currentDirectory, modulePath, context = {}) => {
298
- this.log(`missing: ${modulePath}`);
299
- const modulePathStr = modulePath;
300
- const modules = this._options.testConfig.modules;
301
- if (modules && modulePathStr in modules) {
302
- this.log(`mock module: ${modulePathStr}`);
303
- return modules[modulePathStr];
304
- }
305
- this.log(`native require: ${modulePathStr}`);
306
- return require(modulePathStr.startsWith('node:')
307
- ? modulePathStr.slice(5)
308
- : modulePathStr);
309
- };
310
- }
311
- createJsonRequirer() {
312
- return (currentDirectory, modulePath, context = {}) => {
313
- if (Array.isArray(modulePath)) {
314
- throw new Error('Array module path is not supported in hot cases');
315
- }
316
- const file = context.file || this.getFile(modulePath, currentDirectory);
317
- this.log(`json: ${modulePath} -> ${file?.path}`);
318
- if (!file) {
319
- return this.requirers.get('miss')(currentDirectory, modulePath);
320
- }
321
- return JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(this._options.dist, modulePath), 'utf-8'));
322
- };
323
- }
324
- createCjsRequirer() {
325
- return (currentDirectory, modulePath, context = {}) => {
326
- if (modulePath === '@rspack/test-tools') {
327
- return require('@rspack/test-tools');
328
- }
329
- const file = context.file || this.getFile(modulePath, currentDirectory);
330
- this.log(`cjs: ${modulePath} -> ${file?.path}`);
331
- if (!file) {
332
- return this.requirers.get('miss')(currentDirectory, modulePath);
333
- }
334
- if (file.path in this.requireCache) {
335
- this.log(`cjs cache hit: ${file.path}`);
336
- return this.requireCache[file.path].exports;
337
- }
338
- const m = {
339
- exports: {},
340
- webpackTestSuiteModule: true,
263
+ }
264
+ createMissRequirer() {
265
+ return (currentDirectory, modulePath, context = {})=>{
266
+ this.log(`missing: ${modulePath}`);
267
+ const modulePathStr = modulePath;
268
+ const modules = this._options.testConfig.modules;
269
+ if (modules && modulePathStr in modules) {
270
+ this.log(`mock module: ${modulePathStr}`);
271
+ return modules[modulePathStr];
272
+ }
273
+ this.log(`native require: ${modulePathStr}`);
274
+ return require(modulePathStr.startsWith('node:') ? modulePathStr.slice(5) : modulePathStr);
341
275
  };
342
- this.requireCache[file.path] = m;
343
- if (!this._options.runInNewContext) {
344
- file.content = `Object.assign(global, _globalAssign);${file.content}`;
345
- }
346
- const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
347
- if (this._options.testConfig.moduleScope) {
348
- this._options.testConfig.moduleScope(currentModuleScope, this._options.stats, this._options.compilerOptions);
349
- }
350
- if (file.content.includes('__STATS__') && this._options.stats) {
351
- currentModuleScope.__STATS__ = this._options.stats();
352
- }
353
- if (file.content.includes('__STATS_I__')) {
354
- const statsIndex = this._options.stats?.()?.__index__;
355
- if (typeof statsIndex === 'number') {
356
- currentModuleScope.__STATS_I__ = statsIndex;
276
+ }
277
+ createJsonRequirer() {
278
+ return (currentDirectory, modulePath, context = {})=>{
279
+ if (Array.isArray(modulePath)) throw new Error('Array module path is not supported in hot cases');
280
+ const file = context.file || this.getFile(modulePath, currentDirectory);
281
+ this.log(`json: ${modulePath} -> ${file?.path}`);
282
+ if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
283
+ return JSON.parse(external_node_fs_default().readFileSync(external_node_path_default().join(this._options.dist, modulePath), 'utf-8'));
284
+ };
285
+ }
286
+ createCjsRequirer() {
287
+ return (currentDirectory, modulePath, context = {})=>{
288
+ if ('@rspack/test-tools' === modulePath) return __webpack_require__("@rspack/test-tools");
289
+ const file = context.file || this.getFile(modulePath, currentDirectory);
290
+ this.log(`cjs: ${modulePath} -> ${file?.path}`);
291
+ if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
292
+ if (file.path in this.requireCache) {
293
+ this.log(`cjs cache hit: ${file.path}`);
294
+ return this.requireCache[file.path].exports;
357
295
  }
358
- }
359
- if (file.content.includes('webpack/runtime/startup_chunk_dependencies')) {
360
- currentModuleScope.__AFTER_CHUNK_LOADED__ = (next) => {
361
- let done;
362
- const task = new Promise((resolve) => (done = resolve));
363
- currentModuleScope.WAITING.push(task);
364
- return () => {
365
- next();
366
- done();
367
- };
296
+ const m = {
297
+ exports: {},
298
+ webpackTestSuiteModule: true
368
299
  };
369
- file.content = file.content.replace('var next = __webpack_require__.x', 'var next = __AFTER_CHUNK_LOADED__(__webpack_require__.x)');
370
- }
371
- const args = Object.keys(currentModuleScope);
372
- const argValues = args.map((arg) => currentModuleScope[arg]);
373
- const code = `(function(${args.join(', ')}) {
300
+ this.requireCache[file.path] = m;
301
+ if (!this._options.runInNewContext) file.content = `Object.assign(global, _globalAssign);${file.content}`;
302
+ const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
303
+ if (this._options.testConfig.moduleScope) this._options.testConfig.moduleScope(currentModuleScope, this._options.stats, this._options.compilerOptions);
304
+ if (file.content.includes('__STATS__') && this._options.stats) currentModuleScope.__STATS__ = this._options.stats();
305
+ if (file.content.includes('__STATS_I__')) {
306
+ const statsIndex = this._options.stats?.()?.__index__;
307
+ if ('number' == typeof statsIndex) currentModuleScope.__STATS_I__ = statsIndex;
308
+ }
309
+ if (file.content.includes('webpack/runtime/startup_chunk_dependencies')) {
310
+ currentModuleScope.__AFTER_CHUNK_LOADED__ = (next)=>{
311
+ let done;
312
+ const task = new Promise((resolve)=>done = resolve);
313
+ currentModuleScope.WAITING.push(task);
314
+ return ()=>{
315
+ next();
316
+ done();
317
+ };
318
+ };
319
+ file.content = file.content.replace('var next = __webpack_require__.x', 'var next = __AFTER_CHUNK_LOADED__(__webpack_require__.x)');
320
+ }
321
+ const args = Object.keys(currentModuleScope);
322
+ const argValues = args.map((arg)=>currentModuleScope[arg]);
323
+ const code = `(function(${args.join(', ')}) {
374
324
  ${file.content}
375
325
  })`;
376
- this.preExecute(code, file);
377
- this.log(`run mode: ${this._options.runInNewContext ? 'new context' : 'this context'}`);
378
- try {
379
- const fn = this._options.runInNewContext
380
- ? node_vm_1.default.runInNewContext(code, this.globalContext, {
326
+ this.preExecute(code, file);
327
+ this.log(`run mode: ${this._options.runInNewContext ? 'new context' : 'this context'}`);
328
+ try {
329
+ const fn = this._options.runInNewContext ? external_node_vm_default().runInNewContext(code, this.globalContext, {
381
330
  filename: file.path,
382
- lineOffset: -1,
383
- })
384
- : node_vm_1.default.runInThisContext(code, {
331
+ lineOffset: -1
332
+ }) : external_node_vm_default().runInThisContext(code, {
385
333
  filename: file.path,
386
- lineOffset: -1,
334
+ lineOffset: -1
387
335
  });
388
- fn.call(this._options.testConfig.nonEsmThis
389
- ? this._options.testConfig.nonEsmThis(modulePath)
390
- : m.exports, ...argValues);
391
- }
392
- catch (e) {
393
- this._options.errors?.push(e);
394
- throw e;
395
- }
396
- this.postExecute(m, file);
397
- this.log(`end cjs: ${modulePath}`);
398
- return m.exports;
399
- };
400
- }
401
- createEsmRequirer() {
402
- const esmContext = node_vm_1.default.createContext(this.baseModuleScope, {
403
- name: 'context for esm',
404
- });
405
- const esmCache = new Map();
406
- const esmIdentifier = this._options.name;
407
- return (currentDirectory, modulePath, context = {}) => {
408
- if (!node_vm_1.SourceTextModule) {
409
- throw new Error("Running this test requires '--experimental-vm-modules'.\nRun with 'node --experimental-vm-modules node_modules/@rstest/core/bin/rstest'.");
410
- }
411
- const _require = this.getRequire();
412
- const file = context.file || this.getFile(modulePath, currentDirectory);
413
- this.log(`esm: ${modulePath} -> ${file?.path}`);
414
- if (!file) {
415
- return this.requirers.get('miss')(currentDirectory, modulePath);
416
- }
417
- if (file.content.includes('__STATS__')) {
418
- esmContext.__STATS__ = this._options.stats?.();
419
- }
420
- if (file.content.includes('__STATS_I__')) {
421
- const statsIndex = this._options.stats?.()?.__index__;
422
- if (typeof statsIndex === 'number') {
423
- esmContext.__STATS_I__ = statsIndex;
336
+ fn.call(this._options.testConfig.nonEsmThis ? this._options.testConfig.nonEsmThis(modulePath) : m.exports, ...argValues);
337
+ } catch (e) {
338
+ this._options.errors?.push(e);
339
+ throw e;
424
340
  }
425
- }
426
- let esm = esmCache.get(file.path);
427
- if (!esm) {
428
- esm = new node_vm_1.SourceTextModule(file.content, {
429
- identifier: `${esmIdentifier}-${file.path}`,
430
- // no attribute
431
- url: `${(0, node_url_1.pathToFileURL)(file.path).href}?${esmIdentifier}`,
432
- context: esmContext,
433
- initializeImportMeta: (meta, _) => {
434
- meta.url = (0, node_url_1.pathToFileURL)(file.path).href;
435
- meta.dirname = node_path_1.default.dirname(file.path);
436
- meta.filename = file.path;
437
- },
438
- importModuleDynamically: async (specifier, module) => {
439
- this.log(`import: ${specifier} from ${file?.path}`);
440
- const result = await _require(node_path_1.default.dirname(file.path), specifier, {
441
- esmMode: type_1.EEsmMode.Evaluated,
442
- });
443
- return await (0, asModule_1.default)(result, module.context);
444
- },
445
- });
446
- esmCache.set(file.path, esm);
447
- }
448
- if (context.esmMode === type_1.EEsmMode.Unlinked)
449
- return esm;
450
- return (async () => {
451
- if (esm.status === 'unlinked') {
452
- await esm.link(async (specifier, referencingModule) => {
453
- return await (0, asModule_1.default)(await _require(node_path_1.default.dirname(referencingModule.identifier
454
- ? referencingModule.identifier.slice(esmIdentifier.length + 1)
455
- : (0, node_url_1.fileURLToPath)(referencingModule.url)), specifier, {
456
- esmMode: type_1.EEsmMode.Unlinked,
457
- }), referencingModule.context, true);
458
- });
341
+ this.postExecute(m, file);
342
+ this.log(`end cjs: ${modulePath}`);
343
+ return m.exports;
344
+ };
345
+ }
346
+ createEsmRequirer() {
347
+ const esmContext = external_node_vm_default().createContext(this.baseModuleScope, {
348
+ name: 'context for esm'
349
+ });
350
+ const esmCache = new Map();
351
+ const esmIdentifier = this._options.name;
352
+ return (currentDirectory, modulePath, context = {})=>{
353
+ if (!external_node_vm_namespaceObject.SourceTextModule) throw new Error("Running this test requires '--experimental-vm-modules'.\nRun with 'node --experimental-vm-modules node_modules/@rstest/core/bin/rstest'.");
354
+ const _require = this.getRequire();
355
+ const file = context.file || this.getFile(modulePath, currentDirectory);
356
+ this.log(`esm: ${modulePath} -> ${file?.path}`);
357
+ if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
358
+ if (file.content.includes('__STATS__')) esmContext.__STATS__ = this._options.stats?.();
359
+ if (file.content.includes('__STATS_I__')) {
360
+ const statsIndex = this._options.stats?.()?.__index__;
361
+ if ('number' == typeof statsIndex) esmContext.__STATS_I__ = statsIndex;
459
362
  }
460
- await esm.evaluate();
461
- if (context.esmMode === type_1.EEsmMode.Evaluated) {
462
- return esm;
363
+ let esm = esmCache.get(file.path);
364
+ if (!esm) {
365
+ esm = new external_node_vm_namespaceObject.SourceTextModule(file.content, {
366
+ identifier: `${esmIdentifier}-${file.path}`,
367
+ url: `${(0, external_node_url_namespaceObject.pathToFileURL)(file.path).href}?${esmIdentifier}`,
368
+ context: esmContext,
369
+ initializeImportMeta: (meta, _)=>{
370
+ meta.url = (0, external_node_url_namespaceObject.pathToFileURL)(file.path).href;
371
+ meta.dirname = external_node_path_default().dirname(file.path);
372
+ meta.filename = file.path;
373
+ },
374
+ importModuleDynamically: async (specifier, module)=>{
375
+ this.log(`import: ${specifier} from ${file?.path}`);
376
+ const result = await _require(external_node_path_default().dirname(file.path), specifier, {
377
+ esmMode: external_type_js_namespaceObject.EEsmMode.Evaluated
378
+ });
379
+ return (0, asModule_js_namespaceObject.asModule)(result, module.context);
380
+ }
381
+ });
382
+ esmCache.set(file.path, esm);
463
383
  }
464
- const ns = esm.namespace;
465
- this.log(`end esm: ${modulePath}`);
466
- return ns.default && ns.default instanceof Promise ? ns.default : ns;
467
- })();
468
- };
384
+ if (context.esmMode === external_type_js_namespaceObject.EEsmMode.Unlinked) return esm;
385
+ return (async ()=>{
386
+ if ('unlinked' === esm.status) await esm.link(async (specifier, referencingModule)=>(0, asModule_js_namespaceObject.asModule)(await _require(external_node_path_default().dirname(referencingModule.identifier ? referencingModule.identifier.slice(esmIdentifier.length + 1) : (0, external_node_url_namespaceObject.fileURLToPath)(referencingModule.url)), specifier, {
387
+ esmMode: external_type_js_namespaceObject.EEsmMode.Unlinked
388
+ }), referencingModule.context, true));
389
+ await esm.evaluate();
390
+ if (context.esmMode === external_type_js_namespaceObject.EEsmMode.Evaluated) return esm;
391
+ const ns = esm.namespace;
392
+ this.log(`end esm: ${modulePath}`);
393
+ return ns.default && ns.default instanceof Promise ? ns.default : ns;
394
+ })();
395
+ };
396
+ }
469
397
  }
470
- }
471
- exports.NodeRunner = NodeRunner;
398
+ })();
399
+ exports.NodeRunner = __webpack_exports__.NodeRunner;
400
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
401
+ "NodeRunner"
402
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
403
+ Object.defineProperty(exports, '__esModule', {
404
+ value: true
405
+ });