@rspack-debug/test-tools 1.4.11 → 1.6.2

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 (257) hide show
  1. package/README.md +1 -1
  2. package/dist/case/builtin.d.ts +3 -0
  3. package/dist/case/builtin.js +152 -14
  4. package/dist/case/cache.d.ts +2 -2
  5. package/dist/case/cache.js +214 -12
  6. package/dist/case/common.d.ts +11 -0
  7. package/dist/case/common.js +249 -0
  8. package/dist/case/compiler.d.ts +17 -4
  9. package/dist/case/compiler.js +149 -12
  10. package/dist/case/config.d.ts +7 -2
  11. package/dist/case/config.js +106 -18
  12. package/dist/case/defaults.d.ts +13 -4
  13. package/dist/case/defaults.js +73 -18
  14. package/dist/case/diagnostic.d.ts +6 -0
  15. package/dist/case/diagnostic.js +121 -14
  16. package/dist/case/error.d.ts +15 -4
  17. package/dist/case/error.js +137 -12
  18. package/dist/case/esm-output.d.ts +1 -0
  19. package/dist/case/esm-output.js +117 -0
  20. package/dist/case/example.d.ts +1 -0
  21. package/dist/case/example.js +57 -0
  22. package/dist/case/hash.d.ts +2 -2
  23. package/dist/case/hash.js +72 -9
  24. package/dist/case/hook.d.ts +36 -4
  25. package/dist/case/hook.js +209 -20
  26. package/dist/case/hot-step.d.ts +2 -2
  27. package/dist/case/hot-step.js +309 -13
  28. package/dist/case/hot.d.ts +11 -2
  29. package/dist/case/hot.js +217 -12
  30. package/dist/case/incremental.d.ts +2 -2
  31. package/dist/case/incremental.js +24 -45
  32. package/dist/case/index.d.ts +31 -20
  33. package/dist/case/index.js +50 -34
  34. package/dist/case/multi-compiler.d.ts +19 -0
  35. package/dist/case/multi-compiler.js +97 -0
  36. package/dist/case/{nativeWatcher.js → native-watcher.js} +11 -23
  37. package/dist/case/normal.d.ts +3 -0
  38. package/dist/case/normal.js +202 -18
  39. package/dist/case/runner.d.ts +19 -0
  40. package/dist/case/runner.js +113 -0
  41. package/dist/case/serial.d.ts +2 -2
  42. package/dist/case/serial.js +10 -14
  43. package/dist/case/stats-api.d.ts +8 -3
  44. package/dist/case/stats-api.js +69 -10
  45. package/dist/case/stats-output.d.ts +11 -0
  46. package/dist/case/stats-output.js +199 -8
  47. package/dist/case/treeshaking.js +34 -7
  48. package/dist/case/watch.d.ts +27 -0
  49. package/dist/case/watch.js +318 -22
  50. package/dist/compiler.d.ts +16 -16
  51. package/dist/compiler.js +120 -15
  52. package/dist/helper/directory.d.ts +1 -1
  53. package/dist/helper/directory.js +2 -2
  54. package/dist/helper/expect/error.js +1 -1
  55. package/dist/helper/expect/placeholder.js +7 -7
  56. package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -2
  57. package/dist/helper/expect/to-match-file-snapshot.js +3 -3
  58. package/dist/helper/hot-update/loader.d.ts +2 -1
  59. package/dist/helper/hot-update/loader.js +5 -30
  60. package/dist/helper/hot-update/plugin.d.ts +1 -1
  61. package/dist/helper/hot-update/plugin.js +14 -13
  62. package/dist/helper/index.d.ts +2 -1
  63. package/dist/helper/index.js +2 -1
  64. package/dist/helper/is.d.ts +2 -0
  65. package/dist/helper/is.js +15 -0
  66. package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
  67. package/dist/helper/legacy/LogTestPlugin.js +35 -0
  68. package/dist/helper/legacy/asModule.js +0 -2
  69. package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -1
  70. package/dist/helper/legacy/checkArrayExpectation.js +8 -8
  71. package/dist/helper/legacy/createFakeWorker.d.ts +2 -2
  72. package/dist/helper/legacy/createFakeWorker.js +44 -20
  73. package/dist/helper/legacy/createLazyTestEnv.d.ts +3 -2
  74. package/dist/helper/legacy/createLazyTestEnv.js +3 -3
  75. package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
  76. package/dist/helper/legacy/deprecationTracking.js +41 -0
  77. package/dist/helper/legacy/expectSource.d.ts +10 -0
  78. package/dist/helper/legacy/expectSource.js +23 -0
  79. package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
  80. package/dist/helper/legacy/findOutputFiles.js +14 -0
  81. package/dist/helper/legacy/regexEscape.d.ts +2 -0
  82. package/dist/helper/legacy/regexEscape.js +5 -0
  83. package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
  84. package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
  85. package/dist/helper/legacy/supportsTextDecoder.js +9 -0
  86. package/dist/helper/legacy/supportsUsing.d.ts +2 -0
  87. package/dist/helper/legacy/supportsUsing.js +26 -0
  88. package/dist/helper/legacy/urlToRelativePath.js +5 -2
  89. package/dist/helper/read-config-file.d.ts +3 -2
  90. package/dist/helper/read-config-file.js +12 -2
  91. package/dist/helper/setup-env.js +15 -2
  92. package/dist/helper/setup-expect.js +2 -2
  93. package/dist/helper/setup-wasm.js +2 -2
  94. package/dist/helper/stringify-config.d.ts +2 -0
  95. package/dist/helper/stringify-config.js +43 -0
  96. package/dist/helper/util/checkStats.d.ts +0 -1
  97. package/dist/helper/util/checkStats.js +0 -18
  98. package/dist/helper/util/expectWarningFactory.js +2 -4
  99. package/dist/index.d.ts +0 -4
  100. package/dist/index.js +0 -4
  101. package/dist/plugin/index.d.ts +0 -3
  102. package/dist/plugin/index.js +0 -3
  103. package/dist/plugin/lazy-compilation-test-plugin.js +4 -4
  104. package/dist/runner/index.d.ts +2 -9
  105. package/dist/runner/index.js +2 -9
  106. package/dist/runner/node/index.d.ts +41 -0
  107. package/dist/runner/node/index.js +450 -0
  108. package/dist/runner/web/index.d.ts +30 -0
  109. package/dist/runner/web/index.js +343 -0
  110. package/dist/test/context.d.ts +15 -18
  111. package/dist/test/context.js +52 -57
  112. package/dist/test/creator.d.ts +20 -19
  113. package/dist/test/creator.js +69 -57
  114. package/dist/test/debug.d.ts +15 -0
  115. package/dist/test/debug.js +205 -0
  116. package/dist/test/tester.d.ts +1 -0
  117. package/dist/test/tester.js +44 -6
  118. package/dist/type.d.ts +94 -64
  119. package/dist/type.js +8 -12
  120. package/package.json +22 -61
  121. package/rstest.d.ts +24 -0
  122. package/dist/case/diff.d.ts +0 -3
  123. package/dist/case/diff.js +0 -126
  124. package/dist/compare/comparator.d.ts +0 -17
  125. package/dist/compare/comparator.js +0 -52
  126. package/dist/compare/compare.d.ts +0 -17
  127. package/dist/compare/compare.js +0 -175
  128. package/dist/compare/format-code.d.ts +0 -16
  129. package/dist/compare/format-code.js +0 -239
  130. package/dist/compare/index.d.ts +0 -5
  131. package/dist/compare/index.js +0 -21
  132. package/dist/compare/replace-module-argument.d.ts +0 -1
  133. package/dist/compare/replace-module-argument.js +0 -8
  134. package/dist/compare/replace-runtime-module-name.d.ts +0 -1
  135. package/dist/compare/replace-runtime-module-name.js +0 -71
  136. package/dist/helper/legacy/FakeDocument.d.ts +0 -54
  137. package/dist/helper/legacy/FakeDocument.js +0 -278
  138. package/dist/helper/legacy/createLogger.d.ts +0 -23
  139. package/dist/helper/legacy/createLogger.js +0 -20
  140. package/dist/helper/legacy/supportsImportFn.d.ts +0 -1
  141. package/dist/helper/legacy/supportsImportFn.js +0 -15
  142. package/dist/helper/legacy/supportsWorker.js +0 -17
  143. package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
  144. package/dist/helper/legacy/walkCssTokens.js +0 -761
  145. package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
  146. package/dist/helper/legacy/warmup-webpack.js +0 -26
  147. package/dist/helper/loaders/hot-update.d.ts +0 -1
  148. package/dist/helper/loaders/hot-update.js +0 -40
  149. package/dist/helper/plugins/hot-update.d.ts +0 -7
  150. package/dist/helper/plugins/hot-update.js +0 -40
  151. package/dist/helper/plugins/index.d.ts +0 -1
  152. package/dist/helper/plugins/index.js +0 -17
  153. package/dist/helper/util/currentWatchStep.d.ts +0 -1
  154. package/dist/helper/util/currentWatchStep.js +0 -2
  155. package/dist/helper/util/identifier.d.ts +0 -76
  156. package/dist/helper/util/identifier.js +0 -339
  157. package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
  158. package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
  159. package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
  160. package/dist/plugin/rspack-diff-config-plugin.js +0 -42
  161. package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
  162. package/dist/plugin/webpack-diff-config-plugin.js +0 -41
  163. package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
  164. package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
  165. package/dist/processor/basic.d.ts +0 -24
  166. package/dist/processor/basic.js +0 -146
  167. package/dist/processor/builtin.d.ts +0 -9
  168. package/dist/processor/builtin.js +0 -171
  169. package/dist/processor/cache.d.ts +0 -20
  170. package/dist/processor/cache.js +0 -128
  171. package/dist/processor/config.d.ts +0 -11
  172. package/dist/processor/config.js +0 -81
  173. package/dist/processor/defaults.d.ts +0 -30
  174. package/dist/processor/defaults.js +0 -72
  175. package/dist/processor/diagnostic.d.ts +0 -15
  176. package/dist/processor/diagnostic.js +0 -102
  177. package/dist/processor/diff.d.ts +0 -30
  178. package/dist/processor/diff.js +0 -140
  179. package/dist/processor/error.d.ts +0 -23
  180. package/dist/processor/error.js +0 -95
  181. package/dist/processor/hash.d.ts +0 -10
  182. package/dist/processor/hash.js +0 -63
  183. package/dist/processor/hook.d.ts +0 -44
  184. package/dist/processor/hook.js +0 -204
  185. package/dist/processor/hot-incremental.d.ts +0 -14
  186. package/dist/processor/hot-incremental.js +0 -43
  187. package/dist/processor/hot-step.d.ts +0 -18
  188. package/dist/processor/hot-step.js +0 -304
  189. package/dist/processor/hot.d.ts +0 -17
  190. package/dist/processor/hot.js +0 -140
  191. package/dist/processor/index.d.ts +0 -20
  192. package/dist/processor/index.js +0 -36
  193. package/dist/processor/multi.d.ts +0 -17
  194. package/dist/processor/multi.js +0 -73
  195. package/dist/processor/normal.d.ts +0 -12
  196. package/dist/processor/normal.js +0 -150
  197. package/dist/processor/simple.d.ts +0 -23
  198. package/dist/processor/simple.js +0 -49
  199. package/dist/processor/snapshot.d.ts +0 -12
  200. package/dist/processor/snapshot.js +0 -66
  201. package/dist/processor/stats-api.d.ts +0 -18
  202. package/dist/processor/stats-api.js +0 -48
  203. package/dist/processor/stats.d.ts +0 -18
  204. package/dist/processor/stats.js +0 -206
  205. package/dist/processor/treeshaking.d.ts +0 -10
  206. package/dist/processor/treeshaking.js +0 -33
  207. package/dist/processor/watch.d.ts +0 -30
  208. package/dist/processor/watch.js +0 -241
  209. package/dist/reporter/diff-html.d.ts +0 -15
  210. package/dist/reporter/diff-html.js +0 -69
  211. package/dist/reporter/diff-stats.d.ts +0 -24
  212. package/dist/reporter/diff-stats.js +0 -131
  213. package/dist/reporter/index.d.ts +0 -2
  214. package/dist/reporter/index.js +0 -18
  215. package/dist/runner/basic.d.ts +0 -10
  216. package/dist/runner/basic.js +0 -63
  217. package/dist/runner/cache.d.ts +0 -5
  218. package/dist/runner/cache.js +0 -90
  219. package/dist/runner/hot-step.d.ts +0 -5
  220. package/dist/runner/hot-step.js +0 -87
  221. package/dist/runner/hot.d.ts +0 -5
  222. package/dist/runner/hot.js +0 -83
  223. package/dist/runner/multiple.d.ts +0 -11
  224. package/dist/runner/multiple.js +0 -38
  225. package/dist/runner/normal.d.ts +0 -5
  226. package/dist/runner/normal.js +0 -20
  227. package/dist/runner/runner/basic.d.ts +0 -30
  228. package/dist/runner/runner/basic.js +0 -107
  229. package/dist/runner/runner/cjs.d.ts +0 -14
  230. package/dist/runner/runner/cjs.js +0 -151
  231. package/dist/runner/runner/esm.d.ts +0 -7
  232. package/dist/runner/runner/esm.js +0 -125
  233. package/dist/runner/runner/index.d.ts +0 -8
  234. package/dist/runner/runner/index.js +0 -24
  235. package/dist/runner/runner/normal.d.ts +0 -9
  236. package/dist/runner/runner/normal.js +0 -23
  237. package/dist/runner/runner/watch.d.ts +0 -16
  238. package/dist/runner/runner/watch.js +0 -27
  239. package/dist/runner/runner/web/fake.d.ts +0 -18
  240. package/dist/runner/runner/web/fake.js +0 -143
  241. package/dist/runner/runner/web/jsdom.d.ts +0 -26
  242. package/dist/runner/runner/web/jsdom.js +0 -219
  243. package/dist/runner/runner/web.d.ts +0 -15
  244. package/dist/runner/runner/web.js +0 -32
  245. package/dist/runner/type.d.ts +0 -42
  246. package/dist/runner/type.js +0 -9
  247. package/dist/runner/watch.d.ts +0 -7
  248. package/dist/runner/watch.js +0 -60
  249. package/dist/test/simple.d.ts +0 -5
  250. package/dist/test/simple.js +0 -43
  251. package/jest.d.ts +0 -25
  252. package/template/diff.bundle.css +0 -1
  253. package/template/diff.bundle.js +0 -144
  254. package/template/diff.html +0 -14
  255. package/template/editor.worker.js +0 -1
  256. /package/dist/case/{nativeWatcher.d.ts → native-watcher.d.ts} +0 -0
  257. /package/dist/helper/legacy/{supportsWorker.d.ts → supportDefaultAssignment.d.ts} +0 -0
