@rspack/test-tools 1.7.0-beta.1 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/case/builtin.d.ts +2 -2
- package/dist/case/builtin.js +58 -58
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +34 -34
- package/dist/case/common.d.ts +2 -2
- package/dist/case/common.js +45 -45
- package/dist/case/compiler.d.ts +3 -3
- package/dist/case/compiler.js +21 -21
- package/dist/case/config.d.ts +3 -3
- package/dist/case/config.js +19 -19
- package/dist/case/defaults.d.ts +2 -2
- package/dist/case/defaults.js +10 -10
- package/dist/case/diagnostic.js +29 -29
- package/dist/case/error.d.ts +2 -2
- package/dist/case/error.js +21 -21
- package/dist/case/esm-output.js +28 -28
- package/dist/case/example.js +7 -7
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +16 -16
- package/dist/case/hook.d.ts +3 -3
- package/dist/case/hook.js +42 -42
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +46 -46
- package/dist/case/hot.d.ts +5 -5
- package/dist/case/hot.js +43 -43
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +9 -9
- package/dist/case/index.d.ts +31 -31
- package/dist/case/multi-compiler.d.ts +3 -3
- package/dist/case/multi-compiler.js +15 -15
- package/dist/case/native-watcher.js +6 -6
- package/dist/case/normal.js +46 -46
- package/dist/case/runner.d.ts +2 -2
- package/dist/case/runner.js +22 -15
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/serial.js +4 -4
- package/dist/case/stats-api.d.ts +2 -2
- package/dist/case/stats-api.js +7 -7
- package/dist/case/stats-output.d.ts +2 -2
- package/dist/case/stats-output.js +45 -45
- package/dist/case/treeshaking.js +6 -6
- package/dist/case/watch.d.ts +1 -1
- package/dist/case/watch.js +59 -59
- package/dist/compiler.d.ts +3 -3
- package/dist/compiler.js +31 -31
- package/dist/helper/directory.d.ts +1 -1
- package/dist/helper/directory.js +15 -15
- package/dist/helper/disable-iconv-lite-warning.js +3 -3
- package/dist/helper/expect/diff.js +8 -8
- package/dist/helper/expect/error.js +9 -9
- package/dist/helper/expect/placeholder.js +9 -9
- package/dist/helper/expect/rspack.js +5 -5
- package/dist/helper/expect/to-be-typeof.js +2 -2
- package/dist/helper/expect/to-end-with.js +3 -3
- package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -1
- package/dist/helper/expect/to-match-file-snapshot.js +23 -23
- package/dist/helper/hot-update/index.d.ts +1 -1
- package/dist/helper/hot-update/loader.js +1 -1
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +15 -15
- package/dist/helper/index.d.ts +8 -8
- package/dist/helper/is.js +2 -2
- package/dist/helper/legacy/EventSourceForNode.js +8 -8
- package/dist/helper/legacy/LogTestPlugin.js +18 -18
- package/dist/helper/legacy/asModule.js +6 -6
- package/dist/helper/legacy/captureStdio.js +6 -6
- package/dist/helper/legacy/checkArrayExpectation.js +24 -24
- package/dist/helper/legacy/copyDiff.js +5 -5
- package/dist/helper/legacy/createFakeWorker.js +13 -13
- package/dist/helper/legacy/createLazyTestEnv.js +12 -12
- package/dist/helper/legacy/currentScript.js +1 -1
- package/dist/helper/legacy/deprecationTracking.js +5 -5
- package/dist/helper/legacy/expectSource.js +5 -5
- package/dist/helper/legacy/fakeSystem.js +14 -14
- package/dist/helper/legacy/findOutputFiles.js +4 -4
- package/dist/helper/legacy/parseResource.js +4 -4
- package/dist/helper/legacy/regexEscape.js +2 -2
- package/dist/helper/legacy/supportDefaultAssignment.js +2 -2
- package/dist/helper/legacy/supportsTextDecoder.js +2 -2
- package/dist/helper/legacy/supportsUsing.js +1 -1
- package/dist/helper/legacy/urlToRelativePath.js +3 -3
- package/dist/helper/parse-modules.js +13 -13
- package/dist/helper/read-config-file.d.ts +2 -2
- package/dist/helper/read-config-file.js +3 -3
- package/dist/helper/serializers.d.ts +1 -1
- package/dist/helper/serializers.js +11 -11
- package/dist/helper/setup-env.js +17 -17
- package/dist/helper/setup-expect.js +1 -1
- package/dist/helper/setup-wasm.js +4 -4
- package/dist/helper/stringify-config.d.ts +1 -1
- package/dist/helper/stringify-config.js +3 -3
- package/dist/helper/update-snapshot.js +1 -1
- package/dist/helper/util/checkSourceMap.js +16 -17
- package/dist/helper/util/checkStats.js +3 -3
- package/dist/helper/util/expectWarningFactory.js +2 -2
- package/dist/helper/util/filterUtil.js +9 -9
- package/dist/index.d.ts +8 -8
- package/dist/index.js +1 -1
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/lazy-compilation-test-plugin.d.ts +1 -1
- package/dist/plugin/lazy-compilation-test-plugin.js +13 -13
- package/dist/runner/index.d.ts +2 -2
- package/dist/runner/node/index.d.ts +2 -2
- package/dist/runner/node/index.js +75 -74
- package/dist/runner/web/index.d.ts +2 -2
- package/dist/runner/web/index.js +45 -45
- package/dist/test/context.d.ts +2 -2
- package/dist/test/context.js +4 -4
- package/dist/test/creator.d.ts +1 -1
- package/dist/test/creator.js +28 -28
- package/dist/test/debug.d.ts +1 -1
- package/dist/test/debug.js +31 -31
- package/dist/test/tester.d.ts +1 -1
- package/dist/test/tester.js +11 -11
- package/dist/type.d.ts +3 -3
- package/package.json +3 -3
- package/rstest.d.ts +12 -12
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
const FilteredStatus = {
|
|
4
|
-
TODO:
|
|
5
|
-
PARTIAL_PASS:
|
|
6
|
-
FAILED:
|
|
7
|
-
NO_PLAN:
|
|
4
|
+
TODO: 'TODO',
|
|
5
|
+
PARTIAL_PASS: 'PARTIAL_PASS',
|
|
6
|
+
FAILED: 'FAILED',
|
|
7
|
+
NO_PLAN: 'NO_PLAN',
|
|
8
8
|
};
|
|
9
9
|
function validateFilteredStatus(status) {
|
|
10
10
|
return Object.values(FilteredStatus).includes(status);
|
|
11
11
|
}
|
|
12
12
|
function normalizeFilterFlag(flag, testName) {
|
|
13
13
|
if (flag === false) {
|
|
14
|
-
return { status: FilteredStatus.TODO, reason:
|
|
14
|
+
return { status: FilteredStatus.TODO, reason: 'TODO' };
|
|
15
15
|
}
|
|
16
16
|
if (flag === -1) {
|
|
17
|
-
return { status: FilteredStatus.NO_PLAN, reason:
|
|
17
|
+
return { status: FilteredStatus.NO_PLAN, reason: 'No plan' };
|
|
18
18
|
}
|
|
19
|
-
if (typeof flag ===
|
|
19
|
+
if (typeof flag === 'string') {
|
|
20
20
|
return { status: FilteredStatus.FAILED, reason: flag };
|
|
21
21
|
}
|
|
22
22
|
if (Array.isArray(flag)) {
|
|
23
|
-
const [status, reason =
|
|
23
|
+
const [status, reason = 'empty'] = flag;
|
|
24
24
|
if (validateFilteredStatus(status)) {
|
|
25
25
|
return { status, reason };
|
|
26
26
|
}
|
|
@@ -46,5 +46,5 @@ function normalizeFilteredTestName(flag, testName) {
|
|
|
46
46
|
module.exports = {
|
|
47
47
|
FilteredStatus,
|
|
48
48
|
decodeFilteredTest,
|
|
49
|
-
normalizeFilteredTestName
|
|
49
|
+
normalizeFilteredTestName,
|
|
50
50
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
1
|
+
export * from './case';
|
|
2
|
+
export * from './helper';
|
|
3
|
+
export * from './plugin';
|
|
4
|
+
export * from './runner';
|
|
5
|
+
export * from './test/context';
|
|
6
|
+
export * from './test/creator';
|
|
7
|
+
export * from './test/tester';
|
|
8
|
+
export * from './type';
|
package/dist/index.js
CHANGED
|
@@ -22,4 +22,4 @@ __exportStar(require("./test/context"), exports);
|
|
|
22
22
|
__exportStar(require("./test/creator"), exports);
|
|
23
23
|
__exportStar(require("./test/tester"), exports);
|
|
24
24
|
__exportStar(require("./type"), exports);
|
|
25
|
-
require(
|
|
25
|
+
require('./helper/disable-iconv-lite-warning').disableIconvLiteWarning();
|
package/dist/plugin/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './lazy-compilation-test-plugin';
|
|
@@ -9,14 +9,14 @@ class LazyCompilationTestPlugin {
|
|
|
9
9
|
const server = (0, node_http_1.createServer)();
|
|
10
10
|
const sockets = new Set();
|
|
11
11
|
const promise = new Promise((resolve, reject) => {
|
|
12
|
-
server.on(
|
|
12
|
+
server.on('listening', () => {
|
|
13
13
|
const addr = server.address();
|
|
14
|
-
if (typeof addr ===
|
|
15
|
-
throw new Error(
|
|
16
|
-
const protocol =
|
|
17
|
-
const urlBase = addr.address ===
|
|
14
|
+
if (typeof addr === 'string')
|
|
15
|
+
throw new Error('addr must not be a string');
|
|
16
|
+
const protocol = 'http';
|
|
17
|
+
const urlBase = addr.address === '::' || addr.address === '0.0.0.0'
|
|
18
18
|
? `${protocol}://localhost:${addr.port}`
|
|
19
|
-
: addr.family ===
|
|
19
|
+
: addr.family === 'IPv6'
|
|
20
20
|
? `${protocol}://[${addr.address}]:${addr.port}`
|
|
21
21
|
: `${protocol}://${addr.address}:${addr.port}`;
|
|
22
22
|
if (compiler instanceof core_1.MultiCompiler) {
|
|
@@ -32,22 +32,22 @@ class LazyCompilationTestPlugin {
|
|
|
32
32
|
middleware = (0, core_1.lazyCompilationMiddleware)(compiler);
|
|
33
33
|
resolve(null);
|
|
34
34
|
});
|
|
35
|
-
server.on(
|
|
35
|
+
server.on('request', (req, res) => {
|
|
36
36
|
middleware(req, res, () => { });
|
|
37
37
|
});
|
|
38
|
-
server.on(
|
|
38
|
+
server.on('connection', (socket) => {
|
|
39
39
|
sockets.add(socket);
|
|
40
|
-
socket.on(
|
|
40
|
+
socket.on('close', () => {
|
|
41
41
|
sockets.delete(socket);
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
|
-
server.on(
|
|
44
|
+
server.on('error', (e) => {
|
|
45
45
|
reject(e);
|
|
46
46
|
});
|
|
47
47
|
server.listen();
|
|
48
48
|
});
|
|
49
49
|
let initialized = false;
|
|
50
|
-
compiler.hooks.beforeCompile.tapAsync(
|
|
50
|
+
compiler.hooks.beforeCompile.tapAsync('LazyCompilationTestPlugin', async (_, done) => {
|
|
51
51
|
if (initialized) {
|
|
52
52
|
return done();
|
|
53
53
|
}
|
|
@@ -55,12 +55,12 @@ class LazyCompilationTestPlugin {
|
|
|
55
55
|
initialized = true;
|
|
56
56
|
done();
|
|
57
57
|
});
|
|
58
|
-
compiler.hooks.shutdown.tapAsync(
|
|
58
|
+
compiler.hooks.shutdown.tapAsync('LazyCompilationTestPlugin', (done) => {
|
|
59
59
|
server.close(() => {
|
|
60
60
|
done();
|
|
61
61
|
});
|
|
62
62
|
for (const socket of sockets) {
|
|
63
|
-
socket.destroy(new Error(
|
|
63
|
+
socket.destroy(new Error('Server is disposing'));
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
}
|
package/dist/runner/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './node';
|
|
2
|
+
export * from './web';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RspackOptions, StatsCompilation } from
|
|
2
|
-
import { type IGlobalContext, type IModuleScope, type ITestEnv, type ITestRunner, type TModuleObject, type TRunnerFile, type TRunnerRequirer, type TTestConfig } from
|
|
1
|
+
import type { RspackOptions, StatsCompilation } from '@rspack/core';
|
|
2
|
+
import { type IGlobalContext, type IModuleScope, type ITestEnv, type ITestRunner, type TModuleObject, type TRunnerFile, type TRunnerRequirer, type TTestConfig } from '../../type';
|
|
3
3
|
declare global {
|
|
4
4
|
var printLogger: boolean;
|
|
5
5
|
}
|
|
@@ -47,21 +47,21 @@ const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRe
|
|
|
47
47
|
const type_1 = require("../../type");
|
|
48
48
|
const isRelativePath = (p) => /^\.\.?\//.test(p);
|
|
49
49
|
const getSubPath = (p) => {
|
|
50
|
-
const lastSlash = p.lastIndexOf(
|
|
51
|
-
let firstSlash = p.indexOf(
|
|
50
|
+
const lastSlash = p.lastIndexOf('/');
|
|
51
|
+
let firstSlash = p.indexOf('/');
|
|
52
52
|
if (lastSlash !== -1 && firstSlash !== lastSlash) {
|
|
53
53
|
if (firstSlash !== -1) {
|
|
54
|
-
let next = p.indexOf(
|
|
54
|
+
let next = p.indexOf('/', firstSlash + 1);
|
|
55
55
|
let dir = p.slice(firstSlash + 1, next);
|
|
56
|
-
while (dir ===
|
|
56
|
+
while (dir === '.') {
|
|
57
57
|
firstSlash = next;
|
|
58
|
-
next = p.indexOf(
|
|
58
|
+
next = p.indexOf('/', firstSlash + 1);
|
|
59
59
|
dir = p.slice(firstSlash + 1, next);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
return p.slice(firstSlash + 1, lastSlash + 1);
|
|
63
63
|
}
|
|
64
|
-
return
|
|
64
|
+
return '';
|
|
65
65
|
};
|
|
66
66
|
const cached = new Map();
|
|
67
67
|
class NodeRunner {
|
|
@@ -80,25 +80,25 @@ class NodeRunner {
|
|
|
80
80
|
this.globalContext = this.createGlobalContext();
|
|
81
81
|
}
|
|
82
82
|
this.baseModuleScope = this.createBaseModuleScope();
|
|
83
|
-
if (typeof this._options.testConfig.moduleScope ===
|
|
83
|
+
if (typeof this._options.testConfig.moduleScope === 'function') {
|
|
84
84
|
this._options.testConfig.moduleScope(this.baseModuleScope, this._options.stats, this._options.compilerOptions);
|
|
85
85
|
}
|
|
86
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(
|
|
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
89
|
node_path_1.default.isAbsolute(file)
|
|
90
90
|
? file
|
|
91
91
|
: `./${file}`);
|
|
92
92
|
if (this.globalContext.WAITING.length) {
|
|
93
93
|
return Promise.all(this.globalContext.WAITING).then(() => res);
|
|
94
94
|
}
|
|
95
|
-
if (typeof res ===
|
|
95
|
+
if (typeof res === 'object' && 'then' in res) {
|
|
96
96
|
return res;
|
|
97
97
|
}
|
|
98
98
|
return Promise.resolve(res);
|
|
99
99
|
}
|
|
100
100
|
getRequire() {
|
|
101
|
-
const entryRequire = this.requirers.get(
|
|
101
|
+
const entryRequire = this.requirers.get('entry');
|
|
102
102
|
const runner = this;
|
|
103
103
|
return function (currentDirectory, modulePath, context = {}) {
|
|
104
104
|
const from = this?.from;
|
|
@@ -110,7 +110,7 @@ class NodeRunner {
|
|
|
110
110
|
}
|
|
111
111
|
const p = Array.isArray(modulePath)
|
|
112
112
|
? modulePath
|
|
113
|
-
: modulePath.split(
|
|
113
|
+
: modulePath.split('?')[0];
|
|
114
114
|
return entryRequire(currentDirectory, p, context);
|
|
115
115
|
};
|
|
116
116
|
}
|
|
@@ -153,7 +153,7 @@ class NodeRunner {
|
|
|
153
153
|
},
|
|
154
154
|
clear: () => {
|
|
155
155
|
console.clear();
|
|
156
|
-
}
|
|
156
|
+
},
|
|
157
157
|
},
|
|
158
158
|
WAITING: [],
|
|
159
159
|
setTimeout: ((cb, ms, ...args) => {
|
|
@@ -161,7 +161,7 @@ class NodeRunner {
|
|
|
161
161
|
timeout.unref();
|
|
162
162
|
return timeout;
|
|
163
163
|
}),
|
|
164
|
-
clearTimeout: clearTimeout
|
|
164
|
+
clearTimeout: clearTimeout,
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
167
|
createBaseModuleScope() {
|
|
@@ -171,12 +171,13 @@ class NodeRunner {
|
|
|
171
171
|
clearTimeout: this.globalContext.clearTimeout,
|
|
172
172
|
nsObj: (m) => {
|
|
173
173
|
Object.defineProperty(m, Symbol.toStringTag, {
|
|
174
|
-
value:
|
|
174
|
+
value: 'Module',
|
|
175
175
|
});
|
|
176
176
|
return m;
|
|
177
177
|
},
|
|
178
178
|
WAITING: this.globalContext.WAITING,
|
|
179
179
|
process,
|
|
180
|
+
TextDecoder,
|
|
180
181
|
URL,
|
|
181
182
|
Blob,
|
|
182
183
|
Symbol,
|
|
@@ -187,18 +188,18 @@ class NodeRunner {
|
|
|
187
188
|
__TEST_SOURCE_PATH__: this._options.source,
|
|
188
189
|
__TEST_DIST_PATH__: this._options.dist,
|
|
189
190
|
__MODE__: this._options.compilerOptions.mode,
|
|
190
|
-
__SNAPSHOT__: node_path_1.default.join(this._options.source,
|
|
191
|
+
__SNAPSHOT__: node_path_1.default.join(this._options.source, '__snapshot__'),
|
|
191
192
|
Worker: (0, createFakeWorker_1.default)(this._options.env, {
|
|
192
|
-
outputDirectory: this._options.dist
|
|
193
|
+
outputDirectory: this._options.dist,
|
|
193
194
|
}),
|
|
194
|
-
...this._options.env
|
|
195
|
+
...this._options.env,
|
|
195
196
|
};
|
|
196
197
|
return baseModuleScope;
|
|
197
198
|
}
|
|
198
199
|
createModuleScope(requireFn, m, file) {
|
|
199
200
|
const requirer = requireFn.bind({
|
|
200
201
|
from: file.path,
|
|
201
|
-
module: m
|
|
202
|
+
module: m,
|
|
202
203
|
}, node_path_1.default.dirname(file.path));
|
|
203
204
|
requirer.webpackTestSuiteRequire = true;
|
|
204
205
|
return {
|
|
@@ -209,8 +210,8 @@ class NodeRunner {
|
|
|
209
210
|
__dirname: node_path_1.default.dirname(file.path),
|
|
210
211
|
__filename: file.path,
|
|
211
212
|
_globalAssign: {
|
|
212
|
-
expect: this._options.env.expect
|
|
213
|
-
}
|
|
213
|
+
expect: this._options.env.expect,
|
|
214
|
+
},
|
|
214
215
|
};
|
|
215
216
|
}
|
|
216
217
|
getFile(modulePath, currentDirectory) {
|
|
@@ -221,37 +222,37 @@ class NodeRunner {
|
|
|
221
222
|
let res = null;
|
|
222
223
|
if (Array.isArray(modulePath)) {
|
|
223
224
|
res = {
|
|
224
|
-
path: node_path_1.default.join(currentDirectory,
|
|
225
|
+
path: node_path_1.default.join(currentDirectory, '.array-require.js'),
|
|
225
226
|
content: `module.exports = (${modulePath
|
|
226
|
-
.map(arg => {
|
|
227
|
+
.map((arg) => {
|
|
227
228
|
return `require(${JSON.stringify(`./${arg}`)})`;
|
|
228
229
|
})
|
|
229
|
-
.join(
|
|
230
|
-
subPath:
|
|
230
|
+
.join(', ')});`,
|
|
231
|
+
subPath: '',
|
|
231
232
|
};
|
|
232
233
|
}
|
|
233
|
-
else if (modulePath.startsWith(
|
|
234
|
+
else if (modulePath.startsWith('https://test.cases/')) {
|
|
234
235
|
const relativePath = (0, urlToRelativePath_1.default)(modulePath);
|
|
235
236
|
const absPath = node_path_1.default.join(currentDirectory, relativePath);
|
|
236
237
|
res = {
|
|
237
238
|
path: absPath,
|
|
238
|
-
content: node_fs_1.default.readFileSync(absPath,
|
|
239
|
-
subPath:
|
|
239
|
+
content: node_fs_1.default.readFileSync(absPath, 'utf-8'),
|
|
240
|
+
subPath: '',
|
|
240
241
|
};
|
|
241
242
|
}
|
|
242
243
|
else if (isRelativePath(modulePath)) {
|
|
243
244
|
const p = node_path_1.default.join(currentDirectory, modulePath);
|
|
244
245
|
res = {
|
|
245
246
|
path: p,
|
|
246
|
-
content: node_fs_1.default.readFileSync(p,
|
|
247
|
-
subPath: getSubPath(modulePath)
|
|
247
|
+
content: node_fs_1.default.readFileSync(p, 'utf-8'),
|
|
248
|
+
subPath: getSubPath(modulePath),
|
|
248
249
|
};
|
|
249
250
|
}
|
|
250
251
|
else if (node_path_1.default.isAbsolute(modulePath)) {
|
|
251
252
|
res = {
|
|
252
253
|
path: modulePath,
|
|
253
|
-
content: node_fs_1.default.readFileSync(modulePath,
|
|
254
|
-
subPath:
|
|
254
|
+
content: node_fs_1.default.readFileSync(modulePath, 'utf-8'),
|
|
255
|
+
subPath: 'absolute_path',
|
|
255
256
|
};
|
|
256
257
|
}
|
|
257
258
|
if (this._options.cachable && res) {
|
|
@@ -262,32 +263,32 @@ class NodeRunner {
|
|
|
262
263
|
preExecute(code, file) { }
|
|
263
264
|
postExecute(m, file) { }
|
|
264
265
|
createRunner() {
|
|
265
|
-
this.requirers.set(
|
|
266
|
-
this.requirers.set(
|
|
267
|
-
this.requirers.set(
|
|
268
|
-
this.requirers.set(
|
|
269
|
-
this.requirers.set(
|
|
266
|
+
this.requirers.set('cjs', this.createCjsRequirer());
|
|
267
|
+
this.requirers.set('esm', this.createEsmRequirer());
|
|
268
|
+
this.requirers.set('miss', this.createMissRequirer());
|
|
269
|
+
this.requirers.set('json', this.createJsonRequirer());
|
|
270
|
+
this.requirers.set('entry', (currentDirectory, modulePath, context) => {
|
|
270
271
|
const file = this.getFile(modulePath, currentDirectory);
|
|
271
272
|
this.log(`entry: ${modulePath} -> ${file?.path}`);
|
|
272
273
|
if (!file) {
|
|
273
|
-
return this.requirers.get(
|
|
274
|
+
return this.requirers.get('miss')(currentDirectory, modulePath);
|
|
274
275
|
}
|
|
275
|
-
if (file.path.endsWith(
|
|
276
|
-
return this.requirers.get(
|
|
276
|
+
if (file.path.endsWith('.json')) {
|
|
277
|
+
return this.requirers.get('json')(currentDirectory, modulePath, {
|
|
277
278
|
...context,
|
|
278
|
-
file
|
|
279
|
+
file,
|
|
279
280
|
});
|
|
280
281
|
}
|
|
281
|
-
if (file.path.endsWith(
|
|
282
|
+
if (file.path.endsWith('.mjs') &&
|
|
282
283
|
this._options.compilerOptions.experiments?.outputModule) {
|
|
283
|
-
return this.requirers.get(
|
|
284
|
+
return this.requirers.get('esm')(currentDirectory, modulePath, {
|
|
284
285
|
...context,
|
|
285
|
-
file
|
|
286
|
+
file,
|
|
286
287
|
});
|
|
287
288
|
}
|
|
288
|
-
return this.requirers.get(
|
|
289
|
+
return this.requirers.get('cjs')(currentDirectory, modulePath, {
|
|
289
290
|
...context,
|
|
290
|
-
file
|
|
291
|
+
file,
|
|
291
292
|
});
|
|
292
293
|
});
|
|
293
294
|
}
|
|
@@ -301,7 +302,7 @@ class NodeRunner {
|
|
|
301
302
|
return modules[modulePathStr];
|
|
302
303
|
}
|
|
303
304
|
this.log(`native require: ${modulePathStr}`);
|
|
304
|
-
return require(modulePathStr.startsWith(
|
|
305
|
+
return require(modulePathStr.startsWith('node:')
|
|
305
306
|
? modulePathStr.slice(5)
|
|
306
307
|
: modulePathStr);
|
|
307
308
|
};
|
|
@@ -309,25 +310,25 @@ class NodeRunner {
|
|
|
309
310
|
createJsonRequirer() {
|
|
310
311
|
return (currentDirectory, modulePath, context = {}) => {
|
|
311
312
|
if (Array.isArray(modulePath)) {
|
|
312
|
-
throw new Error(
|
|
313
|
+
throw new Error('Array module path is not supported in hot cases');
|
|
313
314
|
}
|
|
314
315
|
const file = context.file || this.getFile(modulePath, currentDirectory);
|
|
315
316
|
this.log(`json: ${modulePath} -> ${file?.path}`);
|
|
316
317
|
if (!file) {
|
|
317
|
-
return this.requirers.get(
|
|
318
|
+
return this.requirers.get('miss')(currentDirectory, modulePath);
|
|
318
319
|
}
|
|
319
|
-
return JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(this._options.dist, modulePath),
|
|
320
|
+
return JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(this._options.dist, modulePath), 'utf-8'));
|
|
320
321
|
};
|
|
321
322
|
}
|
|
322
323
|
createCjsRequirer() {
|
|
323
324
|
return (currentDirectory, modulePath, context = {}) => {
|
|
324
|
-
if (modulePath ===
|
|
325
|
-
return require(
|
|
325
|
+
if (modulePath === '@rspack/test-tools') {
|
|
326
|
+
return require('@rspack/test-tools');
|
|
326
327
|
}
|
|
327
328
|
const file = context.file || this.getFile(modulePath, currentDirectory);
|
|
328
329
|
this.log(`cjs: ${modulePath} -> ${file?.path}`);
|
|
329
330
|
if (!file) {
|
|
330
|
-
return this.requirers.get(
|
|
331
|
+
return this.requirers.get('miss')(currentDirectory, modulePath);
|
|
331
332
|
}
|
|
332
333
|
if (file.path in this.requireCache) {
|
|
333
334
|
this.log(`cjs cache hit: ${file.path}`);
|
|
@@ -335,7 +336,7 @@ class NodeRunner {
|
|
|
335
336
|
}
|
|
336
337
|
const m = {
|
|
337
338
|
exports: {},
|
|
338
|
-
webpackTestSuiteModule: true
|
|
339
|
+
webpackTestSuiteModule: true,
|
|
339
340
|
};
|
|
340
341
|
this.requireCache[file.path] = m;
|
|
341
342
|
if (!this._options.runInNewContext) {
|
|
@@ -345,43 +346,43 @@ class NodeRunner {
|
|
|
345
346
|
if (this._options.testConfig.moduleScope) {
|
|
346
347
|
this._options.testConfig.moduleScope(currentModuleScope, this._options.stats, this._options.compilerOptions);
|
|
347
348
|
}
|
|
348
|
-
if (file.content.includes(
|
|
349
|
+
if (file.content.includes('__STATS__') && this._options.stats) {
|
|
349
350
|
currentModuleScope.__STATS__ = this._options.stats();
|
|
350
351
|
}
|
|
351
|
-
if (file.content.includes(
|
|
352
|
+
if (file.content.includes('__STATS_I__')) {
|
|
352
353
|
const statsIndex = this._options.stats?.()?.__index__;
|
|
353
|
-
if (typeof statsIndex ===
|
|
354
|
+
if (typeof statsIndex === 'number') {
|
|
354
355
|
currentModuleScope.__STATS_I__ = statsIndex;
|
|
355
356
|
}
|
|
356
357
|
}
|
|
357
|
-
if (file.content.includes(
|
|
358
|
+
if (file.content.includes('webpack/runtime/startup_chunk_dependencies')) {
|
|
358
359
|
currentModuleScope.__AFTER_CHUNK_LOADED__ = (next) => {
|
|
359
360
|
let done;
|
|
360
|
-
const task = new Promise(resolve => (done = resolve));
|
|
361
|
+
const task = new Promise((resolve) => (done = resolve));
|
|
361
362
|
currentModuleScope.WAITING.push(task);
|
|
362
363
|
return () => {
|
|
363
364
|
next();
|
|
364
365
|
done();
|
|
365
366
|
};
|
|
366
367
|
};
|
|
367
|
-
file.content = file.content.replace(
|
|
368
|
+
file.content = file.content.replace('var next = __webpack_require__.x', 'var next = __AFTER_CHUNK_LOADED__(__webpack_require__.x)');
|
|
368
369
|
}
|
|
369
370
|
const args = Object.keys(currentModuleScope);
|
|
370
|
-
const argValues = args.map(arg => currentModuleScope[arg]);
|
|
371
|
-
const code = `(function(${args.join(
|
|
371
|
+
const argValues = args.map((arg) => currentModuleScope[arg]);
|
|
372
|
+
const code = `(function(${args.join(', ')}) {
|
|
372
373
|
${file.content}
|
|
373
374
|
})`;
|
|
374
375
|
this.preExecute(code, file);
|
|
375
|
-
this.log(`run mode: ${this._options.runInNewContext ?
|
|
376
|
+
this.log(`run mode: ${this._options.runInNewContext ? 'new context' : 'this context'}`);
|
|
376
377
|
try {
|
|
377
378
|
const fn = this._options.runInNewContext
|
|
378
379
|
? node_vm_1.default.runInNewContext(code, this.globalContext, {
|
|
379
380
|
filename: file.path,
|
|
380
|
-
lineOffset: -1
|
|
381
|
+
lineOffset: -1,
|
|
381
382
|
})
|
|
382
383
|
: node_vm_1.default.runInThisContext(code, {
|
|
383
384
|
filename: file.path,
|
|
384
|
-
lineOffset: -1
|
|
385
|
+
lineOffset: -1,
|
|
385
386
|
});
|
|
386
387
|
fn.call(this._options.testConfig.nonEsmThis
|
|
387
388
|
? this._options.testConfig.nonEsmThis(modulePath)
|
|
@@ -398,7 +399,7 @@ class NodeRunner {
|
|
|
398
399
|
}
|
|
399
400
|
createEsmRequirer() {
|
|
400
401
|
const esmContext = node_vm_1.default.createContext(this.baseModuleScope, {
|
|
401
|
-
name:
|
|
402
|
+
name: 'context for esm',
|
|
402
403
|
});
|
|
403
404
|
const esmCache = new Map();
|
|
404
405
|
const esmIdentifier = this._options.name;
|
|
@@ -410,14 +411,14 @@ class NodeRunner {
|
|
|
410
411
|
const file = context.file || this.getFile(modulePath, currentDirectory);
|
|
411
412
|
this.log(`esm: ${modulePath} -> ${file?.path}`);
|
|
412
413
|
if (!file) {
|
|
413
|
-
return this.requirers.get(
|
|
414
|
+
return this.requirers.get('miss')(currentDirectory, modulePath);
|
|
414
415
|
}
|
|
415
|
-
if (file.content.includes(
|
|
416
|
+
if (file.content.includes('__STATS__')) {
|
|
416
417
|
esmContext.__STATS__ = this._options.stats?.();
|
|
417
418
|
}
|
|
418
|
-
if (file.content.includes(
|
|
419
|
+
if (file.content.includes('__STATS_I__')) {
|
|
419
420
|
const statsIndex = this._options.stats?.()?.__index__;
|
|
420
|
-
if (typeof statsIndex ===
|
|
421
|
+
if (typeof statsIndex === 'number') {
|
|
421
422
|
esmContext.__STATS_I__ = statsIndex;
|
|
422
423
|
}
|
|
423
424
|
}
|
|
@@ -436,22 +437,22 @@ class NodeRunner {
|
|
|
436
437
|
importModuleDynamically: async (specifier, module) => {
|
|
437
438
|
this.log(`import: ${specifier} from ${file?.path}`);
|
|
438
439
|
const result = await _require(node_path_1.default.dirname(file.path), specifier, {
|
|
439
|
-
esmMode: type_1.EEsmMode.Evaluated
|
|
440
|
+
esmMode: type_1.EEsmMode.Evaluated,
|
|
440
441
|
});
|
|
441
442
|
return await (0, asModule_1.default)(result, module.context);
|
|
442
|
-
}
|
|
443
|
+
},
|
|
443
444
|
});
|
|
444
445
|
esmCache.set(file.path, esm);
|
|
445
446
|
}
|
|
446
447
|
if (context.esmMode === type_1.EEsmMode.Unlinked)
|
|
447
448
|
return esm;
|
|
448
449
|
return (async () => {
|
|
449
|
-
if (esm.status ===
|
|
450
|
+
if (esm.status === 'unlinked') {
|
|
450
451
|
await esm.link(async (specifier, referencingModule) => {
|
|
451
452
|
return await (0, asModule_1.default)(await _require(node_path_1.default.dirname(referencingModule.identifier
|
|
452
453
|
? referencingModule.identifier.slice(esmIdentifier.length + 1)
|
|
453
454
|
: (0, node_url_1.fileURLToPath)(referencingModule.url)), specifier, {
|
|
454
|
-
esmMode: type_1.EEsmMode.Unlinked
|
|
455
|
+
esmMode: type_1.EEsmMode.Unlinked,
|
|
455
456
|
}), referencingModule.context, true);
|
|
456
457
|
});
|
|
457
458
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TRunnerFile, TRunnerRequirer } from
|
|
2
|
-
import { type INodeRunnerOptions, NodeRunner } from
|
|
1
|
+
import type { TRunnerFile, TRunnerRequirer } from '../../type';
|
|
2
|
+
import { type INodeRunnerOptions, NodeRunner } from '../node';
|
|
3
3
|
export interface IWebRunnerOptions extends INodeRunnerOptions {
|
|
4
4
|
location: string;
|
|
5
5
|
}
|