@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
package/README.md CHANGED
@@ -16,7 +16,7 @@ We expect to reuse the tests for Rspack wasm target as many as possible and we h
16
16
  2. Set `maxWorkers` to `1`, `maxConcurrency` to `1` and disable concurrent mode to avoid flaky failures.
17
17
  3. `forceExit` is needed.
18
18
 
19
- Also check all the skipped testcases with `!process.env.WASM` in `test.filter.js`s and the skipped testsuits in `jest.config.js`s. They are divided into two categories:
19
+ Also check all the skipped testcases with `!process.env.WASM` in `test.filter.js`s and the skipped testsuits in `rstest.config.ts`s. They are divided into two categories:
20
20
 
21
21
  1. Skip due to lacks of api support, such as tests related to swc wasm plugins, pnp and profiling. We skip them to avoid obsolete snapshot errors.
22
22
  2. Skip temporarily and should be investigate in the future. There could be something wrong with test harness and rspack wasm itself. Since it could be time-consuming to figure out all of them so in this stage we use the wasm test ci to avoid the regression rather than improve its stability.
@@ -1 +1,4 @@
1
+ import type { RspackOptions } from "@rspack/core";
2
+ import type { ITestContext } from "../type";
1
3
  export declare function createBuiltinCase(name: string, src: string, dist: string): void;
4
+ export declare function defaultOptions(context: ITestContext): RspackOptions;
@@ -4,16 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createBuiltinCase = createBuiltinCase;
7
+ exports.defaultOptions = defaultOptions;
7
8
  const node_path_1 = __importDefault(require("node:path"));
8
- const processor_1 = require("../processor");
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ const webpack_merge_1 = require("webpack-merge");
11
+ const helper_1 = require("../helper");
9
12
  const creator_1 = require("../test/creator");
