@rspack-debug/test-tools 1.3.14
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/LICENSE +22 -0
- package/README.md +17 -0
- package/dist/case/builtin.d.ts +1 -0
- package/dist/case/builtin.js +39 -0
- package/dist/case/cache.d.ts +2 -0
- package/dist/case/cache.js +34 -0
- package/dist/case/compiler.d.ts +6 -0
- package/dist/case/compiler.js +17 -0
- package/dist/case/config.d.ts +3 -0
- package/dist/case/config.js +39 -0
- package/dist/case/defaults.d.ts +6 -0
- package/dist/case/defaults.js +39 -0
- package/dist/case/diagnostic.d.ts +1 -0
- package/dist/case/diagnostic.js +29 -0
- package/dist/case/diff.d.ts +3 -0
- package/dist/case/diff.js +126 -0
- package/dist/case/error.d.ts +6 -0
- package/dist/case/error.js +21 -0
- package/dist/case/hash.d.ts +3 -0
- package/dist/case/hash.js +30 -0
- package/dist/case/hook.d.ts +6 -0
- package/dist/case/hook.js +35 -0
- package/dist/case/hot-step.d.ts +2 -0
- package/dist/case/hot-step.js +32 -0
- package/dist/case/hot.d.ts +2 -0
- package/dist/case/hot.js +32 -0
- package/dist/case/index.d.ts +19 -0
- package/dist/case/index.js +35 -0
- package/dist/case/new-incremental.d.ts +6 -0
- package/dist/case/new-incremental.js +100 -0
- package/dist/case/normal.d.ts +1 -0
- package/dist/case/normal.js +29 -0
- package/dist/case/serial.d.ts +3 -0
- package/dist/case/serial.js +34 -0
- package/dist/case/stats-api.d.ts +6 -0
- package/dist/case/stats-api.js +21 -0
- package/dist/case/stats-output.d.ts +1 -0
- package/dist/case/stats-output.js +22 -0
- package/dist/case/treeshaking.d.ts +1 -0
- package/dist/case/treeshaking.js +23 -0
- package/dist/case/watch.d.ts +1 -0
- package/dist/case/watch.js +53 -0
- package/dist/compare/comparator.d.ts +17 -0
- package/dist/compare/comparator.js +52 -0
- package/dist/compare/compare.d.ts +17 -0
- package/dist/compare/compare.js +175 -0
- package/dist/compare/format-code.d.ts +16 -0
- package/dist/compare/format-code.js +239 -0
- package/dist/compare/index.d.ts +5 -0
- package/dist/compare/index.js +21 -0
- package/dist/compare/replace-module-argument.d.ts +1 -0
- package/dist/compare/replace-module-argument.js +8 -0
- package/dist/compare/replace-runtime-module-name.d.ts +1 -0
- package/dist/compare/replace-runtime-module-name.js +71 -0
- package/dist/compiler.d.ts +28 -0
- package/dist/compiler.js +111 -0
- package/dist/helper/directory.d.ts +12 -0
- package/dist/helper/directory.js +81 -0
- package/dist/helper/expect/diff.d.ts +3 -0
- package/dist/helper/expect/diff.js +21 -0
- package/dist/helper/expect/error.d.ts +5 -0
- package/dist/helper/expect/error.js +51 -0
- package/dist/helper/expect/placeholder.d.ts +1 -0
- package/dist/helper/expect/placeholder.js +41 -0
- package/dist/helper/expect/rspack.d.ts +3 -0
- package/dist/helper/expect/rspack.js +14 -0
- package/dist/helper/expect/to-be-typeof.d.ts +4 -0
- package/dist/helper/expect/to-be-typeof.js +12 -0
- package/dist/helper/expect/to-end-with.d.ts +4 -0
- package/dist/helper/expect/to-end-with.js +11 -0
- package/dist/helper/expect/to-match-file-snapshot.d.ts +23 -0
- package/dist/helper/expect/to-match-file-snapshot.js +108 -0
- package/dist/helper/hot-update/index.d.ts +1 -0
- package/dist/helper/hot-update/index.js +5 -0
- package/dist/helper/hot-update/loader.d.ts +1 -0
- package/dist/helper/hot-update/loader.js +32 -0
- package/dist/helper/hot-update/plugin.d.ts +17 -0
- package/dist/helper/hot-update/plugin.js +133 -0
- package/dist/helper/index.d.ts +7 -0
- package/dist/helper/index.js +23 -0
- package/dist/helper/legacy/EventSourceForNode.d.ts +8 -0
- package/dist/helper/legacy/EventSourceForNode.js +40 -0
- package/dist/helper/legacy/FakeDocument.d.ts +54 -0
- package/dist/helper/legacy/FakeDocument.js +278 -0
- package/dist/helper/legacy/asModule.d.ts +3 -0
- package/dist/helper/legacy/asModule.js +25 -0
- package/dist/helper/legacy/captureStdio.d.ts +8 -0
- package/dist/helper/legacy/captureStdio.js +32 -0
- package/dist/helper/legacy/checkArrayExpectation.d.ts +2 -0
- package/dist/helper/legacy/checkArrayExpectation.js +111 -0
- package/dist/helper/legacy/copyDiff.d.ts +2 -0
- package/dist/helper/legacy/copyDiff.js +33 -0
- package/dist/helper/legacy/createFakeWorker.d.ts +13 -0
- package/dist/helper/legacy/createFakeWorker.js +80 -0
- package/dist/helper/legacy/createLazyTestEnv.d.ts +10 -0
- package/dist/helper/legacy/createLazyTestEnv.js +116 -0
- package/dist/helper/legacy/createLogger.d.ts +23 -0
- package/dist/helper/legacy/createLogger.js +20 -0
- package/dist/helper/legacy/currentScript.d.ts +6 -0
- package/dist/helper/legacy/currentScript.js +8 -0
- package/dist/helper/legacy/fakeSystem.d.ts +9 -0
- package/dist/helper/legacy/fakeSystem.js +124 -0
- package/dist/helper/legacy/parseResource.d.ts +6 -0
- package/dist/helper/legacy/parseResource.js +15 -0
- package/dist/helper/legacy/supportsImportFn.d.ts +1 -0
- package/dist/helper/legacy/supportsImportFn.js +15 -0
- package/dist/helper/legacy/supportsWorker.d.ts +2 -0
- package/dist/helper/legacy/supportsWorker.js +17 -0
- package/dist/helper/legacy/urlToRelativePath.d.ts +2 -0
- package/dist/helper/legacy/urlToRelativePath.js +7 -0
- package/dist/helper/legacy/walkCssTokens.d.ts +40 -0
- package/dist/helper/legacy/walkCssTokens.js +761 -0
- package/dist/helper/legacy/warmup-webpack.d.ts +1 -0
- package/dist/helper/legacy/warmup-webpack.js +26 -0
- package/dist/helper/loaders/hot-update.d.ts +1 -0
- package/dist/helper/loaders/hot-update.js +40 -0
- package/dist/helper/parse-modules.d.ts +7 -0
- package/dist/helper/parse-modules.js +73 -0
- package/dist/helper/plugins/hot-update.d.ts +7 -0
- package/dist/helper/plugins/hot-update.js +40 -0
- package/dist/helper/plugins/index.d.ts +1 -0
- package/dist/helper/plugins/index.js +17 -0
- package/dist/helper/read-config-file.d.ts +2 -0
- package/dist/helper/read-config-file.js +13 -0
- package/dist/helper/serializers.d.ts +2 -0
- package/dist/helper/serializers.js +52 -0
- package/dist/helper/setup-env.d.ts +1 -0
- package/dist/helper/setup-env.js +80 -0
- package/dist/helper/setup-expect.d.ts +1 -0
- package/dist/helper/setup-expect.js +16 -0
- package/dist/helper/update-snapshot.d.ts +1 -0
- package/dist/helper/update-snapshot.js +6 -0
- package/dist/helper/util/checkSourceMap.d.ts +1 -0
- package/dist/helper/util/checkSourceMap.js +96 -0
- package/dist/helper/util/checkStats.d.ts +2 -0
- package/dist/helper/util/checkStats.js +43 -0
- package/dist/helper/util/currentWatchStep.d.ts +1 -0
- package/dist/helper/util/currentWatchStep.js +2 -0
- package/dist/helper/util/expectWarningFactory.d.ts +2 -0
- package/dist/helper/util/expectWarningFactory.js +21 -0
- package/dist/helper/util/filterUtil.d.ts +8 -0
- package/dist/helper/util/filterUtil.js +50 -0
- package/dist/helper/util/identifier.d.ts +76 -0
- package/dist/helper/util/identifier.js +339 -0
- package/dist/helper/util/replaceMitteDiagnostic.d.ts +2 -0
- package/dist/helper/util/replaceMitteDiagnostic.js +17 -0
- package/dist/helper/win.d.ts +1 -0
- package/dist/helper/win.js +10 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +28 -0
- package/dist/plugin/index.d.ts +4 -0
- package/dist/plugin/index.js +20 -0
- package/dist/plugin/lazy-compilation-test-plugin.d.ts +4 -0
- package/dist/plugin/lazy-compilation-test-plugin.js +67 -0
- package/dist/plugin/rspack-diff-config-plugin.d.ts +7 -0
- package/dist/plugin/rspack-diff-config-plugin.js +42 -0
- package/dist/plugin/webpack-diff-config-plugin.d.ts +7 -0
- package/dist/plugin/webpack-diff-config-plugin.js +41 -0
- package/dist/plugin/webpack-module-placeholder-plugin.d.ts +3 -0
- package/dist/plugin/webpack-module-placeholder-plugin.js +107 -0
- package/dist/processor/basic.d.ts +24 -0
- package/dist/processor/basic.js +146 -0
- package/dist/processor/builtin.d.ts +9 -0
- package/dist/processor/builtin.js +171 -0
- package/dist/processor/cache.d.ts +20 -0
- package/dist/processor/cache.js +127 -0
- package/dist/processor/config.d.ts +11 -0
- package/dist/processor/config.js +81 -0
- package/dist/processor/defaults.d.ts +30 -0
- package/dist/processor/defaults.js +72 -0
- package/dist/processor/diagnostic.d.ts +15 -0
- package/dist/processor/diagnostic.js +102 -0
- package/dist/processor/diff.d.ts +30 -0
- package/dist/processor/diff.js +140 -0
- package/dist/processor/error.d.ts +23 -0
- package/dist/processor/error.js +95 -0
- package/dist/processor/hash.d.ts +10 -0
- package/dist/processor/hash.js +63 -0
- package/dist/processor/hook.d.ts +44 -0
- package/dist/processor/hook.js +204 -0
- package/dist/processor/hot-new-incremental.d.ts +14 -0
- package/dist/processor/hot-new-incremental.js +43 -0
- package/dist/processor/hot-step.d.ts +18 -0
- package/dist/processor/hot-step.js +299 -0
- package/dist/processor/hot.d.ts +17 -0
- package/dist/processor/hot.js +138 -0
- package/dist/processor/index.d.ts +20 -0
- package/dist/processor/index.js +36 -0
- package/dist/processor/multi.d.ts +17 -0
- package/dist/processor/multi.js +73 -0
- package/dist/processor/normal.d.ts +12 -0
- package/dist/processor/normal.js +150 -0
- package/dist/processor/simple.d.ts +23 -0
- package/dist/processor/simple.js +49 -0
- package/dist/processor/snapshot.d.ts +12 -0
- package/dist/processor/snapshot.js +62 -0
- package/dist/processor/stats-api.d.ts +18 -0
- package/dist/processor/stats-api.js +48 -0
- package/dist/processor/stats.d.ts +18 -0
- package/dist/processor/stats.js +206 -0
- package/dist/processor/treeshaking.d.ts +10 -0
- package/dist/processor/treeshaking.js +33 -0
- package/dist/processor/watch.d.ts +29 -0
- package/dist/processor/watch.js +234 -0
- package/dist/reporter/diff-html.d.ts +15 -0
- package/dist/reporter/diff-html.js +69 -0
- package/dist/reporter/diff-stats.d.ts +24 -0
- package/dist/reporter/diff-stats.js +131 -0
- package/dist/reporter/index.d.ts +2 -0
- package/dist/reporter/index.js +18 -0
- package/dist/runner/basic.d.ts +10 -0
- package/dist/runner/basic.js +63 -0
- package/dist/runner/cache.d.ts +5 -0
- package/dist/runner/cache.js +90 -0
- package/dist/runner/hot-step.d.ts +5 -0
- package/dist/runner/hot-step.js +87 -0
- package/dist/runner/hot.d.ts +5 -0
- package/dist/runner/hot.js +83 -0
- package/dist/runner/index.d.ts +9 -0
- package/dist/runner/index.js +25 -0
- package/dist/runner/multiple.d.ts +11 -0
- package/dist/runner/multiple.js +38 -0
- package/dist/runner/normal.d.ts +5 -0
- package/dist/runner/normal.js +20 -0
- package/dist/runner/runner/basic.d.ts +30 -0
- package/dist/runner/runner/basic.js +107 -0
- package/dist/runner/runner/cjs.d.ts +14 -0
- package/dist/runner/runner/cjs.js +151 -0
- package/dist/runner/runner/esm.d.ts +7 -0
- package/dist/runner/runner/esm.js +125 -0
- package/dist/runner/runner/index.d.ts +8 -0
- package/dist/runner/runner/index.js +24 -0
- package/dist/runner/runner/normal.d.ts +9 -0
- package/dist/runner/runner/normal.js +23 -0
- package/dist/runner/runner/watch.d.ts +16 -0
- package/dist/runner/runner/watch.js +27 -0
- package/dist/runner/runner/web/fake.d.ts +18 -0
- package/dist/runner/runner/web/fake.js +143 -0
- package/dist/runner/runner/web/jsdom.d.ts +26 -0
- package/dist/runner/runner/web/jsdom.js +219 -0
- package/dist/runner/runner/web.d.ts +15 -0
- package/dist/runner/runner/web.js +32 -0
- package/dist/runner/type.d.ts +42 -0
- package/dist/runner/type.js +9 -0
- package/dist/runner/watch.d.ts +7 -0
- package/dist/runner/watch.js +60 -0
- package/dist/test/context.d.ts +26 -0
- package/dist/test/context.js +108 -0
- package/dist/test/creator.d.ts +46 -0
- package/dist/test/creator.js +310 -0
- package/dist/test/simple.d.ts +5 -0
- package/dist/test/simple.js +43 -0
- package/dist/test/tester.d.ts +17 -0
- package/dist/test/tester.js +88 -0
- package/dist/type.d.ts +168 -0
- package/dist/type.js +22 -0
- package/jest.d.ts +25 -0
- package/package.json +116 -0
- package/template/diff.bundle.css +1 -0
- package/template/diff.bundle.js +144 -0
- package/template/diff.html +14 -0
- package/template/editor.worker.js +1 -0
|
@@ -0,0 +1,107 @@
|
|
|
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.BasicRunner = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const isRelativePath = (p) => /^\.\.?\//.test(p);
|
|
10
|
+
const getSubPath = (p) => {
|
|
11
|
+
const lastSlash = p.lastIndexOf("/");
|
|
12
|
+
let firstSlash = p.indexOf("/");
|
|
13
|
+
if (lastSlash !== -1 && firstSlash !== lastSlash) {
|
|
14
|
+
if (firstSlash !== -1) {
|
|
15
|
+
let next = p.indexOf("/", firstSlash + 1);
|
|
16
|
+
let dir = p.slice(firstSlash + 1, next);
|
|
17
|
+
while (dir === ".") {
|
|
18
|
+
firstSlash = next;
|
|
19
|
+
next = p.indexOf("/", firstSlash + 1);
|
|
20
|
+
dir = p.slice(firstSlash + 1, next);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return p.slice(firstSlash + 1, lastSlash + 1);
|
|
24
|
+
}
|
|
25
|
+
return "";
|
|
26
|
+
};
|
|
27
|
+
const cached = new Map();
|
|
28
|
+
class BasicRunner {
|
|
29
|
+
constructor(_options) {
|
|
30
|
+
this._options = _options;
|
|
31
|
+
this.globalContext = null;
|
|
32
|
+
this.baseModuleScope = null;
|
|
33
|
+
this.requirers = new Map();
|
|
34
|
+
}
|
|
35
|
+
run(file) {
|
|
36
|
+
if (!this.globalContext) {
|
|
37
|
+
this.globalContext = this.createGlobalContext();
|
|
38
|
+
}
|
|
39
|
+
this.baseModuleScope = this.createBaseModuleScope();
|
|
40
|
+
if (typeof this._options.testConfig.moduleScope === "function") {
|
|
41
|
+
this._options.testConfig.moduleScope(this.baseModuleScope, this._options.stats);
|
|
42
|
+
}
|
|
43
|
+
this.createRunner();
|
|
44
|
+
const res = this.getRequire()(this._options.dist, file.startsWith("./") ? file : `./${file}`);
|
|
45
|
+
if (typeof res === "object" && "then" in res) {
|
|
46
|
+
return res;
|
|
47
|
+
}
|
|
48
|
+
return Promise.resolve(res);
|
|
49
|
+
}
|
|
50
|
+
getRequire() {
|
|
51
|
+
const entryRequire = this.requirers.get("entry");
|
|
52
|
+
return (currentDirectory, modulePath, context = {}) => {
|
|
53
|
+
const p = Array.isArray(modulePath)
|
|
54
|
+
? modulePath
|
|
55
|
+
: modulePath.split("?")[0];
|
|
56
|
+
return entryRequire(currentDirectory, p, context);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
getGlobal(name) {
|
|
60
|
+
return (this.globalContext || {})[name];
|
|
61
|
+
}
|
|
62
|
+
getFile(modulePath, currentDirectory) {
|
|
63
|
+
const cacheKey = `${currentDirectory}|${modulePath}`;
|
|
64
|
+
if (this._options.cachable && cached.has(cacheKey)) {
|
|
65
|
+
return cached.get(cacheKey);
|
|
66
|
+
}
|
|
67
|
+
let res = null;
|
|
68
|
+
if (Array.isArray(modulePath)) {
|
|
69
|
+
res = {
|
|
70
|
+
path: node_path_1.default.join(currentDirectory, ".array-require.js"),
|
|
71
|
+
content: `module.exports = (${modulePath
|
|
72
|
+
.map(arg => {
|
|
73
|
+
return `require(${JSON.stringify(`./${arg}`)})`;
|
|
74
|
+
})
|
|
75
|
+
.join(", ")});`,
|
|
76
|
+
subPath: ""
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
else if (isRelativePath(modulePath)) {
|
|
80
|
+
const p = node_path_1.default.join(currentDirectory, modulePath);
|
|
81
|
+
res = {
|
|
82
|
+
path: p,
|
|
83
|
+
content: node_fs_1.default.readFileSync(p, "utf-8"),
|
|
84
|
+
subPath: getSubPath(modulePath)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else if (node_path_1.default.isAbsolute(modulePath)) {
|
|
88
|
+
res = {
|
|
89
|
+
path: modulePath,
|
|
90
|
+
content: node_fs_1.default.readFileSync(modulePath, "utf-8"),
|
|
91
|
+
subPath: "absolute_path"
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (this._options.cachable && res) {
|
|
95
|
+
cached.set(cacheKey, res);
|
|
96
|
+
}
|
|
97
|
+
return res;
|
|
98
|
+
}
|
|
99
|
+
preExecute(code, file) { }
|
|
100
|
+
postExecute(m, file) { }
|
|
101
|
+
createRunner() {
|
|
102
|
+
this.requirers.set("entry", (currentDirectory, modulePath, context = {}) => {
|
|
103
|
+
throw new Error("Not implement");
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.BasicRunner = BasicRunner;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ECompilerType } from "../../type";
|
|
2
|
+
import type { IBasicGlobalContext, IBasicModuleScope, TBasicRunnerFile, TModuleObject, TRunnerRequirer } from "../type";
|
|
3
|
+
import { BasicRunner } from "./basic";
|
|
4
|
+
declare global {
|
|
5
|
+
var printLogger: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare class CommonJsRunner<T extends ECompilerType = ECompilerType.Rspack> extends BasicRunner<T> {
|
|
8
|
+
protected createGlobalContext(): IBasicGlobalContext;
|
|
9
|
+
protected createBaseModuleScope(): IBasicModuleScope;
|
|
10
|
+
protected createModuleScope(requireFn: TRunnerRequirer, m: TModuleObject, file: TBasicRunnerFile): IBasicModuleScope;
|
|
11
|
+
protected createRunner(): void;
|
|
12
|
+
protected createMissRequirer(): TRunnerRequirer;
|
|
13
|
+
protected createCjsRequirer(): TRunnerRequirer;
|
|
14
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
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.CommonJsRunner = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const node_vm_1 = __importDefault(require("node:vm"));
|
|
9
|
+
const basic_1 = require("./basic");
|
|
10
|
+
const define = (...args) => {
|
|
11
|
+
const factory = args.pop();
|
|
12
|
+
factory();
|
|
13
|
+
};
|
|
14
|
+
class CommonJsRunner extends basic_1.BasicRunner {
|
|
15
|
+
createGlobalContext() {
|
|
16
|
+
return {
|
|
17
|
+
console: {
|
|
18
|
+
log: (...args) => {
|
|
19
|
+
if (printLogger) {
|
|
20
|
+
console.log(...args);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
warn: (...args) => {
|
|
24
|
+
if (printLogger) {
|
|
25
|
+
console.warn(...args);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
error: (...args) => {
|
|
29
|
+
console.error(...args);
|
|
30
|
+
},
|
|
31
|
+
info: (...args) => {
|
|
32
|
+
if (printLogger) {
|
|
33
|
+
console.info(...args);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
debug: (...args) => {
|
|
37
|
+
if (printLogger) {
|
|
38
|
+
console.info(...args);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
trace: (...args) => {
|
|
42
|
+
if (printLogger) {
|
|
43
|
+
console.info(...args);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
assert: (...args) => {
|
|
47
|
+
console.assert(...args);
|
|
48
|
+
},
|
|
49
|
+
clear: () => {
|
|
50
|
+
console.clear();
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
setTimeout: ((cb, ms, ...args) => {
|
|
54
|
+
const timeout = setTimeout(cb, ms, ...args);
|
|
55
|
+
timeout.unref();
|
|
56
|
+
return timeout;
|
|
57
|
+
}),
|
|
58
|
+
clearTimeout: clearTimeout
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
createBaseModuleScope() {
|
|
62
|
+
const baseModuleScope = {
|
|
63
|
+
console: this.globalContext.console,
|
|
64
|
+
setTimeout: this.globalContext.setTimeout,
|
|
65
|
+
clearTimeout: this.globalContext.clearTimeout,
|
|
66
|
+
nsObj: (m) => {
|
|
67
|
+
Object.defineProperty(m, Symbol.toStringTag, {
|
|
68
|
+
value: "Module"
|
|
69
|
+
});
|
|
70
|
+
return m;
|
|
71
|
+
},
|
|
72
|
+
__SNAPSHOT__: node_path_1.default.join(this._options.source, "__snapshot__"),
|
|
73
|
+
...this._options.env
|
|
74
|
+
};
|
|
75
|
+
return baseModuleScope;
|
|
76
|
+
}
|
|
77
|
+
createModuleScope(requireFn, m, file) {
|
|
78
|
+
return {
|
|
79
|
+
...this.baseModuleScope,
|
|
80
|
+
require: requireFn.bind(null, node_path_1.default.dirname(file.path)),
|
|
81
|
+
module: m,
|
|
82
|
+
exports: m.exports,
|
|
83
|
+
__dirname: node_path_1.default.dirname(file.path),
|
|
84
|
+
__filename: file.path,
|
|
85
|
+
_globalAssign: {
|
|
86
|
+
expect: this._options.env.expect
|
|
87
|
+
},
|
|
88
|
+
define
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
createRunner() {
|
|
92
|
+
this.requirers.set("miss", this.createMissRequirer());
|
|
93
|
+
this.requirers.set("entry", this.createCjsRequirer());
|
|
94
|
+
}
|
|
95
|
+
createMissRequirer() {
|
|
96
|
+
return (currentDirectory, modulePath, context = {}) => {
|
|
97
|
+
const modulePathStr = modulePath;
|
|
98
|
+
const modules = this._options.testConfig.modules;
|
|
99
|
+
if (modules && modulePathStr in modules) {
|
|
100
|
+
return modules[modulePathStr];
|
|
101
|
+
}
|
|
102
|
+
return require(modulePathStr.startsWith("node:")
|
|
103
|
+
? modulePathStr.slice(5)
|
|
104
|
+
: modulePathStr);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
createCjsRequirer() {
|
|
108
|
+
const requireCache = Object.create(null);
|
|
109
|
+
return (currentDirectory, modulePath, context = {}) => {
|
|
110
|
+
if (modulePath === "@rspack/test-tools") {
|
|
111
|
+
return require("@rspack/test-tools");
|
|
112
|
+
}
|
|
113
|
+
const file = context.file || this.getFile(modulePath, currentDirectory);
|
|
114
|
+
if (!file) {
|
|
115
|
+
return this.requirers.get("miss")(currentDirectory, modulePath);
|
|
116
|
+
}
|
|
117
|
+
if (file.path in requireCache) {
|
|
118
|
+
return requireCache[file.path].exports;
|
|
119
|
+
}
|
|
120
|
+
const m = {
|
|
121
|
+
exports: {}
|
|
122
|
+
};
|
|
123
|
+
requireCache[file.path] = m;
|
|
124
|
+
const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
|
|
125
|
+
if (this._options.testConfig.moduleScope) {
|
|
126
|
+
this._options.testConfig.moduleScope(currentModuleScope);
|
|
127
|
+
}
|
|
128
|
+
if (!this._options.runInNewContext) {
|
|
129
|
+
file.content = `Object.assign(global, _globalAssign);\n ${file.content}`;
|
|
130
|
+
}
|
|
131
|
+
if (file.content.includes("__STATS__") && this._options.stats) {
|
|
132
|
+
currentModuleScope.__STATS__ = this._options.stats();
|
|
133
|
+
}
|
|
134
|
+
const args = Object.keys(currentModuleScope);
|
|
135
|
+
const argValues = args.map(arg => currentModuleScope[arg]);
|
|
136
|
+
const code = `(function(${args.join(", ")}) {
|
|
137
|
+
${file.content}
|
|
138
|
+
})`;
|
|
139
|
+
this.preExecute(code, file);
|
|
140
|
+
const fn = this._options.runInNewContext
|
|
141
|
+
? node_vm_1.default.runInNewContext(code, this.globalContext, file.path)
|
|
142
|
+
: node_vm_1.default.runInThisContext(code, file.path);
|
|
143
|
+
fn.call(this._options.testConfig.nonEsmThis
|
|
144
|
+
? this._options.testConfig.nonEsmThis(modulePath)
|
|
145
|
+
: m.exports, ...argValues);
|
|
146
|
+
this.postExecute(m, file);
|
|
147
|
+
return m.exports;
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.CommonJsRunner = CommonJsRunner;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ECompilerType } from "../../type";
|
|
2
|
+
import { type TRunnerRequirer } from "../type";
|
|
3
|
+
import { CommonJsRunner } from "./cjs";
|
|
4
|
+
export declare class EsmRunner<T extends ECompilerType = ECompilerType.Rspack> extends CommonJsRunner<T> {
|
|
5
|
+
protected createRunner(): void;
|
|
6
|
+
protected createEsmRequirer(): TRunnerRequirer;
|
|
7
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
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.EsmRunner = void 0;
|
|
40
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
41
|
+
const node_url_1 = require("node:url");
|
|
42
|
+
const node_vm_1 = __importStar(require("node:vm"));
|
|
43
|
+
const asModule_1 = __importDefault(require("../../helper/legacy/asModule"));
|
|
44
|
+
const type_1 = require("../type");
|
|
45
|
+
const cjs_1 = require("./cjs");
|
|
46
|
+
class EsmRunner extends cjs_1.CommonJsRunner {
|
|
47
|
+
createRunner() {
|
|
48
|
+
super.createRunner();
|
|
49
|
+
this.requirers.set("cjs", this.getRequire());
|
|
50
|
+
this.requirers.set("esm", this.createEsmRequirer());
|
|
51
|
+
this.requirers.set("entry", (currentDirectory, modulePath, context) => {
|
|
52
|
+
const file = this.getFile(modulePath, currentDirectory);
|
|
53
|
+
if (!file) {
|
|
54
|
+
return this.requirers.get("miss")(currentDirectory, modulePath);
|
|
55
|
+
}
|
|
56
|
+
if (file.path.endsWith(".mjs") &&
|
|
57
|
+
this._options.compilerOptions.experiments?.outputModule) {
|
|
58
|
+
return this.requirers.get("esm")(currentDirectory, modulePath, {
|
|
59
|
+
...context,
|
|
60
|
+
file
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return this.requirers.get("cjs")(currentDirectory, modulePath, {
|
|
64
|
+
...context,
|
|
65
|
+
file
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
createEsmRequirer() {
|
|
70
|
+
const esmContext = node_vm_1.default.createContext(this.baseModuleScope, {
|
|
71
|
+
name: "context for esm"
|
|
72
|
+
});
|
|
73
|
+
const esmCache = new Map();
|
|
74
|
+
const esmIdentifier = this._options.name;
|
|
75
|
+
return (currentDirectory, modulePath, context = {}) => {
|
|
76
|
+
if (!node_vm_1.SourceTextModule) {
|
|
77
|
+
throw new Error("Running this test requires '--experimental-vm-modules'.\nRun with 'node --experimental-vm-modules node_modules/jest-cli/bin/jest'.");
|
|
78
|
+
}
|
|
79
|
+
const _require = this.getRequire();
|
|
80
|
+
const file = context.file || this.getFile(modulePath, currentDirectory);
|
|
81
|
+
if (!file) {
|
|
82
|
+
return this.requirers.get("miss")(currentDirectory, modulePath);
|
|
83
|
+
}
|
|
84
|
+
let esm = esmCache.get(file.path);
|
|
85
|
+
if (!esm) {
|
|
86
|
+
esm = new node_vm_1.SourceTextModule(file.content, {
|
|
87
|
+
identifier: `${esmIdentifier}-${file.path}`,
|
|
88
|
+
// no attribute
|
|
89
|
+
url: `${(0, node_url_1.pathToFileURL)(file.path).href}?${esmIdentifier}`,
|
|
90
|
+
context: esmContext,
|
|
91
|
+
initializeImportMeta: (meta, _) => {
|
|
92
|
+
meta.url = (0, node_url_1.pathToFileURL)(file.path).href;
|
|
93
|
+
},
|
|
94
|
+
importModuleDynamically: async (specifier, module) => {
|
|
95
|
+
const result = await _require(node_path_1.default.dirname(file.path), specifier, {
|
|
96
|
+
esmMode: type_1.EEsmMode.Evaluated
|
|
97
|
+
});
|
|
98
|
+
return await (0, asModule_1.default)(result, module.context);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
esmCache.set(file.path, esm);
|
|
102
|
+
}
|
|
103
|
+
if (context.esmMode === type_1.EEsmMode.Unlinked)
|
|
104
|
+
return esm;
|
|
105
|
+
return (async () => {
|
|
106
|
+
await esm.link(async (specifier, referencingModule) => {
|
|
107
|
+
return await (0, asModule_1.default)(await _require(node_path_1.default.dirname(referencingModule.identifier
|
|
108
|
+
? referencingModule.identifier.slice(esmIdentifier.length + 1)
|
|
109
|
+
: (0, node_url_1.fileURLToPath)(referencingModule.url)), specifier, {
|
|
110
|
+
esmMode: type_1.EEsmMode.Unlinked
|
|
111
|
+
}), referencingModule.context, true);
|
|
112
|
+
});
|
|
113
|
+
if (esm.instantiate)
|
|
114
|
+
esm.instantiate();
|
|
115
|
+
await esm.evaluate();
|
|
116
|
+
if (context.esmMode === type_1.EEsmMode.Evaluated) {
|
|
117
|
+
return esm;
|
|
118
|
+
}
|
|
119
|
+
const ns = esm.namespace;
|
|
120
|
+
return ns.default && ns.default instanceof Promise ? ns.default : ns;
|
|
121
|
+
})();
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.EsmRunner = EsmRunner;
|
|
@@ -0,0 +1,24 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./basic"), exports);
|
|
18
|
+
__exportStar(require("./cjs"), exports);
|
|
19
|
+
__exportStar(require("./esm"), exports);
|
|
20
|
+
__exportStar(require("./normal"), exports);
|
|
21
|
+
__exportStar(require("./watch"), exports);
|
|
22
|
+
__exportStar(require("./web"), exports);
|
|
23
|
+
__exportStar(require("./web/fake"), exports);
|
|
24
|
+
__exportStar(require("./web/jsdom"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ECompilerType } from "../../type";
|
|
2
|
+
import type { IBasicModuleScope, TBasicRunnerFile, TRunnerRequirer } from "../type";
|
|
3
|
+
import { EsmRunner } from "./esm";
|
|
4
|
+
export declare class NormalRunner<T extends ECompilerType = ECompilerType.Rspack> extends EsmRunner<T> {
|
|
5
|
+
protected createBaseModuleScope(): IBasicModuleScope;
|
|
6
|
+
protected createModuleScope(requireFn: TRunnerRequirer, m: {
|
|
7
|
+
exports: unknown;
|
|
8
|
+
}, file: TBasicRunnerFile): IBasicModuleScope;
|
|
9
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NormalRunner = void 0;
|
|
4
|
+
const node_url_1 = require("node:url");
|
|
5
|
+
const esm_1 = require("./esm");
|
|
6
|
+
class NormalRunner extends esm_1.EsmRunner {
|
|
7
|
+
createBaseModuleScope() {
|
|
8
|
+
const baseModuleScope = Object.assign(super.createBaseModuleScope(), {
|
|
9
|
+
process,
|
|
10
|
+
global,
|
|
11
|
+
URL: node_url_1.URL,
|
|
12
|
+
Buffer,
|
|
13
|
+
setImmediate
|
|
14
|
+
});
|
|
15
|
+
return baseModuleScope;
|
|
16
|
+
}
|
|
17
|
+
createModuleScope(requireFn, m, file) {
|
|
18
|
+
const moduleScope = super.createModuleScope(requireFn, m, file);
|
|
19
|
+
delete moduleScope.define;
|
|
20
|
+
return moduleScope;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.NormalRunner = NormalRunner;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ECompilerType } from "../../type";
|
|
2
|
+
import type { IBasicModuleScope, TBasicRunnerFile, TRunnerRequirer } from "../type";
|
|
3
|
+
import type { IBasicRunnerOptions } from "./basic";
|
|
4
|
+
import { FakeDocumentWebRunner } from "./web/fake";
|
|
5
|
+
interface IWatchRunnerOptions<T extends ECompilerType = ECompilerType.Rspack> extends IBasicRunnerOptions<T> {
|
|
6
|
+
stepName: string;
|
|
7
|
+
isWeb: boolean;
|
|
8
|
+
state: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
export declare class WatchRunner<T extends ECompilerType = ECompilerType.Rspack> extends FakeDocumentWebRunner<T> {
|
|
11
|
+
protected _watchOptions: IWatchRunnerOptions<T>;
|
|
12
|
+
constructor(_watchOptions: IWatchRunnerOptions<T>);
|
|
13
|
+
protected createModuleScope(requireFn: TRunnerRequirer, m: any, file: TBasicRunnerFile): IBasicModuleScope;
|
|
14
|
+
run(file: string): Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
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.WatchRunner = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const fake_1 = require("./web/fake");
|
|
9
|
+
class WatchRunner extends fake_1.FakeDocumentWebRunner {
|
|
10
|
+
constructor(_watchOptions) {
|
|
11
|
+
super(_watchOptions);
|
|
12
|
+
this._watchOptions = _watchOptions;
|
|
13
|
+
}
|
|
14
|
+
createModuleScope(requireFn, m, file) {
|
|
15
|
+
const moduleScope = super.createModuleScope(requireFn, m, file);
|
|
16
|
+
moduleScope.__dirname = node_path_1.default.dirname(file.path);
|
|
17
|
+
moduleScope.document = this.globalContext.document;
|
|
18
|
+
moduleScope.STATE = this._watchOptions.state;
|
|
19
|
+
moduleScope.WATCH_STEP = this._watchOptions.stepName;
|
|
20
|
+
moduleScope.__STATS__ = this._options.stats;
|
|
21
|
+
return moduleScope;
|
|
22
|
+
}
|
|
23
|
+
run(file) {
|
|
24
|
+
return super.run(file);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.WatchRunner = WatchRunner;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ECompilerType } from "../../../type";
|
|
2
|
+
import type { TBasicRunnerFile, TRunnerRequirer } from "../../type";
|
|
3
|
+
import type { IBasicRunnerOptions } from "../basic";
|
|
4
|
+
import { CommonJsRunner } from "../cjs";
|
|
5
|
+
export declare class FakeDocumentWebRunner<T extends ECompilerType = ECompilerType.Rspack> extends CommonJsRunner<T> {
|
|
6
|
+
protected _webOptions: IBasicRunnerOptions<T>;
|
|
7
|
+
private document;
|
|
8
|
+
private oldCurrentScript;
|
|
9
|
+
constructor(_webOptions: IBasicRunnerOptions<T>);
|
|
10
|
+
run(file: string): Promise<unknown>;
|
|
11
|
+
protected createGlobalContext(): import("../../type").IBasicGlobalContext;
|
|
12
|
+
protected createModuleScope(requireFn: TRunnerRequirer, m: any, file: TBasicRunnerFile): import("../../type").IBasicModuleScope;
|
|
13
|
+
protected createBaseModuleScope(): import("../../type").IBasicModuleScope;
|
|
14
|
+
protected createJsonRequirer(): TRunnerRequirer;
|
|
15
|
+
protected createRunner(): void;
|
|
16
|
+
protected preExecute(_: string, file: TBasicRunnerFile): void;
|
|
17
|
+
protected postExecute(_: Object, file: TBasicRunnerFile): void;
|
|
18
|
+
}
|