@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,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebpackDiffConfigPlugin = void 0;
4
- const webpack_module_placeholder_plugin_1 = require("./webpack-module-placeholder-plugin");
5
- const PLUGIN_NAME = "WebpackDiffConfigPlugin";
6
- class WebpackDiffConfigPlugin {
7
- constructor(modifier) {
8
- this.modifier = modifier;
9
- this.name = PLUGIN_NAME;
10
- }
11
- apply(compiler) {
12
- const { options } = compiler;
13
- options.mode = "development";
14
- options.devtool = false;
15
- options.optimization ??= {};
16
- options.optimization.minimize = false;
17
- options.optimization.chunkIds = "named";
18
- options.optimization.moduleIds = "named";
19
- options.optimization.mangleExports ??= false;
20
- options.optimization.concatenateModules ??= false;
21
- options.output ??= {};
22
- options.output.pathinfo ??= false;
23
- options.output.environment ??= {};
24
- options.output.environment.arrowFunction ??= false;
25
- options.output.environment.bigIntLiteral ??= false;
26
- options.output.environment.const ??= false;
27
- options.output.environment.destructuring ??= false;
28
- options.output.environment.dynamicImport ??= false;
29
- options.output.environment.dynamicImportInWorker ??= false;
30
- options.output.environment.forOf ??= false;
31
- options.output.environment.globalThis ??= false;
32
- options.output.environment.module ??= false;
33
- options.output.environment.optionalChaining ??= false;
34
- options.output.environment.templateLiteral ??= false;
35
- if (typeof this.modifier === "function") {
36
- this.modifier(compiler.options);
37
- }
38
- new webpack_module_placeholder_plugin_1.WebpackModulePlaceholderPlugin().apply(compiler);
39
- }
40
- }
41
- exports.WebpackDiffConfigPlugin = WebpackDiffConfigPlugin;
@@ -1,3 +0,0 @@
1
- export declare class WebpackModulePlaceholderPlugin {
2
- apply(compiler: any): void;
3
- }
@@ -1,106 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebpackModulePlaceholderPlugin = void 0;
4
- // @ts-nocheck
5
- const { ConcatSource, RawSource, CachedSource, PrefixSource } = require("webpack-sources");
6
- function createRenderRuntimeModulesFn(Template) {
7
- return function renderRuntimeModules(runtimeModules, renderContext) {
8
- const source = new ConcatSource();
9
- for (const module of runtimeModules) {
10
- const codeGenerationResults = renderContext.codeGenerationResults;
11
- let runtimeSource;
12
- if (codeGenerationResults) {
13
- runtimeSource = codeGenerationResults.getSource(module, renderContext.chunk.runtime, "runtime");
14
- }
15
- else {
16
- const codeGenResult = module.codeGeneration({
17
- chunkGraph: renderContext.chunkGraph,
18
- dependencyTemplates: renderContext.dependencyTemplates,
19
- moduleGraph: renderContext.moduleGraph,
20
- runtimeTemplate: renderContext.runtimeTemplate,
21
- runtime: renderContext.chunk.runtime,
22
- codeGenerationResults
23
- });
24
- if (!codeGenResult)
25
- continue;
26
- runtimeSource = codeGenResult.sources.get("runtime");
27
- }
28
- if (runtimeSource) {
29
- const identifier = module.identifier();
30
- source.add(`${Template.toNormalComment(`start::${identifier}`)}\n`);
31
- if (!module.shouldIsolate()) {
32
- source.add(runtimeSource);
33
- source.add("\n\n");
34
- }
35
- else if (renderContext.runtimeTemplate.supportsArrowFunction()) {
36
- source.add("(() => {\n");
37
- source.add(new PrefixSource("\t", runtimeSource));
38
- source.add("\n})();\n\n");
39
- }
40
- else {
41
- source.add("!function() {\n");
42
- source.add(new PrefixSource("\t", runtimeSource));
43
- source.add("\n}();\n\n");
44
- }
45
- source.add(`${Template.toNormalComment(`end::${identifier}`)}\n`);
46
- }
47
- }
48
- return source;
49
- };
50
- }
51
- const caches = new WeakMap();
52
- class WebpackModulePlaceholderPlugin {
53
- apply(compiler) {
54
- const { webpack } = compiler;
55
- const { Template, javascript: { JavascriptModulesPlugin } } = webpack;
56
- Template.renderRuntimeModules = createRenderRuntimeModulesFn(Template);
57
- compiler.hooks.compilation.tap("RuntimeDiffPlugin", compilation => {
58
- const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
59
- hooks.inlineInRuntimeBailout.tap("RuntimeDiffPlugin", () => "not allow inline startup");
60
- hooks.renderModulePackage.tap("RuntimeDiffPlugin", (moduleSource, module) => {
61
- let cacheEntry;
62
- let cache = caches.get(compilation);
63
- if (cache === undefined) {
64
- caches.set(compilation, (cache = new WeakMap()));
65
- cache.set(module, (cacheEntry = {
66
- header: undefined,
67
- footer: undefined,
68
- full: new WeakMap()
69
- }));
70
- }
71
- else {
72
- cacheEntry = cache.get(module);
73
- if (cacheEntry === undefined) {
74
- cache.set(module, (cacheEntry = {
75
- header: undefined,
76
- footer: undefined,
77
- full: new WeakMap()
78
- }));
79
- }
80
- else {
81
- const cachedSource = cacheEntry.full.get(moduleSource);
82
- if (cachedSource !== undefined)
83
- return cachedSource;
84
- }
85
- }
86
- const source = new ConcatSource();
87
- let header = cacheEntry.header;
88
- let footer = cacheEntry.footer;
89
- if (header === undefined) {
90
- const identifier = module.identifier();
91
- header = new RawSource(`\n${Template.toNormalComment(`start::${identifier}`)}\n`);
92
- footer = new RawSource(`\n${Template.toNormalComment(`end::${identifier}`)}\n`);
93
- cacheEntry.header = header;
94
- cacheEntry.footer = footer;
95
- }
96
- source.add(header);
97
- source.add(moduleSource);
98
- source.add(footer);
99
- const cachedSource = new CachedSource(source);
100
- cacheEntry.full.set(moduleSource, cachedSource);
101
- return cachedSource;
102
- });
103
- });
104
- }
105
- }
106
- exports.WebpackModulePlaceholderPlugin = WebpackModulePlaceholderPlugin;
@@ -1,24 +0,0 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, ITestProcessor, TCompilerOptions } from "../type";
2
- export interface IBasicProcessorOptions<T extends ECompilerType> {
3
- defaultOptions?: (context: ITestContext) => TCompilerOptions<T>;
4
- configFiles?: string[];
5
- overrideOptions?: (context: ITestContext, options: TCompilerOptions<T>) => void;
6
- findBundle?: (context: ITestContext, options: TCompilerOptions<T>) => string[] | string | void;
7
- compilerType: T;
8
- runable: boolean;
9
- name: string;
10
- }
11
- export declare class BasicProcessor<T extends ECompilerType> implements ITestProcessor {
12
- protected _options: IBasicProcessorOptions<T>;
13
- constructor(_options: IBasicProcessorOptions<T>);
14
- config(context: ITestContext): Promise<void>;
15
- compiler(context: ITestContext): Promise<void>;
16
- build(context: ITestContext): Promise<void>;
17
- run(env: ITestEnv, context: ITestContext): Promise<void>;
18
- check(env: ITestEnv, context: ITestContext): Promise<void>;
19
- before(context: ITestContext): Promise<void>;
20
- after(context: ITestContext): Promise<void>;
21
- beforeAll(context: ITestContext): Promise<void>;
22
- afterAll(context: ITestContext): Promise<void>;
23
- protected getCompiler(context: ITestContext): import("../type").ITestCompilerManager<T>;
24
- }
@@ -1,146 +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.BasicProcessor = void 0;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const helper_1 = require("../helper");
10
- const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
11
- class BasicProcessor {
12
- constructor(_options) {
13
- this._options = _options;
14
- }
15
- async config(context) {
16
- const compiler = this.getCompiler(context);
17
- if (typeof this._options.defaultOptions === "function") {
18
- compiler.setOptions(this._options.defaultOptions.apply(this, [context]));
19
- }
20
- if (Array.isArray(this._options.configFiles)) {
21
- const fileOptions = (0, helper_1.readConfigFile)(this._options.configFiles.map(i => context.getSource(i)))[0];
22
- compiler.mergeOptions(fileOptions);
23
- }
24
- if (typeof this._options.overrideOptions === "function") {
25
- const compilerOptions = compiler.getOptions();
26
- this._options.overrideOptions.apply(this, [context, compilerOptions]);
27
- }
28
- }
29
- async compiler(context) {
30
- const compiler = this.getCompiler(context);
31
- compiler.createCompiler();
32
- }
33
- async build(context) {
34
- const compiler = this.getCompiler(context);
35
- await compiler.build();
36
- }
37
- async run(env, context) {
38
- if (!this._options.runable)
39
- return;
40
- const testConfig = context.getTestConfig();
41
- if (testConfig.noTest)
42
- return;
43
- if (testConfig.documentType) {
44
- context.setValue(this._options.name, "documentType", testConfig.documentType);
45
- }
46
- if (typeof testConfig.beforeExecute === "function") {
47
- testConfig.beforeExecute();
48
- }
49
- const compiler = this.getCompiler(context);
50
- let bundles;
51
- if (testConfig.bundlePath) {
52
- bundles = testConfig.bundlePath;
53
- }
54
- else if (typeof this._options.findBundle === "function") {
55
- bundles = this._options.findBundle.apply(this, [
56
- context,
57
- compiler.getOptions()
58
- ]);
59
- }
60
- else {
61
- bundles = [];
62
- }
63
- if (typeof bundles === "string") {
64
- bundles = [bundles];
65
- }
66
- if (!bundles || !bundles.length) {
67
- return;
68
- }
69
- for (const bundle of bundles) {
70
- if (!bundle) {
71
- continue;
72
- }
73
- const runnerFactory = context.getRunnerFactory(this._options.name);
74
- if (!runnerFactory) {
75
- throw new Error(`Test case ${this._options.name} is not runable`);
76
- }
77
- const runner = runnerFactory.create(bundle, compiler.getOptions(), env);
78
- const mod = runner.run(bundle);
79
- const result = context.getValue(this._options.name, "modules") || [];
80
- result.push(mod);
81
- context.setValue(this._options.name, "modules", result);
82
- }
83
- const results = context.getValue(this._options.name, "modules") || [];
84
- await Promise.all(results);
85
- if (typeof testConfig.afterExecute === "function") {
86
- testConfig.afterExecute();
87
- }
88
- }
89
- async check(env, context) {
90
- const testConfig = context.getTestConfig();
91
- if (testConfig.noTest)
92
- return;
93
- const errors = (context.getError(this._options.name) || []).map(e => ({
94
- message: e.message,
95
- stack: e.stack
96
- }));
97
- const warnings = [];
98
- const compiler = this.getCompiler(context);
99
- const stats = compiler.getStats();
100
- if (stats) {
101
- if (testConfig.writeStatsOuptut) {
102
- node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
103
- preset: "verbose",
104
- colors: false
105
- }), "utf-8");
106
- }
107
- if (testConfig.writeStatsJson) {
108
- const jsonStats = stats.toJson({
109
- errorDetails: true
110
- });
111
- node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.json"), JSON.stringify(jsonStats, null, 2), "utf-8");
112
- }
113
- if (node_fs_1.default.existsSync(context.getSource("errors.js")) ||
114
- node_fs_1.default.existsSync(context.getSource("warnings.js")) ||
115
- stats.hasErrors() ||
116
- stats.hasWarnings()) {
117
- const statsJson = stats.toJson({
118
- errorDetails: true
119
- });
120
- if (statsJson.errors) {
121
- errors.push(...statsJson.errors);
122
- }
123
- if (statsJson.warnings) {
124
- warnings.push(...statsJson.warnings);
125
- }
126
- }
127
- }
128
- await (0, checkArrayExpectation_1.default)(context.getSource(), { errors }, "error", "errors", "Error");
129
- await (0, checkArrayExpectation_1.default)(context.getSource(), { warnings }, "warning", "warnings", "Warning");
130
- // clear error if checked
131
- if (node_fs_1.default.existsSync(context.getSource("errors.js"))) {
132
- context.clearError(this._options.name);
133
- }
134
- }
135
- async before(context) { }
136
- async after(context) { }
137
- async beforeAll(context) { }
138
- async afterAll(context) {
139
- const compiler = this.getCompiler(context);
140
- await compiler.close();
141
- }
142
- getCompiler(context) {
143
- return context.getCompiler(this._options.name, this._options.compilerType);
144
- }
145
- }
146
- exports.BasicProcessor = BasicProcessor;
@@ -1,9 +0,0 @@
1
- import { ECompilerType, type ITestContext, type TCompilerOptions } from "../type";
2
- import { type ISnapshotProcessorOptions, SnapshotProcessor } from "./snapshot";
3
- export interface IBuiltinProcessorOptions<T extends ECompilerType> extends Omit<ISnapshotProcessorOptions<T>, "runable"> {
4
- }
5
- export declare class BuiltinProcessor<T extends ECompilerType> extends SnapshotProcessor<T> {
6
- protected _builtinOptions: IBuiltinProcessorOptions<T>;
7
- constructor(_builtinOptions: IBuiltinProcessorOptions<T>);
8
- static defaultOptions<T extends ECompilerType>(this: BuiltinProcessor<T>, context: ITestContext): TCompilerOptions<T>;
9
- }
@@ -1,171 +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.BuiltinProcessor = void 0;
7
- const core_1 = require("@rspack/core");
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const webpack_merge_1 = require("webpack-merge");
10
- const type_1 = require("../type");
11
- const snapshot_1 = require("./snapshot");
12
- class BuiltinProcessor extends snapshot_1.SnapshotProcessor {
13
- constructor(_builtinOptions) {
14
- super({
15
- defaultOptions: BuiltinProcessor.defaultOptions,
16
- runable: false,
17
- ..._builtinOptions
18
- });
19
- this._builtinOptions = _builtinOptions;
20
- }
21
- static defaultOptions(context) {
22
- let defaultOptions = {
23
- entry: {
24
- main: {
25
- import: "./index"
26
- }
27
- },
28
- output: {
29
- publicPath: "/",
30
- path: context.getDist(),
31
- filename: "[name].js",
32
- chunkFilename: "[name].js",
33
- chunkFormat: "array-push",
34
- cssFilename: "[name].css",
35
- cssChunkFilename: "[name].css",
36
- assetModuleFilename: "[hash][ext][query]",
37
- sourceMapFilename: "[file].map",
38
- chunkLoadingGlobal: "webpackChunkwebpack",
39
- chunkLoading: "jsonp",
40
- uniqueName: "__rspack_test__",
41
- enabledLibraryTypes: ["system"],
42
- strictModuleErrorHandling: false,
43
- iife: true,
44
- module: false,
45
- asyncChunks: true,
46
- scriptType: false,
47
- globalObject: "self",
48
- importFunctionName: "import",
49
- wasmLoading: "fetch",
50
- webassemblyModuleFilename: "[hash].module.wasm",
51
- workerChunkLoading: "import-scripts",
52
- workerWasmLoading: "fetch"
53
- },
54
- module: {
55
- rules: [
56
- {
57
- test: /\.json$/,
58
- type: "json"
59
- },
60
- {
61
- test: /\.mjs$/,
62
- type: "javascript/esm"
63
- },
64
- {
65
- test: /\.cjs$/,
66
- type: "javascript/dynamic"
67
- },
68
- {
69
- test: /\.js$/,
70
- type: "javascript/auto"
71
- },
72
- {
73
- test: /\.css$/,
74
- type: "css"
75
- },
76
- {
77
- test: /\.wasm$/,
78
- type: "webassembly/async"
79
- }
80
- ]
81
- },
82
- node: {
83
- __dirname: "mock",
84
- __filename: "mock",
85
- global: "warn"
86
- },
87
- optimization: {
88
- runtimeChunk: {
89
- name: "runtime"
90
- },
91
- minimize: false,
92
- removeAvailableModules: true,
93
- removeEmptyChunks: true,
94
- moduleIds: "named",
95
- chunkIds: "named",
96
- sideEffects: false,
97
- mangleExports: false,
98
- usedExports: false,
99
- concatenateModules: false,
100
- nodeEnv: false
101
- },
102
- resolve: {
103
- extensions: [
104
- ".js",
105
- ".jsx",
106
- ".ts",
107
- ".tsx",
108
- ".json",
109
- ".d.ts",
110
- ".css",
111
- ".wasm"
112
- ]
113
- },
114
- resolveLoader: {
115
- extensions: [".js"]
116
- },
117
- experiments: {
118
- css: true,
119
- futureDefaults: true,
120
- rspackFuture: {
121
- bundlerInfo: {
122
- force: false
123
- }
124
- }
125
- },
126
- devtool: false,
127
- context: context.getSource(),
128
- plugins: []
129
- };
130
- if (this._options.compilerType === type_1.ECompilerType.Rspack) {
131
- let rspackDefaultOptions = defaultOptions;
132
- const testConfigFile = context.getSource("rspack.config.js");
133
- if (fs_extra_1.default.existsSync(testConfigFile)) {
134
- const caseOptions = require(testConfigFile);
135
- if (caseOptions.entry) {
136
- delete rspackDefaultOptions.entry;
137
- }
138
- rspackDefaultOptions = (0, webpack_merge_1.merge)(rspackDefaultOptions, caseOptions);
139
- }
140
- // TODO: remove builtin compatible code
141
- const defineOptions = rspackDefaultOptions.builtins?.define;
142
- if (defineOptions) {
143
- rspackDefaultOptions.plugins.push(new core_1.rspack.DefinePlugin(defineOptions));
144
- }
145
- const provideOptions = rspackDefaultOptions.builtins?.provide;
146
- if (provideOptions) {
147
- rspackDefaultOptions.plugins.push(new core_1.rspack.ProvidePlugin(provideOptions));
148
- }
149
- const htmlOptions = rspackDefaultOptions.builtins?.html;
150
- if (htmlOptions) {
151
- if (Array.isArray(htmlOptions)) {
152
- for (const item of htmlOptions) {
153
- rspackDefaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(item));
154
- }
155
- }
156
- else {
157
- rspackDefaultOptions.plugins.push(new core_1.rspack.HtmlRspackPlugin(htmlOptions));
158
- }
159
- }
160
- delete rspackDefaultOptions.builtins;
161
- defaultOptions = rspackDefaultOptions;
162
- }
163
- if (!global.printLogger) {
164
- defaultOptions.infrastructureLogging = {
165
- level: "error"
166
- };
167
- }
168
- return defaultOptions;
169
- }
170
- }
171
- exports.BuiltinProcessor = BuiltinProcessor;
@@ -1,20 +0,0 @@
1
- import { HotUpdatePlugin } from "../helper/hot-update";
2
- import { ECompilerType, type ITestContext, type ITestEnv, type ITestRunner, type TCompilerOptions } from "../type";
3
- import { BasicProcessor, type IBasicProcessorOptions } from "./basic";
4
- export interface ICacheProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
5
- target: TCompilerOptions<T>["target"];
6
- tempDir: string;
7
- sourceDir: string;
8
- }
9
- export declare class CacheProcessor<T extends ECompilerType> extends BasicProcessor<T> {
10
- protected _cacheOptions: ICacheProcessorOptions<T>;
11
- protected updatePlugin: HotUpdatePlugin;
12
- protected runner: ITestRunner | null;
13
- constructor(_cacheOptions: ICacheProcessorOptions<T>);
14
- config(context: ITestContext): Promise<void>;
15
- run(env: ITestEnv, context: ITestContext): Promise<void>;
16
- static findBundle<T extends ECompilerType>(this: CacheProcessor<T>, context: ITestContext): string[];
17
- afterAll(context: ITestContext): Promise<void>;
18
- static defaultOptions<T extends ECompilerType>(this: CacheProcessor<T>, context: ITestContext): TCompilerOptions<T>;
19
- static overrideOptions<T extends ECompilerType>(this: CacheProcessor<T>, context: ITestContext, options: TCompilerOptions<T>): void;
20
- }
@@ -1,128 +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.CacheProcessor = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const core_1 = require("@rspack/core");
9
- const hot_update_1 = require("../helper/hot-update");
10
- const type_1 = require("../type");
11
- const basic_1 = require("./basic");
12
- class CacheProcessor extends basic_1.BasicProcessor {
13
- constructor(_cacheOptions) {
14
- super({
15
- defaultOptions: CacheProcessor.defaultOptions,
16
- overrideOptions: CacheProcessor.overrideOptions,
17
- findBundle: CacheProcessor.findBundle,
18
- runable: true,
19
- ..._cacheOptions
20
- });
21
- this._cacheOptions = _cacheOptions;
22
- this.runner = null;
23
- this.updatePlugin = new hot_update_1.HotUpdatePlugin(_cacheOptions.sourceDir, _cacheOptions.tempDir);
24
- }
25
- async config(context) {
26
- await this.updatePlugin.initialize();
27
- this._options.configFiles = this._options.configFiles?.map(item => {
28
- return node_path_1.default.resolve(this._cacheOptions.tempDir, item);
29
- });
30
- super.config(context);
31
- }
32
- async run(env, context) {
33
- context.setValue(this._options.name, "hotUpdateContext", this.updatePlugin);
34
- await super.run(env, context);
35
- }
36
- static findBundle(context) {
37
- const files = [];
38
- const prefiles = [];
39
- const compiler = context.getCompiler(this._cacheOptions.name);
40
- if (!compiler)
41
- throw new Error("Compiler should exists when find bundle");
42
- const stats = compiler.getStats();
43
- if (!stats)
44
- throw new Error("Stats should exists when find bundle");
45
- const info = stats.toJson({ all: false, entrypoints: true });
46
- if (this._cacheOptions.target === "web" ||
47
- this._cacheOptions.target === "webworker") {
48
- for (const file of info.entrypoints.main.assets) {
49
- if (file.name.endsWith(".js")) {
50
- files.push(file.name);
51
- }
52
- else {
53
- prefiles.push(file.name);
54
- }
55
- }
56
- }
57
- else {
58
- const assets = info.entrypoints.main.assets.filter(s => s.name.endsWith(".js"));
59
- files.push(assets[assets.length - 1].name);
60
- }
61
- return [...prefiles, ...files];
62
- }
63
- async afterAll(context) {
64
- await super.afterAll(context);
65
- const updateIndex = this.updatePlugin.getUpdateIndex();
66
- const totalUpdates = this.updatePlugin.getTotalUpdates();
67
- if (updateIndex + 1 !== totalUpdates) {
68
- throw new Error(`Should run all hot steps (${updateIndex + 1} / ${totalUpdates}): ${this._options.name}`);
69
- }
70
- }
71
- static defaultOptions(context) {
72
- const options = {
73
- context: this._cacheOptions.tempDir,
74
- mode: "production",
75
- cache: true,
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
- emitOnErrors: true
87
- },
88
- target: this._cacheOptions.target,
89
- experiments: {
90
- css: true,
91
- rspackFuture: {
92
- bundlerInfo: {
93
- force: false
94
- }
95
- }
96
- }
97
- };
98
- if (this._cacheOptions.compilerType === type_1.ECompilerType.Rspack) {
99
- options.plugins ??= [];
100
- options.plugins.push(new core_1.rspack.HotModuleReplacementPlugin());
101
- }
102
- return options;
103
- }
104
- static overrideOptions(context, options) {
105
- if (!options.entry) {
106
- options.entry = "./index.js";
107
- }
108
- // rewrite context to temp dir
109
- options.context = this._cacheOptions.tempDir;
110
- options.module ??= {};
111
- for (const cssModuleType of ["css/auto", "css/module", "css"]) {
112
- options.module.generator ??= {};
113
- options.module.generator[cssModuleType] ??= {};
114
- options.module.generator[cssModuleType].exportsOnly ??=
115
- this._cacheOptions.target === "async-node";
116
- }
117
- if (this._cacheOptions.compilerType === type_1.ECompilerType.Rspack) {
118
- options.plugins ??= [];
119
- options.plugins.push(this.updatePlugin);
120
- }
121
- if (!global.printLogger) {
122
- options.infrastructureLogging = {
123
- level: "error"
124
- };
125
- }
126
- }
127
- }
128
- exports.CacheProcessor = CacheProcessor;
@@ -1,11 +0,0 @@
1
- import type { ECompilerType, ITestContext, TCompilerOptions } from "../type";
2
- import { type IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";
3
- export interface IConfigProcessorOptions<T extends ECompilerType> extends IMultiTaskProcessorOptions<T> {
4
- }
5
- export declare class ConfigProcessor<T extends ECompilerType> extends MultiTaskProcessor<T> {
6
- protected _configOptions: IConfigProcessorOptions<T>;
7
- constructor(_configOptions: IConfigProcessorOptions<T>);
8
- static findBundle<T extends ECompilerType>(index: number, context: ITestContext, options: TCompilerOptions<T>): string | string[];
9
- static defaultOptions<T extends ECompilerType>(index: number, context: ITestContext): TCompilerOptions<T>;
10
- static overrideOptions<T extends ECompilerType>(index: number, context: ITestContext, options: TCompilerOptions<T>): void;
11
- }