@rspack-canary/test-tools 1.6.0-canary-e28e40e9-20251022173516 → 1.6.0-canary-941e2203-20251024173714
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.js +1 -1
- package/dist/case/cache.js +5 -5
- package/dist/case/common.d.ts +1 -2
- package/dist/case/common.js +32 -26
- package/dist/case/compiler.js +5 -6
- package/dist/case/defaults.js +9 -9
- package/dist/case/diagnostic.js +4 -5
- package/dist/case/error.js +7 -8
- package/dist/case/example.js +2 -2
- package/dist/case/hash.js +1 -1
- package/dist/case/hook.js +3 -2
- package/dist/case/hot-step.js +4 -5
- package/dist/case/hot.js +6 -6
- package/dist/case/multi-compiler.js +3 -4
- package/dist/case/normal.js +1 -1
- package/dist/case/runner.js +12 -8
- package/dist/case/stats-api.js +4 -5
- package/dist/case/stats-output.js +1 -1
- package/dist/case/treeshaking.js +1 -1
- package/dist/case/watch.js +13 -13
- package/dist/compiler.d.ts +4 -3
- package/dist/compiler.js +113 -6
- package/dist/helper/index.d.ts +1 -0
- package/dist/helper/index.js +1 -0
- package/dist/helper/read-config-file.js +7 -0
- package/dist/helper/setup-env.js +1 -0
- package/dist/helper/stringify-config.d.ts +2 -0
- package/dist/helper/stringify-config.js +43 -0
- package/dist/runner/node/index.d.ts +4 -0
- package/dist/runner/node/index.js +83 -6
- package/dist/runner/web/index.d.ts +1 -0
- package/dist/runner/web/index.js +38 -50
- package/dist/test/context.d.ts +13 -14
- package/dist/test/context.js +44 -51
- package/dist/test/creator.js +1 -1
- package/dist/test/debug.d.ts +15 -0
- package/dist/test/debug.js +205 -0
- package/dist/test/tester.js +13 -4
- package/dist/type.d.ts +10 -10
- package/package.json +3 -2
package/dist/runner/web/index.js
CHANGED
|
@@ -13,7 +13,6 @@ const helper_1 = require("../../helper");
|
|
|
13
13
|
const EventSourceForNode_1 = __importDefault(require("../../helper/legacy/EventSourceForNode"));
|
|
14
14
|
const urlToRelativePath_1 = __importDefault(require("../../helper/legacy/urlToRelativePath"));
|
|
15
15
|
const node_1 = require("../node");
|
|
16
|
-
const EVAL_LOCATION_REGEX = /<anonymous>:(\d+)/;
|
|
17
16
|
// Compatibility code to suppress iconv-lite warnings
|
|
18
17
|
require("iconv-lite").skipDecodeWarning = true;
|
|
19
18
|
const FAKE_HOSTS = [
|
|
@@ -73,6 +72,7 @@ class WebRunner extends node_1.NodeRunner {
|
|
|
73
72
|
}
|
|
74
73
|
run(file) {
|
|
75
74
|
if (!file.endsWith(".js") && !file.endsWith(".mjs")) {
|
|
75
|
+
this.log(`css: ${file}`);
|
|
76
76
|
const cssElement = this.dom.window.document.createElement("link");
|
|
77
77
|
cssElement.href = file;
|
|
78
78
|
cssElement.rel = "stylesheet";
|
|
@@ -84,11 +84,15 @@ class WebRunner extends node_1.NodeRunner {
|
|
|
84
84
|
getGlobal(name) {
|
|
85
85
|
return this.globalContext[name];
|
|
86
86
|
}
|
|
87
|
+
log(message) {
|
|
88
|
+
this._options.logs?.push(`[WebRunner] ${message}`);
|
|
89
|
+
}
|
|
87
90
|
createResourceLoader() {
|
|
88
91
|
const that = this;
|
|
89
92
|
class CustomResourceLoader extends jsdom_1.ResourceLoader {
|
|
90
93
|
fetch(url, _) {
|
|
91
94
|
const filePath = that.urlToPath(url);
|
|
95
|
+
that.log(`resource loader: ${url} -> ${filePath}`);
|
|
92
96
|
let finalCode;
|
|
93
97
|
if (node_path_1.default.extname(filePath) === ".js") {
|
|
94
98
|
const currentDirectory = node_path_1.default.dirname(filePath);
|
|
@@ -139,7 +143,9 @@ class WebRunner extends node_1.NodeRunner {
|
|
|
139
143
|
moduleScope.EventSource = EventSourceForNode_1.default;
|
|
140
144
|
moduleScope.fetch = async (url) => {
|
|
141
145
|
try {
|
|
142
|
-
const
|
|
146
|
+
const filePath = this.urlToPath(url);
|
|
147
|
+
this.log(`fetch: ${url} -> ${filePath}`);
|
|
148
|
+
const buffer = await new Promise((resolve, reject) => node_fs_1.default.readFile(filePath, (err, b) => (err ? reject(err) : resolve(b))));
|
|
143
149
|
return {
|
|
144
150
|
status: 200,
|
|
145
151
|
ok: true,
|
|
@@ -158,8 +164,9 @@ class WebRunner extends node_1.NodeRunner {
|
|
|
158
164
|
};
|
|
159
165
|
moduleScope.URL = URL;
|
|
160
166
|
moduleScope.importScripts = (url) => {
|
|
161
|
-
|
|
162
|
-
this.
|
|
167
|
+
const path = (0, urlToRelativePath_1.default)(url);
|
|
168
|
+
this.log(`importScripts: ${url} -> ${path}`);
|
|
169
|
+
this.requirers.get("entry")(this._options.dist, path);
|
|
163
170
|
};
|
|
164
171
|
moduleScope.getComputedStyle = (element) => {
|
|
165
172
|
const computedStyle = this.dom.window.getComputedStyle(element);
|
|
@@ -195,51 +202,7 @@ class WebRunner extends node_1.NodeRunner {
|
|
|
195
202
|
currentModuleScope.__STATS_I__ = statsIndex;
|
|
196
203
|
}
|
|
197
204
|
}
|
|
198
|
-
const
|
|
199
|
-
const match = (e.stack || e.message).match(EVAL_LOCATION_REGEX);
|
|
200
|
-
if (match) {
|
|
201
|
-
const [, line] = match;
|
|
202
|
-
const realLine = Number(line) - 34;
|
|
203
|
-
const codeLines = file.content.split("\n");
|
|
204
|
-
const lineContents = [
|
|
205
|
-
...codeLines
|
|
206
|
-
.slice(Math.max(0, realLine - 3), Math.max(0, realLine - 1))
|
|
207
|
-
.map(line => `│ ${line}`),
|
|
208
|
-
`│> ${codeLines[realLine - 1]}`,
|
|
209
|
-
...codeLines.slice(realLine, realLine + 2).map(line => `│ ${line}`)
|
|
210
|
-
];
|
|
211
|
-
const message = `Error in JSDOM when running file '${file.path}' at line ${realLine}: ${e.message}\n${lineContents.join("\n")}`;
|
|
212
|
-
const finalError = new Error(message);
|
|
213
|
-
finalError.stack = undefined;
|
|
214
|
-
return finalError;
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
return e;
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
const originIt = currentModuleScope.it;
|
|
221
|
-
currentModuleScope.it = (description, fn) => {
|
|
222
|
-
originIt(description, async () => {
|
|
223
|
-
try {
|
|
224
|
-
await fn();
|
|
225
|
-
}
|
|
226
|
-
catch (err) {
|
|
227
|
-
throw createLocatedError(err, file);
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
};
|
|
231
|
-
const scopeKey = (0, helper_1.escapeSep)(file.path);
|
|
232
|
-
const args = Object.keys(currentModuleScope).filter(arg => !["window", "self", "globalThis", "console"].includes(arg));
|
|
233
|
-
const argValues = args
|
|
234
|
-
.map(arg => `window["${scopeKey}"]["${arg}"]`)
|
|
235
|
-
.join(", ");
|
|
236
|
-
this.dom.window[scopeKey] = currentModuleScope;
|
|
237
|
-
this.dom.window["__GLOBAL_SHARED__"] = this.globalContext;
|
|
238
|
-
this.dom.window["__FILE__"] = file;
|
|
239
|
-
this.dom.window["__CREATE_LOCATED_ERROR__"] = createLocatedError;
|
|
240
|
-
return [
|
|
241
|
-
m,
|
|
242
|
-
`// hijack document.currentScript for auto public path
|
|
205
|
+
const proxyCode = `// hijack document.currentScript for auto public path
|
|
243
206
|
var $$g$$ = new Proxy(window, {
|
|
244
207
|
get(target, prop, receiver) {
|
|
245
208
|
if (prop === "document") {
|
|
@@ -270,7 +233,31 @@ class WebRunner extends node_1.NodeRunner {
|
|
|
270
233
|
}
|
|
271
234
|
return Reflect.set(target, prop, value, receiver);
|
|
272
235
|
}
|
|
273
|
-
})
|
|
236
|
+
});`;
|
|
237
|
+
const createJSDOMLocatedError = (0, node_1.createLocatedError)(this._options.errors || [], proxyCode.split("\n").length + 2);
|
|
238
|
+
const originIt = currentModuleScope.it;
|
|
239
|
+
currentModuleScope.it = (description, fn) => {
|
|
240
|
+
originIt(description, async () => {
|
|
241
|
+
try {
|
|
242
|
+
await fn();
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
throw createJSDOMLocatedError(err, file);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
const scopeKey = (0, helper_1.escapeSep)(file.path);
|
|
250
|
+
const args = Object.keys(currentModuleScope).filter(arg => !["window", "self", "globalThis", "console"].includes(arg));
|
|
251
|
+
const argValues = args
|
|
252
|
+
.map(arg => `window["${scopeKey}"]["${arg}"]`)
|
|
253
|
+
.join(", ");
|
|
254
|
+
this.dom.window[scopeKey] = currentModuleScope;
|
|
255
|
+
this.dom.window["__GLOBAL_SHARED__"] = this.globalContext;
|
|
256
|
+
this.dom.window["__FILE__"] = file;
|
|
257
|
+
this.dom.window["__CREATE_LOCATED_ERROR__"] = createJSDOMLocatedError;
|
|
258
|
+
return [
|
|
259
|
+
m,
|
|
260
|
+
`${proxyCode}
|
|
274
261
|
(function(window, self, globalThis, console, ${args.join(", ")}) {
|
|
275
262
|
try {
|
|
276
263
|
${file.content}
|
|
@@ -283,6 +270,7 @@ class WebRunner extends node_1.NodeRunner {
|
|
|
283
270
|
createJSDOMRequirer() {
|
|
284
271
|
return (currentDirectory, modulePath, context = {}) => {
|
|
285
272
|
const file = context.file || this.getFile(modulePath, currentDirectory);
|
|
273
|
+
this.log(`jsdom: ${modulePath} -> ${file?.path}`);
|
|
286
274
|
if (!file) {
|
|
287
275
|
return this.requirers.get("miss")(currentDirectory, modulePath);
|
|
288
276
|
}
|
package/dist/test/context.d.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import type { ITestCompilerManager, ITestContext, ITestEnv, ITesterConfig, ITestRunner, TTestConfig } from "../type";
|
|
2
|
-
export type TTestContextOptions = Omit<ITesterConfig, "
|
|
2
|
+
export type TTestContextOptions = Omit<ITesterConfig, "steps">;
|
|
3
3
|
export declare class TestContext implements ITestContext {
|
|
4
4
|
private config;
|
|
5
|
-
protected errors:
|
|
6
|
-
protected
|
|
7
|
-
protected store: Map<string,
|
|
5
|
+
protected errors: Error[];
|
|
6
|
+
protected compiler: ITestCompilerManager | null;
|
|
7
|
+
protected store: Map<string, unknown>;
|
|
8
8
|
protected runners: Map<string, ITestRunner>;
|
|
9
9
|
constructor(config: TTestContextOptions);
|
|
10
10
|
getSource(sub?: string): string;
|
|
11
11
|
getDist(sub?: string): string;
|
|
12
12
|
getTemp(sub?: string): string | null;
|
|
13
|
-
getCompiler(
|
|
14
|
-
getRunner(
|
|
13
|
+
getCompiler(): ITestCompilerManager;
|
|
14
|
+
getRunner(file: string, env: ITestEnv): ITestRunner;
|
|
15
15
|
getTestConfig(): TTestConfig;
|
|
16
|
-
setValue<T>(
|
|
17
|
-
getValue<T>(
|
|
18
|
-
hasError(
|
|
19
|
-
emitError(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
closeCompiler(name: string): Promise<void>;
|
|
16
|
+
setValue<T>(key: string, value: T): void;
|
|
17
|
+
getValue<T>(key: string): T | void;
|
|
18
|
+
hasError(): boolean;
|
|
19
|
+
emitError(err: Error | string): void;
|
|
20
|
+
getError(): Error[];
|
|
21
|
+
clearError(): void;
|
|
22
|
+
closeCompiler(): Promise<void>;
|
|
24
23
|
}
|
package/dist/test/context.js
CHANGED
|
@@ -6,11 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.TestContext = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const compiler_1 = require("../compiler");
|
|
9
|
+
const debug_1 = require("./debug");
|
|
9
10
|
class TestContext {
|
|
10
11
|
constructor(config) {
|
|
11
12
|
this.config = config;
|
|
12
|
-
this.errors =
|
|
13
|
-
this.
|
|
13
|
+
this.errors = [];
|
|
14
|
+
this.compiler = null;
|
|
14
15
|
this.store = new Map();
|
|
15
16
|
this.runners = new Map();
|
|
16
17
|
}
|
|
@@ -34,76 +35,68 @@ class TestContext {
|
|
|
34
35
|
}
|
|
35
36
|
return this.config.temp;
|
|
36
37
|
}
|
|
37
|
-
getCompiler(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
compiler = new compiler_1.TestCompilerManager();
|
|
41
|
-
this.compilers.set(name, compiler);
|
|
38
|
+
getCompiler() {
|
|
39
|
+
if (!this.compiler) {
|
|
40
|
+
this.compiler = new compiler_1.TestCompilerManager(this);
|
|
42
41
|
}
|
|
43
|
-
return compiler;
|
|
42
|
+
return this.compiler;
|
|
44
43
|
}
|
|
45
|
-
getRunner(
|
|
44
|
+
getRunner(file, env) {
|
|
46
45
|
if (!this.config.runnerCreator) {
|
|
47
46
|
throw new Error("TestContext: Runner creator not found");
|
|
48
47
|
}
|
|
49
|
-
const runnerKey = this.config.runnerCreator.key(this, name, file);
|
|
48
|
+
const runnerKey = this.config.runnerCreator.key(this, this.config.name, file);
|
|
50
49
|
let runner = this.runners.get(runnerKey);
|
|
51
50
|
if (runner) {
|
|
51
|
+
if (__DEBUG__) {
|
|
52
|
+
const getRunnerInfo = this.getValue(debug_1.DEBUG_SCOPES.RunGetRunner) || {};
|
|
53
|
+
getRunnerInfo[file] = {
|
|
54
|
+
runnerKey,
|
|
55
|
+
reused: true,
|
|
56
|
+
runnerType: runner.constructor.name
|
|
57
|
+
};
|
|
58
|
+
this.setValue(debug_1.DEBUG_SCOPES.RunGetRunner, getRunnerInfo);
|
|
59
|
+
}
|
|
52
60
|
return runner;
|
|
53
61
|
}
|
|
54
|
-
runner = this.config.runnerCreator.runner(this, name, file, env);
|
|
62
|
+
runner = this.config.runnerCreator.runner(this, this.config.name, file, env);
|
|
63
|
+
runner.__key__ = runnerKey;
|
|
64
|
+
if (__DEBUG__) {
|
|
65
|
+
const getRunnerInfo = this.getValue(debug_1.DEBUG_SCOPES.RunGetRunner) || {};
|
|
66
|
+
getRunnerInfo[file] = {
|
|
67
|
+
runnerKey,
|
|
68
|
+
reused: false,
|
|
69
|
+
runnerType: runner.constructor.name
|
|
70
|
+
};
|
|
71
|
+
this.setValue(debug_1.DEBUG_SCOPES.RunGetRunner, getRunnerInfo);
|
|
72
|
+
}
|
|
55
73
|
this.runners.set(runnerKey, runner);
|
|
56
74
|
return runner;
|
|
57
75
|
}
|
|
58
76
|
getTestConfig() {
|
|
59
77
|
return this.config.testConfig || {};
|
|
60
78
|
}
|
|
61
|
-
setValue(
|
|
62
|
-
|
|
63
|
-
this.store.set(name, {});
|
|
64
|
-
}
|
|
65
|
-
const scope = this.store.get(name);
|
|
66
|
-
scope[key] = value;
|
|
67
|
-
}
|
|
68
|
-
getValue(name, key) {
|
|
69
|
-
if (!this.store.has(name)) {
|
|
70
|
-
this.store.set(name, {});
|
|
71
|
-
}
|
|
72
|
-
const scope = this.store.get(name);
|
|
73
|
-
return scope[key];
|
|
79
|
+
setValue(key, value) {
|
|
80
|
+
this.store.set(key, value);
|
|
74
81
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return this.getError(name).length > 0;
|
|
78
|
-
}
|
|
79
|
-
return !!Array.from(this.errors.values()).reduce((res, arr) => res + arr.length, 0);
|
|
82
|
+
getValue(key) {
|
|
83
|
+
return this.store.get(key);
|
|
80
84
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
errors.push(typeof err === "string" ? new Error(err) : err);
|
|
84
|
-
this.errors.set(name, errors);
|
|
85
|
+
hasError() {
|
|
86
|
+
return this.errors.length > 0;
|
|
85
87
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
emitError(err) {
|
|
89
|
+
this.errors.push(typeof err === "string" ? new Error(err) : err);
|
|
88
90
|
}
|
|
89
|
-
getError(
|
|
90
|
-
|
|
91
|
-
return this.errors.get(name) || [];
|
|
92
|
-
}
|
|
93
|
-
return Array.prototype.concat(...this.errors.values());
|
|
91
|
+
getError() {
|
|
92
|
+
return this.errors;
|
|
94
93
|
}
|
|
95
|
-
clearError(
|
|
96
|
-
|
|
97
|
-
this.errors.delete(name);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
this.errors.clear();
|
|
101
|
-
}
|
|
94
|
+
clearError() {
|
|
95
|
+
this.errors.length = 0;
|
|
102
96
|
}
|
|
103
|
-
async closeCompiler(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
await compiler.close();
|
|
97
|
+
async closeCompiler() {
|
|
98
|
+
if (this.compiler) {
|
|
99
|
+
await this.compiler.close();
|
|
107
100
|
}
|
|
108
101
|
}
|
|
109
102
|
}
|
package/dist/test/creator.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ITestContext } from "../type";
|
|
2
|
+
export declare function generateDebugReport(context: ITestContext): void;
|
|
3
|
+
export declare const DEBUG_SCOPES: {
|
|
4
|
+
CompilerOptionsReadConfigFile: string;
|
|
5
|
+
CompilerOptionsFinalOptions: string;
|
|
6
|
+
CreateCompilerInstance: string;
|
|
7
|
+
CreateCompilerSetProperties: string;
|
|
8
|
+
BuildMethod: string;
|
|
9
|
+
BuildError: string;
|
|
10
|
+
BuildWarning: string;
|
|
11
|
+
RunFindBundle: string;
|
|
12
|
+
RunGetRunner: string;
|
|
13
|
+
RunLogs: string;
|
|
14
|
+
RunErrors: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1,205 @@
|
|
|
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.DEBUG_SCOPES = void 0;
|
|
7
|
+
exports.generateDebugReport = generateDebugReport;
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const javascript_stringify_1 = require("javascript-stringify");
|
|
11
|
+
const stringify_config_1 = __importDefault(require("../helper/stringify-config"));
|
|
12
|
+
function generateDebugReport(context) {
|
|
13
|
+
const report = `
|
|
14
|
+
## Case Meta
|
|
15
|
+
|
|
16
|
+
${generateCaseMetaPathReport(context)}
|
|
17
|
+
|
|
18
|
+
${generateCaseMetaTestConfigReport(context)}
|
|
19
|
+
|
|
20
|
+
## Compiler Options
|
|
21
|
+
|
|
22
|
+
${generateReadConfigFileReport(context)}
|
|
23
|
+
|
|
24
|
+
${generateFinalOptionsReport(context)}
|
|
25
|
+
|
|
26
|
+
## Create Compiler
|
|
27
|
+
|
|
28
|
+
${generateCreateCompilerInstanceReport(context)}
|
|
29
|
+
|
|
30
|
+
${generateCreateCompilerSetPropertiesReport(context)}
|
|
31
|
+
|
|
32
|
+
## Build
|
|
33
|
+
|
|
34
|
+
${generateBuildMethodReport(context)}
|
|
35
|
+
|
|
36
|
+
${generateBuildErrorReport(context)}
|
|
37
|
+
|
|
38
|
+
${generateBuildWarningReport(context)}
|
|
39
|
+
|
|
40
|
+
## Run
|
|
41
|
+
|
|
42
|
+
${generateRunFindBundleReport(context)}
|
|
43
|
+
|
|
44
|
+
${generateRunGetRunnerReport(context)}
|
|
45
|
+
|
|
46
|
+
${generateRunLogsReport(context)}
|
|
47
|
+
|
|
48
|
+
${generateRunErrorsReport(context)}
|
|
49
|
+
|
|
50
|
+
`;
|
|
51
|
+
const dist = context.getDist("debug.md");
|
|
52
|
+
fs_extra_1.default.ensureDirSync(node_path_1.default.dirname(dist));
|
|
53
|
+
fs_extra_1.default.writeFileSync(dist, report);
|
|
54
|
+
}
|
|
55
|
+
function generateCaseMetaPathReport(context) {
|
|
56
|
+
return `
|
|
57
|
+
### Case Path
|
|
58
|
+
|
|
59
|
+
- Source: ${context.getSource()}
|
|
60
|
+
- Dist: ${context.getDist()}
|
|
61
|
+
- Temp: ${context.getTemp()}
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
function generateCaseMetaTestConfigReport(context) {
|
|
65
|
+
return `
|
|
66
|
+
### Test Config
|
|
67
|
+
|
|
68
|
+
\`\`\`js
|
|
69
|
+
// ${node_path_1.default.resolve(context.getSource(), "./test.config.js")}
|
|
70
|
+
${(0, javascript_stringify_1.stringify)(context.getTestConfig(), null, 2)}
|
|
71
|
+
\`\`\`
|
|
72
|
+
`;
|
|
73
|
+
}
|
|
74
|
+
function generateReadConfigFileReport(context) {
|
|
75
|
+
const configFileInfo = context.getValue(exports.DEBUG_SCOPES.CompilerOptionsReadConfigFile);
|
|
76
|
+
if (!configFileInfo)
|
|
77
|
+
return "";
|
|
78
|
+
return `
|
|
79
|
+
### Read Config File
|
|
80
|
+
|
|
81
|
+
\`\`\`js
|
|
82
|
+
// ${configFileInfo.file}
|
|
83
|
+
${(0, stringify_config_1.default)(configFileInfo.config)}
|
|
84
|
+
\`\`\`
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
87
|
+
function generateFinalOptionsReport(context) {
|
|
88
|
+
const finalOptions = context.getCompiler().getOptions();
|
|
89
|
+
return `
|
|
90
|
+
### Final Options
|
|
91
|
+
|
|
92
|
+
\`\`\`js
|
|
93
|
+
${(0, stringify_config_1.default)(finalOptions)}
|
|
94
|
+
\`\`\`
|
|
95
|
+
`;
|
|
96
|
+
}
|
|
97
|
+
function generateCreateCompilerInstanceReport(context) {
|
|
98
|
+
const instanceInfo = context.getValue(exports.DEBUG_SCOPES.CreateCompilerInstance);
|
|
99
|
+
if (!instanceInfo)
|
|
100
|
+
return "";
|
|
101
|
+
return `
|
|
102
|
+
### Create Compiler Instance
|
|
103
|
+
|
|
104
|
+
- Rspack Path: ${instanceInfo.path}
|
|
105
|
+
- Callback Mode: ${instanceInfo.mode}
|
|
106
|
+
`;
|
|
107
|
+
}
|
|
108
|
+
function generateCreateCompilerSetPropertiesReport(context) {
|
|
109
|
+
const setPropertiesInfo = context.getValue(exports.DEBUG_SCOPES.CreateCompilerSetProperties);
|
|
110
|
+
if (!setPropertiesInfo || setPropertiesInfo.length === 0)
|
|
111
|
+
return "";
|
|
112
|
+
return `
|
|
113
|
+
### Set Properties
|
|
114
|
+
|
|
115
|
+
${setPropertiesInfo.map(p => `- ${p}`).join("\n")}
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
function generateBuildMethodReport(context) {
|
|
119
|
+
const buildMethod = context.getValue(exports.DEBUG_SCOPES.BuildMethod);
|
|
120
|
+
if (!buildMethod)
|
|
121
|
+
return "";
|
|
122
|
+
return `
|
|
123
|
+
### Build Method
|
|
124
|
+
|
|
125
|
+
- Method: \`compiler.${buildMethod.method}()\`
|
|
126
|
+
${buildMethod.options ? `- Options:\n\`\`\`js\n${(0, javascript_stringify_1.stringify)(buildMethod.options, null, 2)}\n\`\`\`` : ""}
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
function generateBuildErrorReport(context) {
|
|
130
|
+
const buildError = context.getValue(exports.DEBUG_SCOPES.BuildError);
|
|
131
|
+
if (!buildError)
|
|
132
|
+
return "";
|
|
133
|
+
return `
|
|
134
|
+
### Build Error
|
|
135
|
+
|
|
136
|
+
type: ${buildError.type}
|
|
137
|
+
|
|
138
|
+
${buildError.errors.map(e => `\`\`\`\n// message:\n${e.message}\n// stack:\n${e.stack}\n\`\`\``).join("\n\n")}
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
function generateBuildWarningReport(context) {
|
|
142
|
+
const buildWarning = context.getValue(exports.DEBUG_SCOPES.BuildWarning);
|
|
143
|
+
if (!buildWarning)
|
|
144
|
+
return "";
|
|
145
|
+
return `
|
|
146
|
+
### Build Warning
|
|
147
|
+
|
|
148
|
+
${buildWarning.map(w => `\`\`\`\n// message:\n${w.message}\n// stack:\n${w.stack}\n\`\`\``).join("\n\n")}
|
|
149
|
+
`;
|
|
150
|
+
}
|
|
151
|
+
function generateRunFindBundleReport(context) {
|
|
152
|
+
const runFindBundle = context.getValue(exports.DEBUG_SCOPES.RunFindBundle);
|
|
153
|
+
if (!runFindBundle)
|
|
154
|
+
return "";
|
|
155
|
+
return `
|
|
156
|
+
### Find Bundle
|
|
157
|
+
|
|
158
|
+
${runFindBundle.map(b => `- ${context.getDist(b)}`).join("\n")}
|
|
159
|
+
`;
|
|
160
|
+
}
|
|
161
|
+
function generateRunGetRunnerReport(context) {
|
|
162
|
+
const getRunnerInfo = context.getValue(exports.DEBUG_SCOPES.RunGetRunner);
|
|
163
|
+
if (!getRunnerInfo)
|
|
164
|
+
return "";
|
|
165
|
+
return `
|
|
166
|
+
### Get Runner
|
|
167
|
+
|
|
168
|
+
${Object.entries(getRunnerInfo)
|
|
169
|
+
.map(([file, info]) => `- ${file}: ${info.runnerKey} (Reused: ${info.reused}, Type: \`${info.runnerType}\`)`)
|
|
170
|
+
.join("\n")}
|
|
171
|
+
`;
|
|
172
|
+
}
|
|
173
|
+
function generateRunLogsReport(context) {
|
|
174
|
+
const runLogs = context.getValue(exports.DEBUG_SCOPES.RunLogs);
|
|
175
|
+
if (!runLogs)
|
|
176
|
+
return "";
|
|
177
|
+
return `
|
|
178
|
+
### Run Logs
|
|
179
|
+
|
|
180
|
+
${runLogs.map(l => `- ${l}`).join("\n")}
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
183
|
+
function generateRunErrorsReport(context) {
|
|
184
|
+
const runErrors = context.getValue(exports.DEBUG_SCOPES.RunErrors);
|
|
185
|
+
if (!runErrors)
|
|
186
|
+
return "";
|
|
187
|
+
return `
|
|
188
|
+
### Run Errors
|
|
189
|
+
|
|
190
|
+
${runErrors.map(e => `\`\`\`\n// message:\n${e.message}\n// stack:\n${e.stack}\n\`\`\``).join("\n\n")}
|
|
191
|
+
`;
|
|
192
|
+
}
|
|
193
|
+
exports.DEBUG_SCOPES = {
|
|
194
|
+
CompilerOptionsReadConfigFile: "compiler-options:read-config-file",
|
|
195
|
+
CompilerOptionsFinalOptions: "compiler-options:final-options",
|
|
196
|
+
CreateCompilerInstance: "create-compiler:instance",
|
|
197
|
+
CreateCompilerSetProperties: "create-compiler:set-properties",
|
|
198
|
+
BuildMethod: "build:method",
|
|
199
|
+
BuildError: "build:error",
|
|
200
|
+
BuildWarning: "build:warning",
|
|
201
|
+
RunFindBundle: "run:find-bundle",
|
|
202
|
+
RunGetRunner: "run:get-runner",
|
|
203
|
+
RunLogs: "run:logs",
|
|
204
|
+
RunErrors: "run:errors"
|
|
205
|
+
};
|
package/dist/test/tester.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Tester = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const context_1 = require("./context");
|
|
9
|
+
const debug_1 = require("./debug");
|
|
9
10
|
class Tester {
|
|
10
11
|
constructor(config) {
|
|
11
12
|
this.config = config;
|
|
@@ -20,7 +21,7 @@ class Tester {
|
|
|
20
21
|
this.total = config.steps?.length || 0;
|
|
21
22
|
if (config.contextValue) {
|
|
22
23
|
for (const [key, value] of Array.from(Object.entries(config.contextValue))) {
|
|
23
|
-
this.context.setValue(
|
|
24
|
+
this.context.setValue(key, value);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -79,11 +80,19 @@ class Tester {
|
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
try {
|
|
82
|
-
await this.context.closeCompiler(
|
|
83
|
+
await this.context.closeCompiler();
|
|
83
84
|
}
|
|
84
85
|
catch (e) {
|
|
85
86
|
console.warn(`Error occured while closing compilers of '${this.config.name}':\n${e.stack}`);
|
|
86
87
|
}
|
|
88
|
+
if (__DEBUG__) {
|
|
89
|
+
try {
|
|
90
|
+
(0, debug_1.generateDebugReport)(this.context);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
console.warn(`Generate debug report failed: ${e.message}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
87
96
|
}
|
|
88
97
|
async runStepMethods(step, methods, force = false) {
|
|
89
98
|
for (const i of methods) {
|
|
@@ -94,7 +103,7 @@ class Tester {
|
|
|
94
103
|
await step[i](this.context);
|
|
95
104
|
}
|
|
96
105
|
catch (e) {
|
|
97
|
-
this.context.emitError(
|
|
106
|
+
this.context.emitError(e);
|
|
98
107
|
}
|
|
99
108
|
}
|
|
100
109
|
}
|
|
@@ -108,7 +117,7 @@ class Tester {
|
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
119
|
catch (e) {
|
|
111
|
-
const errors = this.context.getError(
|
|
120
|
+
const errors = this.context.getError();
|
|
112
121
|
console.error(new Error([...errors, e].map(e => e.message).join("\n")));
|
|
113
122
|
throw e;
|
|
114
123
|
}
|
package/dist/type.d.ts
CHANGED
|
@@ -4,17 +4,16 @@ export interface ITestContext {
|
|
|
4
4
|
getSource(sub?: string): string;
|
|
5
5
|
getDist(sub?: string): string;
|
|
6
6
|
getTemp(sub?: string): string | null;
|
|
7
|
-
getCompiler(
|
|
8
|
-
closeCompiler(
|
|
7
|
+
getCompiler(): ITestCompilerManager;
|
|
8
|
+
closeCompiler(): Promise<void>;
|
|
9
9
|
getTestConfig(): TTestConfig;
|
|
10
|
-
getRunner(
|
|
11
|
-
setValue<T>(
|
|
12
|
-
getValue<T>(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
clearError(name?: string): void;
|
|
10
|
+
getRunner(file: string, env: ITestEnv): ITestRunner;
|
|
11
|
+
setValue<T>(key: string, value: T): void;
|
|
12
|
+
getValue<T>(key: string): T | void;
|
|
13
|
+
hasError(): boolean;
|
|
14
|
+
emitError(err: Error | string): void;
|
|
15
|
+
getError(): Error[];
|
|
16
|
+
clearError(): void;
|
|
18
17
|
}
|
|
19
18
|
export interface ITestCompilerManager {
|
|
20
19
|
getOptions(): RspackOptions;
|
|
@@ -189,6 +188,7 @@ export type TTestRunnerCreator = {
|
|
|
189
188
|
runner: (context: ITestContext, name: string, file: string, env: ITestEnv) => ITestRunner;
|
|
190
189
|
};
|
|
191
190
|
declare global {
|
|
191
|
+
var __DEBUG__: boolean;
|
|
192
192
|
var __TEST_PATH__: string;
|
|
193
193
|
var __TEST_FIXTURES_PATH__: string;
|
|
194
194
|
var __TEST_DIST_PATH__: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack-canary/test-tools",
|
|
3
|
-
"version": "1.6.0-canary-
|
|
3
|
+
"version": "1.6.0-canary-941e2203-20251024173714",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"filenamify": "4.3.0",
|
|
46
46
|
"fs-extra": "^11.3.2",
|
|
47
47
|
"iconv-lite": "^0.6.3",
|
|
48
|
+
"javascript-stringify": "^2.1.0",
|
|
48
49
|
"jest-diff": "^29.7.0",
|
|
49
50
|
"jest-snapshot": "29.7.0",
|
|
50
51
|
"jest-environment-node": "29.7.0",
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
"@types/jsdom": "^21.1.7",
|
|
68
69
|
"typescript": "^5.9.3",
|
|
69
70
|
"wast-loader": "^1.14.1",
|
|
70
|
-
"@rspack/core": "npm:@rspack-canary/core@1.6.0-canary-
|
|
71
|
+
"@rspack/core": "npm:@rspack-canary/core@1.6.0-canary-941e2203-20251024173714"
|
|
71
72
|
},
|
|
72
73
|
"peerDependencies": {
|
|
73
74
|
"@rspack/core": ">=1.0.0"
|