@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
@@ -9,38 +9,42 @@ const node_path_1 = __importDefault(require("node:path"));
9
9
  const rimraf_1 = require("rimraf");
10
10
  const createLazyTestEnv_1 = __importDefault(require("../helper/legacy/createLazyTestEnv"));
11
11
  const tester_1 = require("./tester");
12
- const DEFAULT_MAX_CONCURRENT = 5;
12
+ const DEFAULT_MAX_CONCURRENT = process.env.WASM ? 1 : 5;
13
13
  class BasicCaseCreator {
14
14
  constructor(_options) {
15
15
  this._options = _options;
16
16
  this.currentConcurrent = 0;
17
17
  this.tasks = [];
18
18
  }
19
- create(name, src, dist, temp) {
19
+ create(name, src, dist, temp, caseOptions) {
20
+ const options = {
21
+ ...this._options,
22
+ ...caseOptions
23
+ };
20
24
  const testConfig = this.readTestConfig(src);
21
- if (typeof this._options.testConfig === "function") {
22
- this._options.testConfig(testConfig);
25
+ if (typeof options.testConfig === "function") {
26
+ options.testConfig(testConfig);
23
27
  }
24
- const skipped = this.checkSkipped(src, testConfig);
28
+ const skipped = this.checkSkipped(src, testConfig, options);
25
29
  if (skipped) {
26
30
  this.skip(name, skipped);
27
31
  return;
28
32
  }
29
- if (this._options.clean) {
33
+ if (options.clean) {
30
34
  this.clean([dist, temp || ""].filter(Boolean));
31
35
  }
32
36
  const run = this.shouldRun(name);
33
- const tester = this.createTester(name, src, dist, temp, testConfig);
37
+ const tester = this.createTester(name, src, dist, temp, testConfig, options);
34
38
  const concurrent = process.env.WASM
35
- ? false
36
- : testConfig.concurrent || this._options.concurrent;
37
- if (this._options.describe) {
39
+ ? 1
40
+ : testConfig.concurrent || options.concurrent;
41
+ if (options.describe) {
38
42
  if (run) {
39
43
  if (concurrent) {
40
- describe(name, () => this.describeConcurrent(name, tester, testConfig));
44
+ describe(name, () => this.describeConcurrent(name, tester, testConfig, options));
41
45
  }
42
46
  else {
43
- describe(name, () => this.describe(name, tester, testConfig));
47
+ describe(name, () => this.describe(name, tester, testConfig, options));
44
48
  }
45
49
  }
46
50
  else {
@@ -52,10 +56,10 @@ class BasicCaseCreator {
52
56
  else {
53
57
  if (run) {
54
58
  if (concurrent) {
55
- this.describeConcurrent(name, tester, testConfig);
59
+ this.describeConcurrent(name, tester, testConfig, options);
56
60
  }
57
61
  else {
58
- this.describe(name, tester, testConfig);
62
+ this.describe(name, tester, testConfig, options);
59
63
  }
60
64
  }
61
65
  else {
@@ -71,7 +75,7 @@ class BasicCaseCreator {
71
75
  }
72
76
  return name.includes(global.testFilter);
73
77
  }
74
- describeConcurrent(name, tester, testConfig) {
78
+ describeConcurrent(name, tester, testConfig, options) {
75
79
  beforeAll(async () => {
76
80
  await tester.prepare();
77
81
  });
@@ -79,7 +83,7 @@ class BasicCaseCreator {
79
83
  let chain = new Promise((resolve, reject) => {
80
84
  starter = resolve;
81
85
  });
82
- const ender = this.registerConcurrentTask(name, starter);
86
+ const ender = this.registerConcurrentTask(name, starter, options.concurrent);
83
87
  const env = this.createConcurrentEnv();
84
88
  for (let index = 0; index < tester.total; index++) {
85
89
  let stepSignalResolve = null;
@@ -88,22 +92,24 @@ class BasicCaseCreator {
88
92
  }).catch(() => {
89
93
  // prevent unhandled rejection
90
94
  });
91
- const description = typeof this._options.description === "function"
92
- ? this._options.description(name, index)
95
+ const description = typeof options.description === "function"
96
+ ? options.description(name, index)
93
97
  : index
94
98
  ? `step [${index}] should pass`
95
99
  : "should pass";
96
- it(description, cb => {
97
- stepSignal.then((e) => {
98
- cb(e);
99
- });
100
- }, this._options.timeout || 180000);
100
+ it(description, async () => {
101
+ const e = await stepSignal;
102
+ if (e) {
103
+ throw e;
104
+ }
105
+ }, options.timeout || 300000);
101
106
  chain = chain.then(async () => {
102
107
  try {
103
108
  env.clear();
104
109
  await tester.compile();
105
110
  await tester.check(env);
106
111
  await env.run();
112
+ await tester.after();
107
113
  const context = tester.getContext();
108
114
  if (!tester.next() && context.hasError()) {
109
115
  const errors = context
@@ -136,22 +142,28 @@ class BasicCaseCreator {
136
142
  await tester.resume();
137
143
  });
138
144
  }
139
- describe(name, tester, testConfig) {
145
+ describe(name, tester, testConfig, options) {
140
146
  beforeAll(async () => {
141
147
  await tester.prepare();
142
148
  });
143
149
  let bailout = false;
144
150
  for (let index = 0; index < tester.total; index++) {
145
- const description = typeof this._options.description === "function"
146
- ? this._options.description(name, index)
147
- : `step ${index ? `[${index}]` : ""} should pass`;
151
+ const description = typeof options.description === "function"
152
+ ? options.description(name, index)
153
+ : `step [${index}] should pass`;
148
154
  it(description, async () => {
149
155
  if (bailout) {
150
156
  throw `Case "${name}" step ${index + 1} bailout because ${tester.step + 1} failed`;
151
157
  }
152
- await tester.compile();
153
- await tester.check(env);
154
158
  const context = tester.getContext();
159
+ try {
160
+ await tester.compile();
161
+ }
162
+ catch (e) {
163
+ bailout = true;
164
+ context.emitError(e);
165
+ }
166
+ await tester.check(env);
155
167
  if (!tester.next() && context.hasError()) {
156
168
  bailout = true;
157
169
  const errors = context
@@ -160,8 +172,8 @@ class BasicCaseCreator {
160
172
  .join("\n\n");
161
173
  throw new Error(`Case "${name}" failed at step ${tester.step + 1}:\n${errors}`);
162
174
  }
163
- }, this._options.timeout || 30000);
164
- const env = this.createEnv(testConfig);
175
+ }, options.timeout || 60000);
176
+ const env = this.createEnv(testConfig, options);
165
177
  }
166
178
  afterAll(async () => {
167
179
  await tester.resume();
@@ -205,8 +217,11 @@ class BasicCaseCreator {
205
217
  try {
206
218
  await runFn(fn);
207
219
  }
208
- catch (e) {
209
- throw new Error(`Error: ${description} failed\n${e.stack}`);
220
+ catch (err) {
221
+ const e = err;
222
+ const message = `Error: ${description} failed:\n${e.message}`;
223
+ e.message = message;
224
+ throw e;
210
225
  }
211
226
  for (const after of afterTasks) {
212
227
  await runFn(after);
@@ -227,11 +242,11 @@ class BasicCaseCreator {
227
242
  expect(typeof fn === "function");
228
243
  afterTasks.push(fn);
229
244
  },
230
- jest
245
+ rstest
231
246
  };
232
247
  }
233
- createEnv(testConfig) {
234
- if (typeof this._options.runner === "function" && !testConfig.noTest) {
248
+ createEnv(testConfig, options) {
249
+ if (options.runner && !testConfig.noTests) {
235
250
  return (0, createLazyTestEnv_1.default)(10000);
236
251
  }
237
252
  return {
@@ -239,47 +254,46 @@ class BasicCaseCreator {
239
254
  it,
240
255
  beforeEach,
241
256
  afterEach,
242
- jest
257
+ rstest
243
258
  };
244
259
  }
245
260
  clean(folders) {
246
261
  for (const f of folders) {
247
262
  (0, rimraf_1.rimrafSync)(f);
248
- node_fs_1.default.mkdirSync(f, { recursive: true });
249
263
  }
250
264
  }
251
265
  skip(name, reason) {
252
- describe.skip(name, () => {
253
- it(typeof reason === "string" ? `filtered by ${reason}` : "filtered", () => { });
254
- });
266
+ it(typeof reason === "string" ? `filtered by ${reason}` : "filtered", () => { });
255
267
  }
256
268
  readTestConfig(src) {
257
269
  const testConfigFile = node_path_1.default.join(src, "test.config.js");
258
270
  return node_fs_1.default.existsSync(testConfigFile) ? require(testConfigFile) : {};
259
271
  }
260
- checkSkipped(src, testConfig) {
272
+ checkSkipped(src, testConfig, options) {
261
273
  const filterPath = node_path_1.default.join(src, "test.filter.js");
262
274
  // no test.filter.js, should not skip
263
275
  if (!node_fs_1.default.existsSync(filterPath)) {
264
276
  return false;
265
277
  }
266
278
  // test.filter.js exists, skip if it returns false|string|array
267
- const filtered = require(filterPath)(this._options, testConfig);
279
+ const filtered = require(filterPath)(options, testConfig);
268
280
  if (typeof filtered === "string" || Array.isArray(filtered)) {
269
281
  return true;
270
282
  }
271
283
  return !filtered;
272
284
  }
273
- createTester(name, src, dist, temp, testConfig) {
285
+ createTester(name, src, dist, temp, testConfig, options) {
274
286
  return new tester_1.Tester({
275
287
  name,
276
288
  src,
277
289
  dist,
290
+ temp,
278
291
  testConfig,
279
- contextValue: this._options.contextValue,
280
- runnerFactory: this._options.runner,
281
- steps: this._options.steps({
282
- ...this._options,
292
+ contextValue: options.contextValue,
293
+ runnerCreator: options.runner,
294
+ createContext: options.createContext,
295
+ steps: options.steps({
296
+ ...options,
283
297
  name,
284
298
  src,
285
299
  dist,
@@ -287,25 +301,23 @@ class BasicCaseCreator {
287
301
  })
288
302
  });
289
303
  }
290
- tryRunTask() {
304
+ tryRunTask(concurrent) {
291
305
  while (this.tasks.length !== 0 &&
292
- this.currentConcurrent < this.getMaxConcurrent()) {
306
+ this.currentConcurrent < this.getMaxConcurrent(concurrent)) {
293
307
  const [_name, starter] = this.tasks.shift();
294
308
  this.currentConcurrent++;
295
309
  starter();
296
310
  }
297
311
  }
298
- getMaxConcurrent() {
299
- return typeof this._options.concurrent === "number"
300
- ? this._options.concurrent
301
- : DEFAULT_MAX_CONCURRENT;
312
+ getMaxConcurrent(concurrent) {
313
+ return typeof concurrent === "number" ? concurrent : DEFAULT_MAX_CONCURRENT;
302
314
  }
303
- registerConcurrentTask(name, starter) {
315
+ registerConcurrentTask(name, starter, concurrent) {
304
316
  this.tasks.push([name, starter]);
305
- this.tryRunTask();
317
+ this.tryRunTask(concurrent);
306
318
  return () => {
307
319
  this.currentConcurrent--;
308
- this.tryRunTask();
320
+ this.tryRunTask(concurrent);
309
321
  };
310
322
  }
311
323
  }
@@ -0,0 +1,15 @@
1
+ import type { ITestContext } from "../type";
2
+ export declare function generateDebugReport(context: ITestContext): void;
3
+ export declare const DEBUG_SCOPES: {
4
+ CompilerOptionsReadConfigFile: string;
5
+ CompilerOptionsFinalOptions: string;
6
+ CreateCompilerInstance: string;
7
+ CreateCompilerSetProperties: string;
8
+ BuildMethod: string;
9
+ BuildError: string;
10
+ BuildWarning: string;
11
+ RunFindBundle: string;
12
+ RunGetRunner: string;
13
+ RunLogs: string;
14
+ RunErrors: string;
15
+ };
@@ -0,0 +1,205 @@
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.DEBUG_SCOPES = void 0;
7
+ exports.generateDebugReport = generateDebugReport;
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ const javascript_stringify_1 = require("javascript-stringify");
11
+ const stringify_config_1 = __importDefault(require("../helper/stringify-config"));
12
+ function generateDebugReport(context) {
13
+ const report = `
14
+ ## Case Meta
15
+
16
+ ${generateCaseMetaPathReport(context)}
17
+
18
+ ${generateCaseMetaTestConfigReport(context)}
19
+
20
+ ## Compiler Options
21
+
22
+ ${generateReadConfigFileReport(context)}
23
+
24
+ ${generateFinalOptionsReport(context)}
25
+
26
+ ## Create Compiler
27
+
28
+ ${generateCreateCompilerInstanceReport(context)}
29
+
30
+ ${generateCreateCompilerSetPropertiesReport(context)}
31
+
32
+ ## Build
33
+
34
+ ${generateBuildMethodReport(context)}
35
+
36
+ ${generateBuildErrorReport(context)}
37
+
38
+ ${generateBuildWarningReport(context)}
39
+
40
+ ## Run
41
+
42
+ ${generateRunFindBundleReport(context)}
43
+
44
+ ${generateRunGetRunnerReport(context)}
45
+
46
+ ${generateRunLogsReport(context)}
47
+
48
+ ${generateRunErrorsReport(context)}
49
+
50
+ `;
51
+ const dist = context.getDist("debug.md");
52
+ fs_extra_1.default.ensureDirSync(node_path_1.default.dirname(dist));
53
+ fs_extra_1.default.writeFileSync(dist, report);
54
+ }
55
+ function generateCaseMetaPathReport(context) {
56
+ return `
57
+ ### Case Path
58
+
59
+ - Source: ${context.getSource()}
60
+ - Dist: ${context.getDist()}
61
+ - Temp: ${context.getTemp()}
62
+ `;
63
+ }
64
+ function generateCaseMetaTestConfigReport(context) {
65
+ return `
66
+ ### Test Config
67
+
68
+ \`\`\`js
69
+ // ${node_path_1.default.resolve(context.getSource(), "./test.config.js")}
70
+ ${(0, javascript_stringify_1.stringify)(context.getTestConfig(), null, 2)}
71
+ \`\`\`
72
+ `;
73
+ }
74
+ function generateReadConfigFileReport(context) {
75
+ const configFileInfo = context.getValue(exports.DEBUG_SCOPES.CompilerOptionsReadConfigFile);
76
+ if (!configFileInfo)
77
+ return "";
78
+ return `
79
+ ### Read Config File
80
+
81
+ \`\`\`js
82
+ // ${configFileInfo.file}
83
+ ${(0, stringify_config_1.default)(configFileInfo.config)}
84
+ \`\`\`
85
+ `;
86
+ }
87
+ function generateFinalOptionsReport(context) {
88
+ const finalOptions = context.getCompiler().getOptions();
89
+ return `
90
+ ### Final Options
91
+
92
+ \`\`\`js
93
+ ${(0, stringify_config_1.default)(finalOptions)}
94
+ \`\`\`
95
+ `;
96
+ }
97
+ function generateCreateCompilerInstanceReport(context) {
98
+ const instanceInfo = context.getValue(exports.DEBUG_SCOPES.CreateCompilerInstance);
99
+ if (!instanceInfo)
100
+ return "";
101
+ return `
102
+ ### Create Compiler Instance
103
+
104
+ - Rspack Path: ${instanceInfo.path}
105
+ - Callback Mode: ${instanceInfo.mode}
106
+ `;
107
+ }
108
+ function generateCreateCompilerSetPropertiesReport(context) {
109
+ const setPropertiesInfo = context.getValue(exports.DEBUG_SCOPES.CreateCompilerSetProperties);
110
+ if (!setPropertiesInfo || setPropertiesInfo.length === 0)
111
+ return "";
112
+ return `
113
+ ### Set Properties
114
+
115
+ ${setPropertiesInfo.map(p => `- ${p}`).join("\n")}
116
+ `;
117
+ }
118
+ function generateBuildMethodReport(context) {
119
+ const buildMethod = context.getValue(exports.DEBUG_SCOPES.BuildMethod);
120
+ if (!buildMethod)
121
+ return "";
122
+ return `
123
+ ### Build Method
124
+
125
+ - Method: \`compiler.${buildMethod.method}()\`
126
+ ${buildMethod.options ? `- Options:\n\`\`\`js\n${(0, javascript_stringify_1.stringify)(buildMethod.options, null, 2)}\n\`\`\`` : ""}
127
+ `;
128
+ }
129
+ function generateBuildErrorReport(context) {
130
+ const buildError = context.getValue(exports.DEBUG_SCOPES.BuildError);
131
+ if (!buildError)
132
+ return "";
133
+ return `
134
+ ### Build Error
135
+
136
+ type: ${buildError.type}
137
+
138
+ ${buildError.errors.map(e => `\`\`\`\n// message:\n${e.message}\n// stack:\n${e.stack}\n\`\`\``).join("\n\n")}
139
+ `;
140
+ }
141
+ function generateBuildWarningReport(context) {
142
+ const buildWarning = context.getValue(exports.DEBUG_SCOPES.BuildWarning);
143
+ if (!buildWarning)
144
+ return "";
145
+ return `
146
+ ### Build Warning
147
+
148
+ ${buildWarning.map(w => `\`\`\`\n// message:\n${w.message}\n// stack:\n${w.stack}\n\`\`\``).join("\n\n")}
149
+ `;
150
+ }
151
+ function generateRunFindBundleReport(context) {
152
+ const runFindBundle = context.getValue(exports.DEBUG_SCOPES.RunFindBundle);
153
+ if (!runFindBundle)
154
+ return "";
155
+ return `
156
+ ### Find Bundle
157
+
158
+ ${runFindBundle.map(b => `- ${context.getDist(b)}`).join("\n")}
159
+ `;
160
+ }
161
+ function generateRunGetRunnerReport(context) {
162
+ const getRunnerInfo = context.getValue(exports.DEBUG_SCOPES.RunGetRunner);
163
+ if (!getRunnerInfo)
164
+ return "";
165
+ return `
166
+ ### Get Runner
167
+
168
+ ${Object.entries(getRunnerInfo)
169
+ .map(([file, info]) => `- ${file}: ${info.runnerKey} (Reused: ${info.reused}, Type: \`${info.runnerType}\`)`)
170
+ .join("\n")}
171
+ `;
172
+ }
173
+ function generateRunLogsReport(context) {
174
+ const runLogs = context.getValue(exports.DEBUG_SCOPES.RunLogs);
175
+ if (!runLogs)
176
+ return "";
177
+ return `
178
+ ### Run Logs
179
+
180
+ ${runLogs.map(l => `- ${l}`).join("\n")}
181
+ `;
182
+ }
183
+ function generateRunErrorsReport(context) {
184
+ const runErrors = context.getValue(exports.DEBUG_SCOPES.RunErrors);
185
+ if (!runErrors)
186
+ return "";
187
+ return `
188
+ ### Run Errors
189
+
190
+ ${runErrors.map(e => `\`\`\`\n// message:\n${e.message}\n// stack:\n${e.stack}\n\`\`\``).join("\n\n")}
191
+ `;
192
+ }
193
+ exports.DEBUG_SCOPES = {
194
+ CompilerOptionsReadConfigFile: "compiler-options:read-config-file",
195
+ CompilerOptionsFinalOptions: "compiler-options:final-options",
196
+ CreateCompilerInstance: "create-compiler:instance",
197
+ CreateCompilerSetProperties: "create-compiler:set-properties",
198
+ BuildMethod: "build:method",
199
+ BuildError: "build:error",
200
+ BuildWarning: "build:warning",
201
+ RunFindBundle: "run:find-bundle",
202
+ RunGetRunner: "run:get-runner",
203
+ RunLogs: "run:logs",
204
+ RunErrors: "run:errors"
205
+ };
@@ -10,6 +10,7 @@ export declare class Tester implements ITester {
10
10
  prepare(): Promise<void>;
11
11
  compile(): Promise<void>;
12
12
  check(env: ITestEnv): Promise<void>;
13
+ after(): Promise<void>;
13
14
  next(): boolean;
14
15
  resume(): Promise<void>;
15
16
  private runStepMethods;
@@ -1,20 +1,27 @@
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.Tester = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
4
8
  const context_1 = require("./context");
9
+ const debug_1 = require("./debug");
5
10
  class Tester {
6
11
  constructor(config) {
7
12
  this.config = config;
8
13
  this.steps = [];
9
14
  this.step = 0;
10
15
  this.total = 0;
11
- this.context = new context_1.TestContext(config);
16
+ this.context = config.createContext
17
+ ? config.createContext(config)
18
+ : new context_1.TestContext(config);
12
19
  this.steps = config.steps || [];
13
20
  this.step = 0;
14
21
  this.total = config.steps?.length || 0;
15
22
  if (config.contextValue) {
16
23
  for (const [key, value] of Array.from(Object.entries(config.contextValue))) {
17
- this.context.setValue(config.name, key, value);
24
+ this.context.setValue(key, value);
18
25
  }
19
26
  }
20
27
  }
@@ -22,6 +29,11 @@ class Tester {
22
29
  return this.context;
23
30
  }
24
31
  async prepare() {
32
+ fs_extra_1.default.mkdirSync(this.context.getDist(), { recursive: true });
33
+ const tempDir = this.context.getTemp();
34
+ if (tempDir) {
35
+ fs_extra_1.default.mkdirSync(tempDir, { recursive: true });
36
+ }
25
37
  for (const i of this.steps) {
26
38
  if (typeof i.beforeAll === "function") {
27
39
  await i.beforeAll(this.context);
@@ -44,6 +56,11 @@ class Tester {
44
56
  if (!currentStep)
45
57
  return;
46
58
  await this.runCheckStepMethods(currentStep, env, this.context.hasError() ? ["check"] : ["run", "check"]);
59
+ }
60
+ async after() {
61
+ const currentStep = this.steps[this.step];
62
+ if (!currentStep)
63
+ return;
47
64
  await this.runStepMethods(currentStep, ["after"], true);
48
65
  }
49
66
  next() {
@@ -62,6 +79,20 @@ class Tester {
62
79
  await i.afterAll(this.context);
63
80
  }
64
81
  }
82
+ try {
83
+ await this.context.closeCompiler();
84
+ }
85
+ catch (e) {
86
+ console.warn(`Error occured while closing compilers of '${this.config.name}':\n${e.stack}`);
87
+ }
88
+ if (__DEBUG__) {
89
+ try {
90
+ (0, debug_1.generateDebugReport)(this.context);
91
+ }
92
+ catch (e) {
93
+ console.warn(`Generate debug report failed: ${e.message}`);
94
+ }
95
+ }
65
96
  }
66
97
  async runStepMethods(step, methods, force = false) {
67
98
  for (const i of methods) {
@@ -72,17 +103,24 @@ class Tester {
72
103
  await step[i](this.context);
73
104
  }
74
105
  catch (e) {
75
- this.context.emitError(this.config.name, e);
106
+ this.context.emitError(e);
76
107
  }
77
108
  }
78
109
  }
79
110
  }
80
111
  async runCheckStepMethods(step, env, methods) {
81
- for (const i of methods) {
82
- if (typeof step[i] === "function") {
83
- await step[i](env, this.context);
112
+ try {
113
+ for (const i of methods) {
114
+ if (typeof step[i] === "function") {
115
+ await step[i](env, this.context);
116
+ }
84
117
  }
85
118
  }
119
+ catch (e) {
120
+ const errors = this.context.getError();
121
+ console.error(new Error([...errors, e].map(e => e.message).join("\n")));
122
+ throw e;
123
+ }
86
124
  }
87
125
  }
88
126
  exports.Tester = Tester;