@rspack-canary/test-tools 1.5.6-canary-7c0091e4-20250920173916 → 1.5.7-canary-a3406c0a-20250922173625

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.
Files changed (70) hide show
  1. package/dist/case/builtin.d.ts +2 -0
  2. package/dist/case/builtin.js +153 -2
  3. package/dist/case/cache.js +115 -9
  4. package/dist/case/compiler.js +1 -1
  5. package/dist/case/config.d.ts +4 -1
  6. package/dist/case/config.js +80 -2
  7. package/dist/case/defaults.d.ts +11 -3
  8. package/dist/case/defaults.js +47 -2
  9. package/dist/case/diagnostic.d.ts +6 -0
  10. package/dist/case/diagnostic.js +109 -9
  11. package/dist/case/error.d.ts +2 -2
  12. package/dist/case/error.js +79 -2
  13. package/dist/case/hash.js +61 -7
  14. package/dist/case/hook.d.ts +35 -3
  15. package/dist/case/hook.js +185 -4
  16. package/dist/case/hot-step.d.ts +1 -1
  17. package/dist/case/hot-step.js +302 -8
  18. package/dist/case/hot.d.ts +8 -1
  19. package/dist/case/hot.js +147 -7
  20. package/dist/case/incremental.js +21 -8
  21. package/dist/case/index.d.ts +20 -20
  22. package/dist/case/index.js +44 -34
  23. package/dist/case/normal.js +152 -5
  24. package/dist/case/serial.js +7 -3
  25. package/dist/case/stats-api.d.ts +0 -5
  26. package/dist/case/stats-api.js +33 -2
  27. package/dist/case/stats-output.js +200 -10
  28. package/dist/case/treeshaking.js +19 -3
  29. package/dist/helper/plugins/hot-update.d.ts +2 -2
  30. package/dist/processor/basic.d.ts +4 -1
  31. package/dist/processor/basic.js +20 -10
  32. package/dist/processor/index.d.ts +0 -14
  33. package/dist/processor/index.js +0 -14
  34. package/dist/processor/multi.d.ts +3 -1
  35. package/dist/processor/multi.js +2 -0
  36. package/dist/processor/simple.d.ts +1 -1
  37. package/dist/processor/simple.js +4 -4
  38. package/dist/processor/snapshot.js +4 -3
  39. package/dist/type.d.ts +1 -1
  40. package/package.json +5 -5
  41. package/dist/processor/builtin.d.ts +0 -9
  42. package/dist/processor/builtin.js +0 -171
  43. package/dist/processor/cache.d.ts +0 -20
  44. package/dist/processor/cache.js +0 -131
  45. package/dist/processor/config.d.ts +0 -11
  46. package/dist/processor/config.js +0 -88
  47. package/dist/processor/defaults.d.ts +0 -30
  48. package/dist/processor/defaults.js +0 -72
  49. package/dist/processor/diagnostic.d.ts +0 -15
  50. package/dist/processor/diagnostic.js +0 -104
  51. package/dist/processor/error.d.ts +0 -23
  52. package/dist/processor/error.js +0 -95
  53. package/dist/processor/hash.d.ts +0 -10
  54. package/dist/processor/hash.js +0 -65
  55. package/dist/processor/hook.d.ts +0 -44
  56. package/dist/processor/hook.js +0 -206
  57. package/dist/processor/hot-incremental.d.ts +0 -14
  58. package/dist/processor/hot-incremental.js +0 -43
  59. package/dist/processor/hot-step.d.ts +0 -18
  60. package/dist/processor/hot-step.js +0 -307
  61. package/dist/processor/hot.d.ts +0 -17
  62. package/dist/processor/hot.js +0 -147
  63. package/dist/processor/normal.d.ts +0 -12
  64. package/dist/processor/normal.js +0 -170
  65. package/dist/processor/stats-api.d.ts +0 -18
  66. package/dist/processor/stats-api.js +0 -48
  67. package/dist/processor/stats.d.ts +0 -18
  68. package/dist/processor/stats.js +0 -206
  69. package/dist/processor/treeshaking.d.ts +0 -10
  70. package/dist/processor/treeshaking.js +0 -33
