@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.
Files changed (122) hide show
  1. package/dist/case/builtin.d.ts +2 -0
  2. package/dist/case/builtin.js +173 -13
  3. package/dist/case/cache.d.ts +1 -1
  4. package/dist/case/cache.js +210 -11
  5. package/dist/case/common.d.ts +10 -0
  6. package/dist/case/common.js +237 -0
  7. package/dist/case/compiler.d.ts +7 -4
  8. package/dist/case/compiler.js +144 -109
  9. package/dist/case/config.d.ts +5 -1
  10. package/dist/case/config.js +102 -16
  11. package/dist/case/defaults.d.ts +12 -4
  12. package/dist/case/defaults.js +67 -12
  13. package/dist/case/diagnostic.d.ts +6 -0
  14. package/dist/case/diagnostic.js +123 -14
  15. package/dist/case/diff.d.ts +17 -1
  16. package/dist/case/diff.js +170 -22
  17. package/dist/case/error.d.ts +14 -4
  18. package/dist/case/error.js +117 -10
  19. package/dist/case/hash.d.ts +1 -1
  20. package/dist/case/hash.js +70 -9
  21. package/dist/case/hook.d.ts +35 -4
  22. package/dist/case/hook.js +210 -21
  23. package/dist/case/hot-step.js +307 -9
  24. package/dist/case/hot.d.ts +8 -1
  25. package/dist/case/hot.js +235 -8
  26. package/dist/case/incremental.d.ts +1 -1
  27. package/dist/case/incremental.js +39 -41
  28. package/dist/case/index.d.ts +20 -20
  29. package/dist/case/index.js +44 -34
  30. package/dist/case/native-watcher.js +10 -23
  31. package/dist/case/normal.js +174 -12
  32. package/dist/case/runner.d.ts +18 -0
  33. package/dist/case/runner.js +108 -0
  34. package/dist/case/serial.d.ts +1 -1
  35. package/dist/case/serial.js +8 -12
  36. package/dist/case/stats-api.d.ts +0 -5
  37. package/dist/case/stats-api.js +71 -10
  38. package/dist/case/stats-output.js +197 -11
  39. package/dist/case/treeshaking.js +34 -7
  40. package/dist/case/watch.d.ts +27 -0
  41. package/dist/case/watch.js +321 -21
  42. package/dist/helper/plugins/hot-update.d.ts +2 -2
  43. package/dist/index.d.ts +0 -2
  44. package/dist/index.js +0 -2
  45. package/dist/runner/index.d.ts +2 -7
  46. package/dist/runner/index.js +2 -7
  47. package/dist/runner/{runner/node → node}/index.d.ts +1 -2
  48. package/dist/runner/{runner/node → node}/index.js +2 -2
  49. package/dist/runner/{runner/web → web}/fake.d.ts +1 -2
  50. package/dist/runner/{runner/web → web}/fake.js +7 -7
  51. package/dist/runner/{runner/web → web}/index.d.ts +2 -2
  52. package/dist/runner/{runner/web → web}/index.js +1 -1
  53. package/dist/runner/{runner/web → web}/jsdom.d.ts +1 -2
  54. package/dist/runner/{runner/web → web}/jsdom.js +4 -4
  55. package/dist/test/context.d.ts +3 -5
  56. package/dist/test/context.js +22 -12
  57. package/dist/test/creator.d.ts +13 -12
  58. package/dist/test/creator.js +52 -43
  59. package/dist/test/tester.js +4 -1
  60. package/dist/type.d.ts +42 -11
  61. package/dist/type.js +7 -1
  62. package/package.json +5 -5
  63. package/dist/processor/basic.d.ts +0 -24
  64. package/dist/processor/basic.js +0 -147
  65. package/dist/processor/builtin.d.ts +0 -9
  66. package/dist/processor/builtin.js +0 -171
  67. package/dist/processor/cache.d.ts +0 -20
  68. package/dist/processor/cache.js +0 -131
  69. package/dist/processor/config.d.ts +0 -11
  70. package/dist/processor/config.js +0 -88
  71. package/dist/processor/defaults.d.ts +0 -30
  72. package/dist/processor/defaults.js +0 -72
  73. package/dist/processor/diagnostic.d.ts +0 -15
  74. package/dist/processor/diagnostic.js +0 -104
  75. package/dist/processor/diff.d.ts +0 -30
  76. package/dist/processor/diff.js +0 -140
  77. package/dist/processor/error.d.ts +0 -23
  78. package/dist/processor/error.js +0 -95
  79. package/dist/processor/hash.d.ts +0 -10
  80. package/dist/processor/hash.js +0 -65
  81. package/dist/processor/hook.d.ts +0 -44
  82. package/dist/processor/hook.js +0 -206
  83. package/dist/processor/hot-incremental.d.ts +0 -14
  84. package/dist/processor/hot-incremental.js +0 -43
  85. package/dist/processor/hot-step.d.ts +0 -18
  86. package/dist/processor/hot-step.js +0 -307
  87. package/dist/processor/hot.d.ts +0 -17
  88. package/dist/processor/hot.js +0 -147
  89. package/dist/processor/index.d.ts +0 -20
  90. package/dist/processor/index.js +0 -36
  91. package/dist/processor/multi.d.ts +0 -17
  92. package/dist/processor/multi.js +0 -73
  93. package/dist/processor/normal.d.ts +0 -12
  94. package/dist/processor/normal.js +0 -170
  95. package/dist/processor/simple.d.ts +0 -24
  96. package/dist/processor/simple.js +0 -51
  97. package/dist/processor/snapshot.d.ts +0 -12
  98. package/dist/processor/snapshot.js +0 -66
  99. package/dist/processor/stats-api.d.ts +0 -18
  100. package/dist/processor/stats-api.js +0 -48
  101. package/dist/processor/stats.d.ts +0 -18
  102. package/dist/processor/stats.js +0 -206
  103. package/dist/processor/treeshaking.d.ts +0 -10
  104. package/dist/processor/treeshaking.js +0 -33
  105. package/dist/processor/watch.d.ts +0 -30
  106. package/dist/processor/watch.js +0 -252
  107. package/dist/runner/basic.d.ts +0 -10
  108. package/dist/runner/basic.js +0 -64
  109. package/dist/runner/cache.d.ts +0 -5
  110. package/dist/runner/cache.js +0 -92
  111. package/dist/runner/hot.d.ts +0 -5
  112. package/dist/runner/hot.js +0 -91
  113. package/dist/runner/multiple.d.ts +0 -11
  114. package/dist/runner/multiple.js +0 -52
  115. package/dist/runner/runner/index.d.ts +0 -2
  116. package/dist/runner/runner/index.js +0 -18
  117. package/dist/runner/type.d.ts +0 -42
  118. package/dist/runner/type.js +0 -9
  119. package/dist/runner/watch.d.ts +0 -7
  120. package/dist/runner/watch.js +0 -71
  121. package/dist/test/simple.d.ts +0 -5
  122. package/dist/test/simple.js +0 -43
