@rspack-canary/test-tools 1.6.0-canary-6cd722f4-20251022123039 → 1.6.0-canary-e28e40e9-20251022173516
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/cache.d.ts +2 -2
- package/dist/case/cache.js +4 -1
- package/dist/case/common.d.ts +11 -10
- package/dist/case/common.js +2 -5
- package/dist/case/compiler.d.ts +9 -8
- package/dist/case/config.d.ts +6 -5
- package/dist/case/defaults.d.ts +5 -4
- package/dist/case/defaults.js +1 -1
- package/dist/case/error.d.ts +5 -5
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hook.d.ts +4 -3
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +1 -2
- package/dist/case/hot.d.ts +5 -4
- 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/runner.d.ts +5 -4
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/stats-api.d.ts +6 -5
- package/dist/case/stats-api.js +1 -2
- package/dist/case/stats-output.d.ts +3 -2
- package/dist/case/watch.d.ts +6 -6
- package/dist/case/watch.js +2 -1
- package/dist/compiler.d.ts +15 -17
- package/dist/compiler.js +4 -11
- package/dist/helper/legacy/checkArrayExpectation.js +1 -1
- package/dist/helper/read-config-file.d.ts +3 -2
- 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 +9 -8
- package/dist/runner/node/index.js +3 -1
- package/dist/runner/web/index.d.ts +5 -5
- package/dist/test/context.d.ts +4 -4
- package/dist/test/context.js +5 -13
- package/dist/test/creator.d.ts +14 -14
- package/dist/test/creator.js +3 -4
- package/dist/type.d.ts +27 -40
- package/dist/type.js +1 -6
- package/package.json +4 -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
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TRunnerFile, TRunnerRequirer } from "../../type";
|
|
2
2
|
import { type INodeRunnerOptions, NodeRunner } from "../node";
|
|
3
|
-
export interface IWebRunnerOptions
|
|
3
|
+
export interface IWebRunnerOptions extends INodeRunnerOptions {
|
|
4
4
|
location: string;
|
|
5
5
|
}
|
|
6
|
-
export declare class WebRunner
|
|
7
|
-
protected _webOptions: IWebRunnerOptions
|
|
6
|
+
export declare class WebRunner extends NodeRunner {
|
|
7
|
+
protected _webOptions: IWebRunnerOptions;
|
|
8
8
|
private dom;
|
|
9
|
-
constructor(_webOptions: IWebRunnerOptions
|
|
9
|
+
constructor(_webOptions: IWebRunnerOptions);
|
|
10
10
|
run(file: string): Promise<unknown>;
|
|
11
11
|
getGlobal(name: string): unknown;
|
|
12
12
|
protected createResourceLoader(): {
|
package/dist/test/context.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ITestCompilerManager, ITestContext, ITestEnv, ITesterConfig, ITestRunner, TTestConfig } from "../type";
|
|
2
2
|
export type TTestContextOptions = Omit<ITesterConfig, "name" | "steps">;
|
|
3
3
|
export declare class TestContext implements ITestContext {
|
|
4
4
|
private config;
|
|
5
5
|
protected errors: Map<string, Error[]>;
|
|
6
|
-
protected compilers: Map<string, ITestCompilerManager
|
|
6
|
+
protected compilers: Map<string, ITestCompilerManager>;
|
|
7
7
|
protected store: Map<string, Record<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
|
|
13
|
+
getCompiler(name: string): ITestCompilerManager;
|
|
14
14
|
getRunner(name: string, file: string, env: ITestEnv): ITestRunner;
|
|
15
|
-
getTestConfig
|
|
15
|
+
getTestConfig(): TTestConfig;
|
|
16
16
|
setValue<T>(name: string, key: string, value: T): void;
|
|
17
17
|
getValue<T>(name: string, key: string): T | void;
|
|
18
18
|
hasError(name?: string): boolean;
|
package/dist/test/context.js
CHANGED
|
@@ -6,7 +6,6 @@ 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 type_1 = require("../type");
|
|
10
9
|
class TestContext {
|
|
11
10
|
constructor(config) {
|
|
12
11
|
this.config = config;
|
|
@@ -35,13 +34,10 @@ class TestContext {
|
|
|
35
34
|
}
|
|
36
35
|
return this.config.temp;
|
|
37
36
|
}
|
|
38
|
-
getCompiler(name
|
|
37
|
+
getCompiler(name) {
|
|
39
38
|
let compiler = this.compilers.get(name);
|
|
40
39
|
if (!compiler) {
|
|
41
|
-
|
|
42
|
-
throw new Error("Compiler does not exists");
|
|
43
|
-
}
|
|
44
|
-
compiler = new compiler_1.TestCompilerManager(type, this.config.compilerFactories);
|
|
40
|
+
compiler = new compiler_1.TestCompilerManager();
|
|
45
41
|
this.compilers.set(name, compiler);
|
|
46
42
|
}
|
|
47
43
|
return compiler;
|
|
@@ -105,13 +101,9 @@ class TestContext {
|
|
|
105
101
|
}
|
|
106
102
|
}
|
|
107
103
|
async closeCompiler(name) {
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
await
|
|
111
|
-
}
|
|
112
|
-
const webpackCompiler = this.getCompiler(name, type_1.ECompilerType.Webpack);
|
|
113
|
-
if (webpackCompiler) {
|
|
114
|
-
await webpackCompiler.close();
|
|
104
|
+
const compiler = this.getCompiler(name);
|
|
105
|
+
if (compiler) {
|
|
106
|
+
await compiler.close();
|
|
115
107
|
}
|
|
116
108
|
}
|
|
117
109
|
}
|
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
|
@@ -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");
|
package/dist/type.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
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
|
|
7
|
+
getCompiler(name: string): ITestCompilerManager;
|
|
9
8
|
closeCompiler(name: string): Promise<void>;
|
|
10
|
-
getTestConfig
|
|
9
|
+
getTestConfig(): TTestConfig;
|
|
11
10
|
getRunner(name: string, file: string, env: ITestEnv): ITestRunner;
|
|
12
11
|
setValue<T>(name: string, key: string, value: T): void;
|
|
13
12
|
getValue<T>(name: string, key: string): T | void;
|
|
@@ -17,26 +16,16 @@ export interface ITestContext {
|
|
|
17
16
|
getError(name?: string): Error[];
|
|
18
17
|
clearError(name?: string): void;
|
|
19
18
|
}
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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>>;
|
|
19
|
+
export interface ITestCompilerManager {
|
|
20
|
+
getOptions(): RspackOptions;
|
|
21
|
+
setOptions(newOptions: RspackOptions): RspackOptions;
|
|
22
|
+
mergeOptions(newOptions: RspackOptions): RspackOptions;
|
|
23
|
+
getCompiler(): Compiler | null;
|
|
24
|
+
createCompiler(): Compiler;
|
|
25
|
+
createCompilerWithCallback(callback: (error: Error | null, stats: Stats | null) => void): Compiler;
|
|
26
|
+
build(): Promise<Stats>;
|
|
38
27
|
watch(timeout?: number): void;
|
|
39
|
-
getStats():
|
|
28
|
+
getStats(): Stats | MultiStats | null;
|
|
40
29
|
getEmitter(): EventEmitter;
|
|
41
30
|
close(): Promise<void>;
|
|
42
31
|
}
|
|
@@ -50,8 +39,7 @@ export interface ITesterConfig {
|
|
|
50
39
|
dist: string;
|
|
51
40
|
temp?: string;
|
|
52
41
|
steps?: ITestProcessor[];
|
|
53
|
-
testConfig?: TTestConfig
|
|
54
|
-
compilerFactories?: TCompilerFactories<ECompilerType>;
|
|
42
|
+
testConfig?: TTestConfig;
|
|
55
43
|
contextValue?: Record<string, unknown>;
|
|
56
44
|
runnerCreator?: TTestRunnerCreator;
|
|
57
45
|
createContext?: (config: ITesterConfig) => ITestContext;
|
|
@@ -78,9 +66,9 @@ export interface ITestProcessor {
|
|
|
78
66
|
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
79
67
|
check(env: ITestEnv, context: ITestContext): Promise<unknown>;
|
|
80
68
|
}
|
|
81
|
-
export interface ITestReporter
|
|
82
|
-
init(data?: T): Promise<void>;
|
|
83
|
-
increment(id: string, data: T): Promise<void>;
|
|
69
|
+
export interface ITestReporter {
|
|
70
|
+
init<T>(data?: T): Promise<void>;
|
|
71
|
+
increment<T>(id: string, data: T): Promise<void>;
|
|
84
72
|
failure(id: string): Promise<void>;
|
|
85
73
|
output(): Promise<void>;
|
|
86
74
|
}
|
|
@@ -130,17 +118,17 @@ export interface ITestEnv {
|
|
|
130
118
|
afterEach: (...args: any[]) => void;
|
|
131
119
|
[key: string]: unknown;
|
|
132
120
|
}
|
|
133
|
-
export type TTestConfig
|
|
121
|
+
export type TTestConfig = {
|
|
134
122
|
location?: string;
|
|
135
|
-
validate?: (stats:
|
|
123
|
+
validate?: (stats: Stats | MultiStats, stderr?: string) => void;
|
|
136
124
|
noTests?: boolean;
|
|
137
125
|
writeStatsOuptut?: boolean;
|
|
138
126
|
writeStatsJson?: boolean;
|
|
139
|
-
beforeExecute?: (options:
|
|
140
|
-
afterExecute?: (options:
|
|
141
|
-
moduleScope?: (ms: IModuleScope, stats?:
|
|
142
|
-
checkStats?: (stepName: string, jsonStats:
|
|
143
|
-
findBundle?: (index: number, options:
|
|
127
|
+
beforeExecute?: (options: RspackOptions) => void;
|
|
128
|
+
afterExecute?: (options: RspackOptions) => void;
|
|
129
|
+
moduleScope?: (ms: IModuleScope, stats?: StatsCompilation, options?: RspackOptions) => IModuleScope;
|
|
130
|
+
checkStats?: (stepName: string, jsonStats: StatsCompilation | undefined, stringStats: String) => boolean;
|
|
131
|
+
findBundle?: (index: number, options: RspackOptions, stepName?: string) => string | string[];
|
|
144
132
|
bundlePath?: string[];
|
|
145
133
|
nonEsmThis?: (p: string | string[]) => Object;
|
|
146
134
|
modules?: Record<string, Object>;
|
|
@@ -153,22 +141,21 @@ export type TTestConfig<T extends ECompilerType> = {
|
|
|
153
141
|
preserveModules?: string;
|
|
154
142
|
};
|
|
155
143
|
};
|
|
156
|
-
export type TTestFilter
|
|
144
|
+
export type TTestFilter = (creatorConfig: Record<string, unknown>, testConfig: TTestConfig) => boolean | string;
|
|
157
145
|
export interface ITestRunner {
|
|
158
146
|
run(file: string): Promise<unknown>;
|
|
159
147
|
getRequire(): TRunnerRequirer;
|
|
160
148
|
getGlobal(name: string): unknown;
|
|
161
149
|
}
|
|
162
|
-
export type TCompilerFactory
|
|
163
|
-
export interface TRunnerFactory
|
|
164
|
-
create(file: string, compilerOptions:
|
|
150
|
+
export type TCompilerFactory = (options: RspackOptions | RspackOptions[], callback?: (error: Error | null, stats: Stats | null) => void) => Compiler;
|
|
151
|
+
export interface TRunnerFactory {
|
|
152
|
+
create(file: string, compilerOptions: RspackOptions, env: ITestEnv): ITestRunner;
|
|
165
153
|
}
|
|
166
154
|
export type THotUpdateContext = {
|
|
167
155
|
updateIndex: number;
|
|
168
156
|
totalUpdates: number;
|
|
169
157
|
changedFiles: string[];
|
|
170
158
|
};
|
|
171
|
-
export type TCompilerFactories<T extends ECompilerType> = Record<T, TCompilerFactory<T>>;
|
|
172
159
|
export type TRunnerRequirer = (currentDirectory: string, modulePath: string[] | string, context?: {
|
|
173
160
|
file?: TRunnerFile;
|
|
174
161
|
esmMode?: EEsmMode;
|
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-e28e40e9-20251022173516",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -42,11 +42,8 @@
|
|
|
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",
|
|
51
48
|
"jest-diff": "^29.7.0",
|
|
52
49
|
"jest-snapshot": "29.7.0",
|
|
@@ -60,19 +57,17 @@
|
|
|
60
57
|
"terser-webpack-plugin": "^5.3.14",
|
|
61
58
|
"webpack": "5.102.1",
|
|
62
59
|
"webpack-merge": "6.0.1",
|
|
63
|
-
"webpack-sources": "3.3.3"
|
|
60
|
+
"webpack-sources": "3.3.3",
|
|
61
|
+
"chalk": "^4.1.2"
|
|
64
62
|
},
|
|
65
63
|
"devDependencies": {
|
|
66
64
|
"@types/babel__generator": "7.27.0",
|
|
67
65
|
"@types/babel__traverse": "7.28.0",
|
|
68
66
|
"@types/fs-extra": "11.0.4",
|
|
69
67
|
"@types/jsdom": "^21.1.7",
|
|
70
|
-
"chalk": "^4.1.2",
|
|
71
|
-
"source-map": "^0.7.6",
|
|
72
|
-
"terser": "5.43.1",
|
|
73
68
|
"typescript": "^5.9.3",
|
|
74
69
|
"wast-loader": "^1.14.1",
|
|
75
|
-
"@rspack/core": "npm:@rspack-canary/core@1.6.0-canary-
|
|
70
|
+
"@rspack/core": "npm:@rspack-canary/core@1.6.0-canary-e28e40e9-20251022173516"
|
|
76
71
|
},
|
|
77
72
|
"peerDependencies": {
|
|
78
73
|
"@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
|
-
}
|