@@ -1,147 +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.HotProcessor = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const core_1 = require("@rspack/core");
9
- const helper_1 = require("../helper");
10
- const plugins_1 = require("../helper/plugins");
11
- const plugin_1 = require("../plugin");
12
- const type_1 = require("../type");
13
- const basic_1 = require("./basic");
14
- class HotProcessor extends basic_1.BasicProcessor {
15
- constructor(_hotOptions) {
16
- const fakeUpdateLoaderOptions = {
17
- updateIndex: 0,
18
- totalUpdates: 1,
19
- changedFiles: []
20
- };
21
- super({
22
- defaultOptions: HotProcessor.defaultOptions,
23
- overrideOptions: HotProcessor.overrideOptions,
24
- findBundle: HotProcessor.findBundle,
25
- runable: true,
26
- ..._hotOptions
27
- });
28
- this._hotOptions = _hotOptions;
29
- this.runner = null;
30
- this.updateOptions = fakeUpdateLoaderOptions;
31
- }
32
- async run(env, context) {
33
- context.setValue(this._options.name, "hotUpdateContext", this.updateOptions);
34
- await super.run(env, context);
35
- }
36
- static findBundle(context) {
37
- const compiler = context.getCompiler(this._hotOptions.name);
38
- if (!compiler)
39
- throw new Error("Compiler should exists when find bundle");
40
- const testConfig = context.getTestConfig();
41
- if (typeof testConfig.findBundle === "function") {
42
- return testConfig.findBundle(this.updateOptions.updateIndex, compiler.getOptions());
43
- }
44
- const files = [];
45
- const prefiles = [];
46
- const stats = compiler.getStats();
47
- if (!stats)
48
- throw new Error("Stats should exists when find bundle");
49
- const info = stats.toJson({ all: false, entrypoints: true });
50
- if (this._hotOptions.target === "web" ||
51
- this._hotOptions.target === "webworker") {
52
- for (const file of info.entrypoints.main.assets) {
53
- if ((0, helper_1.isJavaScript)(file.name)) {
54
- files.push(file.name);
55
- }
56
- else {
57
- prefiles.push(file.name);
58
- }
59
- }
60
- }
61
- else {
62
- const assets = info.entrypoints.main.assets.filter(s => (0, helper_1.isJavaScript)(s.name));
63
- files.push(assets[assets.length - 1].name);
64
- }
65
- return [...prefiles, ...files];
66
- }
67
- async afterAll(context) {
68
- await super.afterAll(context);
69
- if (context.getTestConfig().checkSteps === false) {
70
- return;
71
- }
72
- if (this.updateOptions.updateIndex + 1 !==
73
- this.updateOptions.totalUpdates) {
74
- throw new Error(`Should run all hot steps (${this.updateOptions.updateIndex + 1} / ${this.updateOptions.totalUpdates}): ${this._options.name}`);
75
- }
76
- }
77
- static defaultOptions(context) {
78
- const options = {
79
- context: context.getSource(),
80
- mode: "development",
81
- devtool: false,
82
- output: {
83
- path: context.getDist(),
84
- filename: "bundle.js",
85
- chunkFilename: "[name].chunk.[fullhash].js",
86
- publicPath: "https://test.cases/path/",
87
- library: { type: "commonjs2" }
88
- },
89
- optimization: {
90
- moduleIds: "named"
91
- },
92
- target: this._hotOptions.target,
93
- experiments: {
94
- css: true,
95
- // test incremental: "safe" here, we test default incremental in Incremental-*.test.js
96
- incremental: "safe",
97
- rspackFuture: {
98
- bundlerInfo: {
99
- force: false
100
- }
101
- },
102
- inlineConst: true,
103
- lazyBarrel: true
104
- }
105
- };
106
- if (this._hotOptions.compilerType === type_1.ECompilerType.Rspack) {
107
- options.plugins ??= [];
108
- options.plugins.push(new core_1.rspack.HotModuleReplacementPlugin(), new plugins_1.TestHotUpdatePlugin(this.updateOptions));
109
- }
110
- return options;
111
- }
112
- static overrideOptions(context, options) {
113
- if (!options.entry) {
114
- options.entry = "./index.js";
115
- }
116
- options.module ??= {};
117
- for (const cssModuleType of ["css/auto", "css/module", "css"]) {
118
- options.module.generator ??= {};
119
- options.module.generator[cssModuleType] ??= {};
120
- options.module.generator[cssModuleType].exportsOnly ??=
121
- this._hotOptions.target === "async-node";
122
- }
123
- options.module.rules ??= [];
124
- options.module.rules.push({
125
- use: [
126
- {
127
- loader: node_path_1.default.resolve(__dirname, "../helper/loaders/hot-update.js"),
128
- options: this.updateOptions
129
- }
130
- ],
131
- enforce: "pre"
132
- });
133
- if (this._hotOptions.compilerType === type_1.ECompilerType.Rspack) {
134
- options.plugins ??= [];
135
- options.plugins.push(new core_1.rspack.LoaderOptionsPlugin(this.updateOptions));
136
- }
137
- if (!global.printLogger) {
138
- options.infrastructureLogging = {
139
- level: "error"
140
- };
141
- }
142
- if (options.lazyCompilation) {
143
- options.plugins.push(new plugin_1.LazyCompilationTestPlugin());
144
- }
145
- }
146
- }
147
- exports.HotProcessor = HotProcessor;
@@ -1,12 +0,0 @@
1
- import type { ECompilerType, ITestContext, TCompilerOptions } from "../type";
2
- import { BasicProcessor, type IBasicProcessorOptions } from "./basic";
3
- export interface INormalProcessorOptions<T extends ECompilerType> extends IBasicProcessorOptions<T> {
4
- compilerOptions?: TCompilerOptions<T>;
5
- root: string;
6
- }
7
- export declare class NormalProcessor<T extends ECompilerType> extends BasicProcessor<T> {
8
- protected _normalOptions: INormalProcessorOptions<T>;
9
- constructor(_normalOptions: INormalProcessorOptions<T>);
10
- static defaultOptions<T extends ECompilerType>(this: NormalProcessor<T>, context: ITestContext): TCompilerOptions<T>;
11
- static overrideOptions<T extends ECompilerType>(options: TCompilerOptions<T>): void;
12
- }
@@ -1,170 +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.NormalProcessor = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const basic_1 = require("./basic");
10
- class NormalProcessor extends basic_1.BasicProcessor {
11
- constructor(_normalOptions) {
12
- super({
13
- findBundle: (context, options) => {
14
- const testConfig = context.getTestConfig();
15
- if (typeof testConfig.findBundle === "function") {
16
- return testConfig.findBundle(0, options);
17
- }
18
- const filename = options.output?.filename;
19
- return typeof filename === "string" ? filename : undefined;
20
- },
21
- defaultOptions: NormalProcessor.defaultOptions,
22
- ..._normalOptions
23
- });
24
- this._normalOptions = _normalOptions;
25
- }
26
- static defaultOptions(context) {
27
- let testConfig = {};
28
- const testConfigPath = node_path_1.default.join(context.getSource(), "test.config.js");
29
- if (node_fs_1.default.existsSync(testConfigPath)) {
30
- testConfig = require(testConfigPath);
31
- }
32
- const TerserPlugin = require("terser-webpack-plugin");
33
- const terserForTesting = new TerserPlugin({
34
- parallel: false
35
- });
36
- const { root, compilerOptions } = this._normalOptions;
37
- return {
38
- amd: {},
39
- context: root,
40
- entry: `./${node_path_1.default.relative(root, context.getSource())}/`,
41
- target: compilerOptions?.target || "async-node",
42
- devtool: compilerOptions?.devtool,
43
- mode: compilerOptions?.mode || "none",
44
- optimization: compilerOptions?.mode
45
- ? {
46
- // emitOnErrors: true,
47
- minimizer: [terserForTesting],
48
- ...testConfig.optimization
49
- }
50
- : {
51
- removeAvailableModules: true,
52
- removeEmptyChunks: true,
53
- mergeDuplicateChunks: true,
54
- // CHANGE: rspack does not support `flagIncludedChunks` yet.
55
- // flagIncludedChunks: true,
56
- sideEffects: true,
57
- providedExports: true,
58
- usedExports: true,
59
- mangleExports: true,
60
- // CHANGE: rspack does not support `emitOnErrors` yet.
61
- // emitOnErrors: true,
62
- concatenateModules: !!testConfig?.optimization?.concatenateModules,
63
- innerGraph: true,
64
- // CHANGE: size is not supported yet
65
- // moduleIds: "size",
66
- // chunkIds: "size",
67
- moduleIds: "named",
68
- chunkIds: "named",
69
- minimizer: [terserForTesting],
70
- ...compilerOptions?.optimization
71
- },
72
- // CHANGE: rspack does not support `performance` yet.
73
- // performance: {
74
- // hints: false
75
- // },
76
- node: {
77
- __dirname: "mock",
78
- __filename: "mock"
79
- },
80
- cache: compilerOptions?.cache && {
81
- // cacheDirectory,
82
- ...compilerOptions.cache
83
- },
84
- output: {
85
- pathinfo: "verbose",
86
- path: context.getDist(),
87
- filename: compilerOptions?.module ? "bundle.mjs" : "bundle.js"
88
- },
89
- resolve: {
90
- modules: ["web_modules", "node_modules"],
91
- mainFields: ["webpack", "browser", "web", "browserify", "main"],
92
- aliasFields: ["browser"],
93
- extensions: [".webpack.js", ".web.js", ".js", ".json"]
94
- },
95
- resolveLoader: {
96
- modules: ["web_loaders", "web_modules", "node_loaders", "node_modules"],
97
- mainFields: ["webpackLoader", "webLoader", "loader", "main"],
98
- extensions: [
99
- ".webpack-loader.js",
100
- ".web-loader.js",
101
- ".loader.js",
102
- ".js"
103
- ]
104
- },
105
- module: {
106
- rules: [
107
- {
108
- test: /\.coffee$/,
109
- loader: "coffee-loader"
110
- },
111
- {
112
- test: /\.pug/,
113
- loader: "@webdiscus/pug-loader"
114
- },
115
- {
116
- test: /\.wat$/i,
117
- loader: "wast-loader",
118
- type: "webassembly/async"
119
- }
120
- ]
121
- },
122
- plugins: (compilerOptions?.plugins || [])
123
- .concat(testConfig.plugins || [])
124
- .concat(function () {
125
- this.hooks.compilation.tap("TestCasesTest", compilation => {
126
- const hooks = [
127
- // CHANGE: the following hooks are not supported yet, so comment it out
128
- // "optimize",
129
- // "optimizeModules",
130
- // "optimizeChunks",
131
- // "afterOptimizeTree",
132
- // "afterOptimizeAssets"
133
- ];
134
- for (const hook of hooks) {
135
- compilation.hooks[hook].tap("TestCasesTest", () => compilation.checkConstraints());
136
- }
137
- });
138
- }),
139
- experiments: {
140
- css: false,
141
- rspackFuture: {
142
- bundlerInfo: {
143
- force: false
144
- }
145
- },
146
- asyncWebAssembly: true,
147
- topLevelAwait: true,
148
- inlineConst: true,
149
- lazyBarrel: true,
150
- // CHANGE: rspack does not support `backCompat` yet.
151
- // backCompat: false,
152
- // CHANGE: Rspack enables `css` by default.
153
- // Turning off here to fallback to webpack's default css processing logic.
154
- ...(compilerOptions?.module ? { outputModule: true } : {})
155
- }
156
- // infrastructureLogging: compilerOptions?.cache && {
157
- // debug: true,
158
- // console: createLogger(infraStructureLog)
159
- // }
160
- };
161
- }
162
- static overrideOptions(options) {
163
- if (!global.printLogger) {
164
- options.infrastructureLogging = {
165
- level: "error"
166
- };
167
- }
168
- }
169
- }
170
- exports.NormalProcessor = NormalProcessor;
@@ -1,18 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions, TCompilerStats } from "../type";
2
- import { SimpleTaskProcessor } from "./simple";
3
- export interface IStatsAPIProcessorOptions<T extends ECompilerType> {
4
- options?: (context: ITestContext) => TCompilerOptions<T>;
5
- name: string;
6
- compilerType: T;
7
- snapshotName?: string;
8
- compiler?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
9
- build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
10
- check?: (stats: TCompilerStats<T>, compiler: TCompiler<T>) => Promise<void>;
11
- }
12
- export declare class StatsAPIProcessor<T extends ECompilerType> extends SimpleTaskProcessor<T> {
13
- protected _statsAPIOptions: IStatsAPIProcessorOptions<T>;
14
- constructor(_statsAPIOptions: IStatsAPIProcessorOptions<T>);
15
- compiler(context: ITestContext): Promise<void>;
16
- run(env: ITestEnv, context: ITestContext): Promise<void>;
17
- check(env: ITestEnv, context: ITestContext): Promise<void>;
18
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StatsAPIProcessor = void 0;
4
- const memfs_1 = require("memfs");
5
- const simple_1 = require("./simple");
6
- class StatsAPIProcessor extends simple_1.SimpleTaskProcessor {
7
- constructor(_statsAPIOptions) {
8
- super({
9
- options: context => {
10
- const res = (_statsAPIOptions.options?.(context) ||
11
- {});
12
- res.experiments ??= {};
13
- res.experiments.css ??= true;
14
- res.experiments.rspackFuture ??= {};
15
- res.experiments.rspackFuture.bundlerInfo ??= {};
16
- res.experiments.rspackFuture.bundlerInfo.force ??= false;
17
- if (!global.printLogger) {
18
- res.infrastructureLogging = {
19
- level: "error"
20
- };
21
- }
22
- return res;
23
- },
24
- build: _statsAPIOptions.build,
25
- compilerType: _statsAPIOptions.compilerType,
26
- name: _statsAPIOptions.name,
27
- compiler: _statsAPIOptions.compiler
28
- });
29
- this._statsAPIOptions = _statsAPIOptions;
30
- }
31
- async compiler(context) {
32
- await super.compiler(context);
33
- const compiler = this.getCompiler(context).getCompiler();
34
- if (compiler) {
35
- compiler.outputFileSystem = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume());
36
- }
37
- }
38
- async run(env, context) {
39
- // do nothing
40
- }
41
- async check(env, context) {
42
- const compiler = this.getCompiler(context);
43
- const stats = compiler.getStats();
44
- env.expect(typeof stats).toBe("object");
45
- await this._statsAPIOptions.check?.(stats, compiler.getCompiler());
46
- }
47
- }
48
- exports.StatsAPIProcessor = StatsAPIProcessor;
@@ -1,18 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
2
- import { type IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";
3
- export interface IStatsProcessorOptions<T extends ECompilerType> extends Omit<IMultiTaskProcessorOptions<T>, "runable"> {
4
- snapshotName: string;
5
- writeStatsOuptut?: boolean;
6
- }
7
- export declare class StatsProcessor<T extends ECompilerType> extends MultiTaskProcessor<T> {
8
- private stderr;
9
- private snapshotName;
10
- private writeStatsOuptut?;
11
- constructor(_statsOptions: IStatsProcessorOptions<T>);
12
- before(context: ITestContext): Promise<void>;
13
- after(context: ITestContext): Promise<void>;
14
- compiler(context: ITestContext): Promise<void>;
15
- check(env: ITestEnv, context: ITestContext): Promise<void>;
16
- static defaultOptions<T extends ECompilerType>(index: number, context: ITestContext): TCompilerOptions<T>;
17
- static overrideOptions<T extends ECompilerType>(index: number, context: ITestContext, options: TCompilerOptions<T>): void;
18
- }
@@ -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.StatsProcessor = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const placeholder_1 = require("../helper/expect/placeholder");
10
- const captureStdio_1 = __importDefault(require("../helper/legacy/captureStdio"));
11
- const multi_1 = require("./multi");
12
- const REG_ERROR_CASE = /error$/;
13
- class RspackStats {
14
- constructor(value) {
15
- this.value = value;
16
- }
17
- }
18
- class StatsProcessor extends multi_1.MultiTaskProcessor {
19
- constructor(_statsOptions) {
20
- super({
21
- defaultOptions: (StatsProcessor.defaultOptions),
22
- overrideOptions: (StatsProcessor.overrideOptions),
23
- runable: false,
24
- ..._statsOptions
25
- });
26
- this.snapshotName = _statsOptions.snapshotName;
27
- this.writeStatsOuptut = _statsOptions.writeStatsOuptut;
28
- }
29
- async before(context) {
30
- this.stderr = (0, captureStdio_1.default)(process.stderr, true);
31
- }
32
- async after(context) {
33
- this.stderr.restore();
34
- }
35
- async compiler(context) {
36
- await super.compiler(context);
37
- const instance = this.getCompiler(context).getCompiler();
38
- const compilers = instance.compilers
39
- ? instance.compilers
40
- : [instance];
41
- for (const compiler of compilers) {
42
- if (!compiler.inputFileSystem) {
43
- continue;
44
- }
45
- const ifs = compiler.inputFileSystem;
46
- const inputFileSystem = Object.create(ifs);
47
- compiler.inputFileSystem = inputFileSystem;
48
- inputFileSystem.readFile = (...args) => {
49
- const callback = args.pop();
50
- ifs.readFile.apply(ifs, args.concat([
51
- (err, result) => {
52
- if (err)
53
- return callback(err);
54
- if (!/\.(js|json|txt)$/.test(args[0]))
55
- return callback(null, result);
56
- callback(null, (0, placeholder_1.normalizePlaceholder)(result.toString("utf-8")));
57
- }
58
- ]));
59
- };
60
- // CHANGE: The checkConstraints() function is currently not implemented in rspack
61
- // compiler.hooks.compilation.tap("StatsTestCasesTest", compilation => {
62
- // [
63
- // "optimize",
64
- // "optimizeModules",
65
- // "optimizeChunks",
66
- // "afterOptimizeTree",
67
- // "afterOptimizeAssets",
68
- // "beforeHash"
69
- // ].forEach(hook => {
70
- // compilation.hooks[hook].tap("TestCasesTest", () =>
71
- // compilation.checkConstraints()
72
- // );
73
- // });
74
- // });
75
- }
76
- }
77
- async check(env, context) {
78
- const compiler = this.getCompiler(context);
79
- const stats = compiler.getStats();
80
- const c = compiler.getCompiler();
81
- if (!stats || !c)
82
- return;
83
- for (const compilation of []
84
- .concat(stats.stats || stats)
85
- .map((s) => s.compilation)) {
86
- compilation.logging.delete("webpack.Compilation.ModuleProfile");
87
- }
88
- if (REG_ERROR_CASE.test(this._options.name)) {
89
- env.expect(stats.hasErrors()).toBe(true);
90
- }
91
- else if (stats.hasErrors()) {
92
- throw new Error(stats.toString({
93
- all: false,
94
- errors: true
95
- // errorStack: true,
96
- // errorDetails: true
97
- }));
98
- }
99
- else if (this.writeStatsOuptut) {
100
- node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
101
- preset: "verbose",
102
- // context: context.getSource(),
103
- colors: false
104
- }), "utf-8");
105
- }
106
- let toStringOptions = {
107
- context: context.getSource(),
108
- colors: false
109
- };
110
- let hasColorSetting = false;
111
- if (typeof c.options.stats !== "undefined") {
112
- toStringOptions = c.options.stats;
113
- if (toStringOptions === null || typeof toStringOptions !== "object")
114
- toStringOptions = { preset: toStringOptions };
115
- if (!toStringOptions.context)
116
- toStringOptions.context = context.getSource();
117
- hasColorSetting = typeof toStringOptions.colors !== "undefined";
118
- }
119
- if (Array.isArray(c.options) && !toStringOptions.children) {
120
- toStringOptions.children = c.options.map(o => o.stats);
121
- }
122
- // mock timestamps
123
- for (const { compilation: s } of [].concat(stats.stats || stats)) {
124
- env.expect(s.startTime).toBeGreaterThan(0);
125
- env.expect(s.endTime).toBeGreaterThan(0);
126
- s.endTime = new Date("04/20/1970, 12:42:42 PM").getTime();
127
- s.startTime = s.endTime - 1234;
128
- }
129
- let actual = stats.toString(toStringOptions);
130
- env.expect(typeof actual).toBe("string");
131
- actual = this.stderr.toString() + actual;
132
- if (!hasColorSetting) {
133
- actual = actual
134
- .replace(/\u001b\[[0-9;]*m/g, "")
135
- // CHANGE: The time unit display in Rspack is second
136
- .replace(/[.0-9]+(\s?s)/g, "X$1")
137
- // CHANGE: Replace bundle size, since bundle sizes may differ between platforms
138
- .replace(/[0-9]+\.?[0-9]+ KiB/g, "xx KiB");
139
- }
140
- const snapshotPath = node_path_1.default.isAbsolute(this.snapshotName)
141
- ? this.snapshotName
142
- : node_path_1.default.resolve(context.getSource(), `./__snapshots__/${this.snapshotName}`);
143
- env.expect(new RspackStats(actual)).toMatchFileSnapshot(snapshotPath);
144
- const testConfig = context.getTestConfig();
145
- if (typeof testConfig?.validate === "function") {
146
- testConfig.validate(stats, this.stderr.toString());
147
- }
148
- }
149
- static defaultOptions(index, context) {
150
- if (node_fs_1.default.existsSync(node_path_1.default.join(context.getSource(), "rspack.config.js"))) {
151
- return {
152
- experiments: {
153
- css: true,
154
- rspackFuture: {
155
- bundlerInfo: {
156
- force: false
157
- }
158
- }
159
- }
160
- };
161
- }
162
- return {
163
- context: context.getSource(),
164
- mode: "development",
165
- entry: "./index.js",
166
- output: {
167
- filename: "bundle.js",
168
- path: context.getDist()
169
- },
170
- optimization: {
171
- minimize: false
172
- },
173
- experiments: {
174
- css: true,
175
- rspackFuture: {
176
- bundlerInfo: {
177
- force: false
178
- }
179
- },
180
- inlineConst: true,
181
- lazyBarrel: true
182
- }
183
- };
184
- }
185
- static overrideOptions(index, context, options) {
186
- if (!options.context)
187
- options.context = context.getSource();
188
- if (!options.output)
189
- options.output = options.output || {};
190
- if (!options.output.path)
191
- options.output.path = context.getDist();
192
- if (!options.plugins)
193
- options.plugins = [];
194
- if (!options.optimization)
195
- options.optimization = {};
196
- if (options.optimization.minimize === undefined) {
197
- options.optimization.minimize = false;
198
- }
199
- if (!global.printLogger) {
200
- options.infrastructureLogging = {
201
- level: "error"
202
- };
203
- }
204
- }
205
- }
206
- exports.StatsProcessor = StatsProcessor;
@@ -1,10 +0,0 @@
1
- import type { ECompilerType, ITestContext, TCompilerOptions } from "../type";
2
- import { type ISnapshotProcessorOptions, SnapshotProcessor } from "./snapshot";
3
- export interface ITreeShakingProcessorOptions<T extends ECompilerType> extends Omit<ISnapshotProcessorOptions<T>, "runable"> {
4
- }
5
- export declare class TreeShakingProcessor<T extends ECompilerType> extends SnapshotProcessor<T> {
6
- protected _treeShakingOptions: ITreeShakingProcessorOptions<T>;
7
- constructor(_treeShakingOptions: ITreeShakingProcessorOptions<T>);
8
- static overrideOptions<T extends ECompilerType>(context: ITestContext, options: TCompilerOptions<T>): void;
9
- serializeEachFile(content: string): string;
10
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TreeShakingProcessor = void 0;
4
- const placeholder_1 = require("../helper/expect/placeholder");
5
- const builtin_1 = require("./builtin");
6
- const snapshot_1 = require("./snapshot");
7
- class TreeShakingProcessor extends snapshot_1.SnapshotProcessor {
8
- constructor(_treeShakingOptions) {
9
- super({
10
- defaultOptions: builtin_1.BuiltinProcessor.defaultOptions,
11
- overrideOptions: (TreeShakingProcessor.overrideOptions),
12
- runable: false,
13
- ..._treeShakingOptions
14
- });
15
- this._treeShakingOptions = _treeShakingOptions;
16
- }
17
- static overrideOptions(context, options) {
18
- options.target = options.target || ["web", "es2022"];
19
- options.optimization ??= {};
20
- options.optimization.providedExports = true;
21
- options.optimization.innerGraph = true;
22
- options.optimization.usedExports = true;
23
- if (!global.printLogger) {
24
- options.infrastructureLogging = {
25
- level: "error"
26
- };
27
- }
28
- }
29
- serializeEachFile(content) {
30
- return (0, placeholder_1.normalizePlaceholder)(content);
31
- }
32
- }
33
- exports.TreeShakingProcessor = TreeShakingProcessor;