@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.
- package/dist/case/builtin.js +106 -66
- package/dist/case/cache.js +136 -122
- package/dist/case/common.d.ts +4 -4
- package/dist/case/common.js +162 -157
- package/dist/case/compiler.d.ts +4 -4
- package/dist/case/compiler.js +75 -64
- package/dist/case/config.js +112 -74
- package/dist/case/defaults.js +136 -83
- package/dist/case/diagnostic.js +112 -84
- package/dist/case/error.d.ts +4 -4
- package/dist/case/error.js +105 -89
- package/dist/case/esm-output.js +118 -87
- package/dist/case/example.js +73 -35
- package/dist/case/hash.js +74 -59
- package/dist/case/hook.js +151 -138
- package/dist/case/hot-step.js +130 -161
- package/dist/case/hot.js +148 -134
- package/dist/case/incremental.js +91 -58
- package/dist/case/index.js +134 -51
- package/dist/case/multi-compiler.d.ts +4 -4
- package/dist/case/multi-compiler.js +81 -56
- package/dist/case/native-watcher.js +62 -30
- package/dist/case/normal.js +253 -185
- package/dist/case/runner.js +80 -51
- package/dist/case/serial.js +47 -16
- package/dist/case/stats-api.d.ts +4 -4
- package/dist/case/stats-api.js +63 -43
- package/dist/case/stats-output.d.ts +3 -3
- package/dist/case/stats-output.js +147 -152
- package/dist/case/treeshaking.js +66 -35
- package/dist/case/watch.d.ts +3 -19
- package/dist/case/watch.js +204 -224
- package/dist/compiler.js +222 -195
- package/dist/helper/directory.js +83 -71
- package/dist/helper/disable-iconv-lite-warning.js +35 -9
- package/dist/helper/expect/diff.js +39 -10
- package/dist/helper/expect/error.js +62 -30
- package/dist/helper/expect/placeholder.js +47 -21
- package/dist/helper/expect/rspack.js +35 -13
- package/dist/helper/expect/to-be-typeof.js +39 -7
- package/dist/helper/expect/to-end-with.js +40 -8
- package/dist/helper/expect/to-match-file-snapshot.js +103 -80
- package/dist/helper/hot-update/index.js +35 -4
- package/dist/helper/hot-update/loader.d.ts +1 -0
- package/dist/helper/hot-update/loader.js +39 -4
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +87 -74
- package/dist/helper/index.js +138 -24
- package/dist/helper/is.js +51 -10
- package/dist/helper/legacy/EventSourceForNode.d.ts +11 -3
- package/dist/helper/legacy/EventSourceForNode.js +83 -37
- package/dist/helper/legacy/LogTestPlugin.d.ts +2 -3
- package/dist/helper/legacy/LogTestPlugin.js +39 -6
- package/dist/helper/legacy/asModule.d.ts +3 -3
- package/dist/helper/legacy/asModule.js +68 -19
- package/dist/helper/legacy/captureStdio.d.ts +1 -2
- package/dist/helper/legacy/captureStdio.js +69 -29
- package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -2
- package/dist/helper/legacy/checkArrayExpectation.js +132 -121
- package/dist/helper/legacy/copyDiff.d.ts +1 -2
- package/dist/helper/legacy/copyDiff.js +86 -42
- package/dist/helper/legacy/createFakeWorker.d.ts +2 -3
- package/dist/helper/legacy/createFakeWorker.js +90 -47
- package/dist/helper/legacy/createLazyTestEnv.d.ts +2 -3
- package/dist/helper/legacy/createLazyTestEnv.js +70 -59
- package/dist/helper/legacy/currentScript.d.ts +2 -2
- package/dist/helper/legacy/currentScript.js +35 -2
- package/dist/helper/legacy/deprecationTracking.d.ts +1 -1
- package/dist/helper/legacy/deprecationTracking.js +53 -28
- package/dist/helper/legacy/expectSource.d.ts +3 -2
- package/dist/helper/legacy/expectSource.js +42 -18
- package/dist/helper/legacy/fakeSystem.d.ts +12 -9
- package/dist/helper/legacy/fakeSystem.js +68 -58
- package/dist/helper/legacy/findOutputFiles.d.ts +7 -2
- package/dist/helper/legacy/findOutputFiles.js +60 -13
- package/dist/helper/legacy/parseResource.d.ts +1 -1
- package/dist/helper/legacy/parseResource.js +36 -6
- package/dist/helper/legacy/regexEscape.d.ts +1 -2
- package/dist/helper/legacy/regexEscape.js +39 -5
- package/dist/helper/legacy/supportDefaultAssignment.d.ts +1 -2
- package/dist/helper/legacy/supportDefaultAssignment.js +40 -7
- package/dist/helper/legacy/supportsTextDecoder.d.ts +1 -2
- package/dist/helper/legacy/supportsTextDecoder.js +40 -6
- package/dist/helper/legacy/supportsUsing.d.ts +1 -2
- package/dist/helper/legacy/supportsUsing.js +40 -7
- package/dist/helper/legacy/urlToRelativePath.d.ts +2 -2
- package/dist/helper/legacy/urlToRelativePath.js +56 -7
- package/dist/helper/parse-modules.js +52 -42
- package/dist/helper/read-config-file.js +60 -18
- package/dist/helper/serializers.js +62 -33
- package/dist/helper/setup-env.js +81 -91
- package/dist/helper/setup-expect.js +13 -13
- package/dist/helper/setup-wasm.js +18 -9
- package/dist/helper/stringify-config.js +44 -26
- package/dist/helper/update-snapshot.js +35 -3
- package/dist/helper/util/checkSourceMap.js +119 -80
- package/dist/helper/util/checkStats.d.ts +1 -1
- package/dist/helper/util/checkStats.js +42 -17
- package/dist/helper/util/expectWarningFactory.d.ts +1 -2
- package/dist/helper/util/expectWarningFactory.js +41 -8
- package/dist/helper/util/filterUtil.d.ts +9 -8
- package/dist/helper/util/filterUtil.js +63 -23
- package/dist/helper/win.js +46 -7
- package/dist/index.js +115 -23
- package/dist/plugin/index.js +55 -14
- package/dist/plugin/lazy-compilation-test-plugin.js +55 -41
- package/dist/reporter/index.js +55 -14
- package/dist/reporter/streamed-events-reporter.js +51 -77
- package/dist/runner/index.js +62 -15
- package/dist/runner/node/index.js +365 -431
- package/dist/runner/web/index.js +278 -263
- package/dist/test/context.js +67 -41
- package/dist/test/creator.js +135 -167
- package/dist/test/debug.js +89 -58
- package/dist/test/tester.js +94 -74
- package/dist/type.d.ts +10 -9
- package/dist/type.js +43 -9
- package/package.json +21 -20
package/dist/runner/web/index.js
CHANGED
|
@@ -1,51 +1,99 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"iconv-lite" (module) {
|
|
4
|
+
module.exports = require("iconv-lite");
|
|
5
|
+
}
|
|
4
6
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
116
|
+
if (false !== this._options.compilerOptions.node) {
|
|
117
|
+
const vmContext = this.dom.getInternalVMContext();
|
|
118
|
+
vmContext.global = {};
|
|
119
|
+
}
|
|
71
120
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
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,
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
.join(', ');
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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
|
-
|
|
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
|
-
|
|
343
|
-
return
|
|
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
|
-
|
|
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
|
+
});
|