@@ -4,36 +4,91 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createDefaultsCase = createDefaultsCase;
7
+ exports.getRspackDefaultConfig = getRspackDefaultConfig;
7
8
  const node_path_1 = __importDefault(require("node:path"));
8
- const processor_1 = require("../processor");
9
+ const node_util_1 = require("node:util");
10
+ const jest_diff_1 = require("jest-diff");
9
11
  const context_1 = require("../test/context");
10
- const type_1 = require("../type");
12
+ const CURRENT_CWD = process.cwd();
13
+ function createDefaultsCase(name, src) {
14
+ const caseConfig = require(src);
15
+ it(`should generate the correct defaults from ${caseConfig.description}`, async () => {
16
+ await run(name, {
17
+ config: async (context) => {
18
+ const compiler = context.getCompiler();
19
+ compiler.setOptions(options(context, caseConfig.options));
20
+ },
21
+ compiler: async (context) => {
22
+ const compiler = context.getCompiler();
23
+ compiler.createCompiler();
24
+ },
25
+ build: async (context) => {
26
+ // no need to build, just check the snapshot of compiler options
27
+ },
28
+ run: async (env, context) => {
29
+ // no need to run, just check the snapshot of compiler options
30
+ },
31
+ check: async (env, context) => {
32
+ await check(env, context, name, caseConfig);
33
+ }
34
+ });
35
+ });
36
+ }
37
+ function getRspackDefaultConfig(cwd, config) {
38
+ process.chdir(cwd);
39
+ const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } = require("@rspack/core").config;
40
+ const normalizedConfig = getNormalizedWebpackOptions(config);
41
+ applyWebpackOptionsDefaults(normalizedConfig);
42
+ // make snapshot stable
43
+ normalizedConfig.experiments.rspackFuture.bundlerInfo.version =
44
+ "$version$";
45
+ process.chdir(CURRENT_CWD);
46
+ return normalizedConfig;
47
+ }
11
48
  const srcDir = node_path_1.default.resolve(__dirname, "../../tests/fixtures");
