@rspack/test-tools 2.0.2 → 2.0.4

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 +136 -122
  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 +21 -20
@@ -1,51 +1,99 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __webpack_modules__ = {
3
+ "iconv-lite" (module) {
4
+ module.exports = require("iconv-lite");
5
+ }
4
6
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createLocatedError = exports.WebRunner = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const node_url_1 = require("node:url");
10
- const node_vm_1 = require("node:vm");
11
- const jsdom_1 = require("jsdom");
12
- const helper_1 = require("../../helper");
13
- const EventSourceForNode_1 = __importDefault(require("../../helper/legacy/EventSourceForNode"));
14
- const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
15
- const node_1 = require("../node");
16
- // Compatibility code to suppress iconv-lite warnings
17
- require('iconv-lite').skipDecodeWarning = true;
18
- const FAKE_HOSTS = [
19
- 'https://example.com/public/path',
20
- 'https://example.com',
21
- 'https://test.cases/path/',
22
- 'https://test.cases/server/',
23
- 'https://test.cases',
24
- ];
25
- const FAKE_TEST_ROOT_HOST = 'https://test.cases/root/';
26
- class WebRunner extends node_1.NodeRunner {
27
- constructor(_webOptions) {
28
- super(_webOptions);
29
- this._webOptions = _webOptions;
30
- const virtualConsole = new jsdom_1.VirtualConsole({});
31
- virtualConsole.sendTo(console, {
32
- omitJSDOMErrors: true,
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: {}
13
+ };
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
33
22
  });
34
- this.dom = new jsdom_1.JSDOM(`
23
+ return getter;
24
+ };
25
+ })();
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
+ WebRunner: ()=>WebRunner,
52
+ createLocatedError: ()=>createLocatedError
53
+ });
54
+ const external_node_fs_namespaceObject = require("node:fs");
55
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
56
+ const external_node_path_namespaceObject = require("node:path");
57
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
58
+ const external_node_url_namespaceObject = require("node:url");
59
+ const external_node_vm_namespaceObject = require("node:vm");
60
+ const external_jsdom_namespaceObject = require("jsdom");
61
+ const index_js_namespaceObject = require("../../helper/index.js");
62
+ const EventSourceForNode_js_namespaceObject = require("../../helper/legacy/EventSourceForNode.js");
63
+ const urlToRelativePath_js_namespaceObject = require("../../helper/legacy/urlToRelativePath.js");
64
+ const external_node_index_js_namespaceObject = require("../node/index.js");
65
+ __webpack_require__("iconv-lite").skipDecodeWarning = true;
66
+ const FAKE_HOSTS = [
67
+ 'https://example.com/public/path',
68
+ 'https://example.com',
69
+ 'https://test.cases/path/',
70
+ 'https://test.cases/server/',
71
+ 'https://test.cases'
72
+ ];
73
+ const FAKE_TEST_ROOT_HOST = 'https://test.cases/root/';
74
+ class WebRunner extends external_node_index_js_namespaceObject.NodeRunner {
75
+ _webOptions;
76
+ dom;
77
+ constructor(_webOptions){
78
+ super(_webOptions), this._webOptions = _webOptions;
79
+ const virtualConsole = new external_jsdom_namespaceObject.VirtualConsole({});
80
+ virtualConsole.sendTo(console, {
81
+ omitJSDOMErrors: true
82
+ });
83
+ this.dom = new external_jsdom_namespaceObject.JSDOM(`
35
84
  <!doctype html>
36
85
  <html>
37
86
  <head></head>
38
87
  <body></body>
39
88
  </html>
40
89
  `, {
41
- url: this._webOptions.location,
42
- resources: this.createResourceLoader(),
43
- runScripts: 'dangerously',
44
- virtualConsole,
45
- });
46
- this.dom.window.console = console;
47
- // compat with FakeDocument
48
- this.dom.window.eval(`
90
+ url: this._webOptions.location,
91
+ resources: this.createResourceLoader(),
92
+ runScripts: 'dangerously',
93
+ virtualConsole
94
+ });
95
+ this.dom.window.console = console;
96
+ this.dom.window.eval(`
49
97
  Object.defineProperty(document.head, "_children", {
50
98
  get: function() {
51
99
  return Array.from(document.head.children).map(function(ele) {
@@ -65,159 +113,129 @@ class WebRunner extends node_1.NodeRunner {
65
113
  }
66
114
  });
67
115
  `);
68
- if (this._options.compilerOptions.node !== false) {
69
- const vmContext = this.dom.getInternalVMContext();
70
- vmContext.global = {};
116
+ if (false !== this._options.compilerOptions.node) {
117
+ const vmContext = this.dom.getInternalVMContext();
118
+ vmContext.global = {};
119
+ }
71
120
  }
72
- }
73
- run(file) {
74
- if (!file.endsWith('.js') && !file.endsWith('.mjs')) {
75
- this.log(`css: ${file}`);
76
- const cssElement = this.dom.window.document.createElement('link');
77
- cssElement.href = file;
78
- cssElement.rel = 'stylesheet';
79
- this.dom.window.document.head.appendChild(cssElement);
80
- return Promise.resolve();
121
+ run(file) {
122
+ if (!file.endsWith('.js') && !file.endsWith('.mjs')) {
123
+ this.log(`css: ${file}`);
124
+ const cssElement = this.dom.window.document.createElement('link');
125
+ cssElement.href = file;
126
+ cssElement.rel = 'stylesheet';
127
+ this.dom.window.document.head.appendChild(cssElement);
128
+ return Promise.resolve();
129
+ }
130
+ return super.run(file);
81
131
  }
82
- return super.run(file);
83
- }
84
- getGlobal(name) {
85
- return this.globalContext[name];
86
- }
87
- log(message) {
88
- this._options.logs?.push(`[WebRunner] ${message}`);
89
- }
90
- createResourceLoader() {
91
- const that = this;
92
- class CustomResourceLoader extends jsdom_1.ResourceLoader {
93
- fetch(url, options) {
94
- if (that._options.testConfig.resourceLoader) {
95
- that.log(`resource custom loader: start ${url}`);
96
- const content = that._options.testConfig.resourceLoader(url, options.element);
97
- if (content !== undefined) {
98
- that.log(`resource custom loader: accepted`);
99
- return Promise.resolve(content);
100
- }
101
- else {
102
- that.log(`resource custom loader: not found`);
103
- }
104
- }
105
- const filePath = that.urlToPath(url);
106
- that.log(`resource loader: ${url} -> ${filePath}`);
107
- let finalCode;
108
- if (node_path_1.default.extname(filePath) === '.js') {
109
- const currentDirectory = node_path_1.default.dirname(filePath);
110
- const file = that.getFile(filePath, currentDirectory);
111
- if (!file) {
112
- throw new Error(`File not found: ${filePath}`);
132
+ getGlobal(name) {
133
+ return this.globalContext[name];
134
+ }
135
+ log(message) {
136
+ this._options.logs?.push(`[WebRunner] ${message}`);
137
+ }
138
+ createResourceLoader() {
139
+ const that = this;
140
+ class CustomResourceLoader extends external_jsdom_namespaceObject.ResourceLoader {
141
+ fetch(url, options) {
142
+ if (that._options.testConfig.resourceLoader) {
143
+ that.log(`resource custom loader: start ${url}`);
144
+ const content = that._options.testConfig.resourceLoader(url, options.element);
145
+ if (void 0 !== content) {
146
+ that.log("resource custom loader: accepted");
147
+ return Promise.resolve(content);
148
+ }
149
+ that.log("resource custom loader: not found");
113
150
  }
114
- const [_m, code] = that.getModuleContent(file);
115
- finalCode = code;
116
- }
117
- else {
118
- finalCode = node_fs_1.default.readFileSync(filePath);
119
- }
120
- try {
121
- that.dom.window.__LINK_SHEET__ ??= {};
122
- that.dom.window.__LINK_SHEET__[url] = finalCode.toString();
123
- return Promise.resolve(finalCode);
124
- }
125
- catch (err) {
126
- console.error(err);
127
- if (err.code === 'ENOENT') {
128
- return null;
151
+ const filePath = that.urlToPath(url);
152
+ that.log(`resource loader: ${url} -> ${filePath}`);
153
+ let finalCode;
154
+ if ('.js' === external_node_path_default().extname(filePath)) {
155
+ const currentDirectory = external_node_path_default().dirname(filePath);
156
+ const file = that.getFile(filePath, currentDirectory);
157
+ if (!file) throw new Error(`File not found: ${filePath}`);
158
+ const [_m, code] = that.getModuleContent(file);
159
+ finalCode = code;
160
+ } else finalCode = external_node_fs_default().readFileSync(filePath);
161
+ try {
162
+ that.dom.window.__LINK_SHEET__ ??= {};
163
+ that.dom.window.__LINK_SHEET__[url] = finalCode.toString();
164
+ return Promise.resolve(finalCode);
165
+ } catch (err) {
166
+ console.error(err);
167
+ if ('ENOENT' === err.code) return null;
168
+ throw err;
129
169
  }
130
- throw err;
131
170
  }
132
171
  }
172
+ return new CustomResourceLoader();
133
173
  }
134
- return new CustomResourceLoader();
135
- }
136
- urlToPath(url) {
137
- if (url.startsWith('file://')) {
138
- return (0, node_url_1.fileURLToPath)(url);
139
- }
140
- if (url.startsWith(FAKE_TEST_ROOT_HOST)) {
141
- return node_path_1.default.resolve(__TEST_PATH__, `./${url.slice(FAKE_TEST_ROOT_HOST.length)}`);
142
- }
143
- let dist = url;
144
- for (const host of FAKE_HOSTS) {
145
- if (url.startsWith(host)) {
174
+ urlToPath(url) {
175
+ if (url.startsWith('file://')) return (0, external_node_url_namespaceObject.fileURLToPath)(url);
176
+ if (url.startsWith(FAKE_TEST_ROOT_HOST)) return external_node_path_default().resolve(__TEST_PATH__, `./${url.slice(FAKE_TEST_ROOT_HOST.length)}`);
177
+ let dist = url;
178
+ for (const host of FAKE_HOSTS)if (url.startsWith(host)) {
146
179
  dist = url.slice(host.length);
147
180
  break;
148
181
  }
182
+ return external_node_path_default().resolve(this._webOptions.dist, `./${dist}`).split('?')[0];
149
183
  }
150
- return node_path_1.default.resolve(this._webOptions.dist, `./${dist}`).split('?')[0];
151
- }
152
- createBaseModuleScope() {
153
- const moduleScope = super.createBaseModuleScope();
154
- moduleScope.EventSource = EventSourceForNode_1.default;
155
- moduleScope.fetch = async (url, options) => {
156
- // For Lazy Compilation Proxy the POST request to the real dev server.
157
- if (options?.method === 'POST') {
158
- return fetch(url, options);
159
- }
160
- try {
161
- const filePath = this.urlToPath(url);
162
- this.log(`fetch: ${url} -> ${filePath}`);
163
- const buffer = await new Promise((resolve, reject) => node_fs_1.default.readFile(filePath, (err, b) => (err ? reject(err) : resolve(b))));
164
- return {
165
- status: 200,
166
- ok: true,
167
- json: async () => JSON.parse(buffer.toString('utf-8')),
168
- };
169
- }
170
- catch (err) {
171
- if (err.code === 'ENOENT') {
184
+ createBaseModuleScope() {
185
+ const moduleScope = super.createBaseModuleScope();
186
+ moduleScope.EventSource = EventSourceForNode_js_namespaceObject.EventSource;
187
+ moduleScope.fetch = async (url, options)=>{
188
+ if (options?.method === 'POST') return fetch(url, options);
189
+ try {
190
+ const filePath = this.urlToPath(url);
191
+ this.log(`fetch: ${url} -> ${filePath}`);
192
+ const buffer = await new Promise((resolve, reject)=>external_node_fs_default().readFile(filePath, (err, b)=>err ? reject(err) : resolve(b)));
172
193
  return {
194
+ status: 200,
195
+ ok: true,
196
+ json: ()=>Promise.resolve().then(()=>JSON.parse(buffer.toString('utf-8')))
197
+ };
198
+ } catch (err) {
199
+ if ('ENOENT' === err.code) return {
173
200
  status: 404,
174
- ok: false,
201
+ ok: false
175
202
  };
203
+ throw err;
176
204
  }
177
- throw err;
178
- }
179
- };
180
- moduleScope.URL = URL;
181
- moduleScope.importScripts = (url) => {
182
- const path = (0, urlToRelativePath_1.default)(url);
183
- this.log(`importScripts: ${url} -> ${path}`);
184
- this.requirers.get('entry')(this._options.dist, path);
185
- };
186
- moduleScope.getComputedStyle = (element) => {
187
- const computedStyle = this.dom.window.getComputedStyle(element);
188
- const getPropertyValue = computedStyle.getPropertyValue.bind(computedStyle);
189
- return {
190
- ...computedStyle,
191
- getPropertyValue(v) {
192
- return getPropertyValue(v);
193
- },
194
205
  };
195
- };
196
- moduleScope.window = this.dom.window;
197
- moduleScope.document = this.dom.window.document;
198
- moduleScope.getLinkSheet = (link) => {
199
- return this.dom.window.__LINK_SHEET__[link.href];
200
- };
201
- return moduleScope;
202
- }
203
- getModuleContent(file) {
204
- const m = {
205
- exports: {},
206
- };
207
- const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
208
- if (this._options.testConfig.moduleScope) {
209
- this._options.testConfig.moduleScope(currentModuleScope, this._options.stats, this._options.compilerOptions);
210
- }
211
- if (file.content.includes('__STATS__')) {
212
- currentModuleScope.__STATS__ = this._options.stats?.();
206
+ moduleScope.URL = URL;
207
+ moduleScope.importScripts = (url)=>{
208
+ const path = (0, urlToRelativePath_js_namespaceObject.urlToRelativePath)(url);
209
+ this.log(`importScripts: ${url} -> ${path}`);
210
+ this.requirers.get('entry')(this._options.dist, path);
211
+ };
212
+ moduleScope.getComputedStyle = (element)=>{
213
+ const computedStyle = this.dom.window.getComputedStyle(element);
214
+ const getPropertyValue = computedStyle.getPropertyValue.bind(computedStyle);
215
+ return {
216
+ ...computedStyle,
217
+ getPropertyValue (v) {
218
+ return getPropertyValue(v);
219
+ }
220
+ };
221
+ };
222
+ moduleScope.window = this.dom.window;
223
+ moduleScope.document = this.dom.window.document;
224
+ moduleScope.getLinkSheet = (link)=>this.dom.window.__LINK_SHEET__[link.href];
225
+ return moduleScope;
213
226
  }
214
- if (file.content.includes('__STATS_I__')) {
215
- const statsIndex = this._options.stats?.()?.__index__;
216
- if (typeof statsIndex === 'number') {
217
- currentModuleScope.__STATS_I__ = statsIndex;
227
+ getModuleContent(file) {
228
+ const m = {
229
+ exports: {}
230
+ };
231
+ const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
232
+ if (this._options.testConfig.moduleScope) this._options.testConfig.moduleScope(currentModuleScope, this._options.stats, this._options.compilerOptions);
233
+ if (file.content.includes('__STATS__')) currentModuleScope.__STATS__ = this._options.stats?.();
234
+ if (file.content.includes('__STATS_I__')) {
235
+ const statsIndex = this._options.stats?.()?.__index__;
236
+ if ('number' == typeof statsIndex) currentModuleScope.__STATS_I__ = statsIndex;
218
237
  }
219
- }
220
- const proxyCode = `// hijack document.currentScript for auto public path
238
+ const proxyCode = `// hijack document.currentScript for auto public path
221
239
  var $$g$$ = new Proxy(window, {
222
240
  get(target, prop, receiver) {
223
241
  if (prop === "document") {
@@ -225,7 +243,7 @@ class WebRunner extends node_1.NodeRunner {
225
243
  get(target, prop, receiver) {
226
244
  if (prop === "currentScript") {
227
245
  var script = target.createElement("script");
228
- script.src = "https://test.cases/path/${(0, helper_1.escapeSep)(file.subPath)}index.js";
246
+ script.src = "https://test.cases/path/${(0, index_js_namespaceObject.escapeSep)(file.subPath)}index.js";
229
247
  return script;
230
248
  }
231
249
  return Reflect.get(target, prop, receiver);
@@ -249,99 +267,96 @@ class WebRunner extends node_1.NodeRunner {
249
267
  return Reflect.set(target, prop, value, receiver);
250
268
  }
251
269
  });`;
252
- const proxyLines = proxyCode.split('\n');
253
- const locatedError = (0, exports.createLocatedError)(this._options.errors || [], proxyLines.length + 1);
254
- const originIt = currentModuleScope.it;
255
- currentModuleScope.it = (description, fn) => {
256
- return originIt(description, async (...args) => {
257
- try {
258
- return await fn(...args);
259
- }
260
- catch (e) {
261
- throw locatedError(e, file);
262
- }
263
- });
264
- };
265
- const scopeKey = (0, helper_1.escapeSep)(file.path);
266
- const args = Object.keys(currentModuleScope).filter((arg) => !['window', 'self', 'globalThis', 'console'].includes(arg));
267
- const argValues = args
268
- .map((arg) => `window["${scopeKey}"]["${arg}"]`)
269
- .join(', ');
270
- this.dom.window[scopeKey] = currentModuleScope;
271
- this.dom.window.__GLOBAL_SHARED__ = this.globalContext;
272
- this.dom.window.__LOCATED_ERROR__ = locatedError;
273
- this.dom.window.__FILE__ = file;
274
- return [
275
- m,
276
- `${proxyCode}
270
+ const proxyLines = proxyCode.split('\n');
271
+ const locatedError = createLocatedError(this._options.errors || [], proxyLines.length + 1);
272
+ const originIt = currentModuleScope.it;
273
+ currentModuleScope.it = (description, fn)=>originIt(description, async (...args)=>{
274
+ try {
275
+ return await fn(...args);
276
+ } catch (e) {
277
+ throw locatedError(e, file);
278
+ }
279
+ });
280
+ const scopeKey = (0, index_js_namespaceObject.escapeSep)(file.path);
281
+ const args = Object.keys(currentModuleScope).filter((arg)=>![
282
+ 'window',
283
+ 'self',
284
+ 'globalThis',
285
+ 'console'
286
+ ].includes(arg));
287
+ const argValues = args.map((arg)=>`window["${scopeKey}"]["${arg}"]`).join(', ');
288
+ this.dom.window[scopeKey] = currentModuleScope;
289
+ this.dom.window.__GLOBAL_SHARED__ = this.globalContext;
290
+ this.dom.window.__LOCATED_ERROR__ = locatedError;
291
+ this.dom.window.__FILE__ = file;
292
+ return [
293
+ m,
294
+ `${proxyCode}
277
295
  (function(window, self, globalThis, console, ${args.join(', ')}) { try {
278
296
  ${file.content}
279
297
  } catch (e) {
280
298
  throw __LOCATED_ERROR__(e, window["__FILE__"]);
281
299
  }})($$g$$, $$self$$, $$g$$, window["console"], ${argValues});`,
282
- proxyLines.length + 1,
283
- ];
284
- }
285
- createJSDOMRequirer() {
286
- return (currentDirectory, modulePath, context = {}) => {
287
- const file = context.file || this.getFile(modulePath, currentDirectory);
288
- this.log(`jsdom: ${modulePath} -> ${file?.path}`);
289
- if (!file) {
290
- return this.requirers.get('miss')(currentDirectory, modulePath);
291
- }
292
- if (file.path in this.requireCache) {
293
- return this.requireCache[file.path].exports;
294
- }
295
- const [m, code, lineOffset] = this.getModuleContent(file);
296
- this.preExecute(code, file);
297
- try {
298
- const script = new node_vm_1.Script(code);
299
- const vmContext = this.dom.getInternalVMContext();
300
- script.runInContext(vmContext, {
301
- filename: file.path,
302
- lineOffset: -lineOffset,
303
- });
304
- }
305
- catch (e) {
306
- const error = new Error(`Parse script '${file.path}' failed:\n${e.message}`);
307
- error.stack = `${error.message}\n${e.stack}`;
308
- this._options.errors?.push(error);
309
- throw error;
310
- }
311
- this.postExecute(m, file);
312
- this.requireCache[file.path] = m;
313
- return m.exports;
314
- };
315
- }
316
- createRunner() {
317
- super.createRunner();
318
- this.requirers.set('cjs', this.createJSDOMRequirer());
319
- }
320
- }
321
- exports.WebRunner = WebRunner;
322
- const createLocatedError = (collectedErrors, offset) => {
323
- return (e, file) => {
324
- const match = (e.stack || e.message).match(/<anonymous>:(\d+)/);
325
- if (match) {
326
- const [, line] = match;
327
- const realLine = Number(line) - offset;
328
- const codeLines = file.content.split('\n');
329
- const lineContents = [
330
- ...codeLines
331
- .slice(Math.max(0, realLine - 3), Math.max(0, realLine - 1))
332
- .map((line) => `│ ${line}`),
333
- `│> ${codeLines[realLine - 1]}`,
334
- ...codeLines.slice(realLine, realLine + 2).map((line) => `│ ${line}`),
300
+ proxyLines.length + 1
335
301
  ];
336
- const message = `Error in JSDOM when running file '${file.path}' at line ${realLine}: ${e.message}\n${lineContents.join('\n')}`;
337
- const finalError = new Error(message);
338
- finalError.stack = `${message}\n${e.stack}`;
339
- collectedErrors.push(finalError);
340
- return finalError;
341
302
  }
342
- else {
343
- return e;
303
+ createJSDOMRequirer() {
304
+ return (currentDirectory, modulePath, context = {})=>{
305
+ const file = context.file || this.getFile(modulePath, currentDirectory);
306
+ this.log(`jsdom: ${modulePath} -> ${file?.path}`);
307
+ if (!file) return this.requirers.get('miss')(currentDirectory, modulePath);
308
+ if (file.path in this.requireCache) return this.requireCache[file.path].exports;
309
+ const [m, code, lineOffset] = this.getModuleContent(file);
310
+ this.preExecute(code, file);
311
+ try {
312
+ const script = new external_node_vm_namespaceObject.Script(code);
313
+ const vmContext = this.dom.getInternalVMContext();
314
+ script.runInContext(vmContext, {
315
+ filename: file.path,
316
+ lineOffset: -lineOffset
317
+ });
318
+ } catch (e) {
319
+ const error = new Error(`Parse script '${file.path}' failed:\n${e.message}`);
320
+ error.stack = `${error.message}\n${e.stack}`;
321
+ this._options.errors?.push(error);
322
+ throw error;
323
+ }
324
+ this.postExecute(m, file);
325
+ this.requireCache[file.path] = m;
326
+ return m.exports;
327
+ };
344
328
  }
345
- };
346
- };
347
- exports.createLocatedError = createLocatedError;
329
+ createRunner() {
330
+ super.createRunner();
331
+ this.requirers.set('cjs', this.createJSDOMRequirer());
332
+ }
333
+ }
334
+ const createLocatedError = (collectedErrors, offset)=>(e, file)=>{
335
+ const match = (e.stack || e.message).match(/<anonymous>:(\d+)/);
336
+ if (!match) return e;
337
+ {
338
+ const [, line] = match;
339
+ const realLine = Number(line) - offset;
340
+ const codeLines = file.content.split('\n');
341
+ const lineContents = [
342
+ ...codeLines.slice(Math.max(0, realLine - 3), Math.max(0, realLine - 1)).map((line)=>`│ ${line}`),
343
+ `│> ${codeLines[realLine - 1]}`,
344
+ ...codeLines.slice(realLine, realLine + 2).map((line)=>`│ ${line}`)
345
+ ];
346
+ const message = `Error in JSDOM when running file '${file.path}' at line ${realLine}: ${e.message}\n${lineContents.join('\n')}`;
347
+ const finalError = new Error(message);
348
+ finalError.stack = `${message}\n${e.stack}`;
349
+ collectedErrors.push(finalError);
350
+ return finalError;
351
+ }
352
+ };
353
+ })();
354
+ exports.WebRunner = __webpack_exports__.WebRunner;
355
+ exports.createLocatedError = __webpack_exports__.createLocatedError;
356
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
357
+ "WebRunner",
358
+ "createLocatedError"
359
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
360
+ Object.defineProperty(exports, '__esModule', {
361
+ value: true
362
+ });