@rspack-canary/test-tools 1.5.6-canary-e598f284-20250921173624 → 1.5.8-canary-e350b761-20250924173613
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 +2 -0
- package/dist/case/builtin.js +173 -13
- package/dist/case/cache.d.ts +1 -1
- package/dist/case/cache.js +210 -11
- package/dist/case/common.d.ts +10 -0
- package/dist/case/common.js +237 -0
- package/dist/case/compiler.d.ts +7 -4
- package/dist/case/compiler.js +144 -109
- package/dist/case/config.d.ts +5 -1
- package/dist/case/config.js +102 -16
- package/dist/case/defaults.d.ts +12 -4
- package/dist/case/defaults.js +67 -12
- package/dist/case/diagnostic.d.ts +6 -0
- package/dist/case/diagnostic.js +123 -14
- package/dist/case/diff.d.ts +17 -1
- package/dist/case/diff.js +170 -22
- package/dist/case/error.d.ts +14 -4
- package/dist/case/error.js +117 -10
- package/dist/case/hash.d.ts +1 -1
- package/dist/case/hash.js +70 -9
- package/dist/case/hook.d.ts +35 -4
- package/dist/case/hook.js +210 -21
- package/dist/case/hot-step.js +307 -9
- package/dist/case/hot.d.ts +8 -1
- package/dist/case/hot.js +235 -8
- package/dist/case/incremental.d.ts +1 -1
- package/dist/case/incremental.js +39 -41
- package/dist/case/index.d.ts +20 -20
- package/dist/case/index.js +44 -34
- package/dist/case/native-watcher.js +10 -23
- package/dist/case/normal.js +174 -12
- package/dist/case/runner.d.ts +18 -0
- package/dist/case/runner.js +108 -0
- package/dist/case/serial.d.ts +1 -1
- package/dist/case/serial.js +8 -12
- package/dist/case/stats-api.d.ts +0 -5
- package/dist/case/stats-api.js +71 -10
- package/dist/case/stats-output.js +197 -11
- package/dist/case/treeshaking.js +34 -7
- package/dist/case/watch.d.ts +27 -0
- package/dist/case/watch.js +321 -21
- package/dist/helper/plugins/hot-update.d.ts +2 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/runner/index.d.ts +2 -7
- package/dist/runner/index.js +2 -7
- package/dist/runner/{runner/node → node}/index.d.ts +1 -2
- package/dist/runner/{runner/node → node}/index.js +2 -2
- package/dist/runner/{runner/web → web}/fake.d.ts +1 -2
- package/dist/runner/{runner/web → web}/fake.js +7 -7
- package/dist/runner/{runner/web → web}/index.d.ts +2 -2
- package/dist/runner/{runner/web → web}/index.js +1 -1
- package/dist/runner/{runner/web → web}/jsdom.d.ts +1 -2
- package/dist/runner/{runner/web → web}/jsdom.js +4 -4
- package/dist/test/context.d.ts +3 -5
- package/dist/test/context.js +22 -12
- package/dist/test/creator.d.ts +13 -12
- package/dist/test/creator.js +52 -43
- package/dist/test/tester.js +4 -1
- package/dist/type.d.ts +42 -11
- package/dist/type.js +7 -1
- package/package.json +5 -5
- package/dist/processor/basic.d.ts +0 -24
- package/dist/processor/basic.js +0 -147
- package/dist/processor/builtin.d.ts +0 -9
- package/dist/processor/builtin.js +0 -171
- package/dist/processor/cache.d.ts +0 -20
- package/dist/processor/cache.js +0 -131
- package/dist/processor/config.d.ts +0 -11
- package/dist/processor/config.js +0 -88
- package/dist/processor/defaults.d.ts +0 -30
- package/dist/processor/defaults.js +0 -72
- package/dist/processor/diagnostic.d.ts +0 -15
- package/dist/processor/diagnostic.js +0 -104
- package/dist/processor/diff.d.ts +0 -30
- package/dist/processor/diff.js +0 -140
- package/dist/processor/error.d.ts +0 -23
- package/dist/processor/error.js +0 -95
- package/dist/processor/hash.d.ts +0 -10
- package/dist/processor/hash.js +0 -65
- package/dist/processor/hook.d.ts +0 -44
- package/dist/processor/hook.js +0 -206
- package/dist/processor/hot-incremental.d.ts +0 -14
- package/dist/processor/hot-incremental.js +0 -43
- package/dist/processor/hot-step.d.ts +0 -18
- package/dist/processor/hot-step.js +0 -307
- package/dist/processor/hot.d.ts +0 -17
- package/dist/processor/hot.js +0 -147
- package/dist/processor/index.d.ts +0 -20
- package/dist/processor/index.js +0 -36
- package/dist/processor/multi.d.ts +0 -17
- package/dist/processor/multi.js +0 -73
- package/dist/processor/normal.d.ts +0 -12
- package/dist/processor/normal.js +0 -170
- package/dist/processor/simple.d.ts +0 -24
- package/dist/processor/simple.js +0 -51
- package/dist/processor/snapshot.d.ts +0 -12
- package/dist/processor/snapshot.js +0 -66
- package/dist/processor/stats-api.d.ts +0 -18
- package/dist/processor/stats-api.js +0 -48
- package/dist/processor/stats.d.ts +0 -18
- package/dist/processor/stats.js +0 -206
- package/dist/processor/treeshaking.d.ts +0 -10
- package/dist/processor/treeshaking.js +0 -33
- package/dist/processor/watch.d.ts +0 -30
- package/dist/processor/watch.js +0 -252
- package/dist/runner/basic.d.ts +0 -10
- package/dist/runner/basic.js +0 -64
- package/dist/runner/cache.d.ts +0 -5
- package/dist/runner/cache.js +0 -92
- package/dist/runner/hot.d.ts +0 -5
- package/dist/runner/hot.js +0 -91
- package/dist/runner/multiple.d.ts +0 -11
- package/dist/runner/multiple.js +0 -52
- package/dist/runner/runner/index.d.ts +0 -2
- package/dist/runner/runner/index.js +0 -18
- package/dist/runner/type.d.ts +0 -42
- package/dist/runner/type.js +0 -9
- package/dist/runner/watch.d.ts +0 -7
- package/dist/runner/watch.js +0 -71
- package/dist/test/simple.d.ts +0 -5
- package/dist/test/simple.js +0 -43
package/dist/processor/diff.js
DELETED
|
@@ -1,140 +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.DiffProcessor = void 0;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const compare_1 = require("../compare");
|
|
9
|
-
const plugin_1 = require("../plugin");
|
|
10
|
-
const type_1 = require("../type");
|
|
11
|
-
const basic_1 = require("./basic");
|
|
12
|
-
class DiffProcessor {
|
|
13
|
-
constructor(options) {
|
|
14
|
-
this.options = options;
|
|
15
|
-
this.hashes = [];
|
|
16
|
-
this.webpack = null;
|
|
17
|
-
if (global.updateSnapshot) {
|
|
18
|
-
this.webpack = new basic_1.BasicProcessor({
|
|
19
|
-
defaultOptions: context => this.getDefaultOptions(type_1.ECompilerType.Webpack, context.getSource(), node_path_1.default.join(context.getDist(), type_1.ECompilerType.Webpack)),
|
|
20
|
-
compilerType: type_1.ECompilerType.Webpack,
|
|
21
|
-
name: type_1.ECompilerType.Webpack,
|
|
22
|
-
configFiles: ["webpack.config.js", "rspack.config.js"],
|
|
23
|
-
runable: false
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
this.rspack = new basic_1.BasicProcessor({
|
|
27
|
-
defaultOptions: context => this.getDefaultOptions(type_1.ECompilerType.Rspack, context.getSource(), node_path_1.default.join(context.getDist(), type_1.ECompilerType.Rspack)),
|
|
28
|
-
compilerType: type_1.ECompilerType.Rspack,
|
|
29
|
-
name: type_1.ECompilerType.Rspack,
|
|
30
|
-
configFiles: ["rspack.config.js", "webpack.config.js"],
|
|
31
|
-
runable: false
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
async config(context) {
|
|
35
|
-
if (this.webpack) {
|
|
36
|
-
await this.webpack.config(context);
|
|
37
|
-
}
|
|
38
|
-
await this.rspack.config(context);
|
|
39
|
-
}
|
|
40
|
-
async compiler(context) {
|
|
41
|
-
if (this.webpack) {
|
|
42
|
-
await this.webpack.compiler(context);
|
|
43
|
-
}
|
|
44
|
-
await this.rspack.compiler(context);
|
|
45
|
-
}
|
|
46
|
-
async build(context) {
|
|
47
|
-
if (this.webpack) {
|
|
48
|
-
await this.webpack.build(context);
|
|
49
|
-
}
|
|
50
|
-
await this.rspack.build(context);
|
|
51
|
-
}
|
|
52
|
-
async check(env, context) {
|
|
53
|
-
if (this.webpack) {
|
|
54
|
-
const webpackCompiler = context.getCompiler(type_1.ECompilerType.Webpack);
|
|
55
|
-
const webpackStats = webpackCompiler.getStats();
|
|
56
|
-
//TODO: handle chunk hash and content hash
|
|
57
|
-
webpackStats?.hash && this.hashes.push(webpackStats?.hash);
|
|
58
|
-
if (!this.options.errors) {
|
|
59
|
-
env.expect(webpackStats?.hasErrors()).toBe(false);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const rspackCompiler = context.getCompiler(type_1.ECompilerType.Rspack);
|
|
63
|
-
const rspackStats = rspackCompiler.getStats();
|
|
64
|
-
//TODO: handle chunk hash and content hash
|
|
65
|
-
rspackStats?.hash && this.hashes.push(rspackStats?.hash);
|
|
66
|
-
if (!this.options.errors) {
|
|
67
|
-
env.expect(rspackStats?.hasErrors()).toBe(false);
|
|
68
|
-
}
|
|
69
|
-
const dist = context.getDist();
|
|
70
|
-
const snapshot = context.getSource("__snapshot__");
|
|
71
|
-
for (const file of this.options.files) {
|
|
72
|
-
const rspackDist = node_path_1.default.join(dist, type_1.ECompilerType.Rspack, file);
|
|
73
|
-
const webpackDist = node_path_1.default.join(dist, type_1.ECompilerType.Webpack, file);
|
|
74
|
-
const snapshotDist = node_path_1.default.join(snapshot, file.replace(/\.js$/, ".json"));
|
|
75
|
-
const result = (0, compare_1.compareFile)(rspackDist, webpackDist, {
|
|
76
|
-
modules: this.options.modules,
|
|
77
|
-
runtimeModules: this.options.runtimeModules,
|
|
78
|
-
format: this.createFormatOptions(),
|
|
79
|
-
renameModule: this.options.renameModule,
|
|
80
|
-
bootstrap: this.options.bootstrap,
|
|
81
|
-
detail: this.options.detail,
|
|
82
|
-
snapshot: snapshotDist
|
|
83
|
-
});
|
|
84
|
-
if (typeof this.options.onCompareFile === "function") {
|
|
85
|
-
this.options.onCompareFile(file, result);
|
|
86
|
-
}
|
|
87
|
-
if (typeof this.options.onCompareModules === "function" &&
|
|
88
|
-
result.modules.modules) {
|
|
89
|
-
this.options.onCompareModules(file, result.modules.modules);
|
|
90
|
-
}
|
|
91
|
-
if (typeof this.options.onCompareRuntimeModules === "function" &&
|
|
92
|
-
result.modules.runtimeModules) {
|
|
93
|
-
this.options.onCompareRuntimeModules(file, result.modules.runtimeModules);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
getDefaultOptions(type, src, dist) {
|
|
98
|
-
return {
|
|
99
|
-
entry: node_path_1.default.join(src, "./src/index.js"),
|
|
100
|
-
context: src,
|
|
101
|
-
output: {
|
|
102
|
-
path: dist,
|
|
103
|
-
filename: "bundle.js",
|
|
104
|
-
chunkFilename: "[name].chunk.js"
|
|
105
|
-
},
|
|
106
|
-
plugins: [
|
|
107
|
-
type === type_1.ECompilerType.Webpack && new plugin_1.WebpackDiffConfigPlugin(),
|
|
108
|
-
type === type_1.ECompilerType.Rspack && new plugin_1.RspackDiffConfigPlugin()
|
|
109
|
-
].filter(Boolean),
|
|
110
|
-
experiments: type === type_1.ECompilerType.Rspack
|
|
111
|
-
? {
|
|
112
|
-
css: true,
|
|
113
|
-
rspackFuture: {
|
|
114
|
-
bundlerInfo: {
|
|
115
|
-
force: false
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
: {}
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
createFormatOptions() {
|
|
123
|
-
const formatOptions = {
|
|
124
|
-
ignoreModuleArguments: this.options.ignoreModuleArguments,
|
|
125
|
-
ignoreModuleId: this.options.ignoreModuleId,
|
|
126
|
-
ignorePropertyQuotationMark: this.options.ignorePropertyQuotationMark,
|
|
127
|
-
ignoreBlockOnlyStatement: this.options.ignoreBlockOnlyStatement,
|
|
128
|
-
ignoreIfCertainCondition: this.options.ignoreIfCertainCondition,
|
|
129
|
-
ignoreSwcHelpersPath: this.options.ignoreSwcHelpersPath,
|
|
130
|
-
ignoreObjectPropertySequence: this.options.ignoreObjectPropertySequence,
|
|
131
|
-
ignoreCssFilePath: this.options.ignoreCssFilePath,
|
|
132
|
-
replacements: this.options.replacements || []
|
|
133
|
-
};
|
|
134
|
-
for (const hash of this.hashes) {
|
|
135
|
-
formatOptions.replacements.push({ from: hash, to: "fullhash" });
|
|
136
|
-
}
|
|
137
|
-
return formatOptions;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
exports.DiffProcessor = DiffProcessor;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { StatsError } from "@rspack/core";
|
|
2
|
-
import type { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions } from "../type";
|
|
3
|
-
import { SimpleTaskProcessor } from "./simple";
|
|
4
|
-
declare class RspackStatsDiagnostics {
|
|
5
|
-
errors: StatsError[];
|
|
6
|
-
warnings: StatsError[];
|
|
7
|
-
constructor(errors: StatsError[], warnings: StatsError[]);
|
|
8
|
-
}
|
|
9
|
-
export interface IErrorProcessorOptions<T extends ECompilerType> {
|
|
10
|
-
name: string;
|
|
11
|
-
compilerType: T;
|
|
12
|
-
options?: (options: TCompilerOptions<T>, context: ITestContext) => TCompilerOptions<T>;
|
|
13
|
-
build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
|
|
14
|
-
check?: (stats: RspackStatsDiagnostics) => Promise<void>;
|
|
15
|
-
}
|
|
16
|
-
export declare class ErrorProcessor<T extends ECompilerType> extends SimpleTaskProcessor<T> {
|
|
17
|
-
protected _errorOptions: IErrorProcessorOptions<T>;
|
|
18
|
-
constructor(_errorOptions: IErrorProcessorOptions<T>);
|
|
19
|
-
compiler(context: ITestContext): Promise<void>;
|
|
20
|
-
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
21
|
-
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
export {};
|
package/dist/processor/error.js
DELETED
|
@@ -1,95 +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.ErrorProcessor = void 0;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
9
|
-
const simple_1 = require("./simple");
|
|
10
|
-
class RspackStatsDiagnostics {
|
|
11
|
-
constructor(errors, warnings) {
|
|
12
|
-
this.errors = errors;
|
|
13
|
-
this.warnings = warnings;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
class ErrorProcessor extends simple_1.SimpleTaskProcessor {
|
|
17
|
-
constructor(_errorOptions) {
|
|
18
|
-
super({
|
|
19
|
-
options: (context) => {
|
|
20
|
-
let options = {
|
|
21
|
-
context: node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/fixtures/errors"),
|
|
22
|
-
mode: "none",
|
|
23
|
-
devtool: false,
|
|
24
|
-
optimization: {
|
|
25
|
-
minimize: false,
|
|
26
|
-
moduleIds: "named",
|
|
27
|
-
chunkIds: "named"
|
|
28
|
-
},
|
|
29
|
-
experiments: {
|
|
30
|
-
css: true,
|
|
31
|
-
rspackFuture: {
|
|
32
|
-
bundlerInfo: {
|
|
33
|
-
force: false
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
if (typeof _errorOptions.options === "function") {
|
|
39
|
-
options = (0, webpack_merge_1.default)(options, _errorOptions.options(options, context));
|
|
40
|
-
}
|
|
41
|
-
if (options.mode === "production") {
|
|
42
|
-
if (options.optimization)
|
|
43
|
-
options.optimization.minimize = true;
|
|
44
|
-
else
|
|
45
|
-
options.optimization = { minimize: true };
|
|
46
|
-
}
|
|
47
|
-
return options;
|
|
48
|
-
},
|
|
49
|
-
build: _errorOptions.build,
|
|
50
|
-
compilerType: _errorOptions.compilerType,
|
|
51
|
-
name: _errorOptions.name
|
|
52
|
-
});
|
|
53
|
-
this._errorOptions = _errorOptions;
|
|
54
|
-
}
|
|
55
|
-
async compiler(context) {
|
|
56
|
-
await super.compiler(context);
|
|
57
|
-
const compiler = this.getCompiler(context).getCompiler();
|
|
58
|
-
if (compiler) {
|
|
59
|
-
compiler.outputFileSystem = {
|
|
60
|
-
// CHANGE: rspack outputFileSystem `mkdirp` uses option `{ recursive: true }`, webpack's second parameter is alway a callback
|
|
61
|
-
mkdir(dir, maybeOptionOrCallback, maybeCallback) {
|
|
62
|
-
if (typeof maybeOptionOrCallback === "function") {
|
|
63
|
-
maybeOptionOrCallback();
|
|
64
|
-
}
|
|
65
|
-
else if (typeof maybeCallback === "function") {
|
|
66
|
-
maybeCallback();
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
writeFile(file, content, callback) {
|
|
70
|
-
callback();
|
|
71
|
-
},
|
|
72
|
-
stat(file, callback) {
|
|
73
|
-
callback(new Error("ENOENT"));
|
|
74
|
-
},
|
|
75
|
-
mkdirSync() { },
|
|
76
|
-
writeFileSync() { }
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
async run(env, context) {
|
|
81
|
-
// do nothing
|
|
82
|
-
}
|
|
83
|
-
async check(env, context) {
|
|
84
|
-
const compiler = this.getCompiler(context);
|
|
85
|
-
const stats = compiler.getStats();
|
|
86
|
-
env.expect(typeof stats).toBe("object");
|
|
87
|
-
const statsResult = stats.toJson({ errorDetails: false });
|
|
88
|
-
env.expect(typeof statsResult).toBe("object");
|
|
89
|
-
const { errors, warnings } = statsResult;
|
|
90
|
-
env.expect(Array.isArray(errors)).toBe(true);
|
|
91
|
-
env.expect(Array.isArray(warnings)).toBe(true);
|
|
92
|
-
await this._errorOptions.check?.(new RspackStatsDiagnostics(errors, warnings));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.ErrorProcessor = ErrorProcessor;
|
package/dist/processor/hash.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
|
|
2
|
-
import { type IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";
|
|
3
|
-
export interface IHashProcessorOptions<T extends ECompilerType> extends Omit<IMultiTaskProcessorOptions<T>, "runable"> {
|
|
4
|
-
}
|
|
5
|
-
export declare class HashProcessor<T extends ECompilerType> extends MultiTaskProcessor<T> {
|
|
6
|
-
constructor(_hashOptions: IHashProcessorOptions<T>);
|
|
7
|
-
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
8
|
-
static defaultOptions<T extends ECompilerType>(index: number, context: ITestContext): TCompilerOptions<T>;
|
|
9
|
-
static overrideOptions<T extends ECompilerType>(index: number, context: ITestContext, options: TCompilerOptions<T>): void;
|
|
10
|
-
}
|
package/dist/processor/hash.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HashProcessor = void 0;
|
|
4
|
-
const multi_1 = require("./multi");
|
|
5
|
-
const REG_ERROR_CASE = /error$/;
|
|
6
|
-
class HashProcessor extends multi_1.MultiTaskProcessor {
|
|
7
|
-
constructor(_hashOptions) {
|
|
8
|
-
super({
|
|
9
|
-
defaultOptions: (HashProcessor.defaultOptions),
|
|
10
|
-
overrideOptions: (HashProcessor.overrideOptions),
|
|
11
|
-
runable: false,
|
|
12
|
-
..._hashOptions
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
async check(env, context) {
|
|
16
|
-
const compiler = this.getCompiler(context);
|
|
17
|
-
const testConfig = context.getTestConfig();
|
|
18
|
-
const stats = compiler.getStats();
|
|
19
|
-
if (!stats) {
|
|
20
|
-
env.expect(false);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (REG_ERROR_CASE.test(this._options.name)) {
|
|
24
|
-
env.expect(stats.hasErrors());
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
env.expect(!stats.hasErrors());
|
|
28
|
-
}
|
|
29
|
-
if (typeof testConfig.validate === "function") {
|
|
30
|
-
testConfig.validate(stats);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
throw new Error("HashTestCases should have test.config.js and a validate method");
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
static defaultOptions(index, context) {
|
|
37
|
-
return {
|
|
38
|
-
context: context.getSource(),
|
|
39
|
-
output: {
|
|
40
|
-
path: context.getDist()
|
|
41
|
-
},
|
|
42
|
-
experiments: {
|
|
43
|
-
css: true,
|
|
44
|
-
rspackFuture: {
|
|
45
|
-
bundlerInfo: {
|
|
46
|
-
force: false
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
inlineConst: true,
|
|
50
|
-
lazyBarrel: true
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
static overrideOptions(index, context, options) {
|
|
55
|
-
if (!options.entry) {
|
|
56
|
-
options.entry = "./index.js";
|
|
57
|
-
}
|
|
58
|
-
if (!global.printLogger) {
|
|
59
|
-
options.infrastructureLogging = {
|
|
60
|
-
level: "error"
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.HashProcessor = HashProcessor;
|
package/dist/processor/hook.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { TestContext, type TTestContextOptions } from "../test/context";
|
|
2
|
-
import type { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions } from "../type";
|
|
3
|
-
import { type ISnapshotProcessorOptions, SnapshotProcessor } from "./snapshot";
|
|
4
|
-
export declare class HookCasesContext extends TestContext {
|
|
5
|
-
protected src: string;
|
|
6
|
-
protected testName: string;
|
|
7
|
-
protected options: TTestContextOptions;
|
|
8
|
-
protected promises: Promise<void>[];
|
|
9
|
-
protected count: number;
|
|
10
|
-
protected snapshots: Record<string | number, Array<[string | Buffer, string]>>;
|
|
11
|
-
protected snapshotsList: Array<string | number>;
|
|
12
|
-
constructor(src: string, testName: string, options: TTestContextOptions);
|
|
13
|
-
/**
|
|
14
|
-
* Snapshot function arguments and return value.
|
|
15
|
-
* Generated snapshot is located in the same directory with the test source.
|
|
16
|
-
* @example
|
|
17
|
-
* compiler.hooks.compilation("name", context.snapped((...args) => { ... }))
|
|
18
|
-
*/
|
|
19
|
-
snapped(cb: (...args: unknown[]) => Promise<unknown>, prefix?: string): (this: any, ...args: unknown[]) => Promise<unknown>;
|
|
20
|
-
/**
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
_addSnapshot(content: unknown, name: string, group: string | number): void;
|
|
24
|
-
/**
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
collectSnapshots(env: ITestEnv, options?: {
|
|
28
|
-
diff: {};
|
|
29
|
-
}): Promise<void>;
|
|
30
|
-
}
|
|
31
|
-
export interface IHookProcessorOptions<T extends ECompilerType> extends ISnapshotProcessorOptions<T> {
|
|
32
|
-
options?: (context: ITestContext) => TCompilerOptions<T>;
|
|
33
|
-
compiler?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
|
|
34
|
-
check?: (context: ITestContext) => Promise<void>;
|
|
35
|
-
}
|
|
36
|
-
export declare class HookTaskProcessor<T extends ECompilerType> extends SnapshotProcessor<T> {
|
|
37
|
-
protected _hookOptions: IHookProcessorOptions<T>;
|
|
38
|
-
constructor(_hookOptions: IHookProcessorOptions<T>);
|
|
39
|
-
config(context: ITestContext): Promise<void>;
|
|
40
|
-
compiler(context: ITestContext): Promise<void>;
|
|
41
|
-
check(env: ITestEnv, context: HookCasesContext): Promise<void>;
|
|
42
|
-
static defaultOptions<T extends ECompilerType>(context: ITestContext): TCompilerOptions<T>;
|
|
43
|
-
static overrideOptions<T extends ECompilerType>(options: TCompilerOptions<T>): void;
|
|
44
|
-
}
|
package/dist/processor/hook.js
DELETED
|
@@ -1,206 +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.HookTaskProcessor = exports.HookCasesContext = void 0;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const core_1 = require("@rspack/core");
|
|
9
|
-
const jest_snapshot_1 = require("jest-snapshot");
|
|
10
|
-
const path_serializer_1 = require("path-serializer");
|
|
11
|
-
const pretty_format_1 = require("pretty-format");
|
|
12
|
-
const context_1 = require("../test/context");
|
|
13
|
-
const snapshot_1 = require("./snapshot");
|
|
14
|
-
const srcDir = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/fixtures");
|
|
15
|
-
const distDir = node_path_1.default.resolve(__dirname, "../../../../tests/rspack-test/js/hook");
|
|
16
|
-
const sourceSerializer = {
|
|
17
|
-
test(val) {
|
|
18
|
-
return val instanceof core_1.sources.Source;
|
|
19
|
-
},
|
|
20
|
-
print(val) {
|
|
21
|
-
return val.source();
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const internalSerializer = {
|
|
25
|
-
test(val) {
|
|
26
|
-
return val instanceof core_1.Compiler || val instanceof core_1.Compilation;
|
|
27
|
-
},
|
|
28
|
-
print(val) {
|
|
29
|
-
return JSON.stringify(`${val.constructor.name}(internal ignored)`);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const testPathSerializer = (0, path_serializer_1.createSnapshotSerializer)({
|
|
33
|
-
replace: [
|
|
34
|
-
{
|
|
35
|
-
match: srcDir,
|
|
36
|
-
mark: "<HOOK_SRC_DIR>"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
match: distDir,
|
|
40
|
-
mark: "<HOOK_DIST_DIR>"
|
|
41
|
-
}
|
|
42
|
-
]
|
|
43
|
-
});
|
|
44
|
-
const escapeRegex = true;
|
|
45
|
-
const printFunctionName = false;
|
|
46
|
-
const normalizeNewlines = (str) => str.replace(/\r\n|\r/g, "\n");
|
|
47
|
-
const serialize = (val, indent = 2, formatOverrides = {}) => normalizeNewlines((0, pretty_format_1.format)(val, {
|
|
48
|
-
escapeRegex,
|
|
49
|
-
indent,
|
|
50
|
-
plugins: [
|
|
51
|
-
...(0, jest_snapshot_1.getSerializers)(),
|
|
52
|
-
sourceSerializer,
|
|
53
|
-
internalSerializer,
|
|
54
|
-
testPathSerializer
|
|
55
|
-
],
|
|
56
|
-
printFunctionName,
|
|
57
|
-
...formatOverrides
|
|
58
|
-
}));
|
|
59
|
-
class HookCasesContext extends context_1.TestContext {
|
|
60
|
-
constructor(src, testName, options) {
|
|
61
|
-
super(options);
|
|
62
|
-
this.src = src;
|
|
63
|
-
this.testName = testName;
|
|
64
|
-
this.options = options;
|
|
65
|
-
this.promises = [];
|
|
66
|
-
this.count = 0;
|
|
67
|
-
this.snapshots = {};
|
|
68
|
-
this.snapshotsList = [];
|
|
69
|
-
this.snapped = this.snapped.bind(this);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Snapshot function arguments and return value.
|
|
73
|
-
* Generated snapshot is located in the same directory with the test source.
|
|
74
|
-
* @example
|
|
75
|
-
* compiler.hooks.compilation("name", context.snapped((...args) => { ... }))
|
|
76
|
-
*/
|
|
77
|
-
snapped(cb, prefix = "") {
|
|
78
|
-
// eslint-disable-next-line
|
|
79
|
-
const context = this;
|
|
80
|
-
return function SNAPPED_HOOK(...args) {
|
|
81
|
-
const group = prefix ? prefix : context.count++;
|
|
82
|
-
context._addSnapshot(args, "input", group);
|
|
83
|
-
const output = cb.apply(this, args);
|
|
84
|
-
if (output && typeof output.then === "function") {
|
|
85
|
-
let resolve;
|
|
86
|
-
context.promises.push(new Promise(r => (resolve = r)));
|
|
87
|
-
return output
|
|
88
|
-
.then((o) => {
|
|
89
|
-
context._addSnapshot(o, "output (Promise resolved)", group);
|
|
90
|
-
return o;
|
|
91
|
-
})
|
|
92
|
-
.catch((o) => {
|
|
93
|
-
context._addSnapshot(o, "output (Promise rejected)", group);
|
|
94
|
-
return o;
|
|
95
|
-
})
|
|
96
|
-
.finally(resolve);
|
|
97
|
-
}
|
|
98
|
-
context._addSnapshot(output, "output", group);
|
|
99
|
-
return output;
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* @internal
|
|
104
|
-
*/
|
|
105
|
-
_addSnapshot(content, name, group) {
|
|
106
|
-
const normalizedContent = Buffer.isBuffer(content)
|
|
107
|
-
? content
|
|
108
|
-
: serialize(content, undefined, {
|
|
109
|
-
escapeString: true,
|
|
110
|
-
printBasicPrototype: true
|
|
111
|
-
}).replace(/\r\n/g, "\n");
|
|
112
|
-
(this.snapshots[group] = this.snapshots[group] || []).push([
|
|
113
|
-
normalizedContent,
|
|
114
|
-
name
|
|
115
|
-
]);
|
|
116
|
-
if (!this.snapshotsList.includes(group)) {
|
|
117
|
-
this.snapshotsList.push(group);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* @internal
|
|
122
|
-
*/
|
|
123
|
-
async collectSnapshots(env, options = {
|
|
124
|
-
diff: {}
|
|
125
|
-
}) {
|
|
126
|
-
await Promise.allSettled(this.promises);
|
|
127
|
-
if (!this.snapshotsList.length)
|
|
128
|
-
return;
|
|
129
|
-
const snapshots = this.snapshotsList.reduce((acc, group, index) => {
|
|
130
|
-
const block = this.snapshots[group || index].reduce((acc, [content, name]) => {
|
|
131
|
-
name = `## ${name || `test: ${index}`}\n\n`;
|
|
132
|
-
const block = `\`\`\`javascript\n${content}\n\`\`\`\n`;
|
|
133
|
-
return `${acc}${name + block}\n`;
|
|
134
|
-
}, "");
|
|
135
|
-
return `${acc}# ${Number.isInteger(group) ? `Group: ${index}` : group}\n\n${block}`;
|
|
136
|
-
}, "");
|
|
137
|
-
env
|
|
138
|
-
.expect(snapshots)
|
|
139
|
-
.toMatchFileSnapshot(node_path_1.default.join(this.src, "hooks.snap.txt"), options);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
exports.HookCasesContext = HookCasesContext;
|
|
143
|
-
class HookTaskProcessor extends snapshot_1.SnapshotProcessor {
|
|
144
|
-
constructor(_hookOptions) {
|
|
145
|
-
super({
|
|
146
|
-
defaultOptions: (HookTaskProcessor.defaultOptions),
|
|
147
|
-
..._hookOptions
|
|
148
|
-
});
|
|
149
|
-
this._hookOptions = _hookOptions;
|
|
150
|
-
}
|
|
151
|
-
async config(context) {
|
|
152
|
-
await super.config(context);
|
|
153
|
-
const compiler = this.getCompiler(context);
|
|
154
|
-
if (typeof this._hookOptions.options === "function") {
|
|
155
|
-
compiler.mergeOptions(this._hookOptions.options(context));
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
async compiler(context) {
|
|
159
|
-
await super.compiler(context);
|
|
160
|
-
if (typeof this._hookOptions.compiler === "function") {
|
|
161
|
-
const compiler = this.getCompiler(context);
|
|
162
|
-
await this._hookOptions.compiler(context, compiler.getCompiler());
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
async check(env, context) {
|
|
166
|
-
await context.collectSnapshots(env);
|
|
167
|
-
await super.check(env, context);
|
|
168
|
-
if (typeof this._hookOptions.check === "function") {
|
|
169
|
-
await this._hookOptions.check(context);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
static defaultOptions(context) {
|
|
173
|
-
return {
|
|
174
|
-
context: context.getSource(),
|
|
175
|
-
mode: "production",
|
|
176
|
-
target: "async-node",
|
|
177
|
-
devtool: false,
|
|
178
|
-
cache: false,
|
|
179
|
-
entry: "./hook",
|
|
180
|
-
output: {
|
|
181
|
-
path: context.getDist()
|
|
182
|
-
},
|
|
183
|
-
optimization: {
|
|
184
|
-
minimize: false
|
|
185
|
-
},
|
|
186
|
-
experiments: {
|
|
187
|
-
css: true,
|
|
188
|
-
rspackFuture: {
|
|
189
|
-
bundlerInfo: {
|
|
190
|
-
force: false
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
inlineConst: true,
|
|
194
|
-
lazyBarrel: true
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
static overrideOptions(options) {
|
|
199
|
-
if (!global.printLogger) {
|
|
200
|
-
options.infrastructureLogging = {
|
|
201
|
-
level: "error"
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
exports.HookTaskProcessor = HookTaskProcessor;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ECompilerType, type ITestContext, type ITestEnv, type TCompilerOptions } from "../type";
|
|
2
|
-
import type { IBasicProcessorOptions } from "./basic";
|
|
3
|
-
import { HotProcessor } from "./hot";
|
|
4
|
-
export interface IHotIncrementalProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
|
|
5
|
-
target: TCompilerOptions<T>["target"];
|
|
6
|
-
webpackCases: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare class HotIncrementalProcessor<T extends ECompilerType> extends HotProcessor<T> {
|
|
9
|
-
protected _hotOptions: IHotIncrementalProcessorOptions<T>;
|
|
10
|
-
constructor(_hotOptions: IHotIncrementalProcessorOptions<T>);
|
|
11
|
-
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
12
|
-
afterAll(context: ITestContext): Promise<void>;
|
|
13
|
-
static defaultOptions<T extends ECompilerType>(this: HotIncrementalProcessor<T>, context: ITestContext): TCompilerOptions<T>;
|
|
14
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HotIncrementalProcessor = void 0;
|
|
4
|
-
const type_1 = require("../type");
|
|
5
|
-
const hot_1 = require("./hot");
|
|
6
|
-
class HotIncrementalProcessor extends hot_1.HotProcessor {
|
|
7
|
-
constructor(_hotOptions) {
|
|
8
|
-
super({
|
|
9
|
-
defaultOptions: HotIncrementalProcessor.defaultOptions,
|
|
10
|
-
..._hotOptions
|
|
11
|
-
});
|
|
12
|
-
this._hotOptions = _hotOptions;
|
|
13
|
-
}
|
|
14
|
-
async run(env, context) {
|
|
15
|
-
context.setValue(this._options.name, "documentType", this._hotOptions.webpackCases ? type_1.EDocumentType.Fake : type_1.EDocumentType.JSDOM);
|
|
16
|
-
await super.run(env, context);
|
|
17
|
-
}
|
|
18
|
-
async afterAll(context) {
|
|
19
|
-
try {
|
|
20
|
-
await super.afterAll(context);
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
const isFake = context.getValue(this._options.name, "documentType") ===
|
|
24
|
-
type_1.EDocumentType.Fake;
|
|
25
|
-
if (isFake && /Should run all hot steps/.test(e.message))
|
|
26
|
-
return;
|
|
27
|
-
throw e;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
static defaultOptions(context) {
|
|
31
|
-
const options = super.defaultOptions(context);
|
|
32
|
-
if (this._hotOptions.compilerType === type_1.ECompilerType.Rspack) {
|
|
33
|
-
const rspackOptions = options;
|
|
34
|
-
rspackOptions.experiments ??= {};
|
|
35
|
-
rspackOptions.experiments.incremental ??= "advance-silent";
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
throw new Error("HotIncrementalProcessor should only used for Rspack.");
|
|
39
|
-
}
|
|
40
|
-
return options;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.HotIncrementalProcessor = HotIncrementalProcessor;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { THotStepRuntimeData } from "../runner";
|
|
2
|
-
import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions, TCompilerStatsCompilation } from "../type";
|
|
3
|
-
import { HotProcessor, type IHotProcessorOptions } from "./hot";
|
|
4
|
-
type TModuleGetHandler = (file: string, options: TCompilerOptions<ECompilerType>) => string[];
|
|
5
|
-
export interface IHotSnapshotProcessorOptions<T extends ECompilerType> extends IHotProcessorOptions<T> {
|
|
6
|
-
getModuleHandler?: TModuleGetHandler;
|
|
7
|
-
snapshot?: string;
|
|
8
|
-
}
|
|
9
|
-
export declare class HotSnapshotProcessor<T extends ECompilerType> extends HotProcessor<T> {
|
|
10
|
-
protected _hotOptions: IHotSnapshotProcessorOptions<T>;
|
|
11
|
-
private hashes;
|
|
12
|
-
private entries;
|
|
13
|
-
constructor(_hotOptions: IHotSnapshotProcessorOptions<T>);
|
|
14
|
-
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
15
|
-
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
16
|
-
protected matchStepSnapshot(env: ITestEnv, context: ITestContext, step: number, stats: TCompilerStatsCompilation<T>, runtime?: THotStepRuntimeData): void;
|
|
17
|
-
}
|
|
18
|
-
export {};
|