@rspack/test-tools 1.5.3 → 1.5.5
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/compiler.d.ts +11 -2
- package/dist/case/compiler.js +111 -8
- package/dist/case/config.js +2 -2
- package/dist/case/normal.d.ts +1 -0
- package/dist/case/normal.js +27 -15
- package/dist/case/serial.js +2 -2
- package/dist/compiler.d.ts +4 -3
- package/dist/compiler.js +7 -2
- package/dist/helper/expect/placeholder.js +1 -1
- package/dist/helper/legacy/FakeDocument.js +6 -4
- package/dist/helper/legacy/createFakeWorker.d.ts +1 -1
- package/dist/helper/legacy/createFakeWorker.js +44 -20
- 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.d.ts +2 -0
- package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
- package/dist/helper/legacy/supportsBlob.d.ts +2 -0
- package/dist/helper/legacy/supportsBlob.js +10 -0
- package/dist/helper/legacy/supportsClassFields.d.ts +2 -0
- package/dist/helper/legacy/supportsClassFields.js +11 -0
- package/dist/helper/legacy/supportsES6.d.ts +2 -0
- package/dist/helper/legacy/supportsES6.js +11 -0
- package/dist/helper/legacy/supportsForOf.d.ts +2 -0
- package/dist/helper/legacy/supportsForOf.js +11 -0
- package/dist/helper/legacy/supportsIteratorDestructuring.d.ts +2 -0
- package/dist/helper/legacy/supportsIteratorDestructuring.js +11 -0
- package/dist/helper/legacy/supportsLogicalAssignment.d.ts +2 -0
- package/dist/helper/legacy/supportsLogicalAssignment.js +11 -0
- package/dist/helper/legacy/supportsObjectDestructuring.d.ts +2 -0
- package/dist/helper/legacy/supportsObjectDestructuring.js +11 -0
- package/dist/helper/legacy/supportsOptionalCatchBinding.d.ts +2 -0
- package/dist/helper/legacy/supportsOptionalCatchBinding.js +11 -0
- package/dist/helper/legacy/supportsOptionalChaining.d.ts +2 -0
- package/dist/helper/legacy/supportsOptionalChaining.js +11 -0
- package/dist/helper/legacy/supportsRequireInModule.d.ts +2 -0
- package/dist/helper/legacy/supportsRequireInModule.js +5 -0
- package/dist/helper/legacy/supportsResponse.d.ts +2 -0
- package/dist/helper/legacy/supportsResponse.js +10 -0
- package/dist/helper/legacy/supportsSpread.d.ts +2 -0
- package/dist/helper/legacy/supportsSpread.js +12 -0
- package/dist/helper/legacy/supportsTemplateStrings.d.ts +2 -0
- package/dist/helper/legacy/supportsTemplateStrings.js +11 -0
- package/dist/helper/legacy/supportsUsing.d.ts +2 -0
- package/dist/helper/legacy/supportsUsing.js +26 -0
- package/dist/helper/legacy/supportsWebAssembly.d.ts +2 -0
- package/dist/helper/legacy/supportsWebAssembly.js +10 -0
- package/dist/helper/legacy/supportsWorker.d.ts +2 -0
- package/dist/helper/legacy/supportsWorker.js +17 -0
- package/dist/helper/legacy/urlToRelativePath.js +5 -2
- package/dist/processor/basic.js +5 -5
- package/dist/processor/config.js +5 -0
- package/dist/processor/error.js +1 -1
- package/dist/processor/hook.js +2 -2
- package/dist/processor/hot.d.ts +1 -1
- package/dist/processor/hot.js +6 -2
- package/dist/processor/normal.js +21 -2
- package/dist/processor/simple.d.ts +1 -0
- package/dist/processor/simple.js +3 -1
- package/dist/processor/watch.js +1 -1
- package/dist/runner/cache.js +1 -1
- package/dist/runner/hot-step.js +1 -1
- package/dist/runner/hot.js +1 -1
- package/dist/runner/multiple.js +16 -2
- package/dist/runner/runner/basic.js +13 -11
- package/dist/runner/runner/cjs.d.ts +2 -0
- package/dist/runner/runner/cjs.js +42 -13
- package/dist/runner/runner/esm.js +3 -0
- package/dist/runner/runner/normal.js +4 -1
- package/dist/runner/runner/web/fake.d.ts +0 -1
- package/dist/runner/runner/web/fake.js +0 -12
- package/dist/runner/runner/web/jsdom.d.ts +0 -1
- package/dist/runner/runner/web/jsdom.js +1 -2
- package/dist/test/creator.js +1 -1
- package/dist/type.d.ts +11 -9
- package/package.json +22 -24
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
"use strict";
|
|
3
|
+
module.exports = function supportsUsing() {
|
|
4
|
+
try {
|
|
5
|
+
const f = eval(`(function f() {
|
|
6
|
+
let disposed = false;
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
const getResource = () => {
|
|
10
|
+
return {
|
|
11
|
+
[Symbol.dispose]: () => {
|
|
12
|
+
disposed = true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
using resource = getResource();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return disposed;
|
|
20
|
+
})`);
|
|
21
|
+
return f() === true;
|
|
22
|
+
}
|
|
23
|
+
catch (_err) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
const nodeVersion = process.versions.node.split(".").map(Number);
|
|
4
|
+
module.exports = function supportsWorker() {
|
|
5
|
+
// Verify that in the current node version new Worker() accepts URL as the first parameter:
|
|
6
|
+
// https://nodejs.org/api/worker_threads.html#worker_threads_new_worker_filename_options
|
|
7
|
+
if (nodeVersion[0] >= 14) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
else if (nodeVersion[0] === 13 && nodeVersion[1] >= 12) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
else if (nodeVersion[0] === 12 && nodeVersion[1] >= 17) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// @ts-nocheck
|
|
3
|
+
const URL = require("url").URL;
|
|
3
4
|
module.exports = function urlToRelativePath(url) {
|
|
4
|
-
if (url.startsWith("https://
|
|
5
|
-
|
|
5
|
+
if (url.startsWith("https://") || url.startsWith("file://")) {
|
|
6
|
+
const urlObj = new URL(url);
|
|
7
|
+
return `./${urlObj.pathname.split("/").pop()}`;
|
|
8
|
+
}
|
|
6
9
|
return `./${url}`;
|
|
7
10
|
};
|
package/dist/processor/basic.js
CHANGED
|
@@ -38,15 +38,15 @@ class BasicProcessor {
|
|
|
38
38
|
if (!this._options.runable)
|
|
39
39
|
return;
|
|
40
40
|
const testConfig = context.getTestConfig();
|
|
41
|
-
if (testConfig.
|
|
41
|
+
if (testConfig.noTests)
|
|
42
42
|
return;
|
|
43
43
|
if (testConfig.documentType) {
|
|
44
44
|
context.setValue(this._options.name, "documentType", testConfig.documentType);
|
|
45
45
|
}
|
|
46
|
+
const compiler = this.getCompiler(context);
|
|
46
47
|
if (typeof testConfig.beforeExecute === "function") {
|
|
47
|
-
testConfig.beforeExecute();
|
|
48
|
+
testConfig.beforeExecute(compiler.getOptions());
|
|
48
49
|
}
|
|
49
|
-
const compiler = this.getCompiler(context);
|
|
50
50
|
let bundles;
|
|
51
51
|
if (testConfig.bundlePath) {
|
|
52
52
|
bundles = testConfig.bundlePath;
|
|
@@ -83,12 +83,12 @@ class BasicProcessor {
|
|
|
83
83
|
const results = context.getValue(this._options.name, "modules") || [];
|
|
84
84
|
await Promise.all(results);
|
|
85
85
|
if (typeof testConfig.afterExecute === "function") {
|
|
86
|
-
testConfig.afterExecute();
|
|
86
|
+
testConfig.afterExecute(compiler.getOptions());
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
async check(env, context) {
|
|
90
90
|
const testConfig = context.getTestConfig();
|
|
91
|
-
if (testConfig.
|
|
91
|
+
if (testConfig.noTests)
|
|
92
92
|
return;
|
|
93
93
|
const errors = (context.getError(this._options.name) || []).map(e => ({
|
|
94
94
|
message: e.message,
|
package/dist/processor/config.js
CHANGED
|
@@ -66,11 +66,16 @@ class ConfigProcessor extends multi_1.MultiTaskProcessor {
|
|
|
66
66
|
if (!options.entry) {
|
|
67
67
|
options.entry = "./index.js";
|
|
68
68
|
}
|
|
69
|
+
if (options.amd === undefined) {
|
|
70
|
+
options.amd = {};
|
|
71
|
+
}
|
|
69
72
|
if (!options.output?.filename) {
|
|
70
73
|
const outputModule = options.experiments?.outputModule;
|
|
71
74
|
options.output ??= {};
|
|
72
75
|
options.output.filename = `bundle${index}${outputModule ? ".mjs" : ".js"}`;
|
|
73
76
|
}
|
|
77
|
+
if (options.cache === undefined)
|
|
78
|
+
options.cache = false;
|
|
74
79
|
if (!global.printLogger) {
|
|
75
80
|
options.infrastructureLogging = {
|
|
76
81
|
level: "error"
|
package/dist/processor/error.js
CHANGED
|
@@ -18,7 +18,7 @@ class ErrorProcessor extends simple_1.SimpleTaskProcessor {
|
|
|
18
18
|
super({
|
|
19
19
|
options: (context) => {
|
|
20
20
|
let options = {
|
|
21
|
-
context: node_path_1.default.resolve(__dirname, "
|
|
21
|
+
context: node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/fixtures/errors"),
|
|
22
22
|
mode: "none",
|
|
23
23
|
devtool: false,
|
|
24
24
|
optimization: {
|
package/dist/processor/hook.js
CHANGED
|
@@ -11,8 +11,8 @@ const path_serializer_1 = require("path-serializer");
|
|
|
11
11
|
const pretty_format_1 = require("pretty-format");
|
|
12
12
|
const context_1 = require("../test/context");
|
|
13
13
|
const snapshot_1 = require("./snapshot");
|
|
14
|
-
const srcDir = node_path_1.default.resolve(__dirname, "
|
|
15
|
-
const distDir = node_path_1.default.resolve(__dirname, "
|
|
14
|
+
const srcDir = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/fixtures");
|
|
15
|
+
const distDir = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/js/hook");
|
|
16
16
|
const sourceSerializer = {
|
|
17
17
|
test(val) {
|
|
18
18
|
return val instanceof core_1.sources.Source;
|
package/dist/processor/hot.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare class HotProcessor<T extends ECompilerType> extends BasicProcesso
|
|
|
10
10
|
protected runner: ITestRunner | null;
|
|
11
11
|
constructor(_hotOptions: IHotProcessorOptions<T>);
|
|
12
12
|
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
13
|
-
static findBundle<T extends ECompilerType>(this: HotProcessor<T>, context: ITestContext): string[];
|
|
13
|
+
static findBundle<T extends ECompilerType>(this: HotProcessor<T>, context: ITestContext): string | string[];
|
|
14
14
|
afterAll(context: ITestContext): Promise<void>;
|
|
15
15
|
static defaultOptions<T extends ECompilerType>(this: HotProcessor<T>, context: ITestContext): TCompilerOptions<T>;
|
|
16
16
|
static overrideOptions<T extends ECompilerType>(this: HotProcessor<T>, context: ITestContext, options: TCompilerOptions<T>): void;
|
package/dist/processor/hot.js
CHANGED
|
@@ -34,11 +34,15 @@ class HotProcessor extends basic_1.BasicProcessor {
|
|
|
34
34
|
await super.run(env, context);
|
|
35
35
|
}
|
|
36
36
|
static findBundle(context) {
|
|
37
|
-
const files = [];
|
|
38
|
-
const prefiles = [];
|
|
39
37
|
const compiler = context.getCompiler(this._hotOptions.name);
|
|
40
38
|
if (!compiler)
|
|
41
39
|
throw new Error("Compiler should exists when find bundle");
|
|
40
|
+
const testConfig = context.getTestConfig();
|
|
41
|
+
if (typeof testConfig.findBundle === "function") {
|
|
42
|
+
return testConfig.findBundle(this.updateOptions.updateIndex, compiler.getOptions());
|
|
43
|
+
}
|
|
44
|
+
const files = [];
|
|
45
|
+
const prefiles = [];
|
|
42
46
|
const stats = compiler.getStats();
|
|
43
47
|
if (!stats)
|
|
44
48
|
throw new Error("Stats should exists when find bundle");
|
package/dist/processor/normal.js
CHANGED
|
@@ -11,6 +11,10 @@ class NormalProcessor extends basic_1.BasicProcessor {
|
|
|
11
11
|
constructor(_normalOptions) {
|
|
12
12
|
super({
|
|
13
13
|
findBundle: (context, options) => {
|
|
14
|
+
const testConfig = context.getTestConfig();
|
|
15
|
+
if (typeof testConfig.findBundle === "function") {
|
|
16
|
+
return testConfig.findBundle(0, options);
|
|
17
|
+
}
|
|
14
18
|
const filename = options.output?.filename;
|
|
15
19
|
return typeof filename === "string" ? filename : undefined;
|
|
16
20
|
},
|
|
@@ -31,6 +35,7 @@ class NormalProcessor extends basic_1.BasicProcessor {
|
|
|
31
35
|
});
|
|
32
36
|
const { root, compilerOptions } = this._normalOptions;
|
|
33
37
|
return {
|
|
38
|
+
amd: {},
|
|
34
39
|
context: root,
|
|
35
40
|
entry: `./${node_path_1.default.relative(root, context.getSource())}/`,
|
|
36
41
|
target: compilerOptions?.target || "async-node",
|
|
@@ -98,7 +103,21 @@ class NormalProcessor extends basic_1.BasicProcessor {
|
|
|
98
103
|
]
|
|
99
104
|
},
|
|
100
105
|
module: {
|
|
101
|
-
rules: [
|
|
106
|
+
rules: [
|
|
107
|
+
{
|
|
108
|
+
test: /\.coffee$/,
|
|
109
|
+
loader: "coffee-loader"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
test: /\.pug/,
|
|
113
|
+
loader: "@webdiscus/pug-loader"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
test: /\.wat$/i,
|
|
117
|
+
loader: "wast-loader",
|
|
118
|
+
type: "webassembly/async"
|
|
119
|
+
}
|
|
120
|
+
]
|
|
102
121
|
},
|
|
103
122
|
plugins: (compilerOptions?.plugins || [])
|
|
104
123
|
.concat(testConfig.plugins || [])
|
|
@@ -118,7 +137,7 @@ class NormalProcessor extends basic_1.BasicProcessor {
|
|
|
118
137
|
});
|
|
119
138
|
}),
|
|
120
139
|
experiments: {
|
|
121
|
-
css:
|
|
140
|
+
css: false,
|
|
122
141
|
rspackFuture: {
|
|
123
142
|
bundlerInfo: {
|
|
124
143
|
force: false
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ECompilerType, ITestContext, ITestEnv, ITestProcessor, TCompiler, TCompilerOptions, TCompilerStats } from "../type";
|
|
2
2
|
export interface ISimpleProcessorOptions<T extends ECompilerType> {
|
|
3
3
|
options?: (context: ITestContext) => TCompilerOptions<T>;
|
|
4
|
+
compilerCallback?: (error: Error | null, stats: TCompilerStats<T> | null) => void;
|
|
4
5
|
compilerType: T;
|
|
5
6
|
name: string;
|
|
6
7
|
build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
|
package/dist/processor/simple.js
CHANGED
|
@@ -13,7 +13,9 @@ class SimpleTaskProcessor {
|
|
|
13
13
|
}
|
|
14
14
|
async compiler(context) {
|
|
15
15
|
const compiler = this.getCompiler(context);
|
|
16
|
-
const instance =
|
|
16
|
+
const instance = this._options.compilerCallback
|
|
17
|
+
? compiler.createCompilerWithCallback(this._options.compilerCallback)
|
|
18
|
+
: compiler.createCompiler();
|
|
17
19
|
if (typeof this._options.compiler === "function") {
|
|
18
20
|
await this._options.compiler(context, instance);
|
|
19
21
|
}
|
package/dist/processor/watch.js
CHANGED
|
@@ -57,7 +57,7 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
|
|
|
57
57
|
}
|
|
58
58
|
async check(env, context) {
|
|
59
59
|
const testConfig = context.getTestConfig();
|
|
60
|
-
if (testConfig.
|
|
60
|
+
if (testConfig.noTests)
|
|
61
61
|
return;
|
|
62
62
|
const errors = (context.getError(this._options.name) || []).map(e => ({
|
|
63
63
|
message: e.message,
|
package/dist/runner/cache.js
CHANGED
|
@@ -30,7 +30,7 @@ class CacheRunnerFactory extends basic_1.BasicRunnerFactory {
|
|
|
30
30
|
...testConfig,
|
|
31
31
|
moduleScope(ms, stats) {
|
|
32
32
|
const moduleScope = typeof testConfig.moduleScope === "function"
|
|
33
|
-
? testConfig.moduleScope(ms, stats)
|
|
33
|
+
? testConfig.moduleScope(ms, stats, compilerOptions)
|
|
34
34
|
: ms;
|
|
35
35
|
moduleScope.COMPILER_INDEX = compilerIndex;
|
|
36
36
|
moduleScope.NEXT_HMR = nextHmr;
|
package/dist/runner/hot-step.js
CHANGED
|
@@ -69,7 +69,7 @@ class HotStepRunnerFactory extends hot_1.HotRunnerFactory {
|
|
|
69
69
|
moduleScope(ms, stats) {
|
|
70
70
|
const moduleScope = ms;
|
|
71
71
|
if (typeof testConfig.moduleScope === "function") {
|
|
72
|
-
testConfig.moduleScope(moduleScope, stats);
|
|
72
|
+
testConfig.moduleScope(moduleScope, stats, compilerOptions);
|
|
73
73
|
}
|
|
74
74
|
moduleScope.NEXT = next;
|
|
75
75
|
moduleScope.NEXT_HMR = nextHMR;
|
package/dist/runner/hot.js
CHANGED
|
@@ -66,7 +66,7 @@ class HotRunnerFactory extends basic_1.BasicRunnerFactory {
|
|
|
66
66
|
moduleScope(ms, stats) {
|
|
67
67
|
const moduleScope = ms;
|
|
68
68
|
if (typeof testConfig.moduleScope === "function") {
|
|
69
|
-
testConfig.moduleScope(moduleScope, stats);
|
|
69
|
+
testConfig.moduleScope(moduleScope, stats, compilerOptions);
|
|
70
70
|
}
|
|
71
71
|
moduleScope.NEXT = next;
|
|
72
72
|
moduleScope.NEXT_HMR = nextHMR;
|
package/dist/runner/multiple.js
CHANGED
|
@@ -13,11 +13,25 @@ class MultipleRunnerFactory extends basic_1.BasicRunnerFactory {
|
|
|
13
13
|
return `${this.name}-${index}[${seq}]`;
|
|
14
14
|
}
|
|
15
15
|
createRunner(file, stats, compilerOptions, env) {
|
|
16
|
-
const multiCompilerOptions = this.context.getValue(this.name, "multiCompilerOptions") || [];
|
|
17
16
|
const { getIndex, flagIndex } = this.getFileIndexHandler(file);
|
|
17
|
+
const key = this.getRunnerKey(file);
|
|
18
|
+
const exists = this.context.getRunner(key);
|
|
19
|
+
if (exists) {
|
|
20
|
+
flagIndex();
|
|
21
|
+
return exists;
|
|
22
|
+
}
|
|
23
|
+
const multiCompilerOptions = this.context.getValue(this.name, "multiCompilerOptions") || [];
|
|
18
24
|
const [index] = getIndex();
|
|
19
|
-
const runner = super.createRunner(file, () =>
|
|
25
|
+
const runner = super.createRunner(file, () => {
|
|
26
|
+
const s = stats();
|
|
27
|
+
if (s.children?.length && s.children.length > 1) {
|
|
28
|
+
s.__index__ = index;
|
|
29
|
+
return s;
|
|
30
|
+
}
|
|
31
|
+
return s.children[index];
|
|
32
|
+
}, multiCompilerOptions[index], env);
|
|
20
33
|
flagIndex();
|
|
34
|
+
this.context.setRunner(key, runner);
|
|
21
35
|
return runner;
|
|
22
36
|
}
|
|
23
37
|
getFileIndexHandler(file) {
|
|
@@ -39,10 +39,12 @@ class BasicRunner {
|
|
|
39
39
|
}
|
|
40
40
|
this.baseModuleScope = this.createBaseModuleScope();
|
|
41
41
|
if (typeof this._options.testConfig.moduleScope === "function") {
|
|
42
|
-
this._options.testConfig.moduleScope(this.baseModuleScope, this._options.stats);
|
|
42
|
+
this._options.testConfig.moduleScope(this.baseModuleScope, this._options.stats, this._options.compilerOptions);
|
|
43
43
|
}
|
|
44
44
|
this.createRunner();
|
|
45
|
-
const res = this.getRequire()(this._options.dist, file.startsWith("./")
|
|
45
|
+
const res = this.getRequire()(this._options.dist, file.startsWith("./") || file.startsWith("https://test.cases/")
|
|
46
|
+
? file
|
|
47
|
+
: `./${file}`);
|
|
46
48
|
if (typeof res === "object" && "then" in res) {
|
|
47
49
|
return res;
|
|
48
50
|
}
|
|
@@ -77,6 +79,15 @@ class BasicRunner {
|
|
|
77
79
|
subPath: ""
|
|
78
80
|
};
|
|
79
81
|
}
|
|
82
|
+
else if (modulePath.startsWith("https://test.cases/")) {
|
|
83
|
+
const relativePath = (0, urlToRelativePath_1.default)(modulePath);
|
|
84
|
+
const absPath = node_path_1.default.join(currentDirectory, relativePath);
|
|
85
|
+
res = {
|
|
86
|
+
path: absPath,
|
|
87
|
+
content: node_fs_1.default.readFileSync(absPath, "utf-8"),
|
|
88
|
+
subPath: ""
|
|
89
|
+
};
|
|
90
|
+
}
|
|
80
91
|
else if (isRelativePath(modulePath)) {
|
|
81
92
|
const p = node_path_1.default.join(currentDirectory, modulePath);
|
|
82
93
|
res = {
|
|
@@ -92,15 +103,6 @@ class BasicRunner {
|
|
|
92
103
|
subPath: "absolute_path"
|
|
93
104
|
};
|
|
94
105
|
}
|
|
95
|
-
else if (modulePath.startsWith("https://test.cases/path/")) {
|
|
96
|
-
const relativePath = (0, urlToRelativePath_1.default)(modulePath);
|
|
97
|
-
const absPath = node_path_1.default.join(currentDirectory, relativePath);
|
|
98
|
-
res = {
|
|
99
|
-
path: absPath,
|
|
100
|
-
content: node_fs_1.default.readFileSync(absPath, "utf-8"),
|
|
101
|
-
subPath: ""
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
106
|
if (this._options.cachable && res) {
|
|
105
107
|
cached.set(cacheKey, res);
|
|
106
108
|
}
|
|
@@ -5,10 +5,12 @@ declare global {
|
|
|
5
5
|
var printLogger: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare class CommonJsRunner<T extends ECompilerType = ECompilerType.Rspack> extends BasicRunner<T> {
|
|
8
|
+
protected requireCache: any;
|
|
8
9
|
protected createGlobalContext(): IBasicGlobalContext;
|
|
9
10
|
protected createBaseModuleScope(): IBasicModuleScope;
|
|
10
11
|
protected createModuleScope(requireFn: TRunnerRequirer, m: TModuleObject, file: TBasicRunnerFile): IBasicModuleScope;
|
|
11
12
|
protected createRunner(): void;
|
|
12
13
|
protected createMissRequirer(): TRunnerRequirer;
|
|
14
|
+
protected createJsonRequirer(): TRunnerRequirer;
|
|
13
15
|
protected createCjsRequirer(): TRunnerRequirer;
|
|
14
16
|
}
|
|
@@ -4,14 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CommonJsRunner = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
9
|
const node_vm_1 = __importDefault(require("node:vm"));
|
|
9
10
|
const basic_1 = require("./basic");
|
|
10
|
-
const define = (...args) => {
|
|
11
|
-
const factory = args.pop();
|
|
12
|
-
factory();
|
|
13
|
-
};
|
|
14
11
|
class CommonJsRunner extends basic_1.BasicRunner {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.requireCache = Object.create(null);
|
|
15
|
+
}
|
|
15
16
|
createGlobalContext() {
|
|
16
17
|
return {
|
|
17
18
|
console: {
|
|
@@ -69,28 +70,35 @@ class CommonJsRunner extends basic_1.BasicRunner {
|
|
|
69
70
|
});
|
|
70
71
|
return m;
|
|
71
72
|
},
|
|
73
|
+
process,
|
|
74
|
+
URL,
|
|
75
|
+
Blob,
|
|
76
|
+
Symbol,
|
|
77
|
+
__MODE__: this._options.compilerOptions.mode,
|
|
72
78
|
__SNAPSHOT__: node_path_1.default.join(this._options.source, "__snapshot__"),
|
|
73
79
|
...this._options.env
|
|
74
80
|
};
|
|
75
81
|
return baseModuleScope;
|
|
76
82
|
}
|
|
77
83
|
createModuleScope(requireFn, m, file) {
|
|
84
|
+
const requirer = requireFn.bind(null, node_path_1.default.dirname(file.path));
|
|
85
|
+
requirer.webpackTestSuiteRequire = true;
|
|
78
86
|
return {
|
|
79
87
|
...this.baseModuleScope,
|
|
80
|
-
require:
|
|
88
|
+
require: requirer,
|
|
81
89
|
module: m,
|
|
82
90
|
exports: m.exports,
|
|
83
91
|
__dirname: node_path_1.default.dirname(file.path),
|
|
84
92
|
__filename: file.path,
|
|
85
93
|
_globalAssign: {
|
|
86
94
|
expect: this._options.env.expect
|
|
87
|
-
}
|
|
88
|
-
define
|
|
95
|
+
}
|
|
89
96
|
};
|
|
90
97
|
}
|
|
91
98
|
createRunner() {
|
|
92
99
|
this.requirers.set("miss", this.createMissRequirer());
|
|
93
100
|
this.requirers.set("entry", this.createCjsRequirer());
|
|
101
|
+
this.requirers.set("json", this.createJsonRequirer());
|
|
94
102
|
}
|
|
95
103
|
createMissRequirer() {
|
|
96
104
|
return (currentDirectory, modulePath, context = {}) => {
|
|
@@ -104,8 +112,19 @@ class CommonJsRunner extends basic_1.BasicRunner {
|
|
|
104
112
|
: modulePathStr);
|
|
105
113
|
};
|
|
106
114
|
}
|
|
115
|
+
createJsonRequirer() {
|
|
116
|
+
return (currentDirectory, modulePath, context = {}) => {
|
|
117
|
+
if (Array.isArray(modulePath)) {
|
|
118
|
+
throw new Error("Array module path is not supported in hot cases");
|
|
119
|
+
}
|
|
120
|
+
const file = context.file || this.getFile(modulePath, currentDirectory);
|
|
121
|
+
if (!file) {
|
|
122
|
+
return this.requirers.get("miss")(currentDirectory, modulePath);
|
|
123
|
+
}
|
|
124
|
+
return JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(this._options.dist, modulePath), "utf-8"));
|
|
125
|
+
};
|
|
126
|
+
}
|
|
107
127
|
createCjsRequirer() {
|
|
108
|
-
const requireCache = Object.create(null);
|
|
109
128
|
return (currentDirectory, modulePath, context = {}) => {
|
|
110
129
|
if (modulePath === "@rspack/test-tools") {
|
|
111
130
|
return require("@rspack/test-tools");
|
|
@@ -114,16 +133,20 @@ class CommonJsRunner extends basic_1.BasicRunner {
|
|
|
114
133
|
if (!file) {
|
|
115
134
|
return this.requirers.get("miss")(currentDirectory, modulePath);
|
|
116
135
|
}
|
|
117
|
-
if (file.path
|
|
118
|
-
return
|
|
136
|
+
if (file.path.endsWith(".json")) {
|
|
137
|
+
return this.requirers.get("json")(currentDirectory, modulePath, context);
|
|
138
|
+
}
|
|
139
|
+
if (file.path in this.requireCache) {
|
|
140
|
+
return this.requireCache[file.path].exports;
|
|
119
141
|
}
|
|
120
142
|
const m = {
|
|
121
|
-
exports: {}
|
|
143
|
+
exports: {},
|
|
144
|
+
webpackTestSuiteModule: true
|
|
122
145
|
};
|
|
123
|
-
requireCache[file.path] = m;
|
|
146
|
+
this.requireCache[file.path] = m;
|
|
124
147
|
const currentModuleScope = this.createModuleScope(this.getRequire(), m, file);
|
|
125
148
|
if (this._options.testConfig.moduleScope) {
|
|
126
|
-
this._options.testConfig.moduleScope(currentModuleScope);
|
|
149
|
+
this._options.testConfig.moduleScope(currentModuleScope, this._options.stats, this._options.compilerOptions);
|
|
127
150
|
}
|
|
128
151
|
if (!this._options.runInNewContext) {
|
|
129
152
|
file.content = `Object.assign(global, _globalAssign);\n ${file.content}`;
|
|
@@ -131,6 +154,12 @@ class CommonJsRunner extends basic_1.BasicRunner {
|
|
|
131
154
|
if (file.content.includes("__STATS__") && this._options.stats) {
|
|
132
155
|
currentModuleScope.__STATS__ = this._options.stats();
|
|
133
156
|
}
|
|
157
|
+
if (file.content.includes("__STATS_I__")) {
|
|
158
|
+
const statsIndex = this._options.stats?.()?.__index__;
|
|
159
|
+
if (typeof statsIndex === "number") {
|
|
160
|
+
currentModuleScope.__STATS_I__ = statsIndex;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
134
163
|
const args = Object.keys(currentModuleScope);
|
|
135
164
|
const argValues = args.map(arg => currentModuleScope[arg]);
|
|
136
165
|
const code = `(function(${args.join(", ")}) {
|