@rspack-canary/test-tools 1.6.0-canary-6cd722f4-20251022123039 → 1.6.0-canary-4ad8b49f-20251023175711
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 +3 -2
- package/dist/case/builtin.js +1 -1
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +9 -6
- package/dist/case/common.d.ts +10 -10
- package/dist/case/common.js +33 -30
- package/dist/case/compiler.d.ts +9 -8
- package/dist/case/compiler.js +5 -6
- package/dist/case/config.d.ts +6 -5
- package/dist/case/defaults.d.ts +5 -4
- package/dist/case/defaults.js +10 -10
- package/dist/case/diagnostic.js +4 -5
- package/dist/case/error.d.ts +5 -5
- package/dist/case/error.js +7 -8
- package/dist/case/example.js +2 -2
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +1 -1
- package/dist/case/hook.d.ts +4 -3
- package/dist/case/hook.js +3 -2
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +4 -6
- package/dist/case/hot.d.ts +5 -4
- package/dist/case/hot.js +6 -6
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/index.d.ts +0 -1
- package/dist/case/index.js +1 -3
- package/dist/case/multi-compiler.d.ts +9 -8
- package/dist/case/multi-compiler.js +3 -4
- package/dist/case/normal.js +1 -1
- package/dist/case/runner.d.ts +5 -4
- package/dist/case/runner.js +12 -8
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/stats-api.d.ts +6 -5
- package/dist/case/stats-api.js +5 -7
- package/dist/case/stats-output.d.ts +3 -2
- package/dist/case/stats-output.js +1 -1
- package/dist/case/treeshaking.js +1 -1
- package/dist/case/watch.d.ts +6 -6
- package/dist/case/watch.js +15 -14
- package/dist/compiler.d.ts +16 -17
- package/dist/compiler.js +116 -16
- package/dist/helper/index.d.ts +1 -0
- package/dist/helper/index.js +1 -0
- package/dist/helper/legacy/checkArrayExpectation.js +1 -1
- package/dist/helper/read-config-file.d.ts +3 -2
- 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/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/plugin/index.d.ts +0 -3
- package/dist/plugin/index.js +0 -3
- package/dist/runner/node/index.d.ts +13 -8
- package/dist/runner/node/index.js +86 -7
- package/dist/runner/web/index.d.ts +6 -5
- package/dist/runner/web/index.js +38 -50
- package/dist/test/context.d.ts +15 -16
- package/dist/test/context.js +44 -59
- package/dist/test/creator.d.ts +14 -14
- package/dist/test/creator.js +4 -5
- 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 +37 -50
- package/dist/type.js +1 -6
- package/package.json +5 -9
- package/dist/case/diff.d.ts +0 -19
- package/dist/case/diff.js +0 -274
- 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 -178
- package/dist/compare/format-code.d.ts +0 -16
- package/dist/compare/format-code.js +0 -244
- 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/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/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/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
|
-
import {
|
|
2
|
-
export type TTestContextOptions = Omit<ITesterConfig, "
|
|
1
|
+
import type { ITestCompilerManager, ITestContext, ITestEnv, ITesterConfig, ITestRunner, TTestConfig } from "../type";
|
|
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(
|
|
15
|
-
getTestConfig
|
|
16
|
-
setValue<T>(
|
|
17
|
-
getValue<T>(
|
|
18
|
-
hasError(
|
|
19
|
-
emitError(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
closeCompiler(name: string): Promise<void>;
|
|
13
|
+
getCompiler(): ITestCompilerManager;
|
|
14
|
+
getRunner(file: string, env: ITestEnv): ITestRunner;
|
|
15
|
+
getTestConfig(): TTestConfig;
|
|
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,12 +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
|
|
9
|
+
const debug_1 = require("./debug");
|
|
10
10
|
class TestContext {
|
|
11
11
|
constructor(config) {
|
|
12
12
|
this.config = config;
|
|
13
|
-
this.errors =
|
|
14
|
-
this.
|
|
13
|
+
this.errors = [];
|
|
14
|
+
this.compiler = null;
|
|
15
15
|
this.store = new Map();
|
|
16
16
|
this.runners = new Map();
|
|
17
17
|
}
|
|
@@ -35,83 +35,68 @@ class TestContext {
|
|
|
35
35
|
}
|
|
36
36
|
return this.config.temp;
|
|
37
37
|
}
|
|
38
|
-
getCompiler(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (!type) {
|
|
42
|
-
throw new Error("Compiler does not exists");
|
|
43
|
-
}
|
|
44
|
-
compiler = new compiler_1.TestCompilerManager(type, this.config.compilerFactories);
|
|
45
|
-
this.compilers.set(name, compiler);
|
|
38
|
+
getCompiler() {
|
|
39
|
+
if (!this.compiler) {
|
|
40
|
+
this.compiler = new compiler_1.TestCompilerManager(this);
|
|
46
41
|
}
|
|
47
|
-
return compiler;
|
|
42
|
+
return this.compiler;
|
|
48
43
|
}
|
|
49
|
-
getRunner(
|
|
44
|
+
getRunner(file, env) {
|
|
50
45
|
if (!this.config.runnerCreator) {
|
|
51
46
|
throw new Error("TestContext: Runner creator not found");
|
|
52
47
|
}
|
|
53
|
-
const runnerKey = this.config.runnerCreator.key(this, name, file);
|
|
48
|
+
const runnerKey = this.config.runnerCreator.key(this, this.config.name, file);
|
|
54
49
|
let runner = this.runners.get(runnerKey);
|
|
55
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
|
+
}
|
|
56
60
|
return runner;
|
|
57
61
|
}
|
|
58
|
-
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
|
+
}
|
|
59
73
|
this.runners.set(runnerKey, runner);
|
|
60
74
|
return runner;
|
|
61
75
|
}
|
|
62
76
|
getTestConfig() {
|
|
63
77
|
return this.config.testConfig || {};
|
|
64
78
|
}
|
|
65
|
-
setValue(
|
|
66
|
-
|
|
67
|
-
this.store.set(name, {});
|
|
68
|
-
}
|
|
69
|
-
const scope = this.store.get(name);
|
|
70
|
-
scope[key] = value;
|
|
79
|
+
setValue(key, value) {
|
|
80
|
+
this.store.set(key, value);
|
|
71
81
|
}
|
|
72
|
-
getValue(
|
|
73
|
-
|
|
74
|
-
this.store.set(name, {});
|
|
75
|
-
}
|
|
76
|
-
const scope = this.store.get(name);
|
|
77
|
-
return scope[key];
|
|
82
|
+
getValue(key) {
|
|
83
|
+
return this.store.get(key);
|
|
78
84
|
}
|
|
79
|
-
hasError(
|
|
80
|
-
|
|
81
|
-
return this.getError(name).length > 0;
|
|
82
|
-
}
|
|
83
|
-
return !!Array.from(this.errors.values()).reduce((res, arr) => res + arr.length, 0);
|
|
85
|
+
hasError() {
|
|
86
|
+
return this.errors.length > 0;
|
|
84
87
|
}
|
|
85
|
-
emitError(
|
|
86
|
-
|
|
87
|
-
errors.push(typeof err === "string" ? new Error(err) : err);
|
|
88
|
-
this.errors.set(name, errors);
|
|
88
|
+
emitError(err) {
|
|
89
|
+
this.errors.push(typeof err === "string" ? new Error(err) : err);
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
-
return
|
|
91
|
+
getError() {
|
|
92
|
+
return this.errors;
|
|
92
93
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return this.errors.get(name) || [];
|
|
96
|
-
}
|
|
97
|
-
return Array.prototype.concat(...this.errors.values());
|
|
94
|
+
clearError() {
|
|
95
|
+
this.errors.length = 0;
|
|
98
96
|
}
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
this.
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
this.errors.clear();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
async closeCompiler(name) {
|
|
108
|
-
const rspackCompiler = this.getCompiler(name, type_1.ECompilerType.Rspack);
|
|
109
|
-
if (rspackCompiler) {
|
|
110
|
-
await rspackCompiler.close();
|
|
111
|
-
}
|
|
112
|
-
const webpackCompiler = this.getCompiler(name, type_1.ECompilerType.Webpack);
|
|
113
|
-
if (webpackCompiler) {
|
|
114
|
-
await webpackCompiler.close();
|
|
97
|
+
async closeCompiler() {
|
|
98
|
+
if (this.compiler) {
|
|
99
|
+
await this.compiler.close();
|
|
115
100
|
}
|
|
116
101
|
}
|
|
117
102
|
}
|
package/dist/test/creator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ITestContext, ITestEnv, ITester, ITesterConfig, ITestProcessor, TTestConfig, TTestRunnerCreator } from "../type";
|
|
2
2
|
declare global {
|
|
3
3
|
var testFilter: string | undefined;
|
|
4
4
|
}
|
|
@@ -6,40 +6,40 @@ interface IConcurrentTestEnv {
|
|
|
6
6
|
clear: () => void;
|
|
7
7
|
run: () => Promise<void>;
|
|
8
8
|
}
|
|
9
|
-
export interface IBasicCaseCreatorOptions
|
|
9
|
+
export interface IBasicCaseCreatorOptions {
|
|
10
10
|
clean?: boolean;
|
|
11
11
|
describe?: boolean;
|
|
12
12
|
timeout?: number;
|
|
13
13
|
contextValue?: Record<string, unknown>;
|
|
14
|
-
steps: (creatorConfig: IBasicCaseCreatorOptions
|
|
14
|
+
steps: (creatorConfig: IBasicCaseCreatorOptions & {
|
|
15
15
|
name: string;
|
|
16
16
|
src: string;
|
|
17
17
|
dist: string;
|
|
18
18
|
temp: string | void;
|
|
19
19
|
}) => ITestProcessor[];
|
|
20
|
-
testConfig?: (testConfig: TTestConfig
|
|
20
|
+
testConfig?: (testConfig: TTestConfig) => void;
|
|
21
21
|
description?: (name: string, step: number) => string;
|
|
22
22
|
runner?: TTestRunnerCreator;
|
|
23
23
|
createContext?: (config: ITesterConfig) => ITestContext;
|
|
24
24
|
concurrent?: boolean | number;
|
|
25
25
|
[key: string]: unknown;
|
|
26
26
|
}
|
|
27
|
-
export declare class BasicCaseCreator
|
|
28
|
-
protected _options: IBasicCaseCreatorOptions
|
|
27
|
+
export declare class BasicCaseCreator {
|
|
28
|
+
protected _options: IBasicCaseCreatorOptions;
|
|
29
29
|
protected currentConcurrent: number;
|
|
30
30
|
protected tasks: [string, () => void][];
|
|
31
|
-
constructor(_options: IBasicCaseCreatorOptions
|
|
32
|
-
create(name: string, src: string, dist: string, temp?: string, caseOptions?: Partial<IBasicCaseCreatorOptions
|
|
31
|
+
constructor(_options: IBasicCaseCreatorOptions);
|
|
32
|
+
create(name: string, src: string, dist: string, temp?: string, caseOptions?: Partial<IBasicCaseCreatorOptions>): ITester | undefined;
|
|
33
33
|
protected shouldRun(name: string): boolean;
|
|
34
|
-
protected describeConcurrent(name: string, tester: ITester, testConfig: TTestConfig
|
|
35
|
-
protected describe(name: string, tester: ITester, testConfig: TTestConfig
|
|
34
|
+
protected describeConcurrent(name: string, tester: ITester, testConfig: TTestConfig, options: IBasicCaseCreatorOptions): void;
|
|
35
|
+
protected describe(name: string, tester: ITester, testConfig: TTestConfig, options: IBasicCaseCreatorOptions): void;
|
|
36
36
|
protected createConcurrentEnv(): ITestEnv & IConcurrentTestEnv;
|
|
37
|
-
protected createEnv(testConfig: TTestConfig
|
|
37
|
+
protected createEnv(testConfig: TTestConfig, options: IBasicCaseCreatorOptions): ITestEnv;
|
|
38
38
|
protected clean(folders: string[]): void;
|
|
39
39
|
protected skip(name: string, reason: string | boolean): void;
|
|
40
|
-
protected readTestConfig(src: string): TTestConfig
|
|
41
|
-
protected checkSkipped(src: string, testConfig: TTestConfig
|
|
42
|
-
protected createTester(name: string, src: string, dist: string, temp: string | undefined, testConfig: TTestConfig
|
|
40
|
+
protected readTestConfig(src: string): TTestConfig;
|
|
41
|
+
protected checkSkipped(src: string, testConfig: TTestConfig, options: IBasicCaseCreatorOptions): boolean | string;
|
|
42
|
+
protected createTester(name: string, src: string, dist: string, temp: string | undefined, testConfig: TTestConfig, options: IBasicCaseCreatorOptions): ITester;
|
|
43
43
|
protected tryRunTask(concurrent?: number): void;
|
|
44
44
|
protected getMaxConcurrent(concurrent?: number): number;
|
|
45
45
|
protected registerConcurrentTask(name: string, starter: () => void, concurrent?: number): () => void;
|
package/dist/test/creator.js
CHANGED
|
@@ -161,7 +161,7 @@ class BasicCaseCreator {
|
|
|
161
161
|
}
|
|
162
162
|
catch (e) {
|
|
163
163
|
bailout = true;
|
|
164
|
-
context.emitError(
|
|
164
|
+
context.emitError(e);
|
|
165
165
|
}
|
|
166
166
|
await tester.check(env);
|
|
167
167
|
if (!tester.next() && context.hasError()) {
|
|
@@ -255,7 +255,8 @@ class BasicCaseCreator {
|
|
|
255
255
|
it,
|
|
256
256
|
beforeEach,
|
|
257
257
|
afterEach,
|
|
258
|
-
jest
|
|
258
|
+
jest: global.jest || global.rstest,
|
|
259
|
+
rstest: global.rstest
|
|
259
260
|
};
|
|
260
261
|
}
|
|
261
262
|
clean(folders) {
|
|
@@ -264,9 +265,7 @@ class BasicCaseCreator {
|
|
|
264
265
|
}
|
|
265
266
|
}
|
|
266
267
|
skip(name, reason) {
|
|
267
|
-
|
|
268
|
-
it(typeof reason === "string" ? `filtered by ${reason}` : "filtered", () => { });
|
|
269
|
-
});
|
|
268
|
+
it(typeof reason === "string" ? `filtered by ${reason}` : "filtered", () => { });
|
|
270
269
|
}
|
|
271
270
|
readTestConfig(src) {
|
|
272
271
|
const testConfigFile = node_path_1.default.join(src, "test.config.js");
|
|
@@ -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
|
+
};
|