12
49
  const distDir = node_path_1.default.resolve(__dirname, "../../tests/js/defaults");
13
- const context = new context_1.TestContext({
14
- src: srcDir,
15
- dist: distDir
16
- });
50
+ function options(context, custom) {
51
+ let res;
52
+ if (typeof custom === "function") {
53
+ res = custom(context);
54
+ }
55
+ else {
56
+ res = {};
57
+ }
58
+ if (!("mode" in res)) {
59
+ res.mode = "none";
60
+ }
61
+ return res;
62
+ }
63
+ class RspackTestDiff {
64
+ constructor(value) {
65
+ this.value = value;
66
+ }
67
+ }
68
+ async function check(env, context, name, options) {
69
+ const compiler = context.getCompiler();
70
+ const config = getRspackDefaultConfig(options.cwd || CURRENT_CWD, compiler.getOptions());
71
+ const defaultConfig = getRspackDefaultConfig(options.cwd || CURRENT_CWD, {
72
+ mode: "none"
73
+ });
74
+ const diff = (0, node_util_1.stripVTControlCharacters)((0, jest_diff_1.diff)(defaultConfig, config, { expand: false, contextLines: 0 }));
75
+ await options.diff(env.expect(new RspackTestDiff(diff)), env.expect(defaultConfig));
76
+ }
17
77
  async function run(name, processor) {
78
+ const context = new context_1.TestContext({
79
+ name: name,
80
+ src: srcDir,
81
+ dist: distDir
82
+ });
18
83
  try {
19
84
  await processor.before?.(context);
20
85
  await processor.config?.(context);
21
86
  }
22
87
  catch (e) {
23
- context.emitError(name, e);
88
+ context.emitError(e);
24
89
  }
25
90
  finally {
26
- await processor.check?.({ expect, it, beforeEach, afterEach, jest }, context);
91
+ await processor.check?.({ expect, it, beforeEach, afterEach, rstest }, context);
27
92
  await processor.after?.(context);
28
93
  }
29
94
  }
