@rspack-debug/test-tools 1.4.9 → 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} +12 -25
  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 +15 -14
  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 +23 -62
  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 -127
  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 -245
  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,26 +4,210 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createNormalCase = createNormalCase;
7
+ exports.createHotNormalCase = createHotNormalCase;
8
+ exports.createDevNormalCase = createDevNormalCase;
9
+ exports.createProdNormalCase = createProdNormalCase;
10
+ const node_fs_1 = __importDefault(require("node:fs"));
7
11
  const node_path_1 = __importDefault(require("node:path"));
8
- const normal_1 = require("../processor/normal");
9
- const runner_1 = require("../runner");
12
+ const core_1 = require("@rspack/core");
10
13
  const creator_1 = require("../test/creator");
11
- const type_1 = require("../type");
12
- const creator = new creator_1.BasicCaseCreator({
13
- clean: true,
14
- describe: false,
15
- steps: ({ name }) => [
16
- new normal_1.NormalProcessor({
17
- name,
18
- root: node_path_1.default.resolve(__dirname, "../../tests/normalCases"),
19
- compilerOptions: {}, // do not used in rspack
20
- runable: true,
21
- compilerType: type_1.ECompilerType.Rspack
22
- })
23
- ],
24
- runner: runner_1.NormalRunnerFactory,
25
- concurrent: true
26
- });
14
+ const common_1 = require("./common");
15
+ const runner_1 = require("./runner");
16
+ const NORMAL_CASES_ROOT = node_path_1.default.resolve(__TEST_PATH__, "normalCases");
17
+ const createCaseOptions = (hot, mode) => {
18
+ return {
19
+ clean: true,
20
+ describe: false,
21
+ steps: ({ name }) => [
22
+ {
23
+ config: async (context) => {
24
+ const compiler = context.getCompiler();
25
+ let options = defaultOptions(context, {
26
+ plugins: hot ? [new core_1.HotModuleReplacementPlugin()] : []
27
+ }, mode);
28
+ options = await (0, common_1.config)(context, name, ["rspack.config.js", "webpack.config.js"], options);
29
+ overrideOptions(context, options);
30
+ compiler.setOptions(options);
31
+ },
32
+ compiler: async (context) => {
33
+ await (0, common_1.compiler)(context, name);
34
+ },
35
+ build: async (context) => {
36
+ await (0, common_1.build)(context, name);
37
+ },
38
+ run: async (env, context) => {
39
+ await (0, common_1.run)(env, context, name, findBundle);
40
+ },
41
+ check: async (env, context) => {
42
+ await (0, common_1.check)(env, context, name);
43
+ },
44
+ after: async (context) => {
45
+ await (0, common_1.afterExecute)(context, name);
46
+ }
47
+ }
48
+ ],
49
+ runner: {
50
+ key: (context, name, file) => name,
51
+ runner: runner_1.createRunner
52
+ },
53
+ concurrent: true
54
+ };
55
+ };
56
+ const creator = new creator_1.BasicCaseCreator(createCaseOptions(false));
27
57
  function createNormalCase(name, src, dist) {
28
58
  creator.create(name, src, dist);
29
59
  }
