@rspack-debug/test-tools 1.4.11 → 1.6.4

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 (259) 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 +6 -2
  54. package/dist/helper/disable-iconv-lite-warning.d.ts +1 -0
  55. package/dist/helper/disable-iconv-lite-warning.js +12 -0
  56. package/dist/helper/expect/error.js +1 -1
  57. package/dist/helper/expect/placeholder.js +7 -7
  58. package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -2
  59. package/dist/helper/expect/to-match-file-snapshot.js +3 -3
  60. package/dist/helper/hot-update/loader.d.ts +2 -1
  61. package/dist/helper/hot-update/loader.js +5 -30
  62. package/dist/helper/hot-update/plugin.d.ts +1 -1
  63. package/dist/helper/hot-update/plugin.js +14 -13
  64. package/dist/helper/index.d.ts +2 -1
  65. package/dist/helper/index.js +2 -1
  66. package/dist/helper/is.d.ts +2 -0
  67. package/dist/helper/is.js +15 -0
  68. package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
  69. package/dist/helper/legacy/LogTestPlugin.js +35 -0
  70. package/dist/helper/legacy/asModule.js +0 -2
  71. package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -1
  72. package/dist/helper/legacy/checkArrayExpectation.js +8 -8
  73. package/dist/helper/legacy/createFakeWorker.d.ts +2 -2
  74. package/dist/helper/legacy/createFakeWorker.js +44 -20
  75. package/dist/helper/legacy/createLazyTestEnv.d.ts +3 -2
  76. package/dist/helper/legacy/createLazyTestEnv.js +3 -3
  77. package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
  78. package/dist/helper/legacy/deprecationTracking.js +41 -0
  79. package/dist/helper/legacy/expectSource.d.ts +10 -0
  80. package/dist/helper/legacy/expectSource.js +23 -0
  81. package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
  82. package/dist/helper/legacy/findOutputFiles.js +14 -0
  83. package/dist/helper/legacy/regexEscape.d.ts +2 -0
  84. package/dist/helper/legacy/regexEscape.js +5 -0
  85. package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
  86. package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
  87. package/dist/helper/legacy/supportsTextDecoder.js +9 -0
  88. package/dist/helper/legacy/supportsUsing.d.ts +2 -0
  89. package/dist/helper/legacy/supportsUsing.js +26 -0
  90. package/dist/helper/legacy/urlToRelativePath.js +5 -2
  91. package/dist/helper/read-config-file.d.ts +3 -2
  92. package/dist/helper/read-config-file.js +12 -2
  93. package/dist/helper/setup-env.js +26 -4
  94. package/dist/helper/setup-expect.js +2 -2
  95. package/dist/helper/setup-wasm.js +2 -2
  96. package/dist/helper/stringify-config.d.ts +2 -0
  97. package/dist/helper/stringify-config.js +43 -0
  98. package/dist/helper/util/checkStats.d.ts +0 -1
  99. package/dist/helper/util/checkStats.js +0 -18
  100. package/dist/helper/util/expectWarningFactory.js +2 -4
  101. package/dist/index.d.ts +0 -4
  102. package/dist/index.js +1 -4
  103. package/dist/plugin/index.d.ts +0 -3
  104. package/dist/plugin/index.js +0 -3
  105. package/dist/plugin/lazy-compilation-test-plugin.js +4 -4
  106. package/dist/runner/index.d.ts +2 -9
  107. package/dist/runner/index.js +2 -9
  108. package/dist/runner/node/index.d.ts +41 -0
  109. package/dist/runner/node/index.js +450 -0
  110. package/dist/runner/web/index.d.ts +30 -0
  111. package/dist/runner/web/index.js +343 -0
  112. package/dist/test/context.d.ts +15 -18
  113. package/dist/test/context.js +52 -57
  114. package/dist/test/creator.d.ts +20 -19
  115. package/dist/test/creator.js +69 -57
  116. package/dist/test/debug.d.ts +15 -0
  117. package/dist/test/debug.js +205 -0
  118. package/dist/test/tester.d.ts +1 -0
  119. package/dist/test/tester.js +44 -6
  120. package/dist/type.d.ts +94 -64
  121. package/dist/type.js +8 -12
  122. package/package.json +22 -61
  123. package/rstest.d.ts +24 -0
  124. package/dist/case/diff.d.ts +0 -3
  125. package/dist/case/diff.js +0 -126
  126. package/dist/compare/comparator.d.ts +0 -17
  127. package/dist/compare/comparator.js +0 -52
  128. package/dist/compare/compare.d.ts +0 -17
  129. package/dist/compare/compare.js +0 -175
  130. package/dist/compare/format-code.d.ts +0 -16
  131. package/dist/compare/format-code.js +0 -239
  132. package/dist/compare/index.d.ts +0 -5
  133. package/dist/compare/index.js +0 -21
  134. package/dist/compare/replace-module-argument.d.ts +0 -1
  135. package/dist/compare/replace-module-argument.js +0 -8
  136. package/dist/compare/replace-runtime-module-name.d.ts +0 -1
  137. package/dist/compare/replace-runtime-module-name.js +0 -71
  138. package/dist/helper/legacy/FakeDocument.d.ts +0 -54
  139. package/dist/helper/legacy/FakeDocument.js +0 -278
  140. package/dist/helper/legacy/createLogger.d.ts +0 -23
  141. package/dist/helper/legacy/createLogger.js +0 -20
  142. package/dist/helper/legacy/supportsImportFn.d.ts +0 -1
  143. package/dist/helper/legacy/supportsImportFn.js +0 -15
  144. package/dist/helper/legacy/supportsWorker.js +0 -17
  145. package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
  146. package/dist/helper/legacy/walkCssTokens.js +0 -761
  147. package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
  148. package/dist/helper/legacy/warmup-webpack.js +0 -26
  149. package/dist/helper/loaders/hot-update.d.ts +0 -1
  150. package/dist/helper/loaders/hot-update.js +0 -40
  151. package/dist/helper/plugins/hot-update.d.ts +0 -7
  152. package/dist/helper/plugins/hot-update.js +0 -40
  153. package/dist/helper/plugins/index.d.ts +0 -1
  154. package/dist/helper/plugins/index.js +0 -17
  155. package/dist/helper/util/currentWatchStep.d.ts +0 -1
  156. package/dist/helper/util/currentWatchStep.js +0 -2
  157. package/dist/helper/util/identifier.d.ts +0 -76
  158. package/dist/helper/util/identifier.js +0 -339
  159. package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
  160. package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
  161. package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
  162. package/dist/plugin/rspack-diff-config-plugin.js +0 -42
  163. package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
  164. package/dist/plugin/webpack-diff-config-plugin.js +0 -41
  165. package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
  166. package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
  167. package/dist/processor/basic.d.ts +0 -24
  168. package/dist/processor/basic.js +0 -146
  169. package/dist/processor/builtin.d.ts +0 -9
  170. package/dist/processor/builtin.js +0 -171
  171. package/dist/processor/cache.d.ts +0 -20
  172. package/dist/processor/cache.js +0 -128
  173. package/dist/processor/config.d.ts +0 -11
  174. package/dist/processor/config.js +0 -81
  175. package/dist/processor/defaults.d.ts +0 -30
  176. package/dist/processor/defaults.js +0 -72
  177. package/dist/processor/diagnostic.d.ts +0 -15
  178. package/dist/processor/diagnostic.js +0 -102
  179. package/dist/processor/diff.d.ts +0 -30
  180. package/dist/processor/diff.js +0 -140
  181. package/dist/processor/error.d.ts +0 -23
  182. package/dist/processor/error.js +0 -95
  183. package/dist/processor/hash.d.ts +0 -10
  184. package/dist/processor/hash.js +0 -63
  185. package/dist/processor/hook.d.ts +0 -44
  186. package/dist/processor/hook.js +0 -204
  187. package/dist/processor/hot-incremental.d.ts +0 -14
  188. package/dist/processor/hot-incremental.js +0 -43
  189. package/dist/processor/hot-step.d.ts +0 -18
  190. package/dist/processor/hot-step.js +0 -304
  191. package/dist/processor/hot.d.ts +0 -17
  192. package/dist/processor/hot.js +0 -140
  193. package/dist/processor/index.d.ts +0 -20
  194. package/dist/processor/index.js +0 -36
  195. package/dist/processor/multi.d.ts +0 -17
  196. package/dist/processor/multi.js +0 -73
  197. package/dist/processor/normal.d.ts +0 -12
  198. package/dist/processor/normal.js +0 -150
  199. package/dist/processor/simple.d.ts +0 -23
  200. package/dist/processor/simple.js +0 -49
  201. package/dist/processor/snapshot.d.ts +0 -12
  202. package/dist/processor/snapshot.js +0 -66
  203. package/dist/processor/stats-api.d.ts +0 -18
  204. package/dist/processor/stats-api.js +0 -48
  205. package/dist/processor/stats.d.ts +0 -18
  206. package/dist/processor/stats.js +0 -206
  207. package/dist/processor/treeshaking.d.ts +0 -10
  208. package/dist/processor/treeshaking.js +0 -33
  209. package/dist/processor/watch.d.ts +0 -30
  210. package/dist/processor/watch.js +0 -241
  211. package/dist/reporter/diff-html.d.ts +0 -15
  212. package/dist/reporter/diff-html.js +0 -69
  213. package/dist/reporter/diff-stats.d.ts +0 -24
  214. package/dist/reporter/diff-stats.js +0 -131
  215. package/dist/reporter/index.d.ts +0 -2
  216. package/dist/reporter/index.js +0 -18
  217. package/dist/runner/basic.d.ts +0 -10
  218. package/dist/runner/basic.js +0 -63
  219. package/dist/runner/cache.d.ts +0 -5
  220. package/dist/runner/cache.js +0 -90
  221. package/dist/runner/hot-step.d.ts +0 -5
  222. package/dist/runner/hot-step.js +0 -87
  223. package/dist/runner/hot.d.ts +0 -5
  224. package/dist/runner/hot.js +0 -83
  225. package/dist/runner/multiple.d.ts +0 -11
  226. package/dist/runner/multiple.js +0 -38
  227. package/dist/runner/normal.d.ts +0 -5
  228. package/dist/runner/normal.js +0 -20
  229. package/dist/runner/runner/basic.d.ts +0 -30
  230. package/dist/runner/runner/basic.js +0 -107
  231. package/dist/runner/runner/cjs.d.ts +0 -14
  232. package/dist/runner/runner/cjs.js +0 -151
  233. package/dist/runner/runner/esm.d.ts +0 -7
  234. package/dist/runner/runner/esm.js +0 -125
  235. package/dist/runner/runner/index.d.ts +0 -8
  236. package/dist/runner/runner/index.js +0 -24
  237. package/dist/runner/runner/normal.d.ts +0 -9
  238. package/dist/runner/runner/normal.js +0 -23
  239. package/dist/runner/runner/watch.d.ts +0 -16
  240. package/dist/runner/runner/watch.js +0 -27
  241. package/dist/runner/runner/web/fake.d.ts +0 -18
  242. package/dist/runner/runner/web/fake.js +0 -143
  243. package/dist/runner/runner/web/jsdom.d.ts +0 -26
  244. package/dist/runner/runner/web/jsdom.js +0 -219
  245. package/dist/runner/runner/web.d.ts +0 -15
  246. package/dist/runner/runner/web.js +0 -32
  247. package/dist/runner/type.d.ts +0 -42
  248. package/dist/runner/type.js +0 -9
  249. package/dist/runner/watch.d.ts +0 -7
  250. package/dist/runner/watch.js +0 -60
  251. package/dist/test/simple.d.ts +0 -5
  252. package/dist/test/simple.js +0 -43
  253. package/jest.d.ts +0 -25
  254. package/template/diff.bundle.css +0 -1
  255. package/template/diff.bundle.js +0 -144
  256. package/template/diff.html +0 -14
  257. package/template/editor.worker.js +0 -1
  258. /package/dist/case/{nativeWatcher.d.ts → native-watcher.d.ts} +0 -0
  259. /package/dist/helper/legacy/{supportsWorker.d.ts → supportDefaultAssignment.d.ts} +0 -0
