@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
|
@@ -0,0 +1,450 @@
|
|
|
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.NodeRunner = 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 asModule_1 = __importDefault(require("../../helper/legacy/asModule"));
|
|
45
|
+
const createFakeWorker_1 = __importDefault(require("../../helper/legacy/createFakeWorker"));
|
|
46
|
+
const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
|
|
47
|
+
const type_1 = require("../../type");
|
|
48
|
+
const isRelativePath = (p) => /^\.\.?\//.test(p);
|
|
49
|
+
const getSubPath = (p) => {
|
|
50
|
+
const lastSlash = p.lastIndexOf("/");
|
|
51
|
+
let firstSlash = p.indexOf("/");
|
|
52
|
+
if (lastSlash !== -1 && firstSlash !== lastSlash) {
|
|
53
|
+
if (firstSlash !== -1) {
|
|
54
|
+
let next = p.indexOf("/", firstSlash + 1);
|
|
55
|
+
let dir = p.slice(firstSlash + 1, next);
|
|
56
|
+
while (dir === ".") {
|
|
57
|
+
firstSlash = next;
|
|
58
|
+
next = p.indexOf("/", firstSlash + 1);
|
|
59
|
+
dir = p.slice(firstSlash + 1, next);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return p.slice(firstSlash + 1, lastSlash + 1);
|
|
63
|
+
}
|
|
64
|
+
return "";
|
|
65
|
+
};
|
|
66
|
+
const cached = new Map();
|
|
67
|
+
class NodeRunner {
|
|
68
|
+
constructor(_options) {
|
|
69
|
+
this._options = _options;
|
|
70
|
+
this.requireCache = Object.create(null);
|
|
71
|
+
this.globalContext = null;
|
|
72
|
+
this.baseModuleScope = null;
|
|
73
|
+
this.requirers = new Map();
|
|
74
|
+
}
|
|
75
|
+
log(message) {
|
|
76
|
+
this._options.logs?.push(`[NodeRunner] ${message}`);
|
|
77
|
+
}
|
|
78
|
+
run(file) {
|
|
79
|
+
if (!this.globalContext) {
|
|
80
|
+
this.globalContext = this.createGlobalContext();
|
|
81
|
+
}
|
|
82
|
+
this.baseModuleScope = this.createBaseModuleScope();
|
|
83
|
+
if (typeof this._options.testConfig.moduleScope === "function") {
|
|
84
|
+
this._options.testConfig.moduleScope(this.baseModuleScope, this._options.stats, this._options.compilerOptions);
|
|
85
|
+
}
|
|
86
|
+
this.createRunner();
|
|
87
|
+
const res = this.getRequire()(node_path_1.default.isAbsolute(file) ? node_path_1.default.dirname(file) : this._options.dist, file.startsWith("./") ||
|
|
88
|
+
file.startsWith("https://test.cases/") ||
|
|
89
|
+
node_path_1.default.isAbsolute(file)
|
|
90
|
+
? file
|
|
91
|
+
: `./${file}`);
|
|
92
|
+
if (typeof res === "object" && "then" in res) {
|
|
93
|
+
return res;
|
|
94
|
+
}
|
|
95
|
+
return Promise.resolve(res);
|
|
96
|
+
}
|
|
97
|
+
getRequire() {
|
|
98
|
+
const entryRequire = this.requirers.get("entry");
|
|
99
|
+
const runner = this;
|
|
100
|
+
return function (currentDirectory, modulePath, context = {}) {
|
|
101
|
+
const from = this?.from;
|
|
102
|
+
if (from) {
|
|
103
|
+
runner.log(`require: ${modulePath} from ${from}`);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
runner.log(`require: ${modulePath}`);
|
|
107
|
+
}
|
|
108
|
+
const p = Array.isArray(modulePath)
|
|
109
|
+
? modulePath
|
|
110
|
+
: modulePath.split("?")[0];
|
|
111
|
+
return entryRequire(currentDirectory, p, context);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
getGlobal(name) {
|
|
115
|
+
return (this.globalContext || {})[name];
|
|
116
|
+
}
|
|
117
|
+
createGlobalContext() {
|
|
118
|
+
return {
|
|
119
|
+
console: {
|
|
120
|
+
log: (...args) => {
|
|
121
|
+
if (printLogger) {
|
|
122
|
+
console.log(...args);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
warn: (...args) => {
|
|
126
|
+
if (printLogger) {
|
|
127
|
+
console.warn(...args);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
error: (...args) => {
|
|
131
|
+
console.error(...args);
|
|
132
|
+
},
|
|
133
|
+
info: (...args) => {
|
|
134
|
+
if (printLogger) {
|
|
135
|
+
console.info(...args);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
debug: (...args) => {
|
|
139
|
+
if (printLogger) {
|
|
140
|
+
console.info(...args);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
trace: (...args) => {
|
|
144
|
+
if (printLogger) {
|
|
145
|
+
console.info(...args);
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
assert: (...args) => {
|
|
149
|
+
console.assert(...args);
|
|
150
|
+
},
|
|
151
|
+
clear: () => {
|
|
152
|
+
console.clear();
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
setTimeout: ((cb, ms, ...args) => {
|
|
156
|
+
const timeout = setTimeout(cb, ms, ...args);
|
|
157
|
+
timeout.unref();
|
|
158
|
+
return timeout;
|
|
159
|
+
}),
|
|
160
|
+
clearTimeout: clearTimeout
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
createBaseModuleScope() {
|
|
164
|
+
const baseModuleScope = {
|
|
165
|
+
console: this.globalContext.console,
|
|
166
|
+
setTimeout: this.globalContext.setTimeout,
|
|
167
|
+
clearTimeout: this.globalContext.clearTimeout,
|
|
168
|
+
nsObj: (m) => {
|
|
169
|
+
Object.defineProperty(m, Symbol.toStringTag, {
|
|
170
|
+
value: "Module"
|
|
171
|
+
});
|
|
172
|
+
return m;
|
|
173
|
+
},
|
|
174
|
+
process,
|
|
175
|
+
URL,
|
|
176
|
+
Blob,
|
|
177
|
+
Symbol,
|
|
178
|
+
Buffer,
|
|
179
|
+
setImmediate,
|
|
180
|
+
self: this.globalContext,
|
|
181
|
+
__TEST_PATH__: __TEST_PATH__,
|
|
182
|
+
__MODE__: this._options.compilerOptions.mode,
|
|
183
|
+
__SNAPSHOT__: node_path_1.default.join(this._options.source, "__snapshot__"),
|
|
184
|
+
Worker: (0, createFakeWorker_1.default)(this._options.env, {
|
|
185
|
+
outputDirectory: this._options.dist
|
|
186
|
+
}),
|
|
187
|
+
...this._options.env
|
|
188
|
+
};
|
|
189
|
+
return baseModuleScope;
|
|
190
|
+
}
|
|
191
|
+
createModuleScope(requireFn, m, file) {
|
|
192
|
+
const requirer = requireFn.bind({
|
|
193
|
+
from: file.path,
|
|
194
|
+
module: m
|
|
195
|
+
}, node_path_1.default.dirname(file.path));
|
|
196
|
+
requirer.webpackTestSuiteRequire = true;
|
|
197
|
+
return {
|
|
198
|
+
...this.baseModuleScope,
|
|
199
|
+
require: requirer,
|
|
200
|
+
module: m,
|
|
201
|
+
exports: m.exports,
|
|
202
|
+
__dirname: node_path_1.default.dirname(file.path),
|
|
203
|
+
__filename: file.path,
|
|
204
|
+
_globalAssign: {
|
|
205
|
+
expect: this._options.env.expect
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
getFile(modulePath, currentDirectory) {
|
|
210
|
+
const cacheKey = `${currentDirectory}|${modulePath}`;
|
|
211
|
+
if (this._options.cachable && cached.has(cacheKey)) {
|
|
212
|
+
return cached.get(cacheKey);
|
|
213
|
+
}
|
|
214
|
+
let res = null;
|
|
215
|
+
if (Array.isArray(modulePath)) {
|
|
216
|
+
res = {
|
|
217
|
+
path: node_path_1.default.join(currentDirectory, ".array-require.js"),
|
|
218
|
+
content: `module.exports = (${modulePath
|
|
219
|
+
.map(arg => {
|
|
220
|
+
return `require(${JSON.stringify(`./${arg}`)})`;
|
|
221
|
+
})
|
|
222
|
+
.join(", ")});`,
|
|
223
|
+
subPath: ""
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
else if (modulePath.startsWith("https://test.cases/")) {
|
|
227
|
+
const relativePath = (0, urlToRelativePath_1.default)(modulePath);
|
|
228
|
+
const absPath = node_path_1.default.join(currentDirectory, relativePath);
|
|
229
|
+
res = {
|
|
230
|
+
path: absPath,
|
|
231
|
+
content: node_fs_1.default.readFileSync(absPath, "utf-8"),
|
|
232
|
+
subPath: ""
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
else if (isRelativePath(modulePath)) {
|
|
236
|
+
const p = node_path_1.default.join(currentDirectory, modulePath);
|
|
237
|
+
res = {
|
|
238
|
+
path: p,
|
|
239
|
+
content: node_fs_1.default.readFileSync(p, "utf-8"),
|
|
240
|
+
subPath: getSubPath(modulePath)
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
else if (node_path_1.default.isAbsolute(modulePath)) {
|
|
244
|
+
res = {
|
|
245
|
+
path: modulePath,
|
|
246
|
+
content: node_fs_1.default.readFileSync(modulePath, "utf-8"),
|
|
247
|
+
subPath: "absolute_path"
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if (this._options.cachable && res) {
|
|
251
|
+
cached.set(cacheKey, res);
|
|
252
|
+
}
|
|
253
|
+
return res;
|
|
254
|
+
}
|
|
255
|
+
preExecute(code, file) { }
|
|
256
|
+
postExecute(m, file) { }
|
|
257
|
+
createRunner() {
|
|
258
|
+
this.requirers.set("cjs", this.createCjsRequirer());
|
|
259
|
+
this.requirers.set("esm", this.createEsmRequirer());
|
|
260
|
+
this.requirers.set("miss", this.createMissRequirer());
|
|
261
|
+
this.requirers.set("json", this.createJsonRequirer());
|
|
262
|
+
this.requirers.set("entry", (currentDirectory, modulePath, context) => {
|
|
263
|
+
const file = this.getFile(modulePath, currentDirectory);
|
|
264
|
+
this.log(`entry: ${modulePath} -> ${file?.path}`);
|
|
265
|
+
if (!file) {
|
|
266
|
+
return this.requirers.get("miss")(currentDirectory, modulePath);
|
|
267
|
+
}
|
|
268
|
+
if (file.path.endsWith(".json")) {
|
|
269
|
+
return this.requirers.get("json")(currentDirectory, modulePath, {
|
|
270
|
+
...context,
|
|
271
|
+
file
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
if (file.path.endsWith(".mjs") &&
|
|
275
|
+
this._options.compilerOptions.experiments?.outputModule) {
|
|
276
|
+
return this.requirers.get("esm")(currentDirectory, modulePath, {
|
|
277
|
+
...context,
|
|
278
|
+
file
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
return this.requirers.get("cjs")(currentDirectory, modulePath, {
|
|
282
|
+
...context,
|
|
283
|
+
file
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
createMissRequirer() {
|
|
288
|
+
return (currentDirectory, modulePath, context = {}) => {
|
|
289
|
+
this.log(`missing: ${modulePath}`);
|
|
290
|
+
const modulePathStr = modulePath;
|
|
291
|
+
const modules = this._options.testConfig.modules;
|
|
292
|
+
if (modules && modulePathStr in modules) {
|
|
293
|
+
this.log(`mock module: ${modulePathStr}`);
|
|
294
|
+
return modules[modulePathStr];
|
|
295
|
+
}
|
|
296
|
+
this.log(`native require: ${modulePathStr}`);
|
|
297
|
+
return require(modulePathStr.startsWith("node:")
|
|
298
|
+
? modulePathStr.slice(5)
|
|
299
|
+
: modulePathStr);
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
createJsonRequirer() {
|
|
303
|
+
return (currentDirectory, modulePath, context = {}) => {
|
|
304
|
+
if (Array.isArray(modulePath)) {
|
|
305
|
+
throw new Error("Array module path is not supported in hot cases");
|
|
306
|
+
}
|
|
307
|
+
const file = context.file || this.getFile(modulePath, currentDirectory);
|
|
308
|
+
this.log(`json: ${modulePath} -> ${file?.path}`);
|
|
309
|
+
if (!file) {
|
|
310
|
+
return this.requirers.get("miss")(currentDirectory, modulePath);
|
|
311
|
+
}
|
|
312
|
+
return JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(this._options.dist, modulePath), "utf-8"));
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
createCjsRequirer() {
|
|
316
|
+
return (currentDirectory, modulePath, context = {}) => {
|
|
317
|
+
if (modulePath === "@rspack/test-tools") {
|
|
318
|
+
return require("@rspack/test-tools");
|
|
319
|
+
}
|
|
320
|
+
const file = context.file || this.getFile(modulePath, currentDirectory);
|
|
321
|
+
this.log(`cjs: ${modulePath} -> ${file?.path}`);
|
|
322
|
+
if (!file) {
|
|
323
|
+
return this.requirers.get("miss")(currentDirectory, modulePath);
|
|
324
|
+
}
|
|
325
|
+
if (file.path in this.requireCache) {
|
|
326
|
+
this.log(`cjs cache hit: ${file.path}`);
|
|
327
|
+
return this.requireCache[file.path].exports;
|
|
328
|
+
}
|
|
329
|
+
const m = {
|
|
330
|
+
exports: {},
|
|
331
|
+
webpackTestSuiteModule: true
|
|
332
|
+
};
|
|
333
|
+
this.requireCache[file.path] = m;
|
|
334
|
+
if (!this._options.runInNewContext) {
|
|
335
|
+
file.content = `Object.assign(global, _globalAssign);${file.content}`;
|
|
336
|
+
}
|
|
337
|
+
const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
|
|
338
|
+
if (this._options.testConfig.moduleScope) {
|
|
339
|
+
this._options.testConfig.moduleScope(currentModuleScope, this._options.stats, this._options.compilerOptions);
|
|
340
|
+
}
|
|
341
|
+
if (file.content.includes("__STATS__") && this._options.stats) {
|
|
342
|
+
currentModuleScope.__STATS__ = this._options.stats();
|
|
343
|
+
}
|
|
344
|
+
if (file.content.includes("__STATS_I__")) {
|
|
345
|
+
const statsIndex = this._options.stats?.()?.__index__;
|
|
346
|
+
if (typeof statsIndex === "number") {
|
|
347
|
+
currentModuleScope.__STATS_I__ = statsIndex;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
const args = Object.keys(currentModuleScope);
|
|
351
|
+
const argValues = args.map(arg => currentModuleScope[arg]);
|
|
352
|
+
const code = `(function(${args.join(", ")}) {
|
|
353
|
+
${file.content}
|
|
354
|
+
})`;
|
|
355
|
+
this.preExecute(code, file);
|
|
356
|
+
this.log(`run mode: ${this._options.runInNewContext ? "new context" : "this context"}`);
|
|
357
|
+
try {
|
|
358
|
+
const fn = this._options.runInNewContext
|
|
359
|
+
? node_vm_1.default.runInNewContext(code, this.globalContext, {
|
|
360
|
+
filename: file.path,
|
|
361
|
+
lineOffset: -1
|
|
362
|
+
})
|
|
363
|
+
: node_vm_1.default.runInThisContext(code, {
|
|
364
|
+
filename: file.path,
|
|
365
|
+
lineOffset: -1
|
|
366
|
+
});
|
|
367
|
+
fn.call(this._options.testConfig.nonEsmThis
|
|
368
|
+
? this._options.testConfig.nonEsmThis(modulePath)
|
|
369
|
+
: m.exports, ...argValues);
|
|
370
|
+
}
|
|
371
|
+
catch (e) {
|
|
372
|
+
this._options.errors?.push(e);
|
|
373
|
+
throw e;
|
|
374
|
+
}
|
|
375
|
+
this.postExecute(m, file);
|
|
376
|
+
this.log(`end cjs: ${modulePath}`);
|
|
377
|
+
return m.exports;
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
createEsmRequirer() {
|
|
381
|
+
const esmContext = node_vm_1.default.createContext(this.baseModuleScope, {
|
|
382
|
+
name: "context for esm"
|
|
383
|
+
});
|
|
384
|
+
const esmCache = new Map();
|
|
385
|
+
const esmIdentifier = this._options.name;
|
|
386
|
+
return (currentDirectory, modulePath, context = {}) => {
|
|
387
|
+
if (!node_vm_1.SourceTextModule) {
|
|
388
|
+
throw new Error("Running this test requires '--experimental-vm-modules'.\nRun with 'node --experimental-vm-modules node_modules/@rstest/core/bin/rstest'.");
|
|
389
|
+
}
|
|
390
|
+
const _require = this.getRequire();
|
|
391
|
+
const file = context.file || this.getFile(modulePath, currentDirectory);
|
|
392
|
+
this.log(`esm: ${modulePath} -> ${file?.path}`);
|
|
393
|
+
if (!file) {
|
|
394
|
+
return this.requirers.get("miss")(currentDirectory, modulePath);
|
|
395
|
+
}
|
|
396
|
+
if (file.content.includes("__STATS__")) {
|
|
397
|
+
esmContext.__STATS__ = this._options.stats?.();
|
|
398
|
+
}
|
|
399
|
+
if (file.content.includes("__STATS_I__")) {
|
|
400
|
+
const statsIndex = this._options.stats?.()?.__index__;
|
|
401
|
+
if (typeof statsIndex === "number") {
|
|
402
|
+
esmContext.__STATS_I__ = statsIndex;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
let esm = esmCache.get(file.path);
|
|
406
|
+
if (!esm) {
|
|
407
|
+
esm = new node_vm_1.SourceTextModule(file.content, {
|
|
408
|
+
identifier: `${esmIdentifier}-${file.path}`,
|
|
409
|
+
// no attribute
|
|
410
|
+
url: `${(0, node_url_1.pathToFileURL)(file.path).href}?${esmIdentifier}`,
|
|
411
|
+
context: esmContext,
|
|
412
|
+
initializeImportMeta: (meta, _) => {
|
|
413
|
+
meta.url = (0, node_url_1.pathToFileURL)(file.path).href;
|
|
414
|
+
meta.dirname = node_path_1.default.dirname(file.path);
|
|
415
|
+
meta.filename = file.path;
|
|
416
|
+
},
|
|
417
|
+
importModuleDynamically: async (specifier, module) => {
|
|
418
|
+
this.log(`import: ${specifier} from ${file?.path}`);
|
|
419
|
+
const result = await _require(node_path_1.default.dirname(file.path), specifier, {
|
|
420
|
+
esmMode: type_1.EEsmMode.Evaluated
|
|
421
|
+
});
|
|
422
|
+
return await (0, asModule_1.default)(result, module.context);
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
esmCache.set(file.path, esm);
|
|
426
|
+
}
|
|
427
|
+
if (context.esmMode === type_1.EEsmMode.Unlinked)
|
|
428
|
+
return esm;
|
|
429
|
+
return (async () => {
|
|
430
|
+
if (esm.status === "unlinked") {
|
|
431
|
+
await esm.link(async (specifier, referencingModule) => {
|
|
432
|
+
return await (0, asModule_1.default)(await _require(node_path_1.default.dirname(referencingModule.identifier
|
|
433
|
+
? referencingModule.identifier.slice(esmIdentifier.length + 1)
|
|
434
|
+
: (0, node_url_1.fileURLToPath)(referencingModule.url)), specifier, {
|
|
435
|
+
esmMode: type_1.EEsmMode.Unlinked
|
|
436
|
+
}), referencingModule.context, true);
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
await esm.evaluate();
|
|
440
|
+
if (context.esmMode === type_1.EEsmMode.Evaluated) {
|
|
441
|
+
return esm;
|
|
442
|
+
}
|
|
443
|
+
const ns = esm.namespace;
|
|
444
|
+
this.log(`end esm: ${modulePath}`);
|
|
445
|
+
return ns.default && ns.default instanceof Promise ? ns.default : ns;
|
|
446
|
+
})();
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
exports.NodeRunner = NodeRunner;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { TRunnerFile, TRunnerRequirer } from "../../type";
|
|
2
|
+
import { type INodeRunnerOptions, NodeRunner } from "../node";
|
|
3
|
+
export interface IWebRunnerOptions extends INodeRunnerOptions {
|
|
4
|
+
location: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class WebRunner extends NodeRunner {
|
|
7
|
+
protected _webOptions: IWebRunnerOptions;
|
|
8
|
+
private dom;
|
|
9
|
+
constructor(_webOptions: IWebRunnerOptions);
|
|
10
|
+
run(file: string): Promise<unknown>;
|
|
11
|
+
getGlobal(name: string): unknown;
|
|
12
|
+
protected log(message: string): void;
|
|
13
|
+
protected createResourceLoader(): {
|
|
14
|
+
fetch(url: string, options: {
|
|
15
|
+
element: HTMLScriptElement;
|
|
16
|
+
}): any;
|
|
17
|
+
};
|
|
18
|
+
private urlToPath;
|
|
19
|
+
protected createBaseModuleScope(): import("../../type").IModuleScope;
|
|
20
|
+
protected getModuleContent(file: TRunnerFile): [
|
|
21
|
+
{
|
|
22
|
+
exports: Record<string, unknown>;
|
|
23
|
+
},
|
|
24
|
+
string,
|
|
25
|
+
number
|
|
26
|
+
];
|
|
27
|
+
protected createJSDOMRequirer(): TRunnerRequirer;
|
|
28
|
+
protected createRunner(): void;
|
|
29
|
+
}
|
|
30
|
+
export declare const createLocatedError: (collectedErrors: Error[], offset: number) => (e: Error, file: TRunnerFile) => Error;
|