@rspack-canary/test-tools 1.6.0-canary-beafb11e-20251019174144 → 1.6.0-canary-0eb13821-20251021173640
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/cache.js +3 -0
- package/dist/case/common.d.ts +1 -0
- package/dist/case/common.js +15 -12
- package/dist/case/config.js +4 -1
- package/dist/case/esm-output.js +28 -2
- package/dist/case/hot.d.ts +1 -1
- package/dist/case/hot.js +4 -3
- package/dist/case/incremental.d.ts +1 -1
- package/dist/case/incremental.js +1 -20
- package/dist/case/normal.js +3 -0
- package/dist/case/runner.d.ts +1 -1
- package/dist/case/runner.js +4 -3
- package/dist/case/watch.d.ts +3 -1
- package/dist/case/watch.js +5 -4
- package/dist/helper/hot-update/plugin.js +1 -1
- package/dist/helper/legacy/asModule.js +0 -2
- package/dist/helper/legacy/createLazyTestEnv.d.ts +1 -0
- package/dist/helper/legacy/createLazyTestEnv.js +3 -1
- package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
- package/dist/helper/legacy/supportsTextDecoder.js +9 -0
- package/dist/helper/setup-env.js +15 -0
- package/dist/runner/node/index.js +7 -3
- package/dist/runner/web/index.d.ts +20 -7
- package/dist/runner/web/index.js +293 -18
- package/dist/test/creator.js +13 -7
- package/dist/test/tester.d.ts +1 -0
- package/dist/test/tester.js +5 -0
- package/dist/type.d.ts +5 -5
- package/dist/type.js +1 -6
- package/jest.d.ts +2 -0
- package/package.json +3 -3
- package/dist/helper/legacy/FakeDocument.d.ts +0 -54
- package/dist/helper/legacy/FakeDocument.js +0 -280
- package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
- package/dist/helper/legacy/walkCssTokens.js +0 -761
- package/dist/runner/web/fake.d.ts +0 -15
- package/dist/runner/web/fake.js +0 -215
- package/dist/runner/web/jsdom.d.ts +0 -24
- package/dist/runner/web/jsdom.js +0 -241
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type ECompilerType, type TRunnerFile, type TRunnerRequirer } from "../../type";
|
|
2
|
-
import { type INodeRunnerOptions, NodeRunner } from "../node";
|
|
3
|
-
export declare class FakeDocumentWebRunner<T extends ECompilerType = ECompilerType.Rspack> extends NodeRunner<T> {
|
|
4
|
-
protected _webOptions: INodeRunnerOptions<T>;
|
|
5
|
-
private document;
|
|
6
|
-
private oldCurrentScript;
|
|
7
|
-
constructor(_webOptions: INodeRunnerOptions<T>);
|
|
8
|
-
run(file: string): Promise<unknown>;
|
|
9
|
-
protected createGlobalContext(): import("../../type").IGlobalContext;
|
|
10
|
-
protected createModuleScope(requireFn: TRunnerRequirer, m: any, file: TRunnerFile): import("../../type").IModuleScope;
|
|
11
|
-
protected createBaseModuleScope(): import("../../type").IModuleScope;
|
|
12
|
-
protected preExecute(_: string, file: TRunnerFile): void;
|
|
13
|
-
protected postExecute(_: Object, file: TRunnerFile): void;
|
|
14
|
-
protected createEsmRequirer(): TRunnerRequirer;
|
|
15
|
-
}
|
package/dist/runner/web/fake.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
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.FakeDocumentWebRunner = 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 helper_1 = require("../../helper");
|
|
45
|
-
const asModule_1 = __importDefault(require("../../helper/legacy/asModule"));
|
|
46
|
-
const createFakeWorker_1 = __importDefault(require("../../helper/legacy/createFakeWorker"));
|
|
47
|
-
const currentScript_1 = __importDefault(require("../../helper/legacy/currentScript"));
|
|
48
|
-
const EventSourceForNode_1 = __importDefault(require("../../helper/legacy/EventSourceForNode"));
|
|
49
|
-
const FakeDocument_1 = __importDefault(require("../../helper/legacy/FakeDocument"));
|
|
50
|
-
const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
|
|
51
|
-
const type_1 = require("../../type");
|
|
52
|
-
const node_1 = require("../node");
|
|
53
|
-
class FakeDocumentWebRunner extends node_1.NodeRunner {
|
|
54
|
-
constructor(_webOptions) {
|
|
55
|
-
super(_webOptions);
|
|
56
|
-
this._webOptions = _webOptions;
|
|
57
|
-
this.oldCurrentScript = null;
|
|
58
|
-
this.document = new FakeDocument_1.default(_webOptions.dist, {
|
|
59
|
-
onScript: (node) => {
|
|
60
|
-
this.getRequire.bind(this)()(_webOptions.dist, (0, urlToRelativePath_1.default)(node.src));
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
run(file) {
|
|
65
|
-
if ((0, helper_1.isCss)(file)) {
|
|
66
|
-
const cssElement = this.document.createElement("link");
|
|
67
|
-
cssElement.href = file;
|
|
68
|
-
cssElement.rel = "stylesheet";
|
|
69
|
-
this.document.head.appendChild(cssElement);
|
|
70
|
-
return Promise.resolve();
|
|
71
|
-
}
|
|
72
|
-
return super.run(file);
|
|
73
|
-
}
|
|
74
|
-
createGlobalContext() {
|
|
75
|
-
const globalContext = super.createGlobalContext();
|
|
76
|
-
globalContext.document = this.document;
|
|
77
|
-
globalContext.getComputedStyle = this.document.getComputedStyle.bind(this.document);
|
|
78
|
-
const urlToPath = (url) => {
|
|
79
|
-
return node_path_1.default.resolve(this._options.dist, `./${url.startsWith("https://test.cases/path/") ? url.slice(24) : url}`);
|
|
80
|
-
};
|
|
81
|
-
globalContext.fetch = async (url) => {
|
|
82
|
-
try {
|
|
83
|
-
const buffer = await new Promise((resolve, reject) => node_fs_1.default.readFile(urlToPath(url), (err, b) => err ? reject(err) : resolve(b)));
|
|
84
|
-
return {
|
|
85
|
-
status: 200,
|
|
86
|
-
ok: true,
|
|
87
|
-
json: async () => JSON.parse(buffer.toString("utf-8"))
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
if (err.code === "ENOENT") {
|
|
92
|
-
return {
|
|
93
|
-
status: 404,
|
|
94
|
-
ok: false
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
throw err;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
globalContext.importScripts = (url) => {
|
|
101
|
-
this._options.env.expect(url).toMatch(/^https:\/\/test\.cases\/path\//);
|
|
102
|
-
this.requirers.get("entry")(this._options.dist, (0, urlToRelativePath_1.default)(url));
|
|
103
|
-
};
|
|
104
|
-
globalContext.document = this.document;
|
|
105
|
-
globalContext.EventSource = EventSourceForNode_1.default;
|
|
106
|
-
globalContext.location = {
|
|
107
|
-
href: "https://test.cases/path/index.html",
|
|
108
|
-
origin: "https://test.cases",
|
|
109
|
-
toString() {
|
|
110
|
-
return "https://test.cases/path/index.html";
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
return globalContext;
|
|
114
|
-
}
|
|
115
|
-
createModuleScope(requireFn, m, file) {
|
|
116
|
-
const subModuleScope = super.createModuleScope(requireFn, m, file);
|
|
117
|
-
subModuleScope.importScripts = (url) => {
|
|
118
|
-
this._options.env.expect(url).toMatch(/^https:\/\/test\.cases\/path\//);
|
|
119
|
-
this.getRequire()(this._options.dist, `.${url.slice("https://test.cases/path".length)}`);
|
|
120
|
-
};
|
|
121
|
-
return subModuleScope;
|
|
122
|
-
}
|
|
123
|
-
createBaseModuleScope() {
|
|
124
|
-
const moduleScope = super.createBaseModuleScope();
|
|
125
|
-
moduleScope.window = this.globalContext;
|
|
126
|
-
moduleScope.globalThis = this.globalContext;
|
|
127
|
-
moduleScope.document = this.globalContext.document;
|
|
128
|
-
moduleScope.getComputedStyle = this.globalContext.getComputedStyle.bind(this.globalContext);
|
|
129
|
-
moduleScope.fetch = this.globalContext.fetch;
|
|
130
|
-
moduleScope.importScripts = this.globalContext.importScripts;
|
|
131
|
-
moduleScope.Worker = this.globalContext.Worker;
|
|
132
|
-
moduleScope.EventSource = this.globalContext.EventSource;
|
|
133
|
-
moduleScope.URL = URL;
|
|
134
|
-
moduleScope.Worker = (0, createFakeWorker_1.default)(this._options.env, {
|
|
135
|
-
outputDirectory: this._options.dist
|
|
136
|
-
});
|
|
137
|
-
moduleScope.__dirname = this._options.dist;
|
|
138
|
-
return moduleScope;
|
|
139
|
-
}
|
|
140
|
-
preExecute(_, file) {
|
|
141
|
-
this.oldCurrentScript = this.document.currentScript;
|
|
142
|
-
this.document.currentScript = new currentScript_1.default(file.subPath);
|
|
143
|
-
super.preExecute(_, file);
|
|
144
|
-
}
|
|
145
|
-
postExecute(_, file) {
|
|
146
|
-
super.postExecute(_, file);
|
|
147
|
-
this.document.currentScript = this.oldCurrentScript;
|
|
148
|
-
this.oldCurrentScript = null;
|
|
149
|
-
}
|
|
150
|
-
createEsmRequirer() {
|
|
151
|
-
const esmContext = node_vm_1.default.createContext({
|
|
152
|
-
...this.baseModuleScope,
|
|
153
|
-
...this.globalContext
|
|
154
|
-
}, {
|
|
155
|
-
name: "context for esm"
|
|
156
|
-
});
|
|
157
|
-
const esmCache = new Map();
|
|
158
|
-
return (currentDirectory, modulePath, context = {}) => {
|
|
159
|
-
const esmIdentifier = `esm-${currentDirectory}-${modulePath}`;
|
|
160
|
-
if (!node_vm_1.SourceTextModule) {
|
|
161
|
-
throw new Error("Running this test requires '--experimental-vm-modules'.\nRun with 'node --experimental-vm-modules node_modules/jest-cli/bin/jest'.");
|
|
162
|
-
}
|
|
163
|
-
const _require = this.getRequire();
|
|
164
|
-
const file = context.file || this.getFile(modulePath, currentDirectory);
|
|
165
|
-
if (!file) {
|
|
166
|
-
return this.requirers.get("miss")(currentDirectory, modulePath);
|
|
167
|
-
}
|
|
168
|
-
if (file.content.includes("__STATS_I__")) {
|
|
169
|
-
const statsIndex = this._options.stats?.()?.__index__;
|
|
170
|
-
if (typeof statsIndex === "number") {
|
|
171
|
-
esmContext.__STATS_I__ = statsIndex;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
let esm = esmCache.get(file.path);
|
|
175
|
-
if (!esm) {
|
|
176
|
-
esm = new node_vm_1.SourceTextModule(file.content, {
|
|
177
|
-
identifier: `${esmIdentifier}-${file.path}`,
|
|
178
|
-
// no attribute
|
|
179
|
-
url: `${(0, node_url_1.pathToFileURL)(file.path).href}?${esmIdentifier}`,
|
|
180
|
-
context: esmContext,
|
|
181
|
-
initializeImportMeta: (meta, _) => {
|
|
182
|
-
meta.url = (0, node_url_1.pathToFileURL)(file.path).href;
|
|
183
|
-
},
|
|
184
|
-
importModuleDynamically: async (specifier, module) => {
|
|
185
|
-
const result = await _require(node_path_1.default.dirname(file.path), specifier, {
|
|
186
|
-
esmMode: type_1.EEsmMode.Evaluated
|
|
187
|
-
});
|
|
188
|
-
return await (0, asModule_1.default)(result, module.context);
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
esmCache.set(file.path, esm);
|
|
192
|
-
}
|
|
193
|
-
if (context.esmMode === type_1.EEsmMode.Unlinked)
|
|
194
|
-
return esm;
|
|
195
|
-
return (async () => {
|
|
196
|
-
await esm.link(async (specifier, referencingModule) => {
|
|
197
|
-
return await (0, asModule_1.default)(await _require(node_path_1.default.dirname(referencingModule.identifier
|
|
198
|
-
? referencingModule.identifier.slice(esmIdentifier.length + 1)
|
|
199
|
-
: (0, node_url_1.fileURLToPath)(referencingModule.url)), specifier, {
|
|
200
|
-
esmMode: type_1.EEsmMode.Unlinked
|
|
201
|
-
}), referencingModule.context, true);
|
|
202
|
-
});
|
|
203
|
-
if (esm.instantiate)
|
|
204
|
-
esm.instantiate();
|
|
205
|
-
await esm.evaluate();
|
|
206
|
-
if (context.esmMode === type_1.EEsmMode.Evaluated) {
|
|
207
|
-
return esm;
|
|
208
|
-
}
|
|
209
|
-
const ns = esm.namespace;
|
|
210
|
-
return ns.default && ns.default instanceof Promise ? ns.default : ns;
|
|
211
|
-
})();
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
exports.FakeDocumentWebRunner = FakeDocumentWebRunner;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ECompilerType, TRunnerFile, TRunnerRequirer } from "../../type";
|
|
2
|
-
import { type INodeRunnerOptions, NodeRunner } from "../node";
|
|
3
|
-
export declare class JSDOMWebRunner<T extends ECompilerType = ECompilerType.Rspack> extends NodeRunner<T> {
|
|
4
|
-
protected _webOptions: INodeRunnerOptions<T>;
|
|
5
|
-
private dom;
|
|
6
|
-
constructor(_webOptions: INodeRunnerOptions<T>);
|
|
7
|
-
run(file: string): Promise<unknown>;
|
|
8
|
-
getGlobal(name: string): unknown;
|
|
9
|
-
protected createResourceLoader(): {
|
|
10
|
-
fetch(url: string, _: {
|
|
11
|
-
element: HTMLScriptElement;
|
|
12
|
-
}): any;
|
|
13
|
-
};
|
|
14
|
-
private urlToPath;
|
|
15
|
-
protected createBaseModuleScope(): import("../../type").IModuleScope;
|
|
16
|
-
protected getModuleContent(file: TRunnerFile): [
|
|
17
|
-
{
|
|
18
|
-
exports: Record<string, unknown>;
|
|
19
|
-
},
|
|
20
|
-
string
|
|
21
|
-
];
|
|
22
|
-
protected createJSDOMRequirer(): TRunnerRequirer;
|
|
23
|
-
protected createRunner(): void;
|
|
24
|
-
}
|
package/dist/runner/web/jsdom.js
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.JSDOMWebRunner = void 0;
|
|
7
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const jsdom_1 = require("jsdom");
|
|
10
|
-
const helper_1 = require("../../helper");
|
|
11
|
-
const EventSourceForNode_1 = __importDefault(require("../../helper/legacy/EventSourceForNode"));
|
|
12
|
-
const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
|
|
13
|
-
const node_1 = require("../node");
|
|
14
|
-
// Compatibility code to suppress iconv-lite warnings
|
|
15
|
-
require("iconv-lite").skipDecodeWarning = true;
|
|
16
|
-
class JSDOMWebRunner extends node_1.NodeRunner {
|
|
17
|
-
constructor(_webOptions) {
|
|
18
|
-
super(_webOptions);
|
|
19
|
-
this._webOptions = _webOptions;
|
|
20
|
-
const virtualConsole = new jsdom_1.VirtualConsole({});
|
|
21
|
-
virtualConsole.sendTo(console, {
|
|
22
|
-
omitJSDOMErrors: true
|
|
23
|
-
});
|
|
24
|
-
this.dom = new jsdom_1.JSDOM(`
|
|
25
|
-
<!doctype html>
|
|
26
|
-
<html>
|
|
27
|
-
<head></head>
|
|
28
|
-
<body></body>
|
|
29
|
-
</html>
|
|
30
|
-
`, {
|
|
31
|
-
url: "https://test.cases/path/index.html",
|
|
32
|
-
resources: this.createResourceLoader(),
|
|
33
|
-
runScripts: "dangerously",
|
|
34
|
-
virtualConsole
|
|
35
|
-
});
|
|
36
|
-
this.dom.window.console = console;
|
|
37
|
-
// compat with FakeDocument
|
|
38
|
-
this.dom.window.eval(`
|
|
39
|
-
Object.defineProperty(document.head, "_children", {
|
|
40
|
-
get: function() {
|
|
41
|
-
return Array.from(document.head.children).map(function(ele) {
|
|
42
|
-
var type = ele.tagName.toLowerCase();
|
|
43
|
-
return new Proxy(ele, {
|
|
44
|
-
get(target, prop, receiver) {
|
|
45
|
-
if (prop === "_type") {
|
|
46
|
-
return target.tagName.toLowerCase();
|
|
47
|
-
}
|
|
48
|
-
if (prop === "_href") {
|
|
49
|
-
return Reflect.get(target, "href", receiver);
|
|
50
|
-
}
|
|
51
|
-
return Reflect.get(target, prop, receiver);
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
`);
|
|
58
|
-
const vmContext = this.dom.getInternalVMContext();
|
|
59
|
-
vmContext.global = {};
|
|
60
|
-
}
|
|
61
|
-
run(file) {
|
|
62
|
-
if (!file.endsWith(".js") && !file.endsWith(".mjs")) {
|
|
63
|
-
const cssElement = this.dom.window.document.createElement("link");
|
|
64
|
-
cssElement.href = file;
|
|
65
|
-
cssElement.rel = "stylesheet";
|
|
66
|
-
this.dom.window.document.head.appendChild(cssElement);
|
|
67
|
-
return Promise.resolve();
|
|
68
|
-
}
|
|
69
|
-
return super.run(file);
|
|
70
|
-
}
|
|
71
|
-
getGlobal(name) {
|
|
72
|
-
return this.globalContext[name];
|
|
73
|
-
}
|
|
74
|
-
createResourceLoader() {
|
|
75
|
-
const that = this;
|
|
76
|
-
class CustomResourceLoader extends jsdom_1.ResourceLoader {
|
|
77
|
-
fetch(url, _) {
|
|
78
|
-
const filePath = that.urlToPath(url);
|
|
79
|
-
let finalCode;
|
|
80
|
-
if (node_path_1.default.extname(filePath) === ".js") {
|
|
81
|
-
const currentDirectory = node_path_1.default.dirname(filePath);
|
|
82
|
-
const file = that.getFile(filePath, currentDirectory);
|
|
83
|
-
if (!file) {
|
|
84
|
-
throw new Error(`File not found: ${filePath}`);
|
|
85
|
-
}
|
|
86
|
-
const [_m, code] = that.getModuleContent(file);
|
|
87
|
-
finalCode = code;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
finalCode = node_fs_1.default.readFileSync(filePath);
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
that.dom.window["__LINK_SHEET__"] ??= {};
|
|
94
|
-
that.dom.window["__LINK_SHEET__"][url] = finalCode.toString();
|
|
95
|
-
return Promise.resolve(finalCode);
|
|
96
|
-
}
|
|
97
|
-
catch (err) {
|
|
98
|
-
console.error(err);
|
|
99
|
-
if (err.code === "ENOENT") {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
throw err;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return new CustomResourceLoader();
|
|
107
|
-
}
|
|
108
|
-
urlToPath(url) {
|
|
109
|
-
return node_path_1.default
|
|
110
|
-
.resolve(this._webOptions.dist, `./${url.startsWith("https://test.cases/path/") ? url.slice(24) : url.startsWith("https://example.com/public/path/") ? url.slice(32) : url}`)
|
|
111
|
-
.split("?")[0];
|
|
112
|
-
}
|
|
113
|
-
createBaseModuleScope() {
|
|
114
|
-
const moduleScope = super.createBaseModuleScope();
|
|
115
|
-
moduleScope.EventSource = EventSourceForNode_1.default;
|
|
116
|
-
moduleScope.fetch = async (url) => {
|
|
117
|
-
try {
|
|
118
|
-
const buffer = await new Promise((resolve, reject) => node_fs_1.default.readFile(this.urlToPath(url), (err, b) => err ? reject(err) : resolve(b)));
|
|
119
|
-
return {
|
|
120
|
-
status: 200,
|
|
121
|
-
ok: true,
|
|
122
|
-
json: async () => JSON.parse(buffer.toString("utf-8"))
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
catch (err) {
|
|
126
|
-
if (err.code === "ENOENT") {
|
|
127
|
-
return {
|
|
128
|
-
status: 404,
|
|
129
|
-
ok: false
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
throw err;
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
moduleScope.URL = URL;
|
|
136
|
-
moduleScope.importScripts = (url) => {
|
|
137
|
-
this._options.env.expect(url).toMatch(/^https:\/\/test\.cases\/path\//);
|
|
138
|
-
this.requirers.get("entry")(this._options.dist, (0, urlToRelativePath_1.default)(url));
|
|
139
|
-
};
|
|
140
|
-
moduleScope.getComputedStyle = (element) => {
|
|
141
|
-
const computedStyle = this.dom.window.getComputedStyle(element);
|
|
142
|
-
const getPropertyValue = computedStyle.getPropertyValue.bind(computedStyle);
|
|
143
|
-
return {
|
|
144
|
-
...computedStyle,
|
|
145
|
-
getPropertyValue(v) {
|
|
146
|
-
return getPropertyValue(v);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
moduleScope.window = this.dom.window;
|
|
151
|
-
moduleScope.document = this.dom.window.document;
|
|
152
|
-
return moduleScope;
|
|
153
|
-
}
|
|
154
|
-
getModuleContent(file) {
|
|
155
|
-
const m = {
|
|
156
|
-
exports: {}
|
|
157
|
-
};
|
|
158
|
-
const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
|
|
159
|
-
if (this._options.testConfig.moduleScope) {
|
|
160
|
-
this._options.testConfig.moduleScope(currentModuleScope, this._options.stats, this._options.compilerOptions);
|
|
161
|
-
}
|
|
162
|
-
if (file.content.includes("__STATS__")) {
|
|
163
|
-
currentModuleScope.__STATS__ = this._options.stats?.();
|
|
164
|
-
}
|
|
165
|
-
if (file.content.includes("__STATS_I__")) {
|
|
166
|
-
const statsIndex = this._options.stats?.()?.__index__;
|
|
167
|
-
if (typeof statsIndex === "number") {
|
|
168
|
-
currentModuleScope.__STATS_I__ = statsIndex;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
const scopeKey = (0, helper_1.escapeSep)(file.path);
|
|
172
|
-
const args = Object.keys(currentModuleScope).filter(arg => !["window", "self", "globalThis", "console"].includes(arg));
|
|
173
|
-
const argValues = args
|
|
174
|
-
.map(arg => `window["${scopeKey}"]["${arg}"]`)
|
|
175
|
-
.join(", ");
|
|
176
|
-
this.dom.window[scopeKey] = currentModuleScope;
|
|
177
|
-
this.dom.window["__GLOBAL_SHARED__"] = this.globalContext;
|
|
178
|
-
return [
|
|
179
|
-
m,
|
|
180
|
-
`
|
|
181
|
-
// hijack document.currentScript for auto public path
|
|
182
|
-
var $$g$$ = new Proxy(window, {
|
|
183
|
-
get(target, prop, receiver) {
|
|
184
|
-
if (prop === "document") {
|
|
185
|
-
return new Proxy(window.document, {
|
|
186
|
-
get(target, prop, receiver) {
|
|
187
|
-
if (prop === "currentScript") {
|
|
188
|
-
var script = target.createElement("script");
|
|
189
|
-
script.src = "https://test.cases/path/${(0, helper_1.escapeSep)(file.subPath)}index.js";
|
|
190
|
-
return script;
|
|
191
|
-
}
|
|
192
|
-
return Reflect.get(target, prop, receiver);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
return Reflect.get(target, prop, receiver);
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
var $$self$$ = new Proxy(window, {
|
|
200
|
-
get(target, prop, receiver) {
|
|
201
|
-
if (prop === "__HMR_UPDATED_RUNTIME__") {
|
|
202
|
-
return window["__GLOBAL_SHARED__"]["__HMR_UPDATED_RUNTIME__"];
|
|
203
|
-
}
|
|
204
|
-
return Reflect.get(target, prop, receiver);
|
|
205
|
-
},
|
|
206
|
-
set(target, prop, value, receiver) {
|
|
207
|
-
if (prop === "__HMR_UPDATED_RUNTIME__") {
|
|
208
|
-
window["__GLOBAL_SHARED__"]["__HMR_UPDATED_RUNTIME__"] = value;
|
|
209
|
-
}
|
|
210
|
-
return Reflect.set(target, prop, value, receiver);
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
(function(window, self, globalThis, console, ${args.join(", ")}) {
|
|
214
|
-
${file.content}
|
|
215
|
-
})($$g$$, $$self$$, $$g$$, window["console"], ${argValues});
|
|
216
|
-
`
|
|
217
|
-
];
|
|
218
|
-
}
|
|
219
|
-
createJSDOMRequirer() {
|
|
220
|
-
return (currentDirectory, modulePath, context = {}) => {
|
|
221
|
-
const file = context.file || this.getFile(modulePath, currentDirectory);
|
|
222
|
-
if (!file) {
|
|
223
|
-
return this.requirers.get("miss")(currentDirectory, modulePath);
|
|
224
|
-
}
|
|
225
|
-
if (file.path in this.requireCache) {
|
|
226
|
-
return this.requireCache[file.path].exports;
|
|
227
|
-
}
|
|
228
|
-
const [m, code] = this.getModuleContent(file);
|
|
229
|
-
this.preExecute(code, file);
|
|
230
|
-
this.dom.window.eval(code);
|
|
231
|
-
this.postExecute(m, file);
|
|
232
|
-
this.requireCache[file.path] = m;
|
|
233
|
-
return m.exports;
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
createRunner() {
|
|
237
|
-
super.createRunner();
|
|
238
|
-
this.requirers.set("cjs", this.createJSDOMRequirer());
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
exports.JSDOMWebRunner = JSDOMWebRunner;
|