@@ -1,140 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HotProcessor = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const core_1 = require("@rspack/core");
9
- const plugins_1 = require("../helper/plugins");
10
- const plugin_1 = require("../plugin");
11
- const type_1 = require("../type");
12
- const basic_1 = require("./basic");
13
- class HotProcessor extends basic_1.BasicProcessor {
14
- constructor(_hotOptions) {
15
- const fakeUpdateLoaderOptions = {
16
- updateIndex: 0,
17
- totalUpdates: 1,
18
- changedFiles: []
19
- };
20
- super({
21
- defaultOptions: HotProcessor.defaultOptions,
22
- overrideOptions: HotProcessor.overrideOptions,
23
- findBundle: HotProcessor.findBundle,
24
- runable: true,
25
- ..._hotOptions
26
- });
27
- this._hotOptions = _hotOptions;
28
- this.runner = null;
29
- this.updateOptions = fakeUpdateLoaderOptions;
30
- }
31
- async run(env, context) {
32
- context.setValue(this._options.name, "hotUpdateContext", this.updateOptions);
33
- await super.run(env, context);
34
- }
35
- static findBundle(context) {
36
- const files = [];
37
- const prefiles = [];
38
- const compiler = context.getCompiler(this._hotOptions.name);
39
- if (!compiler)
40
- throw new Error("Compiler should exists when find bundle");
41
- const stats = compiler.getStats();
42
- if (!stats)
43
- throw new Error("Stats should exists when find bundle");
44
- const info = stats.toJson({ all: false, entrypoints: true });
45
- if (this._hotOptions.target === "web" ||
46
- this._hotOptions.target === "webworker") {
47
- for (const file of info.entrypoints.main.assets) {
48
- if (file.name.endsWith(".js")) {
49
- files.push(file.name);
50
- }
51
- else {
52
- prefiles.push(file.name);
53
- }
54
- }
55
- }
56
- else {
57
- const assets = info.entrypoints.main.assets.filter(s => s.name.endsWith(".js"));
58
- files.push(assets[assets.length - 1].name);
59
- }
60
- return [...prefiles, ...files];
61
- }
62
- async afterAll(context) {
63
- await super.afterAll(context);
64
- if (context.getTestConfig().checkSteps === false) {
65
- return;
66
- }
67
- if (this.updateOptions.updateIndex + 1 !==
68
- this.updateOptions.totalUpdates) {
69
- throw new Error(`Should run all hot steps (${this.updateOptions.updateIndex + 1} / ${this.updateOptions.totalUpdates}): ${this._options.name}`);
70
- }
71
- }
72
- static defaultOptions(context) {
73
- const options = {
74
- context: context.getSource(),
75
- mode: "development",
76
- devtool: false,
77
- output: {
78
- path: context.getDist(),
79
- filename: "bundle.js",
80
- chunkFilename: "[name].chunk.[fullhash].js",
81
- publicPath: "https://test.cases/path/",
82
- library: { type: "commonjs2" }
83
- },
84
- optimization: {
85
- moduleIds: "named"
86
- },
87
- target: this._hotOptions.target,
88
- experiments: {
89
- css: true,
90
- // test incremental: "safe" here, we test default incremental in Incremental-*.test.js
91
- incremental: "safe",
92
- rspackFuture: {
93
- bundlerInfo: {
94
- force: false
95
- }
96
- }
97
- }
98
- };
99
- if (this._hotOptions.compilerType === type_1.ECompilerType.Rspack) {
100
- options.plugins ??= [];
101
- options.plugins.push(new core_1.rspack.HotModuleReplacementPlugin(), new plugins_1.TestHotUpdatePlugin(this.updateOptions));
102
- }
103
- return options;
104
- }
105
- static overrideOptions(context, options) {
106
- if (!options.entry) {
107
- options.entry = "./index.js";
108
- }
109
- options.module ??= {};
110
- for (const cssModuleType of ["css/auto", "css/module", "css"]) {
111
- options.module.generator ??= {};
112
- options.module.generator[cssModuleType] ??= {};
113
- options.module.generator[cssModuleType].exportsOnly ??=
114
- this._hotOptions.target === "async-node";
115
- }
116
- options.module.rules ??= [];
117
- options.module.rules.push({
118
- use: [
119
- {
120
- loader: node_path_1.default.resolve(__dirname, "../helper/loaders/hot-update.js"),
121
- options: this.updateOptions
122
- }
123
- ],
124
- enforce: "pre"
125
- });
126
- if (this._hotOptions.compilerType === type_1.ECompilerType.Rspack) {
127
- options.plugins ??= [];
128
- options.plugins.push(new core_1.rspack.LoaderOptionsPlugin(this.updateOptions));
129
- }
130
- if (!global.printLogger) {
131
- options.infrastructureLogging = {
132
- level: "error"
133
- };
134
- }
135
- if (options.experiments?.lazyCompilation) {
136
- options.plugins.push(new plugin_1.LazyCompilationTestPlugin());
137
- }
138
- }
139
- }
140
- exports.HotProcessor = HotProcessor;
@@ -1,20 +0,0 @@
1
- export * from "./basic";
2
- export * from "./builtin";
3
- export * from "./cache";
4
- export * from "./config";
5
- export * from "./defaults";
6
- export * from "./diagnostic";
7
- export * from "./diff";
8
- export * from "./error";
9
- export * from "./hash";
10
- export * from "./hook";
11
- export * from "./hot";
12
- export * from "./hot-incremental";
13
- export * from "./hot-step";
14
- export * from "./multi";
15
- export * from "./normal";
16
- export * from "./simple";
17
- export * from "./snapshot";
18
- export * from "./stats";
19
- export * from "./stats-api";
20
- export * from "./watch";
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./basic"), exports);
18
- __exportStar(require("./builtin"), exports);
19
- __exportStar(require("./cache"), exports);
20
- __exportStar(require("./config"), exports);
21
- __exportStar(require("./defaults"), exports);
22
- __exportStar(require("./diagnostic"), exports);
23
- __exportStar(require("./diff"), exports);
24
- __exportStar(require("./error"), exports);
25
- __exportStar(require("./hash"), exports);
26
- __exportStar(require("./hook"), exports);
27
- __exportStar(require("./hot"), exports);
28
- __exportStar(require("./hot-incremental"), exports);
29
- __exportStar(require("./hot-step"), exports);
30
- __exportStar(require("./multi"), exports);
31
- __exportStar(require("./normal"), exports);
32
- __exportStar(require("./simple"), exports);
33
- __exportStar(require("./snapshot"), exports);
34
- __exportStar(require("./stats"), exports);
35
- __exportStar(require("./stats-api"), exports);
36
- __exportStar(require("./watch"), exports);
@@ -1,17 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestProcessor, TCompilerOptions } from "../type";
2
- import { BasicProcessor } from "./basic";
3
- export interface IMultiTaskProcessorOptions<T extends ECompilerType> {
4
- defaultOptions?: (index: number, context: ITestContext) => TCompilerOptions<T>;
5
- overrideOptions?: (index: number, context: ITestContext, options: TCompilerOptions<T>) => void;
6
- findBundle?: (index: number, context: ITestContext, options: TCompilerOptions<T>) => string[] | string | void;
7
- compilerType: T;
8
- name: string;
9
- configFiles?: string[];
10
- runable: boolean;
11
- }
12
- export declare class MultiTaskProcessor<T extends ECompilerType> extends BasicProcessor<T> implements ITestProcessor {
13
- protected _multiOptions: IMultiTaskProcessorOptions<T>;
14
- protected multiCompilerOptions: TCompilerOptions<T>[];
15
- constructor(_multiOptions: IMultiTaskProcessorOptions<T>);
16
- config(context: ITestContext): Promise<void>;
17
- }
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MultiTaskProcessor = void 0;
4
- const webpack_merge_1 = require("webpack-merge");
5
- const helper_1 = require("../helper");
6
- const basic_1 = require("./basic");
7
- class MultiTaskProcessor extends basic_1.BasicProcessor {
8
- constructor(_multiOptions) {
9
- super({
10
- runable: _multiOptions.runable,
11
- compilerType: _multiOptions.compilerType,
12
- findBundle: (context, _) => {
13
- if (typeof _multiOptions.findBundle !== "function") {
14
- return [];
15
- }
16
- const result = [];
17
- const multiFileIndexMap = context.getValue(_multiOptions.name, "multiFileIndexMap") || {};
18
- for (const [index, compilerOptions] of this.multiCompilerOptions.entries()) {
19
- const curBundles = _multiOptions.findBundle(index, context, compilerOptions);
20
- const bundles = Array.isArray(curBundles)
21
- ? curBundles
22
- : curBundles
23
- ? [curBundles]
24
- : [];
25
- for (const bundle of bundles) {
26
- if (multiFileIndexMap[bundle]) {
27
- multiFileIndexMap[bundle].push(index);
28
- }
29
- else {
30
- multiFileIndexMap[bundle] = [index];
31
- }
32
- }
33
- result.push(...bundles);
34
- }
35
- context.setValue(_multiOptions.name, "multiFileIndexMap", multiFileIndexMap);
36
- return result;
37
- },
38
- name: _multiOptions.name
39
- });
40
- this._multiOptions = _multiOptions;
41
- this.multiCompilerOptions = [];
42
- }
43
- async config(context) {
44
- this.multiCompilerOptions = [];
45
- const caseOptions = Array.isArray(this._multiOptions.configFiles)
46
- ? (0, helper_1.readConfigFile)(this._multiOptions.configFiles.map(i => context.getSource(i)), configs => {
47
- return configs.flatMap(c => {
48
- if (typeof c === "function") {
49
- const options = {
50
- testPath: context.getDist(),
51
- env: undefined
52
- };
53
- return c(options.env, options);
54
- }
55
- return c;
56
- });
57
- })
58
- : [{}];
59
- for (const [index, options] of caseOptions.entries()) {
60
- const compilerOptions = (0, webpack_merge_1.merge)(typeof this._multiOptions.defaultOptions === "function"
61
- ? this._multiOptions.defaultOptions(index, context)
62
- : {}, options);
63
- if (typeof this._multiOptions.overrideOptions === "function") {
64
- this._multiOptions.overrideOptions(index, context, compilerOptions);
65
- }
66
- this.multiCompilerOptions.push(compilerOptions);
67
- }
68
- const compiler = this.getCompiler(context);
69
- compiler.setOptions(this.multiCompilerOptions);
70
- context.setValue(this._options.name, "multiCompilerOptions", this.multiCompilerOptions);
71
- }
72
- }
73
- exports.MultiTaskProcessor = MultiTaskProcessor;
@@ -1,12 +0,0 @@
1
- import type { ECompilerType, ITestContext, TCompilerOptions } from "../type";
2
- import { BasicProcessor, type IBasicProcessorOptions } from "./basic";
3
- export interface INormalProcessorOptions<T extends ECompilerType> extends IBasicProcessorOptions<T> {
4
- compilerOptions?: TCompilerOptions<T>;
5
- root: string;
6
- }
7
- export declare class NormalProcessor<T extends ECompilerType> extends BasicProcessor<T> {
8
- protected _normalOptions: INormalProcessorOptions<T>;
9
- constructor(_normalOptions: INormalProcessorOptions<T>);
10
- static defaultOptions<T extends ECompilerType>(this: NormalProcessor<T>, context: ITestContext): TCompilerOptions<T>;
11
- static overrideOptions<T extends ECompilerType>(options: TCompilerOptions<T>): void;
12
- }
@@ -1,150 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.NormalProcessor = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const basic_1 = require("./basic");
10
- class NormalProcessor extends basic_1.BasicProcessor {
11
- constructor(_normalOptions) {
12
- super({
13
- findBundle: (context, options) => {
14
- const filename = options.output?.filename;
15
- return typeof filename === "string" ? filename : undefined;
16
- },
17
- defaultOptions: NormalProcessor.defaultOptions,
18
- ..._normalOptions
19
- });
20
- this._normalOptions = _normalOptions;
21
- }
22
- static defaultOptions(context) {
23
- let testConfig = {};
24
- const testConfigPath = node_path_1.default.join(context.getSource(), "test.config.js");
25
- if (node_fs_1.default.existsSync(testConfigPath)) {
26
- testConfig = require(testConfigPath);
27
- }
28
- const TerserPlugin = require("terser-webpack-plugin");
29
- const terserForTesting = new TerserPlugin({
30
- parallel: false
31
- });
32
- const { root, compilerOptions } = this._normalOptions;
33
- return {
34
- context: root,
35
- entry: `./${node_path_1.default.relative(root, context.getSource())}/`,
36
- target: compilerOptions?.target || "async-node",
37
- devtool: compilerOptions?.devtool,
38
- mode: compilerOptions?.mode || "none",
39
- optimization: compilerOptions?.mode
40
- ? {
41
- // emitOnErrors: true,
42
- minimizer: [terserForTesting],
43
- ...testConfig.optimization
44
- }
45
- : {
46
- removeAvailableModules: true,
47
- removeEmptyChunks: true,
48
- mergeDuplicateChunks: true,
49
- // CHANGE: rspack does not support `flagIncludedChunks` yet.
50
- // flagIncludedChunks: true,
51
- sideEffects: true,
52
- providedExports: true,
53
- usedExports: true,
54
- mangleExports: true,
55
- // CHANGE: rspack does not support `emitOnErrors` yet.
56
- // emitOnErrors: true,
57
- concatenateModules: !!testConfig?.optimization?.concatenateModules,
58
- innerGraph: true,
59
- // CHANGE: size is not supported yet
60
- // moduleIds: "size",
61
- // chunkIds: "size",
62
- moduleIds: "named",
63
- chunkIds: "named",
64
- minimizer: [terserForTesting],
65
- ...compilerOptions?.optimization
66
- },
67
- // CHANGE: rspack does not support `performance` yet.
68
- // performance: {
69
- // hints: false
70
- // },
71
- node: {
72
- __dirname: "mock",
73
- __filename: "mock"
74
- },
75
- cache: compilerOptions?.cache && {
76
- // cacheDirectory,
77
- ...compilerOptions.cache
78
- },
79
- output: {
80
- pathinfo: "verbose",
81
- path: context.getDist(),
82
- filename: compilerOptions?.module ? "bundle.mjs" : "bundle.js"
83
- },
84
- resolve: {
85
- modules: ["web_modules", "node_modules"],
86
- mainFields: ["webpack", "browser", "web", "browserify", "main"],
87
- aliasFields: ["browser"],
88
- extensions: [".webpack.js", ".web.js", ".js", ".json"]
89
- },
90
- resolveLoader: {
91
- modules: ["web_loaders", "web_modules", "node_loaders", "node_modules"],
92
- mainFields: ["webpackLoader", "webLoader", "loader", "main"],
93
- extensions: [
94
- ".webpack-loader.js",
95
- ".web-loader.js",
96
- ".loader.js",
97
- ".js"
98
- ]
99
- },
100
- module: {
101
- rules: []
102
- },
103
- plugins: (compilerOptions?.plugins || [])
104
- // @ts-ignore
105
- .concat(testConfig.plugins || [])
106
- .concat(function () {
107
- this.hooks.compilation.tap("TestCasesTest", compilation => {
108
- const hooks = [
109
- // CHANGE: the following hooks are not supported yet, so comment it out
110
- // "optimize",
111
- // "optimizeModules",
112
- // "optimizeChunks",
113
- // "afterOptimizeTree",
114
- // "afterOptimizeAssets"
115
- ];
116
- for (const hook of hooks) {
117
- compilation.hooks[hook].tap("TestCasesTest", () => compilation.checkConstraints());
118
- }
119
- });
120
- }),
121
- experiments: {
122
- css: true,
123
- rspackFuture: {
124
- bundlerInfo: {
125
- force: false
126
- }
127
- },
128
- asyncWebAssembly: true,
129
- topLevelAwait: true,
130
- // CHANGE: rspack does not support `backCompat` yet.
131
- // backCompat: false,
132
- // CHANGE: Rspack enables `css` by default.
133
- // Turning off here to fallback to webpack's default css processing logic.
134
- ...(compilerOptions?.module ? { outputModule: true } : {})
135
- }
136
- // infrastructureLogging: compilerOptions?.cache && {
137
- // debug: true,
138
- // console: createLogger(infraStructureLog)
139
- // }
140
- };
141
- }
142
- static overrideOptions(options) {
143
- if (!global.printLogger) {
144
- options.infrastructureLogging = {
145
- level: "error"
146
- };
147
- }
148
- }
149
- }
150
- exports.NormalProcessor = NormalProcessor;
@@ -1,23 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, ITestProcessor, TCompiler, TCompilerOptions, TCompilerStats } from "../type";
2
- export interface ISimpleProcessorOptions<T extends ECompilerType> {
3
- options?: (context: ITestContext) => TCompilerOptions<T>;
4
- compilerType: T;
5
- name: string;
6
- build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
7
- compiler?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
8
- check?: (context: ITestContext, compiler: TCompiler<T>, stats: TCompilerStats<T>) => Promise<void>;
9
- }
10
- export declare class SimpleTaskProcessor<T extends ECompilerType> implements ITestProcessor {
11
- protected _options: ISimpleProcessorOptions<T>;
12
- constructor(_options: ISimpleProcessorOptions<T>);
13
- config(context: ITestContext): Promise<void>;
14
- compiler(context: ITestContext): Promise<void>;
15
- build(context: ITestContext): Promise<void>;
16
- run(env: ITestEnv, context: ITestContext): Promise<void>;
17
- check(env: ITestEnv, context: ITestContext): Promise<void>;
18
- before(context: ITestContext): Promise<void>;
19
- after(context: ITestContext): Promise<void>;
20
- beforeAll(context: ITestContext): Promise<void>;
21
- afterAll(context: ITestContext): Promise<void>;
22
- protected getCompiler(context: ITestContext): import("../type").ITestCompilerManager<T>;
23
- }
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SimpleTaskProcessor = void 0;
4
- class SimpleTaskProcessor {
5
- constructor(_options) {
6
- this._options = _options;
7
- }
8
- async config(context) {
9
- const compiler = this.getCompiler(context);
10
- if (typeof this._options.options === "function") {
11
- compiler.setOptions(this._options.options(context));
12
- }
13
- }
14
- async compiler(context) {
15
- const compiler = this.getCompiler(context);
16
- const instance = compiler.createCompiler();
17
- if (typeof this._options.compiler === "function") {
18
- await this._options.compiler(context, instance);
19
- }
20
- }
21
- async build(context) {
22
- const compiler = this.getCompiler(context);
23
- if (typeof this._options.build === "function") {
24
- await this._options.build(context, compiler.getCompiler());
25
- }
26
- else {
27
- await compiler.build();
28
- }
29
- }
30
- async run(env, context) { }
31
- async check(env, context) {
32
- const compiler = this.getCompiler(context);
33
- const stats = compiler.getStats();
34
- if (typeof this._options.check === "function") {
35
- await this._options.check(context, compiler.getCompiler(), stats);
36
- }
37
- }
38
- async before(context) { }
39
- async after(context) {
40
- const compiler = this.getCompiler(context);
41
- await compiler.close();
42
- }
43
- async beforeAll(context) { }
44
- async afterAll(context) { }
45
- getCompiler(context) {
46
- return context.getCompiler(this._options.name, this._options.compilerType);
47
- }
48
- }
49
- exports.SimpleTaskProcessor = SimpleTaskProcessor;
@@ -1,12 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestEnv } from "../type";
2
- import { BasicProcessor, type IBasicProcessorOptions } from "./basic";
3
- export interface ISnapshotProcessorOptions<T extends ECompilerType> extends IBasicProcessorOptions<T> {
4
- snapshot: string;
5
- snapshotFileFilter?: (file: string) => boolean;
6
- }
7
- export declare class SnapshotProcessor<T extends ECompilerType> extends BasicProcessor<T> {
8
- protected _snapshotOptions: ISnapshotProcessorOptions<T>;
9
- constructor(_snapshotOptions: ISnapshotProcessorOptions<T>);
10
- check(env: ITestEnv, context: ITestContext): Promise<void>;
11
- serializeEachFile(content: string): string;
12
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SnapshotProcessor = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const basic_1 = require("./basic");
9
- class SnapshotProcessor extends basic_1.BasicProcessor {
10
- constructor(_snapshotOptions) {
11
- super(_snapshotOptions);
12
- this._snapshotOptions = _snapshotOptions;
13
- if (node_path_1.default.extname(_snapshotOptions.snapshot) === ".snap") {
14
- throw new Error("Snapshot with `.snap` will be managed by jest, please use `.snap.txt` instead in SnapshotProcessor");
15
- }
16
- }
17
- async check(env, context) {
18
- const compiler = this.getCompiler(context);
19
- const stats = compiler.getStats();
20
- const c = compiler.getCompiler();
21
- if (!stats || !c)
22
- return;
23
- if (stats.hasErrors()) {
24
- const errors = [];
25
- if (stats.stats) {
26
- for (const s of stats.stats) {
27
- if (s.hasErrors()) {
28
- errors.push(...s.compilation.errors);
29
- }
30
- }
31
- }
32
- else {
33
- const s = stats;
34
- errors.push(...s.compilation.errors);
35
- }
36
- throw new Error(`Failed to compile in fixture ${this._options.name}, Errors: ${errors
37
- ?.map(i => `${i.message}\n${i.stack}`)
38
- .join("\n\n")}`);
39
- }
40
- const compilation = c._lastCompilation ||
41
- c._lastCompilation;
42
- const snapshotFileFilter = this._snapshotOptions.snapshotFileFilter ||
43
- ((file) => file.endsWith(".js") && !file.includes("runtime.js"));
44
- const fileContents = Object.entries(compilation.assets)
45
- .filter(([file]) => snapshotFileFilter(file))
46
- .map(([file, source]) => {
47
- const tag = node_path_1.default.extname(file).slice(1) || "txt";
48
- let content = this.serializeEachFile(source.source().toString());
49
- const testConfig = context.getTestConfig();
50
- if (testConfig.snapshotContent) {
51
- content = testConfig.snapshotContent(content);
52
- }
53
- return `\`\`\`${tag} title=${file}\n${content}\n\`\`\``;
54
- });
55
- fileContents.sort();
56
- const content = fileContents.join("\n\n");
57
- const snapshotPath = node_path_1.default.isAbsolute(this._snapshotOptions.snapshot)
58
- ? this._snapshotOptions.snapshot
59
- : node_path_1.default.resolve(context.getSource(), `./__snapshots__/${this._snapshotOptions.snapshot}`);
60
- env.expect(content).toMatchFileSnapshot(snapshotPath);
61
- }
62
- serializeEachFile(content) {
63
- return content;
64
- }
65
- }
66
- exports.SnapshotProcessor = SnapshotProcessor;
@@ -1,18 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, TCompiler, TCompilerOptions, TCompilerStats } from "../type";
2
- import { SimpleTaskProcessor } from "./simple";
3
- export interface IStatsAPIProcessorOptions<T extends ECompilerType> {
4
- options?: (context: ITestContext) => TCompilerOptions<T>;
5
- name: string;
6
- compilerType: T;
7
- snapshotName?: string;
8
- compiler?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
9
- build?: (context: ITestContext, compiler: TCompiler<T>) => Promise<void>;
10
- check?: (stats: TCompilerStats<T>, compiler: TCompiler<T>) => Promise<void>;
11
- }
12
- export declare class StatsAPIProcessor<T extends ECompilerType> extends SimpleTaskProcessor<T> {
13
- protected _statsAPIOptions: IStatsAPIProcessorOptions<T>;
14
- constructor(_statsAPIOptions: IStatsAPIProcessorOptions<T>);
15
- compiler(context: ITestContext): Promise<void>;
16
- run(env: ITestEnv, context: ITestContext): Promise<void>;
17
- check(env: ITestEnv, context: ITestContext): Promise<void>;
18
- }