@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 +1,3 @@
1
+ import { ECompilerType, type ITestContext, type TCompilerOptions } from "../type";
2
+ export declare function defaultOptions<T extends ECompilerType.Rspack>(context: ITestContext): TCompilerOptions<T>;
1
3
  export declare function createBuiltinCase(name: string, src: string, dist: string): void;
@@ -3,12 +3,161 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.defaultOptions = defaultOptions;
6
7
  exports.createBuiltinCase = createBuiltinCase;
7
8
  const node_path_1 = __importDefault(require("node:path"));
9
+ const core_1 = require("@rspack/core");
10
+ const fs_extra_1 = __importDefault(require("fs-extra"));
11
+ const webpack_merge_1 = require("webpack-merge");
8
12
  const helper_1 = require("../helper");
9
13
  const processor_1 = require("../processor");
10
14
  const creator_1 = require("../test/creator");
11
15
  const type_1 = require("../type");
16
+ function defaultOptions(context) {
17
+ let defaultOptions = {
18
+ entry: {
19
+ main: {
20
+ import: "./index"
21
+ }
22
+ },
23
+ output: {
24
+ publicPath: "/",
25
+ path: context.getDist(),
26
+ filename: "[name].js",
27
+ chunkFilename: "[name].js",
28
+ chunkFormat: "array-push",
29
+ cssFilename: "[name].css",
30
+ cssChunkFilename: "[name].css",
31
+ assetModuleFilename: "[hash][ext][query]",
32
+ sourceMapFilename: "[file].map",
33
+ chunkLoadingGlobal: "webpackChunkwebpack",
34
+ chunkLoading: "jsonp",
35
+ uniqueName: "__rspack_test__",
36
+ enabledLibraryTypes: ["system"],
37
+ strictModuleErrorHandling: false,
38
+ iife: true,
39
+ module: false,
40
+ asyncChunks: true,
41
+ scriptType: false,
42
+ globalObject: "self",
43
+ importFunctionName: "import",
44
+ wasmLoading: "fetch",
45
+ webassemblyModuleFilename: "[hash].module.wasm",
46
+ workerChunkLoading: "import-scripts",
47
+ workerWasmLoading: "fetch"
48
+ },
49
+ module: {
50
+ rules: [
51
+ {
52
+ test: /\.json$/,
53
+ type: "json"
54
+ },
55
+ {
56
+ test: /\.mjs$/,
57
+ type: "javascript/esm"
58
+ },
59
+ {
60
+ test: /\.cjs$/,
61
+ type: "javascript/dynamic"
62
+ },
63
+ {
64
+ test: /\.js$/,
65
+ type: "javascript/auto"
66
+ },
67
+ {
68
+ test: /\.css$/,
69
+ type: "css"
70
+ },
71
+ {
72
+ test: /\.wasm$/,
73
+ type: "webassembly/async"
74
+ }
75
+ ]
76
+ },
77
+ node: {
78
+ __dirname: "mock",
79
+ __filename: "mock",
80
+ global: "warn"
81
+ },
82
+ optimization: {
83
+ runtimeChunk: {
84
+ name: "runtime"
85
+ },
86
+ minimize: false,
87
+ removeAvailableModules: true,
88
+ removeEmptyChunks: true,
89
+ moduleIds: "named",
90
+ chunkIds: "named",
91
+ sideEffects: false,
92
+ mangleExports: false,
93
+ usedExports: false,
94
+ concatenateModules: false,
95
+ nodeEnv: false
96
+ },
97
+ resolve: {
98
+ extensions: [
99
+ ".js",
100
+ ".jsx",
101
+ ".ts",
102
+ ".tsx",
103
+ ".json",
104
+ ".d.ts",
105
+ ".css",
106
+ ".wasm"
107
+ ]
108
+ },
109
+ resolveLoader: {
110
+ extensions: [".js"]
111
+ },
112
+ experiments: {
113
+ css: true,
114
+ futureDefaults: true,
115
+ rspackFuture: {
116
+ bundlerInfo: {
117
+ force: false
118
+ }
119
+ }
120
+ },
121
+ devtool: false,
122
+ context: context.getSource(),
123
+ plugins: []
124
+ };
125
+ const testConfigFile = context.getSource("rspack.config.js");
126
+ if (fs_extra_1.default.existsSync(testConfigFile)) {
127
+ const caseOptions = require(testConfigFile);
128
+ if (caseOptions.entry) {
129
+ delete defaultOptions.entry;
130
+ }
131
+ defaultOptions = (0, webpack_merge_1.merge)(defaultOptions, caseOptions);
132
+ }
133
+ // TODO: remove builtin compatible code
134
+ const defineOptions = defaultOptions.builtins?.define;
135
+ if (defineOptions) {
136
+ defaultOptions.plugins.push(new core_1.rspack.DefinePlugin(defineOptions));
137
+ }
138
+ const provideOptions = defaultOptions.builtins?.provide;
139
+ if (provideOptions) {
140
+ defaultOptions.plugins.push(new core_1.rspack.ProvidePlugin(provideOptions));
141
+ }
142
+ const htmlOptions = defaultOptions.builtins?.html;
143
+ if (htmlOptions) {
144
+ if (Array.isArray(htmlOptions)) {
145
+ for (const item of htmlOptions) {
146
+ defaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(item));
147
+ }
148
+ }
149
+ else {
150
+ defaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(htmlOptions));
151
+ }
152
+ }
153
+ delete defaultOptions.builtins;
154
+ if (!global.printLogger) {
155
+ defaultOptions.infrastructureLogging = {
156
+ level: "error"
157
+ };
158
+ }
159
+ return defaultOptions;
160
+ }
12
161
  const FILTERS = {
13
162
  "plugin-css": (file) => file.endsWith(".css"),
14
163
  "plugin-css-modules": (file) => file.endsWith(".css") || ((0, helper_1.isJavaScript)(file) && !file.includes("runtime")),
@@ -24,11 +173,13 @@ const creator = new creator_1.BasicCaseCreator({
24
173
  const cat = node_path_1.default.basename(node_path_1.default.dirname(src));
25
174
  const filter = FILTERS[cat];
26
175
  return [
27
- new processor_1.BuiltinProcessor({
176
+ new processor_1.SnapshotProcessor({
28
177
  name,
29
178
  snapshot: "output.snap.txt",
30
179
  snapshotFileFilter: filter,
31
- compilerType: type_1.ECompilerType.Rspack
180
+ compilerType: type_1.ECompilerType.Rspack,
181
+ defaultOptions,
182
+ runable: false
32
183
  })
33
184
  ];
34
185
  },
@@ -1,11 +1,124 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.createCacheCase = createCacheCase;
4
- const cache_1 = require("../processor/cache");
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const core_1 = __importDefault(require("@rspack/core"));
9
+ const helper_1 = require("../helper");
10
+ const hot_update_1 = require("../helper/hot-update");
11
+ const processor_1 = require("../processor");
5
12
  const runner_1 = require("../runner");
6
13
  const creator_1 = require("../test/creator");
7
14
  const type_1 = require("../type");
8
15
  const creators = new Map();
16
+ function defaultOptions(context, temp, target) {
17
+ const options = {
18
+ context: temp,
19
+ mode: "production",
20
+ cache: true,
21
+ devtool: false,
22
+ output: {
23
+ path: context.getDist(),
24
+ filename: "bundle.js",
25
+ chunkFilename: "[name].chunk.[fullhash].js",
26
+ publicPath: "https://test.cases/path/",
27
+ library: { type: "commonjs2" }
28
+ },
29
+ optimization: {
30
+ moduleIds: "named",
31
+ emitOnErrors: true
32
+ },
33
+ target,
34
+ experiments: {
35
+ css: true,
36
+ rspackFuture: {
37
+ bundlerInfo: {
38
+ force: false
39
+ }
40
+ },
41
+ inlineConst: true,
42
+ lazyBarrel: true
43
+ }
44
+ };
45
+ options.plugins ??= [];
46
+ options.plugins.push(new core_1.default.HotModuleReplacementPlugin());
47
+ return options;
48
+ }
49
+ function overrideOptions(options, temp, target, updatePlugin) {
50
+ if (!options.entry) {
51
+ options.entry = "./index.js";
52
+ }
53
+ // rewrite context to temp dir
54
+ options.context = temp;
55
+ options.module ??= {};
56
+ for (const cssModuleType of ["css/auto", "css/module", "css"]) {
57
+ options.module.generator ??= {};
58
+ options.module.generator[cssModuleType] ??= {};
59
+ options.module.generator[cssModuleType].exportsOnly ??=
60
+ target === "async-node";
61
+ }
62
+ options.plugins ??= [];
63
+ options.plugins.push(updatePlugin);
64
+ if (!global.printLogger) {
65
+ options.infrastructureLogging = {
66
+ level: "error"
67
+ };
68
+ }
69
+ }
70
+ function findBundle(name, target, context) {
71
+ const files = [];
72
+ const prefiles = [];
73
+ const compiler = context.getCompiler(name);
74
+ if (!compiler)
75
+ throw new Error("Compiler should exists when find bundle");
76
+ const stats = compiler.getStats();
77
+ if (!stats)
78
+ throw new Error("Stats should exists when find bundle");
79
+ const info = stats.toJson({ all: false, entrypoints: true });
80
+ if (target === "web" || target === "webworker") {
81
+ for (const file of info.entrypoints.main.assets) {
82
+ if ((0, helper_1.isJavaScript)(file.name)) {
83
+ files.push(file.name);
84
+ }
85
+ else {
86
+ prefiles.push(file.name);
87
+ }
88
+ }
89
+ }
90
+ else {
91
+ const assets = info.entrypoints.main.assets.filter(s => (0, helper_1.isJavaScript)(s.name));
92
+ files.push(assets[assets.length - 1].name);
93
+ }
94
+ return [...prefiles, ...files];
95
+ }
96
+ function createCacheProcessor(name, src, temp, target) {
97
+ const updatePlugin = new hot_update_1.HotUpdatePlugin(src, temp);
98
+ const processor = new processor_1.BasicProcessor({
99
+ name,
100
+ runable: true,
101
+ compilerType: type_1.ECompilerType.Rspack,
102
+ configFiles: ["rspack.config.js", "webpack.config.js"].map(i => node_path_1.default.resolve(temp, i)),
103
+ defaultOptions: context => defaultOptions(context, temp, target),
104
+ overrideOptions: (context, options) => overrideOptions(options, temp, target, updatePlugin),
105
+ findBundle: context => findBundle(name, target, context)
106
+ });
107
+ processor.before = async (context) => {
108
+ await updatePlugin.initialize();
109
+ context.setValue(name, "hotUpdateContext", updatePlugin);
110
+ };
111
+ const originalAfterAll = processor.afterAll;
112
+ processor.afterAll = async function (context) {
113
+ await originalAfterAll.call(this, context);
114
+ const updateIndex = updatePlugin.getUpdateIndex();
115
+ const totalUpdates = updatePlugin.getTotalUpdates();
116
+ if (updateIndex + 1 !== totalUpdates) {
117
+ throw new Error(`Should run all hot steps (${updateIndex + 1} / ${totalUpdates}): ${this._options.name}`);
118
+ }
119
+ };
120
+ return processor;
121
+ }
9
122
  function getCreator(target) {
10
123
  if (!creators.has(target)) {
11
124
  creators.set(target, new creator_1.BasicCaseCreator({
@@ -13,14 +126,7 @@ function getCreator(target) {
13
126
  describe: true,
14
127
  target,
15
128
  steps: ({ name, src, target, temp }) => [
16
- new cache_1.CacheProcessor({
17
- name,
18
- sourceDir: src,
19
- tempDir: temp,
20
- target: target,
21
- compilerType: type_1.ECompilerType.Rspack,
22
- configFiles: ["rspack.config.js", "webpack.config.js"]
23
- })
129
+ createCacheProcessor(name, src, temp, target)
24
130
  ],
25
131
  runner: runner_1.CacheRunnerFactory,
26
132
  concurrent: true
@@ -68,7 +68,7 @@ function createCompilerCase(name, src, dist, testConfig) {
68
68
  compiler.hooks.compilation.tap("CompilerTest", compilation => (compilation.bail = true));
69
69
  await caseConfig.compiler?.(context, compiler);
70
70
  },
71
- async check(context, compiler, stats) {
71
+ async check(env, context, compiler, stats) {
72
72
  if (caseConfig.error) {
73
73
  const statsJson = stats?.toJson({
74
74
  modules: true,
@@ -1,3 +1,6 @@
1
- import { ECompilerType, type TTestConfig } from "../type";
1
+ import { ECompilerType, type ITestContext, type TCompilerOptions, type TTestConfig } from "../type";
2
2
  export type TConfigCaseConfig = Omit<TTestConfig<ECompilerType.Rspack>, "validate">;
3
+ export declare function defaultOptions(index: number, context: ITestContext): TCompilerOptions<ECompilerType.Rspack>;
4
+ export declare function overrideOptions(index: number, context: ITestContext, options: TCompilerOptions<ECompilerType.Rspack>): void;
5
+ export declare function findBundle(index: number, context: ITestContext, options: TCompilerOptions<ECompilerType.Rspack>): string | string[];
3
6
  export declare function createConfigCase(name: string, src: string, dist: string): void;
@@ -1,10 +1,85 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.defaultOptions = defaultOptions;
7
+ exports.overrideOptions = overrideOptions;
8
+ exports.findBundle = findBundle;
3
9
  exports.createConfigCase = createConfigCase;
4
- const config_1 = require("../processor/config");
10
+ const fs_extra_1 = __importDefault(require("fs-extra"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const parseResource_1 = require("../helper/legacy/parseResource");
13
+ const processor_1 = require("../processor");
5
14
  const runner_1 = require("../runner");
6
15
  const creator_1 = require("../test/creator");
7
16
  const type_1 = require("../type");
17
+ function defaultOptions(index, context) {
18
+ return {
19
+ context: context.getSource(),
20
+ mode: "production",
21
+ target: "async-node",
22
+ devtool: false,
23
+ cache: false,
24
+ output: {
25
+ path: context.getDist()
26
+ },
27
+ optimization: {
28
+ minimize: false
29
+ },
30
+ experiments: {
31
+ css: true,
32
+ rspackFuture: {
33
+ bundlerInfo: {
34
+ force: false
35
+ }
36
+ },
37
+ inlineConst: true,
38
+ lazyBarrel: true
39
+ }
40
+ };
41
+ }
42
+ function overrideOptions(index, context, options) {
43
+ if (!options.entry) {
44
+ options.entry = "./index.js";
45
+ }
46
+ if (options.amd === undefined) {
47
+ options.amd = {};
48
+ }
49
+ if (!options.output?.filename) {
50
+ const outputModule = options.experiments?.outputModule;
51
+ options.output ??= {};
52
+ options.output.filename = `bundle${index}${outputModule ? ".mjs" : ".js"}`;
53
+ }
54
+ if (options.cache === undefined)
55
+ options.cache = false;
56
+ if (!global.printLogger) {
57
+ options.infrastructureLogging = {
58
+ level: "error"
59
+ };
60
+ }
61
+ }
62
+ function findBundle(index, context, options) {
63
+ const testConfig = context.getTestConfig();
64
+ if (typeof testConfig.findBundle === "function") {
65
+ return testConfig.findBundle(index, options);
66
+ }
67
+ const ext = path_1.default.extname((0, parseResource_1.parseResource)(options.output?.filename).path);
68
+ const bundlePath = [];
69
+ if (options.output?.path &&
70
+ fs_extra_1.default.existsSync(path_1.default.join(options.output.path, `bundle${index}${ext}`))) {
71
+ if (options.experiments?.css) {
72
+ const cssOutputPath = path_1.default.join(options.output.path, (typeof options.output?.cssFilename === "string" &&
73
+ options.output?.cssFilename) ||
74
+ `bundle${index}.css`);
75
+ if (fs_extra_1.default.existsSync(cssOutputPath)) {
76
+ bundlePath.push(`./bundle${index}.css`);
77
+ }
78
+ }
79
+ bundlePath.push(`./bundle${index}${ext}`);
80
+ }
81
+ return bundlePath;
82
+ }
8
83
  const creator = new creator_1.BasicCaseCreator({
9
84
  clean: true,
10
85
  describe: false,
@@ -20,10 +95,13 @@ const creator = new creator_1.BasicCaseCreator({
20
95
  };
21
96
  },
22
97
  steps: ({ name }) => [
23
- new config_1.ConfigProcessor({
98
+ new processor_1.MultiTaskProcessor({
24
99
  name,
25
100
  runable: true,
26
101
  compilerType: type_1.ECompilerType.Rspack,
102
+ defaultOptions,
103
+ overrideOptions,
104
+ findBundle,
27
105
  configFiles: [
28
106
  "rspack.config.cjs",
29
107
  "rspack.config.js",
@@ -1,6 +1,14 @@
1
- import { type IDefaultsConfigProcessorOptions } from "../processor";
2
- import { ECompilerType } from "../type";
3
- export type TDefaultsCaseConfig = Omit<IDefaultsConfigProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
1
+ import { ECompilerType, type ITestContext, type TCompilerOptions } from "../type";
2
+ export declare function getRspackDefaultConfig(cwd: string, config: TCompilerOptions<ECompilerType>): TCompilerOptions<ECompilerType>;
3
+ export type TDefaultsCaseConfig = {
4
+ options?: (context: ITestContext) => TCompilerOptions<ECompilerType.Rspack>;
5
+ cwd?: string;
6
+ diff: (diff: jest.JestMatchers<RspackTestDiff>, defaults: jest.JestMatchers<TCompilerOptions<ECompilerType.Rspack>>) => Promise<void>;
4
7
  description: string;
5
8
  };
9
+ declare class RspackTestDiff {
10
+ value: string;
11
+ constructor(value: string);
12
+ }
6
13
  export declare function createDefaultsCase(name: string, src: string): void;
14
+ export {};
@@ -3,17 +3,59 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getRspackDefaultConfig = getRspackDefaultConfig;
6
7
  exports.createDefaultsCase = createDefaultsCase;
7
8
  const node_path_1 = __importDefault(require("node:path"));
9
+ const node_util_1 = require("node:util");
10
+ const jest_diff_1 = require("jest-diff");
8
11
  const processor_1 = require("../processor");
9
12
  const context_1 = require("../test/context");
10
13
  const type_1 = require("../type");
14
+ const CURRENT_CWD = process.cwd();
15
+ function getRspackDefaultConfig(cwd, config) {
16
+ process.chdir(cwd);
17
+ const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } = require("@rspack/core").config;
18
+ const normalizedConfig = getNormalizedWebpackOptions(config);
19
+ applyWebpackOptionsDefaults(normalizedConfig);
20
+ // make snapshot stable
21
+ normalizedConfig.experiments.rspackFuture.bundlerInfo.version =
22
+ "$version$";
23
+ process.chdir(CURRENT_CWD);
24
+ return normalizedConfig;
25
+ }
11
26
  const srcDir = node_path_1.default.resolve(__dirname, "../../tests/fixtures");
12
27
  const distDir = node_path_1.default.resolve(__dirname, "../../tests/js/defaults");
13
28
  const context = new context_1.TestContext({
14
29
  src: srcDir,
15
30
  dist: distDir
16
31
  });
32
+ function options(context, custom) {
33
+ let res;
34
+ if (typeof custom === "function") {
35
+ res = custom(context);
36
+ }
37
+ else {
38
+ res = {};
39
+ }
40
+ if (!("mode" in res)) {
41
+ res.mode = "none";
42
+ }
43
+ return res;
44
+ }
45
+ class RspackTestDiff {
46
+ constructor(value) {
47
+ this.value = value;
48
+ }
49
+ }
50
+ async function check(env, context, options) {
51
+ const compiler = this.getCompiler(context);
52
+ const config = getRspackDefaultConfig(options.cwd || CURRENT_CWD, compiler.getOptions());
53
+ const defaultConfig = getRspackDefaultConfig(options.cwd || CURRENT_CWD, {
54
+ mode: "none"
55
+ });
56
+ const diff = (0, node_util_1.stripVTControlCharacters)((0, jest_diff_1.diff)(defaultConfig, config, { expand: false, contextLines: 0 }));
57
+ await options.diff(env.expect(new RspackTestDiff(diff)), env.expect(defaultConfig));
58
+ }
17
59
  async function run(name, processor) {
18
60
  try {
19
61
  await processor.before?.(context);
@@ -30,10 +72,13 @@ async function run(name, processor) {
30
72
  function createDefaultsCase(name, src) {
31
73
  const caseConfig = require(src);
32
74
  it(`should generate the correct defaults from ${caseConfig.description}`, async () => {
33
- await run(name, new processor_1.DefaultsConfigProcessor({
75
+ await run(name, new processor_1.SimpleTaskProcessor({
34
76
  name,
35
77
  compilerType: type_1.ECompilerType.Rspack,
36
- ...caseConfig
78
+ options: (context) => options(context, caseConfig.options),
79
+ check(env, context, _compiler, _stats) {
80
+ return check.call(this, env, context, caseConfig);
81
+ }
37
82
  }));
38
83
  });
39
84
  }
@@ -1 +1,7 @@
1
+ export interface IDiagnosticOptions {
2
+ snapshot: string;
3
+ snapshotErrors: string;
4
+ snapshotWarning: string;
5
+ format?: (output: string) => string;
6
+ }
1
7
  export declare function createDiagnosticCase(name: string, src: string, dist: string): void;
@@ -1,24 +1,124 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.createDiagnosticCase = createDiagnosticCase;
7
+ const node_assert_1 = __importDefault(require("node:assert"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const webpack_merge_1 = __importDefault(require("webpack-merge"));
10
+ const helper_1 = require("../helper");
11
+ const placeholder_1 = require("../helper/expect/placeholder");
4
12
  const processor_1 = require("../processor");
5
13
  const creator_1 = require("../test/creator");
6
14
  const type_1 = require("../type");
15
+ function defaultOptions(context) {
16
+ return {
17
+ target: "node",
18
+ context: context.getSource(),
19
+ entry: {
20
+ main: "./"
21
+ },
22
+ mode: "development",
23
+ devServer: {
24
+ hot: false
25
+ },
26
+ infrastructureLogging: {
27
+ debug: false
28
+ },
29
+ output: {
30
+ path: context.getDist()
31
+ },
32
+ experiments: {
33
+ css: true,
34
+ rspackFuture: {
35
+ bundlerInfo: {
36
+ force: false
37
+ }
38
+ },
39
+ inlineConst: true,
40
+ lazyBarrel: true
41
+ }
42
+ };
43
+ }
44
+ async function check(env, context, options) {
45
+ const compiler = this.getCompiler(context);
46
+ const stats = compiler.getStats();
47
+ if (!stats) {
48
+ throw new Error("Stats should exists");
49
+ }
50
+ (0, node_assert_1.default)(stats.hasErrors() || stats.hasWarnings());
51
+ let output = (0, placeholder_1.normalizePlaceholder)(stats.toString({
52
+ all: false,
53
+ errors: true,
54
+ warnings: true
55
+ })).replaceAll("\\", "/");
56
+ const statsJson = stats.toJson({
57
+ all: false,
58
+ errors: true,
59
+ warnings: true
60
+ });
61
+ const errors = (statsJson.errors || []).map(e => {
62
+ // @ts-expect-error error message is already serialized in `stats.err`
63
+ delete e.message;
64
+ delete e.stack;
65
+ return e;
66
+ });
67
+ const warnings = (statsJson.warnings || []).map(e => {
68
+ // @ts-expect-error error message is already serialized in `stats.err`
69
+ delete e.message;
70
+ delete e.stack;
71
+ return e;
72
+ });
73
+ if (typeof options.format === "function") {
74
+ output = options.format(output);
75
+ }
76
+ env.expect.addSnapshotSerializer({
77
+ test(received) {
78
+ return typeof received === "string";
79
+ },
80
+ serialize(received) {
81
+ return (0, placeholder_1.normalizePlaceholder)(received.trim());
82
+ }
83
+ });
84
+ const errorOutputPath = node_path_1.default.resolve(context.getSource(options.snapshot));
85
+ const errorStatsOutputPath = node_path_1.default.resolve(context.getSource(options.snapshotErrors));
86
+ const warningStatsOutputPath = node_path_1.default.resolve(context.getSource(options.snapshotWarning));
87
+ env.expect(output).toMatchFileSnapshot(errorOutputPath);
88
+ env.expect(errors).toMatchFileSnapshot(errorStatsOutputPath);
89
+ env.expect(warnings).toMatchFileSnapshot(warningStatsOutputPath);
90
+ }
7
91
  const creator = new creator_1.BasicCaseCreator({
8
92
  clean: true,
9
93
  describe: false,
10
94
  steps: ({ name }) => [
11
- new processor_1.DiagnosticProcessor({
95
+ new processor_1.SimpleTaskProcessor({
12
96
  name,
13
- snapshot: "./stats.err",
14
- snapshotErrors: "./raw-error.err",
15
- snapshotWarning: "./raw-warning.err",
16
- configFiles: ["rspack.config.js", "webpack.config.js"],
17
97
  compilerType: type_1.ECompilerType.Rspack,
18
- format: (output) => {
19
- // TODO: change to stats.errorStack
20
- // TODO: add `errorStack: false`
21
- return output.replace(/(│.* at ).*/g, "$1xxx");
98
+ options: context => {
99
+ let options = defaultOptions(context);
100
+ const custom = (0, helper_1.readConfigFile)(["rspack.config.js", "webpack.config.js"].map(i => context.getSource(i)))[0];
101
+ if (custom) {
102
+ options = (0, webpack_merge_1.default)(options, custom);
103
+ }
104
+ if (!global.printLogger) {
105
+ options.infrastructureLogging = {
106
+ level: "error"
107
+ };
108
+ }
109
+ return options;
110
+ },
111
+ check: function (env, context, compiler, stats) {
112
+ return check.call(this, env, context, {
113
+ snapshot: "./stats.err",
114
+ snapshotErrors: "./raw-error.err",
115
+ snapshotWarning: "./raw-warning.err",
116
+ format: (output) => {
117
+ // TODO: change to stats.errorStack
118
+ // TODO: add `errorStack: false`
119
+ return output.replace(/(│.* at ).*/g, "$1xxx");
120
+ }
121
+ });
22
122
  }
23
123
  })
24
124
  ],