30
- function createDefaultsCase(name, src) {
31
- const caseConfig = require(src);
32
- it(`should generate the correct defaults from ${caseConfig.description}`, async () => {
33
- await run(name, new processor_1.DefaultsConfigProcessor({
34
- name,
35
- compilerType: type_1.ECompilerType.Rspack,
36
- ...caseConfig
37
- }));
38
- });
39
- }
@@ -1 +1,7 @@
1
1
  export declare function createDiagnosticCase(name: string, src: string, dist: string): void;
2
+ export type TDiagnosticOptions = {
3
+ snapshot: string;
4
+ snapshotErrors: string;
5
+ snapshotWarning: string;
6
+ format?: (output: string) => string;
7
+ };
@@ -1,29 +1,136 @@
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;
4
- const processor_1 = require("../processor");
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");
5
12
  const creator_1 = require("../test/creator");
6
- const type_1 = require("../type");
7
13
  const creator = new creator_1.BasicCaseCreator({
8
14
  clean: true,
9
15
  describe: false,
10
16
  steps: ({ name }) => [
11
- new processor_1.DiagnosticProcessor({
12
- name,
13
- snapshot: "./stats.err",
14
- snapshotErrors: "./raw-error.err",
15
- snapshotWarning: "./raw-warning.err",
16
- configFiles: ["rspack.config.js", "webpack.config.js"],
17
- 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");
17
+ {
18
+ config: async (context) => {
19
+ const compiler = context.getCompiler();
20
+ let options = defaultOptions(context);
21
+ const custom = (0, helper_1.readConfigFile)(["rspack.config.js", "webpack.config.js"].map(i => context.getSource(i)), context, options)[0];
22
+ if (custom) {
23
+ options = (0, webpack_merge_1.default)(options, custom);
24
+ }
25
+ if (!global.printLogger) {
26
+ options.infrastructureLogging = {
27
+ level: "error"
28
+ };
29
+ }
30
+ compiler.setOptions(options);
31
+ },
32
+ compiler: async (context) => {
33
+ const compiler = context.getCompiler();
34
+ compiler.createCompiler();
35
+ },
36
+ build: async (context) => {
37
+ const compiler = context.getCompiler();
38
+ await compiler.build();
39
+ },
40
+ run: async (env, context) => {
41
+ // no need to run, just check the snapshot of diagnostics
42
+ },
43
+ check: async (env, context) => {
44
+ await check(env, context, name, {
45
+ snapshot: "./stats.err",
46
+ snapshotErrors: "./raw-error.err",
47
+ snapshotWarning: "./raw-warning.err",
48
+ format: (output) => {
49
+ // TODO: change to stats.errorStack
50
+ // TODO: add `errorStack: false`
51
+ return output.replace(/(│.* at ).*/g, "$1xxx");
52
+ }
53
+ });
22
54
  }
23
- })
55
+ }
24
56
  ],
25
57
  concurrent: true
26
58
  });