10
- const type_1 = require("../type");
11
- const FILTERS = {
12
- "plugin-css": (file) => file.endsWith(".css"),
13
- "plugin-css-modules": (file) => file.endsWith(".css") ||
14
- (file.endsWith(".js") && !file.includes("runtime")),
15
- "plugin-html": (file) => file.endsWith(".html")
16
- };
13
+ const common_1 = require("./common");
17
14
  const creator = new creator_1.BasicCaseCreator({
18
15
  clean: true,
19
16
  describe: false,
@@ -24,12 +21,24 @@ const creator = new creator_1.BasicCaseCreator({
24
21
  const cat = node_path_1.default.basename(node_path_1.default.dirname(src));
25
22
  const filter = FILTERS[cat];
26
23
  return [
27
- new processor_1.BuiltinProcessor({
28
- name,
29
- snapshot: "output.snap.txt",
30
- snapshotFileFilter: filter,
31
- compilerType: type_1.ECompilerType.Rspack
32
- })
24
+ {
25
+ config: async (context) => {
26
+ const compiler = context.getCompiler();
27
+ compiler.setOptions(defaultOptions(context));
28
+ },
29
+ compiler: async (context) => {
30
+ await (0, common_1.compiler)(context, name);
31
+ },
32
+ build: async (context) => {
33
+ await (0, common_1.build)(context, name);
34
+ },
35
+ run: async (env, context) => {
36
+ // no need to run, just check snapshot
37
+ },
38
+ check: async (env, context) => {
39
+ await (0, common_1.checkSnapshot)(env, context, name, "output.snap.txt", filter);
40
+ }
41
+ }
33
42
  ];
34
43
  },
35
44
  concurrent: true
@@ -37,3 +46,132 @@ const creator = new creator_1.BasicCaseCreator({
37
46
  function createBuiltinCase(name, src, dist) {
38
47
  creator.create(name, src, dist);
39
48
  }
49
+ function defaultOptions(context) {
50
+ let defaultOptions = {
51
+ entry: {
52
+ main: {
53
+ import: "./index"
54
+ }
55
+ },
56
+ output: {
57
+ publicPath: "/",
58
+ path: context.getDist(),
59
+ filename: "[name].js",
60
+ chunkFilename: "[name].js",
61
+ chunkFormat: "array-push",
62
+ cssFilename: "[name].css",
63
+ cssChunkFilename: "[name].css",
64
+ assetModuleFilename: "[hash][ext][query]",
65
+ sourceMapFilename: "[file].map",
66
+ chunkLoadingGlobal: "webpackChunkwebpack",
67
+ chunkLoading: "jsonp",
68
+ uniqueName: "__rspack_test__",
69
+ enabledLibraryTypes: ["system"],
70
+ strictModuleErrorHandling: false,
71
+ iife: true,
72
+ module: false,
73
+ asyncChunks: true,
74
+ scriptType: false,
75
+ globalObject: "self",
76
+ importFunctionName: "import",
77
+ wasmLoading: "fetch",
78
+ webassemblyModuleFilename: "[hash].module.wasm",
79
+ workerChunkLoading: "import-scripts",
80
+ workerWasmLoading: "fetch"
81
+ },
82
+ module: {
83
+ rules: [
84
+ {
85
+ test: /\.json$/,
86
+ type: "json"
87
+ },
88
+ {
89
+ test: /\.mjs$/,
90
+ type: "javascript/esm"
91
+ },
92
+ {
93
+ test: /\.cjs$/,
94
+ type: "javascript/dynamic"
95
+ },
96
+ {
97
+ test: /\.js$/,
98
+ type: "javascript/auto"
99
+ },
100
+ {
101
+ test: /\.css$/,
102
+ type: "css"
103
+ },
104
+ {
105
+ test: /\.wasm$/,
106
+ type: "webassembly/async"
107
+ }
108
+ ]
109
+ },
110
+ node: {
111
+ __dirname: "mock",
112
+ __filename: "mock",
113
+ global: "warn"
114
+ },
115
+ optimization: {
116
+ runtimeChunk: {
117
+ name: "runtime"
118
+ },
119
+ minimize: false,
120
+ removeAvailableModules: true,
121
+ removeEmptyChunks: true,
122
+ moduleIds: "named",
123
+ chunkIds: "named",
124
+ sideEffects: false,
125
+ mangleExports: false,
126
+ usedExports: false,
127
+ concatenateModules: false,
128
+ nodeEnv: false
129
+ },
130
+ resolve: {
131
+ extensions: [
132
+ ".js",
133
+ ".jsx",
134
+ ".ts",
135
+ ".tsx",
136
+ ".json",
137
+ ".d.ts",
138
+ ".css",
139
+ ".wasm"
140
+ ]
141
+ },
142
+ resolveLoader: {
143
+ extensions: [".js"]
144
+ },
145
+ experiments: {
146
+ css: true,
147
+ futureDefaults: true,
148
+ rspackFuture: {
149
+ bundlerInfo: {
150
+ force: false
151
+ }
152
+ }
153
+ },
154
+ devtool: false,
155
+ context: context.getSource(),
156
+ plugins: []
157
+ };
158
+ const testConfigFile = context.getSource("rspack.config.js");
159
+ if (fs_extra_1.default.existsSync(testConfigFile)) {
160
+ const caseOptions = require(testConfigFile);
161
+ if (caseOptions.entry) {
162
+ delete defaultOptions.entry;
163
+ }
164
+ defaultOptions = (0, webpack_merge_1.merge)(defaultOptions, caseOptions);
165
+ }
166
+ if (!global.printLogger) {
167
+ defaultOptions.infrastructureLogging = {
168
+ level: "error"
169
+ };
170
+ }
171
+ return defaultOptions;
172
+ }
173
+ const FILTERS = {
174
+ "plugin-css": (file) => file.endsWith(".css"),
175
+ "plugin-css-modules": (file) => file.endsWith(".css") || ((0, helper_1.isJavaScript)(file) && !file.includes("runtime")),
176
+ "plugin-html": (file) => file.endsWith(".html")
177
+ };
@@ -1,2 +1,2 @@
1
- import { ECompilerType, type TCompilerOptions } from "../type";
2
- export declare function createCacheCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], temp: string): void;
1
+ import { type RspackOptions } from "@rspack/core";
2
+ export declare function createCacheCase(name: string, src: string, dist: string, target: RspackOptions["target"], temp: string): void;
@@ -1,11 +1,57 @@
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 checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
5
12
  const runner_1 = require("../runner");
6
13
  const creator_1 = require("../test/creator");
7
- const type_1 = require("../type");
8
- const creators = new Map();
14
+ const common_1 = require("./common");
15
+ const runner_2 = require("./runner");
16
+ const MAX_COMPILER_INDEX = 100;
17
+ function createCacheProcessor(name, src, temp, target) {
18
+ const updatePlugin = new hot_update_1.HotUpdatePlugin(src, temp);
19
+ return {
20
+ before: async (context) => {
21
+ await updatePlugin.initialize();
22
+ context.setValue("hotUpdateContext", updatePlugin);
23
+ },
24
+ config: async (context) => {
25
+ const compiler = context.getCompiler();
26
+ let options = defaultOptions(context, temp, target);
27
+ options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"].map(i => node_path_1.default.resolve(temp, i)), options);
28
+ overrideOptions(options, temp, target, updatePlugin);
29
+ compiler.setOptions(options);
30
+ },
31
+ compiler: async (context) => {
32
+ await (0, common_1.compiler)(context, name);
33
+ },
34
+ build: async (context) => {
35
+ await (0, common_1.build)(context, name);
36
+ },
37
+ run: async (env, context) => {
38
+ await (0, common_1.run)(env, context, name, context => findBundle(name, target, context));
39
+ },
40
+ check: async (env, context) => {
41
+ await (0, common_1.check)(env, context, name);
42
+ },
43
+ after: async (context) => {
44
+ await (0, common_1.afterExecute)(context, name);
45
+ },
46
+ afterAll: async (context) => {
47
+ const updateIndex = updatePlugin.getUpdateIndex();
48
+ const totalUpdates = updatePlugin.getTotalUpdates();
49
+ if (updateIndex + 1 !== totalUpdates) {
50
+ throw new Error(`Should run all hot steps (${updateIndex + 1} / ${totalUpdates}): ${name}`);
51
+ }
52
+ }
53
+ };
54
+ }
9
55
  function getCreator(target) {
10
56
  if (!creators.has(target)) {
11
57
  creators.set(target, new creator_1.BasicCaseCreator({
@@ -13,16 +59,12 @@ function getCreator(target) {
13
59
  describe: true,
14
60
  target,
15
61
  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
- })
62
+ createCacheProcessor(name, src, temp, target)
24
63
  ],
25
- runner: runner_1.CacheRunnerFactory,
64
+ runner: {
65
+ key: (context, name, file) => name,
66
+ runner: createRunner
67
+ },
26
68
  concurrent: true
27
69
  }));
28
70
  }
@@ -32,3 +74,163 @@ function createCacheCase(name, src, dist, target, temp) {
32
74
  const creator = getCreator(target);
33
75
  creator.create(name, src, dist, temp);
34
76
  }
77
+ const creators = new Map();
78
+ function defaultOptions(context, temp, target) {
79
+ const options = {
80
+ context: temp,
81
+ mode: "production",
82
+ cache: true,
83
+ devtool: false,
84
+ output: {
85
+ path: context.getDist(),
86
+ filename: "bundle.js",
87
+ chunkFilename: "[name].chunk.[fullhash].js",
88
+ publicPath: "https://test.cases/path/",
89
+ library: { type: "commonjs2" }
90
+ },
91
+ optimization: {
92
+ moduleIds: "named",
93
+ emitOnErrors: true
94
+ },
95
+ target,
96
+ experiments: {
97
+ css: true,
98
+ rspackFuture: {
99
+ bundlerInfo: {
100
+ force: false
101
+ }
102
+ },
103
+ inlineConst: true
104
+ }
105
+ };
106
+ options.plugins ??= [];
107
+ options.plugins.push(new core_1.default.HotModuleReplacementPlugin());
108
+ return options;
109
+ }
110
+ function overrideOptions(options, temp, target, updatePlugin) {
111
+ if (!options.entry) {
112
+ options.entry = "./index.js";
113
+ }
114
+ // rewrite context to temp dir
115
+ options.context = temp;
116
+ options.module ??= {};
117
+ for (const cssModuleType of ["css/auto", "css/module", "css"]) {
118
+ options.module.generator ??= {};
119
+ options.module.generator[cssModuleType] ??= {};
120
+ options.module.generator[cssModuleType].exportsOnly ??=
121
+ target === "async-node";
122
+ }
123
+ options.plugins ??= [];
124
+ options.plugins.push(updatePlugin);
125
+ if (!global.printLogger) {
126
+ options.infrastructureLogging = {
127
+ level: "error"
128
+ };
129
+ }
130
+ }
131
+ function findBundle(name, target, context) {
132
+ const files = [];
133
+ const prefiles = [];
134
+ const compiler = context.getCompiler();
135
+ if (!compiler)
136
+ throw new Error("Compiler should exists when find bundle");
137
+ const stats = compiler.getStats();
138
+ if (!stats)
139
+ throw new Error("Stats should exists when find bundle");
140
+ const info = stats.toJson({
141
+ all: false,
142
+ entrypoints: true
143
+ });
144
+ if (target === "web" || target === "webworker") {
145
+ for (const file of info.entrypoints.main.assets) {
146
+ if ((0, helper_1.isJavaScript)(file.name)) {
147
+ files.push(file.name);
148
+ }
149
+ else {
150
+ prefiles.push(file.name);
151
+ }
152
+ }
153
+ }
154
+ else {
155
+ const assets = info.entrypoints.main.assets.filter(s => (0, helper_1.isJavaScript)(s.name));
156
+ files.push(assets[assets.length - 1].name);
157
+ }
158
+ return [...prefiles, ...files];
159
+ }
160
+ function createRunner(context, name, file, env) {
161
+ const compiler = context.getCompiler();
162
+ const options = compiler.getOptions();
163
+ let compilerIndex = 0;
164
+ const testConfig = context.getTestConfig();
165
+ const source = context.getSource();
166
+ const dist = context.getDist();
167
+ const updatePlugin = context.getValue("hotUpdateContext");
168
+ const getWebRunner = () => {
169
+ return new runner_1.NodeRunner({
170
+ env,
171
+ stats: (0, runner_2.cachedStats)(context, name),
172
+ cachable: false,
173
+ name: name,
174
+ runInNewContext: false,
175
+ testConfig: {
176
+ ...testConfig,
177
+ moduleScope(ms, stats, options) {
178
+ const moduleScope = typeof testConfig.moduleScope === "function"
179
+ ? testConfig.moduleScope(ms, stats, options)
180
+ : ms;
181
+ moduleScope.COMPILER_INDEX = compilerIndex;
182
+ moduleScope.NEXT_HMR = nextHmr;
183
+ moduleScope.NEXT_START = nextStart;
184
+ return moduleScope;
185
+ }
186
+ },
187
+ source,
188
+ dist,
189
+ compilerOptions: options
190
+ });
191
+ };
192
+ const nextHmr = async (m, options) => {
193
+ await updatePlugin.goNext();
194
+ const stats = await compiler.build();
195
+ if (!stats) {
196
+ throw new Error("Should generate stats during build");
197
+ }
198
+ const jsonStats = stats.toJson({
199
+ // errorDetails: true
200
+ });
201
+ const compilerOptions = compiler.getOptions();
202
+ const updateIndex = updatePlugin.getUpdateIndex();
203
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error", compilerOptions);
204
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning", compilerOptions);
205
+ const updatedModules = await m.hot.check(options || true);
206
+ if (!updatedModules) {
207
+ throw new Error("No update available");
208
+ }
209
+ return jsonStats;
210
+ };
211
+ const nextStart = async () => {
212
+ await compiler.close();
213
+ compiler.createCompiler();
214
+ await updatePlugin.goNext();
215
+ const stats = await compiler.build();
216
+ if (!stats) {
217
+ throw new Error("Should generate stats during build");
218
+ }
219
+ const jsonStats = stats.toJson({
220
+ // errorDetails: true
221
+ });
222
+ const compilerOptions = compiler.getOptions();
223
+ const updateIndex = updatePlugin.getUpdateIndex();
224
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error", compilerOptions);
225
+ await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning", compilerOptions);
226
+ env.it(`NEXT_START run with compilerIndex==${compilerIndex + 1}`, async () => {
227
+ if (compilerIndex > MAX_COMPILER_INDEX) {
228
+ throw new Error("NEXT_START has been called more than the maximum times");
229
+ }
230
+ compilerIndex++;
231
+ return getWebRunner().run(file);
232
+ });
233
+ return jsonStats;
234
+ };
235
+ return getWebRunner();
236
+ }
@@ -0,0 +1,11 @@
1
+ import type { Compiler, RspackOptions } from "@rspack/core";
2
+ import type { ITestContext, ITestEnv } from "../type";
3
+ export declare function config(context: ITestContext, name: string, configFiles: string[], defaultOptions?: RspackOptions): Promise<RspackOptions>;
4
+ export declare function compiler(context: ITestContext, name: string): Promise<Compiler>;
5
+ export declare function build(context: ITestContext, name: string): Promise<Compiler>;
6
+ export declare function run(env: ITestEnv, context: ITestContext, name: string, findBundle: (context: ITestContext, options: RspackOptions) => string[] | string | void): Promise<void>;
7
+ export declare function check(env: ITestEnv, context: ITestContext, name: string): Promise<void>;
8
+ export declare function checkSnapshot(env: ITestEnv, context: ITestContext, name: string, snapshot: string, filter?: (file: string) => boolean): Promise<void>;
9
+ export declare function afterExecute(context: ITestContext, name: string): Promise<void>;
10
+ export declare function findMultiCompilerBundle(context: ITestContext, name: string, multiFindBundle: (index: number, context: ITestContext, options: RspackOptions) => string[] | string | void): string[];
11
+ export declare function configMultiCompiler(context: ITestContext, name: string, configFiles: string[], defaultOptions: (index: number, context: ITestContext) => RspackOptions, overrideOptions: (index: number, context: ITestContext, options: RspackOptions) => void): void;