@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/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
|
@@ -1,42 +1,30 @@
|
|
|
1
1
|
import type EventEmitter from "node:events";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Compilation as WebpackCompilation, Compiler as WebpackCompiler, MultiStats as WebpackMultiStats, Configuration as WebpackOptions, Stats as WebpackStats, StatsCompilation as WebpackStatsCompilation } from "webpack";
|
|
2
|
+
import type { Compiler, MultiStats, RspackOptions, Stats, StatsCompilation } from "@rspack/core";
|
|
4
3
|
export interface ITestContext {
|
|
5
4
|
getSource(sub?: string): string;
|
|
6
5
|
getDist(sub?: string): string;
|
|
7
6
|
getTemp(sub?: string): string | null;
|
|
8
|
-
getCompiler
|
|
9
|
-
closeCompiler(
|
|
10
|
-
getTestConfig
|
|
11
|
-
getRunner(
|
|
12
|
-
setValue<T>(
|
|
13
|
-
getValue<T>(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export type TCompilerStats<T> = T extends ECompilerType.Rspack ? RspackStats : WebpackStats;
|
|
28
|
-
export type TCompilerMultiStats<T> = T extends ECompilerType.Rspack ? RspackMultiStats : WebpackMultiStats;
|
|
29
|
-
export type TCompilerStatsCompilation<T> = T extends ECompilerType.Rspack ? RspackStatsCompilation : WebpackStatsCompilation;
|
|
30
|
-
export interface ITestCompilerManager<T extends ECompilerType> {
|
|
31
|
-
getOptions(): TCompilerOptions<T>;
|
|
32
|
-
setOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
|
|
33
|
-
mergeOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
|
|
34
|
-
getCompiler(): TCompiler<T> | null;
|
|
35
|
-
createCompiler(): TCompiler<T>;
|
|
36
|
-
createCompilerWithCallback(callback: (error: Error | null, stats: TCompilerStats<T> | null) => void): TCompiler<T>;
|
|
37
|
-
build(): Promise<TCompilerStats<T>>;
|
|
7
|
+
getCompiler(): ITestCompilerManager;
|
|
8
|
+
closeCompiler(): Promise<void>;
|
|
9
|
+
getTestConfig(): TTestConfig;
|
|
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;
|
|
17
|
+
}
|
|
18
|
+
export interface ITestCompilerManager {
|
|
19
|
+
getOptions(): RspackOptions;
|
|
20
|
+
setOptions(newOptions: RspackOptions): RspackOptions;
|
|
21
|
+
mergeOptions(newOptions: RspackOptions): RspackOptions;
|
|
22
|
+
getCompiler(): Compiler | null;
|
|
23
|
+
createCompiler(): Compiler;
|
|
24
|
+
createCompilerWithCallback(callback: (error: Error | null, stats: Stats | null) => void): Compiler;
|
|
25
|
+
build(): Promise<Stats>;
|
|
38
26
|
watch(timeout?: number): void;
|
|
39
|
-
getStats():
|
|
27
|
+
getStats(): Stats | MultiStats | null;
|
|
40
28
|
getEmitter(): EventEmitter;
|
|
41
29
|
close(): Promise<void>;
|
|
42
30
|
}
|
|
@@ -50,8 +38,7 @@ export interface ITesterConfig {
|
|
|
50
38
|
dist: string;
|
|
51
39
|
temp?: string;
|
|
52
40
|
steps?: ITestProcessor[];
|
|
53
|
-
testConfig?: TTestConfig
|
|
54
|
-
compilerFactories?: TCompilerFactories<ECompilerType>;
|
|
41
|
+
testConfig?: TTestConfig;
|
|
55
42
|
contextValue?: Record<string, unknown>;
|
|
56
43
|
runnerCreator?: TTestRunnerCreator;
|
|
57
44
|
createContext?: (config: ITesterConfig) => ITestContext;
|
|
@@ -78,9 +65,9 @@ export interface ITestProcessor {
|
|
|
78
65
|
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
79
66
|
check(env: ITestEnv, context: ITestContext): Promise<unknown>;
|
|
80
67
|
}
|
|
81
|
-
export interface ITestReporter
|
|
82
|
-
init(data?: T): Promise<void>;
|
|
83
|
-
increment(id: string, data: T): Promise<void>;
|
|
68
|
+
export interface ITestReporter {
|
|
69
|
+
init<T>(data?: T): Promise<void>;
|
|
70
|
+
increment<T>(id: string, data: T): Promise<void>;
|
|
84
71
|
failure(id: string): Promise<void>;
|
|
85
72
|
output(): Promise<void>;
|
|
86
73
|
}
|
|
@@ -130,17 +117,17 @@ export interface ITestEnv {
|
|
|
130
117
|
afterEach: (...args: any[]) => void;
|
|
131
118
|
[key: string]: unknown;
|
|
132
119
|
}
|
|
133
|
-
export type TTestConfig
|
|
120
|
+
export type TTestConfig = {
|
|
134
121
|
location?: string;
|
|
135
|
-
validate?: (stats:
|
|
122
|
+
validate?: (stats: Stats | MultiStats, stderr?: string) => void;
|
|
136
123
|
noTests?: boolean;
|
|
137
124
|
writeStatsOuptut?: boolean;
|
|
138
125
|
writeStatsJson?: boolean;
|
|
139
|
-
beforeExecute?: (options:
|
|
140
|
-
afterExecute?: (options:
|
|
141
|
-
moduleScope?: (ms: IModuleScope, stats?:
|
|
142
|
-
checkStats?: (stepName: string, jsonStats:
|
|
143
|
-
findBundle?: (index: number, options:
|
|
126
|
+
beforeExecute?: (options: RspackOptions) => void;
|
|
127
|
+
afterExecute?: (options: RspackOptions) => void;
|
|
128
|
+
moduleScope?: (ms: IModuleScope, stats?: StatsCompilation, options?: RspackOptions) => IModuleScope;
|
|
129
|
+
checkStats?: (stepName: string, jsonStats: StatsCompilation | undefined, stringStats: String) => boolean;
|
|
130
|
+
findBundle?: (index: number, options: RspackOptions, stepName?: string) => string | string[];
|
|
144
131
|
bundlePath?: string[];
|
|
145
132
|
nonEsmThis?: (p: string | string[]) => Object;
|
|
146
133
|
modules?: Record<string, Object>;
|
|
@@ -153,22 +140,21 @@ export type TTestConfig<T extends ECompilerType> = {
|
|
|
153
140
|
preserveModules?: string;
|
|
154
141
|
};
|
|
155
142
|
};
|
|
156
|
-
export type TTestFilter
|
|
143
|
+
export type TTestFilter = (creatorConfig: Record<string, unknown>, testConfig: TTestConfig) => boolean | string;
|
|
157
144
|
export interface ITestRunner {
|
|
158
145
|
run(file: string): Promise<unknown>;
|
|
159
146
|
getRequire(): TRunnerRequirer;
|
|
160
147
|
getGlobal(name: string): unknown;
|
|
161
148
|
}
|
|
162
|
-
export type TCompilerFactory
|
|
163
|
-
export interface TRunnerFactory
|
|
164
|
-
create(file: string, compilerOptions:
|
|
149
|
+
export type TCompilerFactory = (options: RspackOptions | RspackOptions[], callback?: (error: Error | null, stats: Stats | null) => void) => Compiler;
|
|
150
|
+
export interface TRunnerFactory {
|
|
151
|
+
create(file: string, compilerOptions: RspackOptions, env: ITestEnv): ITestRunner;
|
|
165
152
|
}
|
|
166
153
|
export type THotUpdateContext = {
|
|
167
154
|
updateIndex: number;
|
|
168
155
|
totalUpdates: number;
|
|
169
156
|
changedFiles: string[];
|
|
170
157
|
};
|
|
171
|
-
export type TCompilerFactories<T extends ECompilerType> = Record<T, TCompilerFactory<T>>;
|
|
172
158
|
export type TRunnerRequirer = (currentDirectory: string, modulePath: string[] | string, context?: {
|
|
173
159
|
file?: TRunnerFile;
|
|
174
160
|
esmMode?: EEsmMode;
|
|
@@ -202,6 +188,7 @@ export type TTestRunnerCreator = {
|
|
|
202
188
|
runner: (context: ITestContext, name: string, file: string, env: ITestEnv) => ITestRunner;
|
|
203
189
|
};
|
|
204
190
|
declare global {
|
|
191
|
+
var __DEBUG__: boolean;
|
|
205
192
|
var __TEST_PATH__: string;
|
|
206
193
|
var __TEST_FIXTURES_PATH__: string;
|
|
207
194
|
var __TEST_DIST_PATH__: string;
|
package/dist/type.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/// <reference types="../jest.d.ts" />
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.EEsmMode = exports.ECompareResultType =
|
|
5
|
-
var ECompilerType;
|
|
6
|
-
(function (ECompilerType) {
|
|
7
|
-
ECompilerType["Rspack"] = "rspack";
|
|
8
|
-
ECompilerType["Webpack"] = "webpack";
|
|
9
|
-
})(ECompilerType || (exports.ECompilerType = ECompilerType = {}));
|
|
4
|
+
exports.EEsmMode = exports.ECompareResultType = void 0;
|
|
10
5
|
var ECompareResultType;
|
|
11
6
|
(function (ECompareResultType) {
|
|
12
7
|
ECompareResultType["Same"] = "same";
|
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-4ad8b49f-20251023175711",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -42,12 +42,10 @@
|
|
|
42
42
|
"@babel/types": "7.28.4",
|
|
43
43
|
"@jest/reporters": "29.7.0",
|
|
44
44
|
"cross-env": "^10.1.0",
|
|
45
|
-
"csv-to-markdown-table": "1.5.0",
|
|
46
|
-
"deepmerge": "^4.3.1",
|
|
47
45
|
"filenamify": "4.3.0",
|
|
48
46
|
"fs-extra": "^11.3.2",
|
|
49
|
-
"graceful-fs": "^4.2.11",
|
|
50
47
|
"iconv-lite": "^0.6.3",
|
|
48
|
+
"javascript-stringify": "^2.1.0",
|
|
51
49
|
"jest-diff": "^29.7.0",
|
|
52
50
|
"jest-snapshot": "29.7.0",
|
|
53
51
|
"jest-environment-node": "29.7.0",
|
|
@@ -60,19 +58,17 @@
|
|
|
60
58
|
"terser-webpack-plugin": "^5.3.14",
|
|
61
59
|
"webpack": "5.102.1",
|
|
62
60
|
"webpack-merge": "6.0.1",
|
|
63
|
-
"webpack-sources": "3.3.3"
|
|
61
|
+
"webpack-sources": "3.3.3",
|
|
62
|
+
"chalk": "^4.1.2"
|
|
64
63
|
},
|
|
65
64
|
"devDependencies": {
|
|
66
65
|
"@types/babel__generator": "7.27.0",
|
|
67
66
|
"@types/babel__traverse": "7.28.0",
|
|
68
67
|
"@types/fs-extra": "11.0.4",
|
|
69
68
|
"@types/jsdom": "^21.1.7",
|
|
70
|
-
"chalk": "^4.1.2",
|
|
71
|
-
"source-map": "^0.7.6",
|
|
72
|
-
"terser": "5.43.1",
|
|
73
69
|
"typescript": "^5.9.3",
|
|
74
70
|
"wast-loader": "^1.14.1",
|
|
75
|
-
"@rspack/core": "npm:@rspack-canary/core@1.6.0-canary-
|
|
71
|
+
"@rspack/core": "npm:@rspack-canary/core@1.6.0-canary-4ad8b49f-20251023175711"
|
|
76
72
|
},
|
|
77
73
|
"peerDependencies": {
|
|
78
74
|
"@rspack/core": ">=1.0.0"
|
package/dist/case/diff.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type IFormatCodeOptions, type IFormatCodeReplacement } from "../compare";
|
|
2
|
-
import { type TCompareModules, type TFileCompareResult, type TModuleCompareResult } from "../type";
|
|
3
|
-
export type TDiffCaseConfig = IDiffProcessorOptions;
|
|
4
|
-
export declare function createDiffCase(name: string, src: string, dist: string): void;
|
|
5
|
-
export interface IDiffProcessorOptions extends IFormatCodeOptions {
|
|
6
|
-
webpackPath: string;
|
|
7
|
-
rspackPath: string;
|
|
8
|
-
files?: string[];
|
|
9
|
-
modules?: TCompareModules;
|
|
10
|
-
runtimeModules?: TCompareModules;
|
|
11
|
-
bootstrap?: boolean;
|
|
12
|
-
detail?: boolean;
|
|
13
|
-
errors?: boolean;
|
|
14
|
-
replacements?: IFormatCodeReplacement[];
|
|
15
|
-
renameModule?: (file: string) => string;
|
|
16
|
-
onCompareFile?: (file: string, result: TFileCompareResult) => void;
|
|
17
|
-
onCompareModules?: (file: string, results: TModuleCompareResult[]) => void;
|
|
18
|
-
onCompareRuntimeModules?: (file: string, results: TModuleCompareResult[]) => void;
|
|
19
|
-
}
|
package/dist/case/diff.js
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
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.createDiffCase = createDiffCase;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const rimraf_1 = require("rimraf");
|
|
10
|
-
const compare_1 = require("../compare");
|
|
11
|
-
const createLazyTestEnv_1 = __importDefault(require("../helper/legacy/createLazyTestEnv"));
|
|
12
|
-
const plugin_1 = require("../plugin");
|
|
13
|
-
const tester_1 = require("../test/tester");
|
|
14
|
-
const type_1 = require("../type");
|
|
15
|
-
const common_1 = require("./common");
|
|
16
|
-
const DEFAULT_CASE_CONFIG = {
|
|
17
|
-
webpackPath: require.resolve("webpack"),
|
|
18
|
-
rspackPath: require.resolve("@rspack/core"),
|
|
19
|
-
files: ["bundle.js"],
|
|
20
|
-
bootstrap: true,
|
|
21
|
-
detail: true,
|
|
22
|
-
errors: false
|
|
23
|
-
};
|
|
24
|
-
function createDiffCase(name, src, dist) {
|
|
25
|
-
const caseConfigFile = node_path_1.default.join(src, "test.config.js");
|
|
26
|
-
if (!fs_extra_1.default.existsSync(caseConfigFile)) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const caseConfig = Object.assign({}, DEFAULT_CASE_CONFIG, require(caseConfigFile));
|
|
30
|
-
const [processor, compareMap] = createDiffProcessor(caseConfig);
|
|
31
|
-
const tester = new tester_1.Tester({
|
|
32
|
-
name,
|
|
33
|
-
src,
|
|
34
|
-
dist,
|
|
35
|
-
steps: [processor]
|
|
36
|
-
});
|
|
37
|
-
(0, rimraf_1.rimrafSync)(dist);
|
|
38
|
-
const prefix = node_path_1.default.basename(name);
|
|
39
|
-
describe(`${prefix}:check`, () => {
|
|
40
|
-
beforeAll(async () => {
|
|
41
|
-
await tester.compile();
|
|
42
|
-
compareMap.clear();
|
|
43
|
-
await tester.check(env);
|
|
44
|
-
});
|
|
45
|
-
for (const file of caseConfig.files) {
|
|
46
|
-
describe(`Comparing "${file}"`, () => {
|
|
47
|
-
let moduleResults = [];
|
|
48
|
-
let runtimeResults = [];
|
|
49
|
-
beforeAll(() => {
|
|
50
|
-
const fileResult = compareMap.get(file);
|
|
51
|
-
if (!fileResult) {
|
|
52
|
-
throw new Error(`File ${file} has no results`);
|
|
53
|
-
}
|
|
54
|
-
moduleResults = fileResult.modules;
|
|
55
|
-
runtimeResults = fileResult.runtimeModules;
|
|
56
|
-
});
|
|
57
|
-
if (caseConfig.modules) {
|
|
58
|
-
checkCompareResults("modules", () => moduleResults);
|
|
59
|
-
}
|
|
60
|
-
if (caseConfig.runtimeModules) {
|
|
61
|
-
checkCompareResults("runtime modules", () => runtimeResults);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
const env = (0, createLazyTestEnv_1.default)(1000);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
function defaultOptions(type, src, dist) {
|
|
69
|
-
return {
|
|
70
|
-
entry: node_path_1.default.join(src, "./src/index.js"),
|
|
71
|
-
context: src,
|
|
72
|
-
output: {
|
|
73
|
-
path: dist,
|
|
74
|
-
filename: "bundle.js",
|
|
75
|
-
chunkFilename: "[name].chunk.js"
|
|
76
|
-
},
|
|
77
|
-
plugins: [
|
|
78
|
-
type === type_1.ECompilerType.Webpack && new plugin_1.WebpackDiffConfigPlugin(),
|
|
79
|
-
type === type_1.ECompilerType.Rspack && new plugin_1.RspackDiffConfigPlugin()
|
|
80
|
-
].filter(Boolean),
|
|
81
|
-
experiments: type === type_1.ECompilerType.Rspack
|
|
82
|
-
? {
|
|
83
|
-
css: true,
|
|
84
|
-
rspackFuture: {
|
|
85
|
-
bundlerInfo: {
|
|
86
|
-
force: false
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
: {}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
function createFormatOptions(options, hashes) {
|
|
94
|
-
const formatOptions = {
|
|
95
|
-
ignoreModuleArguments: options.ignoreModuleArguments,
|
|
96
|
-
ignoreModuleId: options.ignoreModuleId,
|
|
97
|
-
ignorePropertyQuotationMark: options.ignorePropertyQuotationMark,
|
|
98
|
-
ignoreBlockOnlyStatement: options.ignoreBlockOnlyStatement,
|
|
99
|
-
ignoreIfCertainCondition: options.ignoreIfCertainCondition,
|
|
100
|
-
ignoreSwcHelpersPath: options.ignoreSwcHelpersPath,
|
|
101
|
-
ignoreObjectPropertySequence: options.ignoreObjectPropertySequence,
|
|
102
|
-
ignoreCssFilePath: options.ignoreCssFilePath,
|
|
103
|
-
replacements: options.replacements || []
|
|
104
|
-
};
|
|
105
|
-
for (const hash of hashes) {
|
|
106
|
-
formatOptions.replacements.push({ from: hash, to: "fullhash" });
|
|
107
|
-
}
|
|
108
|
-
return formatOptions;
|
|
109
|
-
}
|
|
110
|
-
function createDiffProcessor(options) {
|
|
111
|
-
const fileCompareMap = new Map();
|
|
112
|
-
const createCompareResultHandler = (type) => {
|
|
113
|
-
return (file, results) => {
|
|
114
|
-
const fileResult = fileCompareMap.get(file) || {
|
|
115
|
-
modules: [],
|
|
116
|
-
runtimeModules: []
|
|
117
|
-
};
|
|
118
|
-
fileResult[type] = results;
|
|
119
|
-
fileCompareMap.set(file, fileResult);
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
const diffOptions = {
|
|
123
|
-
webpackPath: options.webpackPath,
|
|
124
|
-
rspackPath: options.rspackPath,
|
|
125
|
-
files: options.files,
|
|
126
|
-
modules: options.modules,
|
|
127
|
-
runtimeModules: options.runtimeModules,
|
|
128
|
-
renameModule: options.renameModule,
|
|
129
|
-
ignoreModuleId: options.ignoreModuleId ?? true,
|
|
130
|
-
ignoreModuleArguments: options.ignoreModuleArguments ?? true,
|
|
131
|
-
ignorePropertyQuotationMark: options.ignorePropertyQuotationMark ?? true,
|
|
132
|
-
ignoreBlockOnlyStatement: options.ignoreBlockOnlyStatement ?? true,
|
|
133
|
-
ignoreIfCertainCondition: options.ignoreIfCertainCondition ?? true,
|
|
134
|
-
ignoreSwcHelpersPath: options.ignoreSwcHelpersPath ?? true,
|
|
135
|
-
ignoreObjectPropertySequence: options.ignoreObjectPropertySequence ?? true,
|
|
136
|
-
ignoreCssFilePath: options.ignoreCssFilePath ?? true,
|
|
137
|
-
onCompareModules: createCompareResultHandler("modules"),
|
|
138
|
-
onCompareRuntimeModules: createCompareResultHandler("runtimeModules"),
|
|
139
|
-
bootstrap: options.bootstrap ?? true,
|
|
140
|
-
detail: options.detail ?? true,
|
|
141
|
-
errors: options.errors ?? false,
|
|
142
|
-
replacements: options.replacements
|
|
143
|
-
};
|
|
144
|
-
const hashes = [];
|
|
145
|
-
const webpackProcessor = global.updateSnapshot &&
|
|
146
|
-
{
|
|
147
|
-
config: async (context) => {
|
|
148
|
-
const compiler = (0, common_1.getCompiler)(context, type_1.ECompilerType.Webpack);
|
|
149
|
-
let options = defaultOptions(type_1.ECompilerType.Webpack, context.getSource(), node_path_1.default.join(context.getDist(), type_1.ECompilerType.Webpack));
|
|
150
|
-
options = await (0, common_1.config)(context, type_1.ECompilerType.Webpack, ["webpack.config.js", "rspack.config.js"], options);
|
|
151
|
-
compiler.setOptions(options);
|
|
152
|
-
},
|
|
153
|
-
compiler: async (context) => {
|
|
154
|
-
await (0, common_1.compiler)(context, type_1.ECompilerType.Webpack);
|
|
155
|
-
},
|
|
156
|
-
build: async (context) => {
|
|
157
|
-
await (0, common_1.build)(context, type_1.ECompilerType.Webpack);
|
|
158
|
-
},
|
|
159
|
-
run: async (env, context) => { },
|
|
160
|
-
check: async (env, context) => {
|
|
161
|
-
await (0, common_1.check)(env, context, type_1.ECompilerType.Webpack);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
const rspackProcessor = {
|
|
165
|
-
config: async (context) => {
|
|
166
|
-
const compiler = (0, common_1.getCompiler)(context, type_1.ECompilerType.Rspack);
|
|
167
|
-
let options = defaultOptions(type_1.ECompilerType.Rspack, context.getSource(), node_path_1.default.join(context.getDist(), type_1.ECompilerType.Rspack));
|
|
168
|
-
options = await (0, common_1.config)(context, type_1.ECompilerType.Rspack, ["rspack.config.js", "webpack.config.js"], options);
|
|
169
|
-
compiler.setOptions(options);
|
|
170
|
-
},
|
|
171
|
-
compiler: async (context) => {
|
|
172
|
-
await (0, common_1.compiler)(context, type_1.ECompilerType.Rspack);
|
|
173
|
-
},
|
|
174
|
-
build: async (context) => {
|
|
175
|
-
await (0, common_1.build)(context, type_1.ECompilerType.Rspack);
|
|
176
|
-
},
|
|
177
|
-
run: async (env, context) => { },
|
|
178
|
-
check: async (env, context) => {
|
|
179
|
-
await (0, common_1.check)(env, context, type_1.ECompilerType.Rspack);
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
const processor = {
|
|
183
|
-
config: async (context) => {
|
|
184
|
-
if (webpackProcessor) {
|
|
185
|
-
await webpackProcessor.config(context);
|
|
186
|
-
}
|
|
187
|
-
await rspackProcessor.config(context);
|
|
188
|
-
},
|
|
189
|
-
compiler: async (context) => {
|
|
190
|
-
if (webpackProcessor) {
|
|
191
|
-
await webpackProcessor.compiler(context);
|
|
192
|
-
}
|
|
193
|
-
await rspackProcessor.compiler(context);
|
|
194
|
-
},
|
|
195
|
-
build: async (context) => {
|
|
196
|
-
if (webpackProcessor) {
|
|
197
|
-
await webpackProcessor.build(context);
|
|
198
|
-
}
|
|
199
|
-
await rspackProcessor.build(context);
|
|
200
|
-
},
|
|
201
|
-
run: async (env, context) => { },
|
|
202
|
-
check: async (env, context) => {
|
|
203
|
-
if (webpackProcessor) {
|
|
204
|
-
const webpackCompiler = context.getCompiler(type_1.ECompilerType.Webpack);
|
|
205
|
-
const webpackStats = webpackCompiler.getStats();
|
|
206
|
-
//TODO: handle chunk hash and content hash
|
|
207
|
-
webpackStats?.hash && hashes.push(webpackStats?.hash);
|
|
208
|
-
if (!diffOptions.errors) {
|
|
209
|
-
env.expect(webpackStats?.hasErrors()).toBe(false);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
const rspackCompiler = context.getCompiler(type_1.ECompilerType.Rspack);
|
|
213
|
-
const rspackStats = rspackCompiler.getStats();
|
|
214
|
-
//TODO: handle chunk hash and content hash
|
|
215
|
-
rspackStats?.hash && hashes.push(rspackStats?.hash);
|
|
216
|
-
if (!diffOptions.errors) {
|
|
217
|
-
env.expect(rspackStats?.hasErrors()).toBe(false);
|
|
218
|
-
}
|
|
219
|
-
const dist = context.getDist();
|
|
220
|
-
const snapshot = context.getSource("__snapshot__");
|
|
221
|
-
for (const file of diffOptions.files) {
|
|
222
|
-
const rspackDist = node_path_1.default.join(dist, type_1.ECompilerType.Rspack, file);
|
|
223
|
-
const webpackDist = node_path_1.default.join(dist, type_1.ECompilerType.Webpack, file);
|
|
224
|
-
const snapshotDist = node_path_1.default.join(snapshot, file.replace(/\.js$/, ".json"));
|
|
225
|
-
const result = (0, compare_1.compareFile)(rspackDist, webpackDist, {
|
|
226
|
-
modules: diffOptions.modules,
|
|
227
|
-
runtimeModules: diffOptions.runtimeModules,
|
|
228
|
-
format: createFormatOptions(diffOptions, hashes),
|
|
229
|
-
renameModule: diffOptions.renameModule,
|
|
230
|
-
bootstrap: diffOptions.bootstrap,
|
|
231
|
-
detail: diffOptions.detail,
|
|
232
|
-
snapshot: snapshotDist
|
|
233
|
-
});
|
|
234
|
-
if (typeof diffOptions.onCompareFile === "function") {
|
|
235
|
-
diffOptions.onCompareFile(file, result);
|
|
236
|
-
}
|
|
237
|
-
if (typeof diffOptions.onCompareModules === "function" &&
|
|
238
|
-
result.modules.modules) {
|
|
239
|
-
diffOptions.onCompareModules(file, result.modules.modules);
|
|
240
|
-
}
|
|
241
|
-
if (typeof diffOptions.onCompareRuntimeModules === "function" &&
|
|
242
|
-
result.modules.runtimeModules) {
|
|
243
|
-
diffOptions.onCompareRuntimeModules(file, result.modules.runtimeModules);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
return [processor, fileCompareMap];
|
|
249
|
-
}
|
|
250
|
-
function checkCompareResults(name, getResults) {
|
|
251
|
-
describe(`Comparing ${name}`, () => {
|
|
252
|
-
it("should not miss any module", () => {
|
|
253
|
-
expect(getResults()
|
|
254
|
-
.filter(i => i.type === type_1.ECompareResultType.Missing)
|
|
255
|
-
.map(i => i.name)).toEqual([]);
|
|
256
|
-
});
|
|
257
|
-
it("should not have any rspack-only module", () => {
|
|
258
|
-
expect(getResults()
|
|
259
|
-
.filter(i => i.type === type_1.ECompareResultType.OnlySource)
|
|
260
|
-
.map(i => i.name)).toEqual([]);
|
|
261
|
-
});
|
|
262
|
-
it("should not have any webpack-only module", () => {
|
|
263
|
-
expect(getResults()
|
|
264
|
-
.filter(i => i.type === type_1.ECompareResultType.OnlyDist)
|
|
265
|
-
.map(i => i.name)).toEqual([]);
|
|
266
|
-
});
|
|
267
|
-
it("all modules should be the same", () => {
|
|
268
|
-
for (const result of getResults().filter(i => i.type === type_1.ECompareResultType.Different)) {
|
|
269
|
-
console.log(`${result.name}:\n${result.detail}`);
|
|
270
|
-
}
|
|
271
|
-
expect(getResults().every(i => i.type === type_1.ECompareResultType.Same)).toEqual(true);
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ITestReporter, TCompareModules } from "../type";
|
|
2
|
-
import type { IFormatCodeOptions } from "./format-code";
|
|
3
|
-
export interface IDiffComparatorOptions {
|
|
4
|
-
rspackDist: string;
|
|
5
|
-
webpackDist: string;
|
|
6
|
-
files: string[];
|
|
7
|
-
modules?: TCompareModules;
|
|
8
|
-
runtimeModules?: TCompareModules;
|
|
9
|
-
reporters: ITestReporter<unknown>[];
|
|
10
|
-
formatOptions?: IFormatCodeOptions;
|
|
11
|
-
bootstrap?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export declare class DiffComparator {
|
|
14
|
-
private options;
|
|
15
|
-
constructor(options: IDiffComparatorOptions);
|
|
16
|
-
compare(): Promise<void>;
|
|
17
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
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.DiffComparator = void 0;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
9
|
-
const compare_1 = require("./compare");
|
|
10
|
-
const replace_runtime_module_name_1 = require("./replace-runtime-module-name");
|
|
11
|
-
class DiffComparator {
|
|
12
|
-
constructor(options) {
|
|
13
|
-
this.options = options;
|
|
14
|
-
}
|
|
15
|
-
async compare() {
|
|
16
|
-
for (const file of this.options.files) {
|
|
17
|
-
try {
|
|
18
|
-
const result = (0, compare_1.compareFile)(node_path_1.default.join(this.options.rspackDist, file), node_path_1.default.join(this.options.webpackDist, file), {
|
|
19
|
-
modules: this.options.modules,
|
|
20
|
-
runtimeModules: this.options.runtimeModules,
|
|
21
|
-
format: (0, deepmerge_1.default)({
|
|
22
|
-
replacements: {},
|
|
23
|
-
ignorePropertyQuotationMark: true,
|
|
24
|
-
ignoreModuleId: true,
|
|
25
|
-
ignoreModuleArguments: true,
|
|
26
|
-
ignoreBlockOnlyStatement: true,
|
|
27
|
-
ignoreIfCertainCondition: true,
|
|
28
|
-
ignoreSwcHelpersPath: true,
|
|
29
|
-
ignoreObjectPropertySequence: true,
|
|
30
|
-
ignoreCssFilePath: true
|
|
31
|
-
}, this.options.formatOptions || {}),
|
|
32
|
-
renameModule: replace_runtime_module_name_1.replaceRuntimeModuleName,
|
|
33
|
-
bootstrap: this.options.bootstrap
|
|
34
|
-
});
|
|
35
|
-
for (const reporter of this.options.reporters) {
|
|
36
|
-
reporter.increment(file, result.modules.modules || []);
|
|
37
|
-
}
|
|
38
|
-
for (const reporter of this.options.reporters) {
|
|
39
|
-
reporter.increment(file, result.modules.runtimeModules || []);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
catch (e) {
|
|
43
|
-
console.error(e);
|
|
44
|
-
for (const reporter of this.options.reporters) {
|
|
45
|
-
reporter.failure(file);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
await Promise.all(this.options.reporters.map(r => r.output()));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.DiffComparator = DiffComparator;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type TCompareModules, type TCompareResult, type TFileCompareResult, type TModuleCompareResult } from "../type";
|
|
2
|
-
import { type IFormatCodeOptions } from "./format-code";
|
|
3
|
-
declare global {
|
|
4
|
-
var updateSnapshot: boolean;
|
|
5
|
-
}
|
|
6
|
-
export interface ICompareOptions {
|
|
7
|
-
modules?: TCompareModules;
|
|
8
|
-
runtimeModules?: TCompareModules;
|
|
9
|
-
format: IFormatCodeOptions;
|
|
10
|
-
renameModule?: (name: string) => string;
|
|
11
|
-
bootstrap?: boolean;
|
|
12
|
-
detail?: boolean;
|
|
13
|
-
snapshot?: string;
|
|
14
|
-
}
|
|
15
|
-
export declare function compareFile(sourceFile: string, distFile: string, compareOptions: ICompareOptions): TFileCompareResult;
|
|
16
|
-
export declare function compareModules(modules: string[], sourceModules: Record<string, string>, distModules: Record<string, string>, compareOptions: ICompareOptions): TModuleCompareResult[];
|
|
17
|
-
export declare function compareContent(sourceContent: string | false, distContent: string | false, compareOptions: ICompareOptions): TCompareResult;
|