27
59
  function createDiagnosticCase(name, src, dist) {
28
60
  creator.create(name, src, dist);
29
61
  }
62
+ function defaultOptions(context) {
63
+ return {
64
+ target: "node",
65
+ context: context.getSource(),
66
+ entry: {
67
+ main: "./"
68
+ },
69
+ mode: "development",
70
+ devServer: {
71
+ hot: false
72
+ },
73
+ infrastructureLogging: {
74
+ debug: false
75
+ },
76
+ output: {
77
+ path: context.getDist()
78
+ },
79
+ experiments: {
80
+ css: true,
81
+ rspackFuture: {
82
+ bundlerInfo: {
83
+ force: false
84
+ }
85
+ },
86
+ inlineConst: true
87
+ }
88
+ };
89
+ }
90
+ async function check(env, context, name, options) {
91
+ const compiler = context.getCompiler();
92
+ const stats = compiler.getStats();
93
+ if (!stats) {
94
+ throw new Error("Stats should exists");
95
+ }
96
+ (0, node_assert_1.default)(stats.hasErrors() || stats.hasWarnings());
97
+ let output = (0, placeholder_1.normalizePlaceholder)(stats.toString({
98
+ all: false,
99
+ errors: true,
100
+ warnings: true
101
+ })).replaceAll("\\", "/");
102
+ const statsJson = stats.toJson({
103
+ all: false,
104
+ errors: true,
105
+ warnings: true
106
+ });
107
+ const errors = (statsJson.errors || []).map(e => {
108
+ // @ts-expect-error error message is already serialized in `stats.err`
109
+ delete e.message;
110
+ delete e.stack;
111
+ return e;
112
+ });
113
+ const warnings = (statsJson.warnings || []).map(e => {
114
+ // @ts-expect-error error message is already serialized in `stats.err`
115
+ delete e.message;
116
+ delete e.stack;
117
+ return e;
118
+ });
119
+ if (typeof options.format === "function") {
120
+ output = options.format(output);
121
+ }
122
+ env.expect.addSnapshotSerializer({
123
+ test(received) {
124
+ return typeof received === "string";
125
+ },
126
+ serialize(received) {
127
+ return (0, placeholder_1.normalizePlaceholder)(received.trim());
128
+ }
129
+ });
130
+ const errorOutputPath = node_path_1.default.resolve(context.getSource(options.snapshot));
131
+ const errorStatsOutputPath = node_path_1.default.resolve(context.getSource(options.snapshotErrors));
132
+ const warningStatsOutputPath = node_path_1.default.resolve(context.getSource(options.snapshotWarning));
133
+ env.expect(output).toMatchFileSnapshotSync(errorOutputPath);
134
+ env.expect(errors).toMatchFileSnapshotSync(errorStatsOutputPath);
135
+ env.expect(warnings).toMatchFileSnapshotSync(warningStatsOutputPath);
136
+ }
@@ -1,6 +1,17 @@
1
- import { type IErrorProcessorOptions } from "../processor";
2
- import { ECompilerType } from "../type";
3
- export type TErrorCaseConfig = Omit<IErrorProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
1
+ import type { Compiler, RspackOptions, StatsError } from "@rspack/core";
2
+ import type { ITestContext } from "../type";
3
+ export declare function createErrorCase(name: string, src: string, dist: string, testConfig: string): void;
4
+ declare class RspackStatsDiagnostics {
5
+ errors: StatsError[];
6
+ warnings: StatsError[];
7
+ constructor(errors: StatsError[], warnings: StatsError[]);
8
+ }
9
+ export type TErrorCaseConfig = {
4
10
  description: string;
11
+ skip?: boolean;
12
+ options?: (context: ITestContext) => RspackOptions;
13
+ compiler?: (context: ITestContext, compiler: Compiler) => Promise<void>;
14
+ build?: (context: ITestContext, compiler: Compiler) => Promise<void>;
15
+ check?: (stats: RspackStatsDiagnostics) => Promise<void>;
5
16
  };