@@ -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,24 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, ITestProcessor, TCompiler, TCompilerOptions, TCompilerStats } from "../type";
2
- export interface ISimpleProcessorOptions<T extends ECompilerType> {
3
- options?: (context: ITestContext) => TCompilerOptions<T>;
4
- compilerCallback?: (error: Error | null, stats: TCompilerStats<T> | null) => void;
5
- compilerType: T;
6
- name: string;
7
- build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
8
- compiler?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
9
- check?: (context: ITestContext, compiler: TCompiler<T>, stats: TCompilerStats<T>) => Promise<void>;
10
- }
11
- export declare class SimpleTaskProcessor<T extends ECompilerType> implements ITestProcessor {
12
- protected _options: ISimpleProcessorOptions<T>;
13
- constructor(_options: ISimpleProcessorOptions<T>);
14
- config(context: ITestContext): Promise<void>;
15
- compiler(context: ITestContext): Promise<void>;
16
- build(context: ITestContext): Promise<void>;
17
- run(env: ITestEnv, context: ITestContext): Promise<void>;
18
- check(env: ITestEnv, context: ITestContext): Promise<void>;
19
- before(context: ITestContext): Promise<void>;
20
- after(context: ITestContext): Promise<void>;
21
- beforeAll(context: ITestContext): Promise<void>;
22
- afterAll(context: ITestContext): Promise<void>;
23
- protected getCompiler(context: ITestContext): import("../type").ITestCompilerManager<T>;
24
- }
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SimpleTaskProcessor = void 0;
4
- class SimpleTaskProcessor {
5
- constructor(_options) {
6
- this._options = _options;
7
- }
8
- async config(context) {
9
- const compiler = this.getCompiler(context);
10
- if (typeof this._options.options === "function") {
11
- compiler.setOptions(this._options.options(context));
12
- }
13
- }
14
- async compiler(context) {
15
- const compiler = this.getCompiler(context);
16
- const instance = this._options.compilerCallback
17
- ? compiler.createCompilerWithCallback(this._options.compilerCallback)
18
- : compiler.createCompiler();
19
- if (typeof this._options.compiler === "function") {
20
- await this._options.compiler(context, instance);
21
- }
22
- }
23
- async build(context) {
24
- const compiler = this.getCompiler(context);
25
- if (typeof this._options.build === "function") {
26
- await this._options.build(context, compiler.getCompiler());
27
- }
28
- else {
29
- await compiler.build();
30
- }
31
- }
32
- async run(env, context) { }
33
- async check(env, context) {
34
- const compiler = this.getCompiler(context);
35
- const stats = compiler.getStats();
36
- if (typeof this._options.check === "function") {
37
- await this._options.check(context, compiler.getCompiler(), stats);
38
- }
39
- }
40
- async before(context) { }
41
- async after(context) {
42
- const compiler = this.getCompiler(context);
43
- await compiler.close();
44
- }
45
- async beforeAll(context) { }
46
- async afterAll(context) { }
47
- getCompiler(context) {
48
- return context.getCompiler(this._options.name, this._options.compilerType);
49
- }
50
- }
51
- exports.SimpleTaskProcessor = SimpleTaskProcessor;
@@ -1,12 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestEnv } from "../type";
2
- import { BasicProcessor, type IBasicProcessorOptions } from "./basic";
3
- export interface ISnapshotProcessorOptions<T extends ECompilerType> extends IBasicProcessorOptions<T> {
4
- snapshot: string;
5
- snapshotFileFilter?: (file: string) => boolean;
6
- }
7
- export declare class SnapshotProcessor<T extends ECompilerType> extends BasicProcessor<T> {
8
- protected _snapshotOptions: ISnapshotProcessorOptions<T>;
9
- constructor(_snapshotOptions: ISnapshotProcessorOptions<T>);
10
- check(env: ITestEnv, context: ITestContext): Promise<void>;
11
- serializeEachFile(content: string): string;
12
- }
@@ -1,66 +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.SnapshotProcessor = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const basic_1 = require("./basic");
9
- class SnapshotProcessor extends basic_1.BasicProcessor {
10
- constructor(_snapshotOptions) {
11
- super(_snapshotOptions);
12
- this._snapshotOptions = _snapshotOptions;
13
- if (node_path_1.default.extname(_snapshotOptions.snapshot) === ".snap") {
14
- throw new Error("Snapshot with `.snap` will be managed by jest, please use `.snap.txt` instead in SnapshotProcessor");
15
- }
16
- }
17
- async check(env, context) {
18
- const compiler = this.getCompiler(context);
19
- const stats = compiler.getStats();
20
- const c = compiler.getCompiler();
21
- if (!stats || !c)
22
- return;
23
- if (stats.hasErrors()) {
24
- const errors = [];
25
- if (stats.stats) {
26
- for (const s of stats.stats) {
27
- if (s.hasErrors()) {
28
- errors.push(...s.compilation.errors);
29
- }
30
- }
31
- }
32
- else {
33
- const s = stats;
34
- errors.push(...s.compilation.errors);
35
- }
36
- throw new Error(`Failed to compile in fixture ${this._options.name}, Errors: ${errors
37
- ?.map(i => `${i.message}\n${i.stack}`)
38
- .join("\n\n")}`);
39
- }
40
- const compilation = c._lastCompilation ||
41
- c._lastCompilation;
42
- const snapshotFileFilter = this._snapshotOptions.snapshotFileFilter ||
43
- ((file) => file.endsWith(".js") && !file.includes("runtime.js"));
44
- const fileContents = Object.entries(compilation.assets)
45
- .filter(([file]) => snapshotFileFilter(file))
46
- .map(([file, source]) => {
47
- const tag = node_path_1.default.extname(file).slice(1) || "txt";
48
- let content = this.serializeEachFile(source.source().toString());
49
- const testConfig = context.getTestConfig();
50
- if (testConfig.snapshotContent) {
51
- content = testConfig.snapshotContent(content);
52
- }
53
- return `\`\`\`${tag} title=${file}\n${content}\n\`\`\``;
54
- });
55
- fileContents.sort();
56
- const content = fileContents.join("\n\n");
57
- const snapshotPath = node_path_1.default.isAbsolute(this._snapshotOptions.snapshot)
58
- ? this._snapshotOptions.snapshot
59
- : node_path_1.default.resolve(context.getSource(), `./__snapshots__/${this._snapshotOptions.snapshot}`);
60
- env.expect(content).toMatchFileSnapshot(snapshotPath);
61
- }
62
- serializeEachFile(content) {
63
- return content;
64
- }
65
- }
66
- exports.SnapshotProcessor = SnapshotProcessor;
@@ -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;