@rspack-debug/test-tools 1.4.11 → 1.6.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/README.md +1 -1
- package/dist/case/builtin.d.ts +3 -0
- package/dist/case/builtin.js +152 -14
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +214 -12
- package/dist/case/common.d.ts +11 -0
- package/dist/case/common.js +249 -0
- package/dist/case/compiler.d.ts +17 -4
- package/dist/case/compiler.js +149 -12
- package/dist/case/config.d.ts +7 -2
- package/dist/case/config.js +106 -18
- package/dist/case/defaults.d.ts +13 -4
- package/dist/case/defaults.js +73 -18
- package/dist/case/diagnostic.d.ts +6 -0
- package/dist/case/diagnostic.js +121 -14
- package/dist/case/error.d.ts +15 -4
- package/dist/case/error.js +137 -12
- package/dist/case/esm-output.d.ts +1 -0
- package/dist/case/esm-output.js +117 -0
- package/dist/case/example.d.ts +1 -0
- package/dist/case/example.js +57 -0
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +72 -9
- package/dist/case/hook.d.ts +36 -4
- package/dist/case/hook.js +209 -20
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +309 -13
- package/dist/case/hot.d.ts +11 -2
- package/dist/case/hot.js +217 -12
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +24 -45
- package/dist/case/index.d.ts +31 -20
- package/dist/case/index.js +50 -34
- package/dist/case/multi-compiler.d.ts +19 -0
- package/dist/case/multi-compiler.js +97 -0
- package/dist/case/{nativeWatcher.js → native-watcher.js} +11 -23
- package/dist/case/normal.d.ts +3 -0
- package/dist/case/normal.js +202 -18
- package/dist/case/runner.d.ts +19 -0
- package/dist/case/runner.js +113 -0
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/serial.js +10 -14
- package/dist/case/stats-api.d.ts +8 -3
- package/dist/case/stats-api.js +69 -10
- package/dist/case/stats-output.d.ts +11 -0
- package/dist/case/stats-output.js +199 -8
- package/dist/case/treeshaking.js +34 -7
- package/dist/case/watch.d.ts +27 -0
- package/dist/case/watch.js +318 -22
- package/dist/compiler.d.ts +16 -16
- package/dist/compiler.js +120 -15
- package/dist/helper/directory.d.ts +1 -1
- package/dist/helper/directory.js +6 -2
- package/dist/helper/disable-iconv-lite-warning.d.ts +1 -0
- package/dist/helper/disable-iconv-lite-warning.js +12 -0
- package/dist/helper/expect/error.js +1 -1
- package/dist/helper/expect/placeholder.js +7 -7
- package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -2
- package/dist/helper/expect/to-match-file-snapshot.js +3 -3
- package/dist/helper/hot-update/loader.d.ts +2 -1
- package/dist/helper/hot-update/loader.js +5 -30
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +14 -13
- package/dist/helper/index.d.ts +2 -1
- package/dist/helper/index.js +2 -1
- package/dist/helper/is.d.ts +2 -0
- package/dist/helper/is.js +15 -0
- package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
- package/dist/helper/legacy/LogTestPlugin.js +35 -0
- package/dist/helper/legacy/asModule.js +0 -2
- package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -1
- package/dist/helper/legacy/checkArrayExpectation.js +8 -8
- package/dist/helper/legacy/createFakeWorker.d.ts +2 -2
- package/dist/helper/legacy/createFakeWorker.js +44 -20
- package/dist/helper/legacy/createLazyTestEnv.d.ts +3 -2
- package/dist/helper/legacy/createLazyTestEnv.js +3 -3
- package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
- package/dist/helper/legacy/deprecationTracking.js +41 -0
- package/dist/helper/legacy/expectSource.d.ts +10 -0
- package/dist/helper/legacy/expectSource.js +23 -0
- package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
- package/dist/helper/legacy/findOutputFiles.js +14 -0
- package/dist/helper/legacy/regexEscape.d.ts +2 -0
- package/dist/helper/legacy/regexEscape.js +5 -0
- package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
- package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
- package/dist/helper/legacy/supportsTextDecoder.js +9 -0
- package/dist/helper/legacy/supportsUsing.d.ts +2 -0
- package/dist/helper/legacy/supportsUsing.js +26 -0
- package/dist/helper/legacy/urlToRelativePath.js +5 -2
- package/dist/helper/read-config-file.d.ts +3 -2
- package/dist/helper/read-config-file.js +12 -2
- package/dist/helper/setup-env.js +26 -4
- package/dist/helper/setup-expect.js +2 -2
- package/dist/helper/setup-wasm.js +2 -2
- package/dist/helper/stringify-config.d.ts +2 -0
- package/dist/helper/stringify-config.js +43 -0
- package/dist/helper/util/checkStats.d.ts +0 -1
- package/dist/helper/util/checkStats.js +0 -18
- package/dist/helper/util/expectWarningFactory.js +2 -4
- package/dist/index.d.ts +0 -4
- package/dist/index.js +1 -4
- package/dist/plugin/index.d.ts +0 -3
- package/dist/plugin/index.js +0 -3
- package/dist/plugin/lazy-compilation-test-plugin.js +4 -4
- package/dist/runner/index.d.ts +2 -9
- package/dist/runner/index.js +2 -9
- package/dist/runner/node/index.d.ts +41 -0
- package/dist/runner/node/index.js +450 -0
- package/dist/runner/web/index.d.ts +30 -0
- package/dist/runner/web/index.js +343 -0
- package/dist/test/context.d.ts +15 -18
- package/dist/test/context.js +52 -57
- package/dist/test/creator.d.ts +20 -19
- package/dist/test/creator.js +69 -57
- package/dist/test/debug.d.ts +15 -0
- package/dist/test/debug.js +205 -0
- package/dist/test/tester.d.ts +1 -0
- package/dist/test/tester.js +44 -6
- package/dist/type.d.ts +94 -64
- package/dist/type.js +8 -12
- package/package.json +22 -61
- package/rstest.d.ts +24 -0
- package/dist/case/diff.d.ts +0 -3
- package/dist/case/diff.js +0 -126
- package/dist/compare/comparator.d.ts +0 -17
- package/dist/compare/comparator.js +0 -52
- package/dist/compare/compare.d.ts +0 -17
- package/dist/compare/compare.js +0 -175
- package/dist/compare/format-code.d.ts +0 -16
- package/dist/compare/format-code.js +0 -239
- package/dist/compare/index.d.ts +0 -5
- package/dist/compare/index.js +0 -21
- package/dist/compare/replace-module-argument.d.ts +0 -1
- package/dist/compare/replace-module-argument.js +0 -8
- package/dist/compare/replace-runtime-module-name.d.ts +0 -1
- package/dist/compare/replace-runtime-module-name.js +0 -71
- package/dist/helper/legacy/FakeDocument.d.ts +0 -54
- package/dist/helper/legacy/FakeDocument.js +0 -278
- package/dist/helper/legacy/createLogger.d.ts +0 -23
- package/dist/helper/legacy/createLogger.js +0 -20
- package/dist/helper/legacy/supportsImportFn.d.ts +0 -1
- package/dist/helper/legacy/supportsImportFn.js +0 -15
- package/dist/helper/legacy/supportsWorker.js +0 -17
- package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
- package/dist/helper/legacy/walkCssTokens.js +0 -761
- package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
- package/dist/helper/legacy/warmup-webpack.js +0 -26
- package/dist/helper/loaders/hot-update.d.ts +0 -1
- package/dist/helper/loaders/hot-update.js +0 -40
- package/dist/helper/plugins/hot-update.d.ts +0 -7
- package/dist/helper/plugins/hot-update.js +0 -40
- package/dist/helper/plugins/index.d.ts +0 -1
- package/dist/helper/plugins/index.js +0 -17
- package/dist/helper/util/currentWatchStep.d.ts +0 -1
- package/dist/helper/util/currentWatchStep.js +0 -2
- package/dist/helper/util/identifier.d.ts +0 -76
- package/dist/helper/util/identifier.js +0 -339
- package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
- package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
- package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/rspack-diff-config-plugin.js +0 -42
- package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/webpack-diff-config-plugin.js +0 -41
- package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
- package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
- package/dist/processor/basic.d.ts +0 -24
- package/dist/processor/basic.js +0 -146
- package/dist/processor/builtin.d.ts +0 -9
- package/dist/processor/builtin.js +0 -171
- package/dist/processor/cache.d.ts +0 -20
- package/dist/processor/cache.js +0 -128
- package/dist/processor/config.d.ts +0 -11
- package/dist/processor/config.js +0 -81
- package/dist/processor/defaults.d.ts +0 -30
- package/dist/processor/defaults.js +0 -72
- package/dist/processor/diagnostic.d.ts +0 -15
- package/dist/processor/diagnostic.js +0 -102
- package/dist/processor/diff.d.ts +0 -30
- package/dist/processor/diff.js +0 -140
- package/dist/processor/error.d.ts +0 -23
- package/dist/processor/error.js +0 -95
- package/dist/processor/hash.d.ts +0 -10
- package/dist/processor/hash.js +0 -63
- package/dist/processor/hook.d.ts +0 -44
- package/dist/processor/hook.js +0 -204
- package/dist/processor/hot-incremental.d.ts +0 -14
- package/dist/processor/hot-incremental.js +0 -43
- package/dist/processor/hot-step.d.ts +0 -18
- package/dist/processor/hot-step.js +0 -304
- package/dist/processor/hot.d.ts +0 -17
- package/dist/processor/hot.js +0 -140
- package/dist/processor/index.d.ts +0 -20
- package/dist/processor/index.js +0 -36
- package/dist/processor/multi.d.ts +0 -17
- package/dist/processor/multi.js +0 -73
- package/dist/processor/normal.d.ts +0 -12
- package/dist/processor/normal.js +0 -150
- package/dist/processor/simple.d.ts +0 -23
- package/dist/processor/simple.js +0 -49
- package/dist/processor/snapshot.d.ts +0 -12
- package/dist/processor/snapshot.js +0 -66
- package/dist/processor/stats-api.d.ts +0 -18
- package/dist/processor/stats-api.js +0 -48
- package/dist/processor/stats.d.ts +0 -18
- package/dist/processor/stats.js +0 -206
- package/dist/processor/treeshaking.d.ts +0 -10
- package/dist/processor/treeshaking.js +0 -33
- package/dist/processor/watch.d.ts +0 -30
- package/dist/processor/watch.js +0 -241
- package/dist/reporter/diff-html.d.ts +0 -15
- package/dist/reporter/diff-html.js +0 -69
- package/dist/reporter/diff-stats.d.ts +0 -24
- package/dist/reporter/diff-stats.js +0 -131
- package/dist/reporter/index.d.ts +0 -2
- package/dist/reporter/index.js +0 -18
- package/dist/runner/basic.d.ts +0 -10
- package/dist/runner/basic.js +0 -63
- package/dist/runner/cache.d.ts +0 -5
- package/dist/runner/cache.js +0 -90
- package/dist/runner/hot-step.d.ts +0 -5
- package/dist/runner/hot-step.js +0 -87
- package/dist/runner/hot.d.ts +0 -5
- package/dist/runner/hot.js +0 -83
- package/dist/runner/multiple.d.ts +0 -11
- package/dist/runner/multiple.js +0 -38
- package/dist/runner/normal.d.ts +0 -5
- package/dist/runner/normal.js +0 -20
- package/dist/runner/runner/basic.d.ts +0 -30
- package/dist/runner/runner/basic.js +0 -107
- package/dist/runner/runner/cjs.d.ts +0 -14
- package/dist/runner/runner/cjs.js +0 -151
- package/dist/runner/runner/esm.d.ts +0 -7
- package/dist/runner/runner/esm.js +0 -125
- package/dist/runner/runner/index.d.ts +0 -8
- package/dist/runner/runner/index.js +0 -24
- package/dist/runner/runner/normal.d.ts +0 -9
- package/dist/runner/runner/normal.js +0 -23
- package/dist/runner/runner/watch.d.ts +0 -16
- package/dist/runner/runner/watch.js +0 -27
- package/dist/runner/runner/web/fake.d.ts +0 -18
- package/dist/runner/runner/web/fake.js +0 -143
- package/dist/runner/runner/web/jsdom.d.ts +0 -26
- package/dist/runner/runner/web/jsdom.js +0 -219
- package/dist/runner/runner/web.d.ts +0 -15
- package/dist/runner/runner/web.js +0 -32
- package/dist/runner/type.d.ts +0 -42
- package/dist/runner/type.js +0 -9
- package/dist/runner/watch.d.ts +0 -7
- package/dist/runner/watch.js +0 -60
- package/dist/test/simple.d.ts +0 -5
- package/dist/test/simple.js +0 -43
- package/jest.d.ts +0 -25
- package/template/diff.bundle.css +0 -1
- package/template/diff.bundle.js +0 -144
- package/template/diff.html +0 -14
- package/template/editor.worker.js +0 -1
- /package/dist/case/{nativeWatcher.d.ts → native-watcher.d.ts} +0 -0
- /package/dist/helper/legacy/{supportsWorker.d.ts → supportDefaultAssignment.d.ts} +0 -0
|
@@ -1,107 +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.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;
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,151 +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.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;
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,125 +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.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;
|
|
@@ -1,24 +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 __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);
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
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;
|
|
@@ -1,16 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,27 +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.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;
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
}
|