6
- export declare function createErrorCase(name: string, src: string, dist: string, testConfig: string): void;
17
+ export {};
@@ -1,21 +1,146 @@
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.createErrorCase = createErrorCase;
4
- const processor_1 = require("../processor");
5
- const simple_1 = require("../test/simple");
6
- const type_1 = require("../type");
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const webpack_merge_1 = __importDefault(require("webpack-merge"));
9
+ const creator_1 = require("../test/creator");
7
10
  let addedSerializer = false;
11
+ const creator = new creator_1.BasicCaseCreator({
12
+ clean: true,
13
+ describe: true,
14
+ steps: ({ name, caseConfig }) => {
15
+ const config = caseConfig;
16
+ return [
17
+ {
18
+ config: async (context) => {
19
+ const compiler = context.getCompiler();
20
+ compiler.setOptions(options(context, config.options));
21
+ },
22
+ compiler: async (context) => {
23
+ const compilerManager = context.getCompiler();
24
+ compilerManager.createCompiler();
25
+ compiler(context, compilerManager.getCompiler(), config.compiler);
26
+ },
27
+ build: async (context) => {
28
+ const compiler = context.getCompiler();
29
+ if (typeof config.build === "function") {
30
+ await config.build(context, compiler.getCompiler());
31
+ }
32
+ else {
33
+ await compiler.build();
34
+ }
35
+ },
36
+ run: async (env, context) => {
37
+ // no need to run, just check the snapshot of diagnostics
38
+ },
39
+ check: async (env, context) => {
40
+ await check(env, context, name, config.check);
41
+ }
42
+ }
43
+ ];
44
+ },
45
+ concurrent: true
46
+ });
8
47
  function createErrorCase(name, src, dist, testConfig) {
9
48
  if (!addedSerializer) {
10
49
  addedSerializer = true;
11
50
  }
12
- const caseConfig = require(testConfig);
13
- const runner = (0, simple_1.getSimpleProcessorRunner)(src, dist);
14
- it(caseConfig.description, async () => {
15
- await runner(name, new processor_1.ErrorProcessor({
16
- name: name,
17
- compilerType: type_1.ECompilerType.Rspack,
18
- ...caseConfig
19
- }));
20
- });
51
+ const caseConfigList = require(testConfig);
52
+ function createCase(caseConfig) {
53
+ if (caseConfig.skip) {
54
+ it.skip(name, () => { });
55
+ return;
56
+ }
57
+ creator.create(name, src, dist, undefined, {
58
+ caseConfig,
59
+ description: () => caseConfig.description
60
+ });
61
+ }
62
+ if (Array.isArray(caseConfigList)) {
63
+ for (const caseConfig of caseConfigList) {
64
+ createCase(caseConfig);
65
+ }
66
+ }
67
+ else {
68
+ createCase(caseConfigList);
69
+ }
70
+ }
71
+ function options(context, custom) {
72
+ let options = {
73
+ context: node_path_1.default.resolve(__TEST_FIXTURES_PATH__, "errors"),
74
+ mode: "none",
75
+ devtool: false,
76
+ optimization: {
77
+ minimize: false,
78
+ moduleIds: "named",
79
+ chunkIds: "named"
80
+ },
81
+ experiments: {
82
+ css: true,
83
+ rspackFuture: {
84
+ bundlerInfo: {
85
+ force: false
86
+ }
87
+ }
88
+ }
89
+ };
90
+ if (typeof custom === "function") {
91
+ options = (0, webpack_merge_1.default)(options, custom(context, options));
92
+ }
93
+ if (options.mode === "production") {
94
+ if (options.optimization)
95
+ options.optimization.minimize = true;
96
+ else
97
+ options.optimization = { minimize: true };
98
+ }
99
+ return options;
100
+ }
101
+ async function compiler(context, compiler, custom) {
102
+ if (compiler) {
103
+ compiler.outputFileSystem = {
104
+ // CHANGE: rspack outputFileSystem `mkdirp` uses option `{ recursive: true }`, webpack's second parameter is alway a callback
105
+ mkdir(dir, maybeOptionOrCallback, maybeCallback) {
106
+ if (typeof maybeOptionOrCallback === "function") {
107
+ maybeOptionOrCallback();
108
+ }
109
+ else if (typeof maybeCallback === "function") {
110
+ maybeCallback();
111
+ }
112
+ },
113
+ writeFile(file, content, callback) {
114
+ callback();
115
+ },
116
+ stat(file, callback) {
117
+ callback(new Error("ENOENT"));
118
+ },
119
+ mkdirSync() { },
120
+ writeFileSync() { }
121
+ };
122
+ }
123
+ await custom?.(context, compiler);
124
+ }
125
+ class RspackStatsDiagnostics {
126
+ constructor(errors, warnings) {
127
+ this.errors = errors;
128
+ this.warnings = warnings;
129
+ }
130
+ }
131
+ async function check(env, context, name, check) {
132
+ if (context.getError().length > 0) {
133
+ await check?.(new RspackStatsDiagnostics(context.getError(), []));
134
+ context.clearError();
135
+ return;
136
+ }
137
+ const compiler = context.getCompiler();
138
+ const stats = compiler.getStats();
139
+ env.expect(typeof stats).toBe("object");
140
+ const statsResult = stats.toJson({ errorDetails: false });
141
+ env.expect(typeof statsResult).toBe("object");
142
+ const { errors, warnings } = statsResult;
143
+ env.expect(Array.isArray(errors)).toBe(true);
144
+ env.expect(Array.isArray(warnings)).toBe(true);
145
+ await check?.(new RspackStatsDiagnostics(errors, warnings));
21
146
  }