60
+ const hotCreator = new creator_1.BasicCaseCreator(createCaseOptions(true));
61
+ function createHotNormalCase(name, src, dist) {
62
+ hotCreator.create(name, src, dist);
63
+ }
64
+ const devCreator = new creator_1.BasicCaseCreator(createCaseOptions(false, "development"));
65
+ function createDevNormalCase(name, src, dist) {
66
+ devCreator.create(name, src, dist);
67
+ }
68
+ const prodCreator = new creator_1.BasicCaseCreator(createCaseOptions(false, "production"));
69
+ function createProdNormalCase(name, src, dist) {
70
+ prodCreator.create(name, src, dist);
71
+ }
72
+ function findBundle(context, options) {
73
+ const testConfig = context.getTestConfig();
74
+ if (typeof testConfig.findBundle === "function") {
75
+ return testConfig.findBundle(0, options);
76
+ }
77
+ const filename = options.output?.filename;
78
+ return typeof filename === "string" ? filename : undefined;
79
+ }
80
+ function defaultOptions(context, compilerOptions, mode) {
81
+ let testConfig = {};
82
+ const testConfigPath = node_path_1.default.join(context.getSource(), "test.config.js");
83
+ if (node_fs_1.default.existsSync(testConfigPath)) {
84
+ testConfig = require(testConfigPath);
85
+ }
86
+ const TerserPlugin = require("terser-webpack-plugin");
87
+ const terserForTesting = new TerserPlugin({
88
+ parallel: false
89
+ });
90
+ return {
91
+ amd: {},
92
+ context: NORMAL_CASES_ROOT,
93
+ entry: `./${node_path_1.default.relative(NORMAL_CASES_ROOT, context.getSource())}/`,
94
+ target: compilerOptions?.target || "async-node",
95
+ devtool: mode === "development" ? false : compilerOptions?.devtool,
96
+ mode: compilerOptions?.mode || mode || "none",
97
+ optimization: compilerOptions?.mode
98
+ ? {
99
+ emitOnErrors: true,
100
+ minimizer: [terserForTesting],
101
+ minimize: false,
102
+ ...testConfig.optimization
103
+ }
104
+ : {
105
+ removeAvailableModules: true,
106
+ removeEmptyChunks: true,
107
+ mergeDuplicateChunks: true,
108
+ // CHANGE: rspack does not support `flagIncludedChunks` yet.
109
+ // flagIncludedChunks: true,
110
+ sideEffects: true,
111
+ providedExports: true,
112
+ usedExports: true,
113
+ mangleExports: true,
114
+ // CHANGE: rspack does not support `emitOnErrors` yet.
115
+ emitOnErrors: true,
116
+ concatenateModules: !!testConfig?.optimization?.concatenateModules,
117
+ innerGraph: true,
118
+ // CHANGE: size is not supported yet
119
+ // moduleIds: "size",
120
+ // chunkIds: "size",
121
+ moduleIds: "named",
122
+ chunkIds: "named",
123
+ minimize: false,
124
+ minimizer: [terserForTesting],
125
+ ...compilerOptions?.optimization
126
+ },
127
+ // CHANGE: rspack does not support `performance` yet.
128
+ // performance: {
129
+ // hints: false
130
+ // },
131
+ node: {
132
+ __dirname: "mock",
133
+ __filename: "mock"
134
+ },
135
+ cache: compilerOptions?.cache && {
136
+ // cacheDirectory,
137
+ ...compilerOptions.cache
138
+ },
139
+ output: {
140
+ pathinfo: "verbose",
141
+ path: context.getDist(),
142
+ filename: compilerOptions?.module ? "bundle.mjs" : "bundle.js"
143
+ },
144
+ resolve: {
145
+ modules: ["web_modules", "node_modules"],
146
+ mainFields: ["webpack", "browser", "web", "browserify", "main"],
147
+ aliasFields: ["browser"],
148
+ extensions: [".webpack.js", ".web.js", ".js", ".json"]
149
+ },
150
+ resolveLoader: {
151
+ modules: ["web_loaders", "web_modules", "node_loaders", "node_modules"],
152
+ mainFields: ["webpackLoader", "webLoader", "loader", "main"],
153
+ extensions: [".webpack-loader.js", ".web-loader.js", ".loader.js", ".js"]
154
+ },
155
+ module: {
156
+ rules: [
157
+ {
158
+ test: /\.coffee$/,
159
+ loader: "coffee-loader"
160
+ },
161
+ {
162
+ test: /\.pug/,
163
+ loader: "@webdiscus/pug-loader"
164
+ },
165
+ {
166
+ test: /\.wat$/i,
167
+ loader: "wast-loader",
168
+ type: "webassembly/async"
169
+ }
170
+ ]
171
+ },
172
+ plugins: (compilerOptions?.plugins || [])
173
+ .concat(testConfig.plugins || [])
174
+ .concat(function () {
175
+ this.hooks.compilation.tap("TestCasesTest", compilation => {
176
+ const hooks = [
177
+ // CHANGE: the following hooks are not supported yet, so comment it out
178
+ // "optimize",
179
+ // "optimizeModules",
180
+ // "optimizeChunks",
181
+ // "afterOptimizeTree",
182
+ // "afterOptimizeAssets"
183
+ ];
184
+ for (const hook of hooks) {
185
+ compilation.hooks[hook].tap("TestCasesTest", () => compilation.checkConstraints());
186
+ }
187
+ });
188
+ }),
189
+ experiments: {
190
+ css: false,
191
+ rspackFuture: {
192
+ bundlerInfo: {
193
+ force: false
194
+ }
195
+ },
196
+ asyncWebAssembly: true,
197
+ topLevelAwait: true,
198
+ inlineConst: true,
199
+ // CHANGE: rspack does not support `backCompat` yet.
200
+ // backCompat: false,
201
+ // CHANGE: Rspack enables `css` by default.
202
+ // Turning off here to fallback to webpack's default css processing logic.
203
+ ...(compilerOptions?.module ? { outputModule: true } : {})
204
+ }
205
+ };
206
+ }
207
+ function overrideOptions(context, options) {
208
+ if (!global.printLogger) {
209
+ options.infrastructureLogging = {
210
+ level: "error"
211
+ };
212
+ }
213
+ }
@@ -0,0 +1,19 @@
1
+ import type { StatsCompilation } from "@rspack/core";
2
+ import type { ITestContext, ITestEnv, ITestRunner } from "../type";
3
+ export type THotStepRuntimeLangData = {
4
+ outdatedModules: string[];
5
+ outdatedDependencies: Record<string, string[]>;
6
+ updatedModules: string[];
7
+ updatedRuntime: string[];
8
+ acceptedModules: string[];
9
+ disposedModules: string[];
10
+ };
11
+ export type THotStepRuntimeData = {
12
+ javascript: THotStepRuntimeLangData;
13
+ css: THotStepRuntimeLangData;
14
+ statusPath: string[];
15
+ };
16
+ export declare function cachedStats(context: ITestContext, name: string): () => StatsCompilation;
17
+ export declare function createRunner(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
18
+ export declare function getMultiCompilerRunnerKey(context: ITestContext, name: string, file: string): string;
19
+ export declare function createMultiCompilerRunner(context: ITestContext, name: string, file: string, env: ITestEnv): ITestRunner;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cachedStats = cachedStats;
4
+ exports.createRunner = createRunner;
5
+ exports.getMultiCompilerRunnerKey = getMultiCompilerRunnerKey;
6
+ exports.createMultiCompilerRunner = createMultiCompilerRunner;
7
+ const runner_1 = require("../runner");
8
+ const debug_1 = require("../test/debug");
9
+ function cachedStats(context, name) {
10
+ const compiler = context.getCompiler();
11
+ const statsGetter = (() => {
12
+ let cached = null;
13
+ return () => {
14
+ if (cached) {
15
+ return cached;
16
+ }
17
+ cached = compiler.getStats().toJson({
18
+ errorDetails: true
19
+ });
20
+ return cached;
21
+ };
22
+ })();
23
+ return statsGetter;
24
+ }
25
+ function createRunner(context, name, file, env) {
26
+ const compiler = context.getCompiler();
27
+ const testConfig = context.getTestConfig();
28
+ const compilerOptions = compiler.getOptions();
29
+ const runnerOptions = {
30
+ runInNewContext: false,
31
+ cachable: true,
32
+ env,
33
+ stats: cachedStats(context, name),
34
+ name,
35
+ testConfig: context.getTestConfig(),
36
+ source: context.getSource(),
37
+ dist: context.getDist(),
38
+ compilerOptions
39
+ };
40
+ if (compilerOptions.target === "web" ||
41
+ compilerOptions.target === "webworker") {
42
+ return new runner_1.WebRunner({
43
+ ...runnerOptions,
44
+ runInNewContext: true,
45
+ location: testConfig.location || "https://test.cases/path/index.html"
46
+ });
47
+ }
48
+ return new runner_1.NodeRunner(runnerOptions);
49
+ }
50
+ function getFileIndexHandler(context, name, file) {
51
+ const multiFileIndexMap = context.getValue("multiFileIndexMap") || {};
52
+ const runned = context.getValue("runned") || new Set();
53
+ if (typeof multiFileIndexMap[file] === "undefined") {
54
+ throw new Error("Unexpect file in multiple runner");
55
+ }
56
+ const indexList = multiFileIndexMap[file];
57
+ const seq = indexList.findIndex((index, n) => !runned.has(`${name}:${file}[${n}]`));
58
+ if (seq === -1) {
59
+ throw new Error(`File ${file} should run only ${indexList.length} times`);
60
+ }
61
+ const getIndex = () => [indexList[seq], seq];
62
+ const flagIndex = () => runned.add(`${name}:${file}[${seq}]`);
63
+ context.setValue("runned", runned);
64
+ return { getIndex, flagIndex };
65
+ }
66
+ function getMultiCompilerRunnerKey(context, name, file) {
67
+ const { getIndex } = getFileIndexHandler(context, name, file);
68
+ const [index, seq] = getIndex();
69
+ return `${name}-${index}[${seq}]`;
70
+ }
71
+ function createMultiCompilerRunner(context, name, file, env) {
72
+ const testConfig = context.getTestConfig();
73
+ const { getIndex, flagIndex } = getFileIndexHandler(context, name, file);
74
+ const multiCompilerOptions = context.getValue("multiCompilerOptions") || [];
75
+ const [index] = getIndex();
76
+ const compilerOptions = multiCompilerOptions[index];
77
+ const logs = context.getValue(debug_1.DEBUG_SCOPES.RunLogs);
78
+ const errors = context.getValue(debug_1.DEBUG_SCOPES.RunErrors);
79
+ let runner;
80
+ const runnerOptions = {
81
+ runInNewContext: false,
82
+ cachable: true,
83
+ env,
84
+ stats: () => {
85
+ const s = cachedStats(context, name)();
86
+ if (s.children?.length && s.children.length > 1) {
87
+ s.__index__ = index;
88
+ return s;
89
+ }
90
+ return s.children[index];
91
+ },
92
+ name,
93
+ testConfig: context.getTestConfig(),
94
+ source: context.getSource(),
95
+ dist: context.getDist(),
96
+ compilerOptions,
97
+ logs,
98
+ errors
99
+ };
100
+ if (compilerOptions.target === "web" ||
101
+ compilerOptions.target === "webworker") {
102
+ runner = new runner_1.WebRunner({
103
+ ...runnerOptions,
104
+ runInNewContext: true,
105
+ location: testConfig.location || "https://test.cases/path/index.html"
106
+ });
107
+ }
108
+ else {
109
+ runner = new runner_1.NodeRunner(runnerOptions);
110
+ }
111
+ flagIndex();
112
+ return runner;
113
+ }
@@ -1,3 +1,3 @@
1
- import { ECompilerType, type TTestConfig } from "../type";
2
- export type TSerialCaseConfig = Omit<TTestConfig<ECompilerType.Rspack>, "validate">;
1
+ import type { TTestConfig } from "../type";
2
+ export type TSerialCaseConfig = Omit<TTestConfig, "validate">;
3
3
  export declare function createSerialCase(name: string, src: string, dist: string): void;
@@ -1,33 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createSerialCase = createSerialCase;
4
- const config_1 = require("../processor/config");
5
- const runner_1 = require("../runner");
6
4
  const creator_1 = require("../test/creator");
7
- const type_1 = require("../type");
5
+ const config_1 = require("./config");
6
+ const runner_1 = require("./runner");
8
7
  const creator = new creator_1.BasicCaseCreator({
9
8
  clean: true,
10
9
  describe: false,
11
10
  testConfig: testConfig => {
12
11
  const oldModuleScope = testConfig.moduleScope;
13
- testConfig.moduleScope = (ms, stats) => {
12
+ testConfig.moduleScope = (ms, stats, compilerOptions) => {
14
13
  let res = ms;
15
14
  // TODO: modify runner module scope based on stats here
16
15
  if (typeof oldModuleScope === "function") {
17
- res = oldModuleScope(ms, stats);
16
+ res = oldModuleScope(ms, stats, compilerOptions);
18
17
  }
19
18
  return res;
20
19
  };
21
20
  },
22
- steps: ({ name }) => [
23
- new config_1.ConfigProcessor({
24
- name,
25
- runable: true,
26
- compilerType: type_1.ECompilerType.Rspack,
27
- configFiles: ["rspack.config.js", "webpack.config.js"]
28
- })
29
- ],
30
- runner: runner_1.MultipleRunnerFactory
21
+ steps: ({ name }) => [(0, config_1.createConfigProcessor)(name)],
22
+ runner: {
23
+ key: runner_1.getMultiCompilerRunnerKey,
24
+ runner: runner_1.createMultiCompilerRunner
25
+ },
26
+ concurrent: 1
31
27
  });
32
28
  function createSerialCase(name, src, dist) {
33
29
  creator.create(name, src, dist);
@@ -1,6 +1,11 @@
1
- import { type IStatsAPIProcessorOptions } from "../processor";
2
- import { ECompilerType } from "../type";
3
- export type TStatsAPICaseConfig = Omit<IStatsAPIProcessorOptions<ECompilerType.Rspack>, "name" | "compilerType"> & {
1
+ import type { Compiler, RspackOptions, Stats } from "@rspack/core";
2
+ import type { ITestContext } from "../type";
3
+ export type TStatsAPICaseConfig = {
4
4
  description: string;
5
+ options?: (context: ITestContext) => RspackOptions;
6
+ snapshotName?: string;
7
+ compiler?: (context: ITestContext, compiler: Compiler) => Promise<void>;
8
+ build?: (context: ITestContext, compiler: Compiler) => Promise<void>;
9
+ check?: (stats: Stats, compiler: Compiler) => Promise<void>;
5
10
  };
6
11
  export declare function createStatsAPICase(name: string, src: string, dist: string, testConfig: string): void;
@@ -1,21 +1,80 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createStatsAPICase = createStatsAPICase;
4
- const processor_1 = require("../processor");
5
- const simple_1 = require("../test/simple");
6
- const type_1 = require("../type");
4
+ const memfs_1 = require("memfs");
5
+ const creator_1 = require("../test/creator");
7
6
  let addedSerializer = false;
7
+ const creator = new creator_1.BasicCaseCreator({
8
+ clean: true,
9
+ describe: true,
10
+ steps: ({ name, caseConfig }) => {
11
+ const config = caseConfig;
12
+ return [
13
+ {
14
+ config: async (context) => {
15
+ const compiler = context.getCompiler();
16
+ compiler.setOptions(options(context, config.options));
17
+ },
18
+ compiler: async (context) => {
19
+ const compilerManager = context.getCompiler();
20
+ compilerManager.createCompiler();
21
+ compiler(context, compilerManager.getCompiler(), config.compiler);
22
+ },
23
+ build: async (context) => {
24
+ const compiler = context.getCompiler();
25
+ if (typeof config.build === "function") {
26
+ await config.build(context, compiler.getCompiler());
27
+ }
28
+ else {
29
+ await compiler.build();
30
+ }
31
+ },
32
+ run: async (env, context) => {
33
+ // no need to run, just check the snapshot of diagnostics
34
+ },
35
+ check: async (env, context) => {
36
+ await check(env, context, name, config.check);
37
+ }
38
+ }
39
+ ];
40
+ },
41
+ concurrent: true
42
+ });
8
43
  function createStatsAPICase(name, src, dist, testConfig) {
9
44
  if (!addedSerializer) {
10
45
  addedSerializer = true;
11
46
  }
12
47
  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.StatsAPIProcessor({
16
- name: name,
17
- compilerType: type_1.ECompilerType.Rspack,
18
- ...caseConfig
19
- }));
48
+ creator.create(name, src, dist, undefined, {
49
+ caseConfig,
50
+ description: () => caseConfig.description
20
51
  });
21
52
  }
53
+ function options(context, custom) {
54
+ const res = (custom?.(context) || {});
55
+ res.experiments ??= {};
56
+ res.experiments.css ??= true;
57
+ res.experiments.rspackFuture ??= {};
58
+ res.experiments.rspackFuture.bundlerInfo ??= {};
59
+ res.experiments.rspackFuture.bundlerInfo.force ??= false;
60
+ if (!global.printLogger) {
61
+ res.infrastructureLogging = {
62
+ level: "error"
63
+ };
64
+ }
65
+ return res;
66
+ }
67
+ async function compiler(context, compiler, custom) {
68
+ if (custom) {
69
+ await custom(context, compiler);
70
+ }
71
+ if (compiler) {
72
+ compiler.outputFileSystem = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume());
73
+ }
74
+ }
75
+ async function check(env, context, name, custom) {
76
+ const manager = context.getCompiler();
77
+ const stats = manager.getStats();
78
+ env.expect(typeof stats).toBe("object");
79
+ await custom?.(stats, manager.getCompiler());
80
+ }
@@ -1 +1,12 @@
1
+ import type { RspackOptions } from "@rspack/core";
2
+ import type { ITestContext, ITestEnv } from "../type";
3
+ export declare function createStatsProcessor(name: string, defaultOptions: (index: number, context: ITestContext) => RspackOptions, overrideOptions: (index: number, context: ITestContext, options: RspackOptions) => void): {
4
+ before: (context: ITestContext) => Promise<void>;
5
+ config: (context: ITestContext) => Promise<void>;
6
+ compiler: (context: ITestContext) => Promise<void>;
7
+ build: (context: ITestContext) => Promise<void>;
8
+ run: (env: ITestEnv, context: ITestContext) => Promise<void>;
9
+ check: (env: ITestEnv, context: ITestContext) => Promise<void>;
10
+ after: (context: ITestContext) => Promise<void>;
11
+ };
1
12
  export declare function createStatsOutputCase(name: string, src: string, dist: string): void;