@@ -0,0 +1 @@
1
+ export declare function createEsmOutputCase(name: string, src: string, dist: string): void;
@@ -0,0 +1,117 @@
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.createEsmOutputCase = createEsmOutputCase;
7
+ const core_1 = __importDefault(require("@rspack/core"));
8
+ const creator_1 = require("../test/creator");
9
+ const common_1 = require("./common");
10
+ const runner_1 = require("./runner");
11
+ const creator = new creator_1.BasicCaseCreator({
12
+ clean: true,
13
+ describe: false,
14
+ testConfig: testConfig => {
15
+ const oldModuleScope = testConfig.moduleScope;
16
+ testConfig.moduleScope = (ms, stats) => {
17
+ let res = ms;
18
+ // TODO: modify runner module scope based on stats here
19
+ if (typeof oldModuleScope === "function") {
20
+ res = oldModuleScope(ms, stats);
21
+ }
22
+ return res;
23
+ };
24
+ },
25
+ steps: ({ name }) => [
26
+ {
27
+ config: async (context) => {
28
+ (0, common_1.configMultiCompiler)(context, name, ["rspack.config.cjs", "rspack.config.js", "webpack.config.js"], defaultOptions, (_index, context, options) => {
29
+ const testConfig = context.getTestConfig();
30
+ if (testConfig.esmLibPluginOptions) {
31
+ let target;
32
+ const otherPlugins = options.plugins?.filter(plugin => {
33
+ const isTarget = plugin instanceof core_1.default.experiments.EsmLibraryPlugin;
34
+ if (isTarget) {
35
+ target = plugin;
36
+ }
37
+ return !isTarget;
38
+ }) ?? [];
39
+ options.plugins = [
40
+ ...otherPlugins,
41
+ new core_1.default.experiments.EsmLibraryPlugin({
42
+ ...target.options,
43
+ ...testConfig.esmLibPluginOptions
44
+ })
45
+ ];
46
+ }
47
+ });
48
+ },
49
+ compiler: async (context) => {
50
+ await (0, common_1.compiler)(context, name);
51
+ },
52
+ build: async (context) => {
53
+ await (0, common_1.build)(context, name);
54
+ },
55
+ run: async (env, context) => {
56
+ await (0, common_1.run)(env, context, name, (context) => (0, common_1.findMultiCompilerBundle)(context, name, (_index, context, options) => {
57
+ const testConfig = context.getTestConfig();
58
+ if (typeof testConfig.findBundle === "function") {
59
+ return testConfig.findBundle(_index, options);
60
+ }
61
+ if (options.output?.filename === "[name].mjs") {
62
+ return ["main.mjs"];
63
+ }
64
+ else {
65
+ return [options.output.filename];
66
+ }
67
+ }));
68
+ },
69
+ check: async (env, context) => {
70
+ await (0, common_1.check)(env, context, name);
71
+ await (0, common_1.checkSnapshot)(env, context, name, "esm.snap.txt");
72
+ },
73
+ after: async (context) => {
74
+ await (0, common_1.afterExecute)(context, name);
75
+ }
76
+ }
77
+ ],
78
+ runner: {
79
+ key: runner_1.getMultiCompilerRunnerKey,
80
+ runner: runner_1.createMultiCompilerRunner
81
+ },
82
+ concurrent: 1
83
+ });
84
+ const defaultOptions = (_index, context) => ({
85
+ context: context.getSource(),
86
+ mode: "production",
87
+ target: "async-node",
88
+ devtool: false,
89
+ entry: "./index.js",
90
+ cache: false,
91
+ output: {
92
+ path: context.getDist(),
93
+ filename: "[name].mjs",
94
+ pathinfo: true,
95
+ module: true
96
+ },
97
+ bail: true,
98
+ optimization: {
99
+ minimize: false,
100
+ moduleIds: "named",
101
+ chunkIds: "named",
102
+ runtimeChunk: "single"
103
+ },
104
+ plugins: [new core_1.default.experiments.EsmLibraryPlugin()],
105
+ experiments: {
106
+ css: true,
107
+ rspackFuture: {
108
+ bundlerInfo: {
109
+ force: false
110
+ }
111
+ },
112
+ outputModule: true
113
+ }
114
+ });
115
+ function createEsmOutputCase(name, src, dist) {
116
+ creator.create(name, src, dist);
117
+ }
@@ -0,0 +1 @@
1
+ export declare function createExampleCase(name: string, src: string): void;
@@ -0,0 +1,57 @@
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.createExampleCase = createExampleCase;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const creator_1 = require("../test/creator");
9
+ const common_1 = require("./common");
10
+ function overrideOptions(index, context, options) {
11
+ options.context = context.getSource();
12
+ options.output = options.output || {};
13
+ options.output.pathinfo = true;
14
+ options.output.path = context.getDist();
15
+ options.output.publicPath = "dist/";
16
+ if (!options.entry)
17
+ options.entry = "./example.js";
18
+ if (!options.plugins)
19
+ options.plugins = [];
20
+ }
21
+ function createExampleProcessor(name) {
22
+ return {
23
+ config: async (context) => {
24
+ (0, common_1.configMultiCompiler)(context, name, ["rspack.config.js", "webpack.config.js"], () => ({}), overrideOptions);
25
+ },
26
+ compiler: async (context) => {
27
+ await (0, common_1.compiler)(context, name);
28
+ },
29
+ build: async (context) => {
30
+ await (0, common_1.build)(context, name);
31
+ },
32
+ run: async (env, context) => {
33
+ // no need to run, just check the building
34
+ },
35
+ check: async (env, context) => {
36
+ const compiler = context.getCompiler();
37
+ const stats = compiler.getStats();
38
+ if (stats?.hasErrors()) {
39
+ console.log(stats.toString({
40
+ all: false,
41
+ errors: true,
42
+ errorDetails: true,
43
+ errorStack: true
44
+ }));
45
+ }
46
+ expect(stats?.hasErrors()).toBe(false);
47
+ }
48
+ };
49
+ }
50
+ const creator = new creator_1.BasicCaseCreator({
51
+ clean: true,
52
+ steps: ({ name }) => [createExampleProcessor(name)],
53
+ concurrent: true
54
+ });
55
+ function createExampleCase(name, src) {
56
+ creator.create(name, src, node_path_1.default.join(src, "dist"));
57
+ }
@@ -1,3 +1,3 @@
1
- import { ECompilerType, type TTestConfig } from "../type";
2
- export type THashCaseConfig = Pick<TTestConfig<ECompilerType.Rspack>, "validate">;
1
+ import type { TTestConfig } from "../type";
2
+ export type THashCaseConfig = Pick<TTestConfig, "validate">;
3
3
  export declare function createHashCase(name: string, src: string, dist: string): void;