@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
package/dist/type.d.ts CHANGED
@@ -1,42 +1,30 @@
1
1
  import type EventEmitter from "node:events";
2
- import type { Compiler as RspackCompiler, MultiStats as RspackMultiStats, RspackOptions, Stats as RspackStats, StatsCompilation as RspackStatsCompilation } from "@rspack/core";
3
- import type { Compiler as WebpackCompiler, MultiStats as WebpackMultiStats, Configuration as WebpackOptions, Stats as WebpackStats, StatsCompilation as WebpackStatsCompilation } from "webpack";
4
- import type { IBasicModuleScope, TRunnerRequirer } from "./runner/type";
2
+ import type { Compiler, MultiStats, RspackOptions, Stats, StatsCompilation } from "@rspack/core";
5
3
  export interface ITestContext {
6
4
  getSource(sub?: string): string;
7
5
  getDist(sub?: string): string;
8
6
  getTemp(sub?: string): string | null;
9
- getCompiler<T extends ECompilerType>(name: string, type: T | void): ITestCompilerManager<T>;
10
- getTestConfig<T extends ECompilerType>(): TTestConfig<T>;
11
- getRunnerFactory<T extends ECompilerType>(name: string): TRunnerFactory<T> | null;
12
- getRunner(key: string): ITestRunner | null;
13
- setRunner(key: string, runner: ITestRunner): void;
14
- setValue<T>(name: string, key: string, value: T): void;
15
- getValue<T>(name: string, key: string): T | void;
16
- getNames(): string[];
17
- hasError(name?: string): boolean;
18
- emitError(name: string, err: Error | string): void;
19
- getError(name?: string): Error[];
20
- clearError(name?: string): void;
7
+ getCompiler(): ITestCompilerManager;
8
+ closeCompiler(): Promise<void>;
9
+ getTestConfig(): TTestConfig;
10
+ getRunner(file: string, env: ITestEnv): ITestRunner;
11
+ setValue<T>(key: string, value: T): void;
12
+ getValue<T>(key: string): T | void;
13
+ hasError(): boolean;
14
+ emitError(err: Error | string): void;
15
+ getError(): Error[];
16
+ clearError(): void;
21
17
  }
22
- export declare enum ECompilerType {
23
- Rspack = "rspack",
24
- Webpack = "webpack"
25
- }
26
- export type TCompilerOptions<T> = T extends ECompilerType.Rspack ? RspackOptions : WebpackOptions;
27
- export type TCompiler<T> = T extends ECompilerType.Rspack ? RspackCompiler : WebpackCompiler;
28
- export type TCompilerStats<T> = T extends ECompilerType.Rspack ? RspackStats : WebpackStats;
29
- export type TCompilerMultiStats<T> = T extends ECompilerType.Rspack ? RspackMultiStats : WebpackMultiStats;
30
- export type TCompilerStatsCompilation<T> = T extends ECompilerType.Rspack ? RspackStatsCompilation : WebpackStatsCompilation;
31
- export interface ITestCompilerManager<T extends ECompilerType> {
32
- getOptions(): TCompilerOptions<T>;
33
- setOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
34
- mergeOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
35
- getCompiler(): TCompiler<T> | null;
36
- createCompiler(): TCompiler<T>;
37
- build(): Promise<TCompilerStats<T>>;
18
+ export interface ITestCompilerManager {
19
+ getOptions(): RspackOptions;
20
+ setOptions(newOptions: RspackOptions): RspackOptions;
21
+ mergeOptions(newOptions: RspackOptions): RspackOptions;
22
+ getCompiler(): Compiler | null;
23
+ createCompiler(): Compiler;
24
+ createCompilerWithCallback(callback: (error: Error | null, stats: Stats | null) => void): Compiler;
25
+ build(): Promise<Stats>;
38
26
  watch(timeout?: number): void;
39
- getStats(): TCompilerStats<T> | TCompilerMultiStats<T> | null;
27
+ getStats(): Stats | MultiStats | null;
40
28
  getEmitter(): EventEmitter;
41
29
  close(): Promise<void>;
42
30
  }
@@ -50,10 +38,10 @@ export interface ITesterConfig {
50
38
  dist: string;
51
39
  temp?: string;
52
40
  steps?: ITestProcessor[];
53
- testConfig?: TTestConfig<ECompilerType>;
54
- compilerFactories?: TCompilerFactories;
41
+ testConfig?: TTestConfig;
55
42
  contextValue?: Record<string, unknown>;
56
- runnerFactory?: new (name: string, context: ITestContext) => TRunnerFactory<ECompilerType>;
43
+ runnerCreator?: TTestRunnerCreator;
44
+ createContext?: (config: ITesterConfig) => ITestContext;
57
45
  }
58
46
  export interface ITester {
59
47
  step: number;
@@ -62,6 +50,7 @@ export interface ITester {
62
50
  prepare(): Promise<void>;
63
51
  compile(): Promise<void>;
64
52
  check(env: ITestEnv): Promise<void>;
53
+ after(): Promise<void>;
65
54
  next(): boolean;
66
55
  resume(): Promise<void>;
67
56
  }
@@ -70,15 +59,15 @@ export interface ITestProcessor {
70
59
  afterAll?(context: ITestContext): Promise<void>;
71
60
  before?(context: ITestContext): Promise<void>;
72
61
  after?(context: ITestContext): Promise<void>;
73
- config?(context: ITestContext): Promise<void>;
74
- compiler?(context: ITestContext): Promise<void>;
75
- build?(context: ITestContext): Promise<void>;
76
- run?(env: ITestEnv, context: ITestContext): Promise<void>;
77
- check?(env: ITestEnv, context: ITestContext): Promise<unknown>;
62
+ config(context: ITestContext): Promise<void>;
63
+ compiler(context: ITestContext): Promise<void>;
64
+ build(context: ITestContext): Promise<void>;
65
+ run(env: ITestEnv, context: ITestContext): Promise<void>;
66
+ check(env: ITestEnv, context: ITestContext): Promise<unknown>;
78
67
  }
79
- export interface ITestReporter<T> {
80
- init(data?: T): Promise<void>;
81
- increment(id: string, data: T): Promise<void>;
68
+ export interface ITestReporter {
69
+ init<T>(data?: T): Promise<void>;
70
+ increment<T>(id: string, data: T): Promise<void>;
82
71
  failure(id: string): Promise<void>;
83
72
  output(): Promise<void>;
84
73
  }
@@ -119,30 +108,26 @@ export type TDiffStatsItem = {
119
108
  };
120
109
  export type TDiffStats = {
121
110
  root: string;
122
- data: Array<TDiffStatsItem>;
111
+ data: TDiffStatsItem[];
123
112
  };
124
113
  export interface ITestEnv {
125
- expect: jest.Expect;
114
+ expect: Expect;
126
115
  it: (...args: any[]) => void;
127
116
  beforeEach: (...args: any[]) => void;
128
117
  afterEach: (...args: any[]) => void;
129
118
  [key: string]: unknown;
130
119
  }
131
- export declare enum EDocumentType {
132
- Fake = "fake",
133
- JSDOM = "jsdom"
134
- }
135
- export type TTestConfig<T extends ECompilerType> = {
136
- documentType?: EDocumentType;
137
- validate?: (stats: TCompilerStats<T> | TCompilerMultiStats<T>, stderr?: string) => void;
138
- noTest?: boolean;
120
+ export type TTestConfig = {
121
+ location?: string;
122
+ validate?: (stats: Stats | MultiStats, stderr?: string) => void;
123
+ noTests?: boolean;
139
124
  writeStatsOuptut?: boolean;
140
125
  writeStatsJson?: boolean;
141
- beforeExecute?: () => void;
142
- afterExecute?: () => void;
143
- moduleScope?: (ms: IBasicModuleScope, stats?: TCompilerStatsCompilation<T>) => IBasicModuleScope;
144
- checkStats?: (stepName: string, jsonStats: TCompilerStatsCompilation<T> | undefined, stringStats: String) => boolean;
145
- findBundle?: (index: number, options: TCompilerOptions<T>, stepName?: string) => string | string[];
126
+ beforeExecute?: (options: RspackOptions) => void;
127
+ afterExecute?: (options: RspackOptions) => void;
128
+ moduleScope?: (ms: IModuleScope, stats?: StatsCompilation, options?: RspackOptions) => IModuleScope;
129
+ checkStats?: (stepName: string, jsonStats: StatsCompilation | undefined, stringStats: String) => boolean;
130
+ findBundle?: (index: number, options: RspackOptions, stepName?: string) => string | string[];
146
131
  bundlePath?: string[];
147
132
  nonEsmThis?: (p: string | string[]) => Object;
148
133
  modules?: Record<string, Object>;
@@ -150,20 +135,65 @@ export type TTestConfig<T extends ECompilerType> = {
150
135
  concurrent?: boolean;
151
136
  snapshotContent?(content: string): string;
152
137
  checkSteps?: boolean;
138
+ ignoreNotFriendlyForIncrementalWarnings?: boolean;
139
+ esmLibPluginOptions?: {
140
+ preserveModules?: string;
141
+ };
142
+ resourceLoader?: (url: string, element: HTMLScriptElement) => Buffer | null;
153
143
  };
154
- export type TTestFilter<T extends ECompilerType> = (creatorConfig: Record<string, unknown>, testConfig: TTestConfig<T>) => boolean | string;
144
+ export type TTestFilter = (creatorConfig: Record<string, unknown>, testConfig: TTestConfig) => boolean | string;
155
145
  export interface ITestRunner {
156
146
  run(file: string): Promise<unknown>;
157
147
  getRequire(): TRunnerRequirer;
158
148
  getGlobal(name: string): unknown;
159
149
  }
160
- export type TCompilerFactory<T extends ECompilerType> = (options: TCompilerOptions<T> | TCompilerOptions<T>[]) => TCompiler<T>;
161
- export interface TRunnerFactory<T extends ECompilerType> {
162
- create(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
150
+ export type TCompilerFactory = (options: RspackOptions | RspackOptions[], callback?: (error: Error | null, stats: Stats | null) => void) => Compiler;
151
+ export interface TRunnerFactory {
152
+ create(file: string, compilerOptions: RspackOptions, env: ITestEnv): ITestRunner;
163
153
  }
164
- export type TUpdateOptions = {
154
+ export type THotUpdateContext = {
165
155
  updateIndex: number;
166
156
  totalUpdates: number;
167
157
  changedFiles: string[];
168
158
  };
169
- export type TCompilerFactories = Record<ECompilerType, TCompilerFactory<ECompilerType>>;
159
+ export type TRunnerRequirer = (currentDirectory: string, modulePath: string[] | string, context?: {
160
+ file?: TRunnerFile;
161
+ esmMode?: EEsmMode;
162
+ }) => Object | Promise<Object>;
163
+ export type TRunnerFile = {
164
+ path: string;
165
+ content: string;
166
+ subPath: string;
167
+ };
168
+ export declare enum EEsmMode {
169
+ Unknown = 0,
170
+ Evaluated = 1,
171
+ Unlinked = 2
172
+ }
173
+ export interface IModuleScope extends ITestEnv {
174
+ console: Record<string, (...args: any[]) => void>;
175
+ expect: Expect;
176
+ [key: string]: any;
177
+ }
178
+ export interface IGlobalContext {
179
+ console: Record<string, (...args: any[]) => void>;
180
+ setTimeout: typeof setTimeout;
181
+ clearTimeout: typeof clearTimeout;
182
+ [key: string]: any;
183
+ }
184
+ export type TModuleObject = {
185
+ exports: unknown;
186
+ };
187
+ export type TTestRunnerCreator = {
188
+ key: (context: ITestContext, name: string, file: string) => string;
189
+ runner: (context: ITestContext, name: string, file: string, env: ITestEnv) => ITestRunner;
190
+ };
191
+ declare global {
192
+ var __DEBUG__: boolean;
193
+ var __TEST_PATH__: string;
194
+ var __TEST_FIXTURES_PATH__: string;
195
+ var __TEST_DIST_PATH__: string;
196
+ var __ROOT_PATH__: string;
197
+ var __RSPACK_PATH__: string;
198
+ var __RSPACK_TEST_TOOLS_PATH__: string;
199
+ }
package/dist/type.js CHANGED
@@ -1,12 +1,7 @@
1
1
  "use strict";
2
- /// <reference types="../jest.d.ts" />
2
+ /// <reference types="../rstest.d.ts" />
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.EDocumentType = exports.ECompareResultType = exports.ECompilerType = void 0;
5
- var ECompilerType;
6
- (function (ECompilerType) {
7
- ECompilerType["Rspack"] = "rspack";
8
- ECompilerType["Webpack"] = "webpack";
9
- })(ECompilerType || (exports.ECompilerType = ECompilerType = {}));
4
+ exports.EEsmMode = exports.ECompareResultType = void 0;
10
5
  var ECompareResultType;
11
6
  (function (ECompareResultType) {
12
7
  ECompareResultType["Same"] = "same";
@@ -15,8 +10,9 @@ var ECompareResultType;
15
10
  ECompareResultType["OnlySource"] = "only-source";
16
11
  ECompareResultType["Different"] = "different";
17
12
  })(ECompareResultType || (exports.ECompareResultType = ECompareResultType = {}));
18
- var EDocumentType;
19
- (function (EDocumentType) {
20
- EDocumentType["Fake"] = "fake";
21
- EDocumentType["JSDOM"] = "jsdom";
22
- })(EDocumentType || (exports.EDocumentType = EDocumentType = {}));
13
+ var EEsmMode;
14
+ (function (EEsmMode) {
15
+ EEsmMode[EEsmMode["Unknown"] = 0] = "Unknown";
16
+ EEsmMode[EEsmMode["Evaluated"] = 1] = "Evaluated";
17
+ EEsmMode[EEsmMode["Unlinked"] = 2] = "Unlinked";
18
+ })(EEsmMode || (exports.EEsmMode = EEsmMode = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack-debug/test-tools",
3
- "version": "1.4.11",
3
+ "version": "1.6.4",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -12,13 +12,16 @@
12
12
  "./setup-expect": "./dist/helper/setup-expect.js",
13
13
  "./setup-env": "./dist/helper/setup-env.js",
14
14
  "./setup-wasm": "./dist/helper/setup-wasm.js",
15
- "./package.json": "./package.json"
15
+ "./package.json": "./package.json",
16
+ "./helper/*": "./dist/helper/*.js",
17
+ "./helper/legacy/*": "./dist/helper/legacy/*.js",
18
+ "./helper/util/*": "./dist/helper/util/*.js"
16
19
  },
17
20
  "files": [
18
21
  "client",
19
22
  "dist",
20
23
  "template",
21
- "jest.d.ts"
24
+ "rstest.d.ts"
22
25
  ],
23
26
  "publishConfig": {
24
27
  "access": "public",
@@ -32,74 +35,37 @@
32
35
  "directory": "packages/rspack-test-tools"
33
36
  },
34
37
  "dependencies": {
35
- "@babel/generator": "7.28.0",
36
- "@babel/parser": "7.28.0",
37
- "@babel/traverse": "7.28.0",
38
- "@babel/types": "7.28.2",
39
- "cross-env": "^7.0.3",
40
- "csv-to-markdown-table": "^1.5.0",
41
- "deepmerge": "^4.3.1",
38
+ "@babel/generator": "7.28.5",
39
+ "@babel/parser": "7.28.5",
40
+ "@babel/traverse": "7.28.5",
41
+ "@babel/types": "7.28.5",
42
+ "cross-env": "^10.1.0",
42
43
  "filenamify": "4.3.0",
43
- "fs-extra": "^11.3.0",
44
- "glob": "^11.0.3",
45
- "graceful-fs": "^4.2.11",
46
- "iconv-lite": "^0.6.3",
44
+ "fs-extra": "^11.3.2",
45
+ "iconv-lite": "^0.7.0",
46
+ "javascript-stringify": "^2.1.0",
47
47
  "jest-diff": "^29.7.0",
48
48
  "jest-snapshot": "29.7.0",
49
49
  "jsdom": "^26.1.0",
50
- "memfs": "4.20.0",
51
- "loader-utils": "^2.0.4",
52
- "path-serializer": "0.5.0",
50
+ "memfs": "4.48.1",
51
+ "path-serializer": "0.5.1",
53
52
  "pretty-format": "29.7.0",
54
53
  "rimraf": "^5.0.10",
55
54
  "source-map": "^0.7.6",
56
55
  "terser-webpack-plugin": "^5.3.14",
57
- "webpack": "5.99.9",
56
+ "webpack": "5.102.1",
58
57
  "webpack-merge": "6.0.1",
59
- "webpack-sources": "3.3.3"
58
+ "webpack-sources": "3.3.3",
59
+ "chalk": "^4.1.2"
60
60
  },
61
61
  "devDependencies": {
62
- "@rspack/plugin-preact-refresh": "1.1.2",
63
- "@rspack/plugin-react-refresh": "^1.4.3",
64
- "@swc/helpers": "0.5.17",
65
- "@swc/plugin-remove-console": "^9.0.0",
66
62
  "@types/babel__generator": "7.27.0",
67
- "@types/babel__traverse": "7.20.7",
63
+ "@types/babel__traverse": "7.28.0",
68
64
  "@types/fs-extra": "11.0.4",
69
65
  "@types/jsdom": "^21.1.7",
70
- "@types/react": "^19.1.8",
71
- "@types/react-dom": "^19.1.6",
72
- "@webdiscus/pug-loader": "^2.11.1",
73
- "acorn": "^8.15.0",
74
- "babel-loader": "^10.0.0",
75
- "babel-plugin-import": "^1.13.8",
76
- "chalk": "^4.1.2",
77
- "core-js": "3.44.0",
78
- "css-loader": "^7.1.2",
79
- "file-loader": "^6.2.0",
80
- "graceful-fs": "^4.2.11",
81
- "html-loader": "^5.1.0",
82
- "html-webpack-plugin": "^5.6.3",
83
- "less-loader": "^12.3.0",
84
- "lodash": "^4.17.21",
85
- "postcss-loader": "^8.1.1",
86
- "postcss-pxtorem": "^6.1.0",
87
- "raw-loader": "^4.0.2",
88
- "react": "^19.1.0",
89
- "react-dom": "^19.1.0",
90
- "react-refresh": "^0.17.0",
91
- "sass-loader": "^16.0.5",
92
- "source-map": "^0.7.6",
93
- "source-map-loader": "^5.0.0",
94
- "style-loader": "^4.0.0",
95
- "terser": "5.43.1",
96
- "typescript": "^5.8.3",
66
+ "typescript": "^5.9.3",
97
67
  "wast-loader": "^1.14.1",
98
- "worker-rspack-loader": "^3.1.2",
99
- "@rspack/cli": "npm:@rspack-debug/cli@1.4.11",
100
- "@rspack/core": "npm:@rspack-debug/core@1.4.11",
101
- "@rspack/binding-testing": "1.4.1",
102
- "@rspack/test-tools": "npm:@rspack-debug/test-tools@1.4.11"
68
+ "@rspack/core": "npm:@rspack-debug/core@1.6.4"
103
69
  },
104
70
  "peerDependencies": {
105
71
  "@rspack/core": ">=1.0.0"
@@ -107,11 +73,6 @@
107
73
  "scripts": {
108
74
  "build": "tsc -b ./tsconfig.build.json",
109
75
  "dev": "tsc -b -w",
110
- "test": "cross-env RUST_BACKTRACE=full pnpm run --stream /^test:.*/",
111
- "testu": "pnpm run --stream /^test:.*/ -u",
112
- "test:base": "cross-env node --no-warnings --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --colors --config ./jest.config.js --passWithNoTests",
113
- "test:hot": "cross-env RSPACK_HOT_TEST=true node --no-warnings --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --colors --config ./jest.config.hot.js --passWithNoTests",
114
- "test:diff": "cross-env RSPACK_DIFF=true node --no-warnings --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --colors --config ./jest.config.diff.js --passWithNoTests",
115
76
  "api-extractor": "api-extractor run --verbose",
116
77
  "api-extractor:ci": "api-extractor run --verbose || diff temp/test-tools.api.md etc/test-tools.api.md"
117
78
  }
package/rstest.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ /// <reference types="@rstest/core/globals" />
2
+
3
+ import type { DiffOptions } from "jest-diff";
4
+
5
+ declare interface FileMatcherOptions {
6
+ diff?: DiffOptions;
7
+ }
8
+
9
+ declare module "@rstest/core" {
10
+ interface Assertion {
11
+ toMatchFileSnapshotSync: (
12
+ filename?: string,
13
+ options?: FileMatcherOptions
14
+ ) => void;
15
+ }
16
+ }
17
+
18
+ declare global {
19
+ type Expect = import("@rstest/core").Expect;
20
+ type Describe = import("@rstest/core").Describe;
21
+ type Assertion<T> = import("@rstest/core").Assertion<T>;
22
+ }
23
+
24
+ export {};
@@ -1,3 +0,0 @@
1
- import { type IDiffProcessorOptions } from "../processor";
2
- export type TDiffCaseConfig = IDiffProcessorOptions;
3
- export declare function createDiffCase(name: string, src: string, dist: string): void;
package/dist/case/diff.js DELETED
@@ -1,126 +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.createDiffCase = createDiffCase;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const rimraf_1 = require("rimraf");
10
- const createLazyTestEnv_1 = __importDefault(require("../helper/legacy/createLazyTestEnv"));
11
- const processor_1 = require("../processor");
12
- const tester_1 = require("../test/tester");
13
- const type_1 = require("../type");
14
- const DEFAULT_CASE_CONFIG = {
15
- webpackPath: require.resolve("webpack"),
16
- rspackPath: require.resolve("@rspack/core"),
17
- files: ["bundle.js"],
18
- bootstrap: true,
19
- detail: true,
20
- errors: false
21
- };
22
- function createDiffCase(name, src, dist) {
23
- const caseConfigFile = node_path_1.default.join(src, "test.config.js");
24
- if (!fs_extra_1.default.existsSync(caseConfigFile)) {
25
- return;
26
- }
27
- const caseConfig = Object.assign({}, DEFAULT_CASE_CONFIG, require(caseConfigFile));
28
- const [processor, compareMap] = createDiffProcessor(caseConfig);
29
- const tester = new tester_1.Tester({
30
- name,
31
- src,
32
- dist,
33
- steps: [processor]
34
- });
35
- (0, rimraf_1.rimrafSync)(dist);
36
- const prefix = node_path_1.default.basename(name);
37
- describe(`${prefix}:check`, () => {
38
- beforeAll(async () => {
39
- await tester.compile();
40
- compareMap.clear();
41
- await tester.check(env);
42
- });
43
- for (const file of caseConfig.files) {
44
- describe(`Comparing "${file}"`, () => {
45
- let moduleResults = [];
46
- let runtimeResults = [];
47
- beforeAll(() => {
48
- const fileResult = compareMap.get(file);
49
- if (!fileResult) {
50
- throw new Error(`File ${file} has no results`);
51
- }
52
- moduleResults = fileResult.modules;
53
- runtimeResults = fileResult.runtimeModules;
54
- });
55
- if (caseConfig.modules) {
56
- checkCompareResults("modules", () => moduleResults);
57
- }
58
- if (caseConfig.runtimeModules) {
59
- checkCompareResults("runtime modules", () => runtimeResults);
60
- }
61
- });
62
- }
63
- const env = (0, createLazyTestEnv_1.default)(1000);
64
- });
65
- }
66
- function createDiffProcessor(config) {
67
- const fileCompareMap = new Map();
68
- const createCompareResultHandler = (type) => {
69
- return (file, results) => {
70
- const fileResult = fileCompareMap.get(file) || {
71
- modules: [],
72
- runtimeModules: []
73
- };
74
- fileResult[type] = results;
75
- fileCompareMap.set(file, fileResult);
76
- };
77
- };
78
- const processor = new processor_1.DiffProcessor({
79
- webpackPath: config.webpackPath,
80
- rspackPath: config.rspackPath,
81
- files: config.files,
82
- modules: config.modules,
83
- runtimeModules: config.runtimeModules,
84
- renameModule: config.renameModule,
85
- ignoreModuleId: config.ignoreModuleId ?? true,
86
- ignoreModuleArguments: config.ignoreModuleArguments ?? true,
87
- ignorePropertyQuotationMark: config.ignorePropertyQuotationMark ?? true,
88
- ignoreBlockOnlyStatement: config.ignoreBlockOnlyStatement ?? true,
89
- ignoreIfCertainCondition: config.ignoreIfCertainCondition ?? true,
90
- ignoreSwcHelpersPath: config.ignoreSwcHelpersPath ?? true,
91
- ignoreObjectPropertySequence: config.ignoreObjectPropertySequence ?? true,
92
- ignoreCssFilePath: config.ignoreCssFilePath ?? true,
93
- onCompareModules: createCompareResultHandler("modules"),
94
- onCompareRuntimeModules: createCompareResultHandler("runtimeModules"),
95
- bootstrap: config.bootstrap ?? true,
96
- detail: config.detail ?? true,
97
- errors: config.errors ?? false,
98
- replacements: config.replacements
99
- });
100
- return [processor, fileCompareMap];
101
- }
102
- function checkCompareResults(name, getResults) {
103
- describe(`Comparing ${name}`, () => {
104
- it("should not miss any module", () => {
105
- expect(getResults()
106
- .filter(i => i.type === type_1.ECompareResultType.Missing)
107
- .map(i => i.name)).toEqual([]);
108
- });
109
- it("should not have any rspack-only module", () => {
110
- expect(getResults()
111
- .filter(i => i.type === type_1.ECompareResultType.OnlySource)
112
- .map(i => i.name)).toEqual([]);
113
- });
114
- it("should not have any webpack-only module", () => {
115
- expect(getResults()
116
- .filter(i => i.type === type_1.ECompareResultType.OnlyDist)
117
- .map(i => i.name)).toEqual([]);
118
- });
119
- it("all modules should be the same", () => {
120
- for (const result of getResults().filter(i => i.type === type_1.ECompareResultType.Different)) {
121
- console.log(`${result.name}:\n${result.detail}`);
122
- }
123
- expect(getResults().every(i => i.type === type_1.ECompareResultType.Same)).toEqual(true);
124
- });
125
- });
126
- }
@@ -1,17 +0,0 @@
1
- import type { ITestReporter, TCompareModules } from "../type";
2
- import type { IFormatCodeOptions } from "./format-code";
3
- export interface IDiffComparatorOptions {
4
- rspackDist: string;
5
- webpackDist: string;
6
- files: string[];
7
- modules?: TCompareModules;
8
- runtimeModules?: TCompareModules;
9
- reporters: ITestReporter<unknown>[];
10
- formatOptions?: IFormatCodeOptions;
11
- bootstrap?: boolean;
12
- }
13
- export declare class DiffComparator {
14
- private options;
15
- constructor(options: IDiffComparatorOptions);
16
- compare(): Promise<void>;
17
- }
@@ -1,52 +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.DiffComparator = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const deepmerge_1 = __importDefault(require("deepmerge"));
9
- const compare_1 = require("./compare");
10
- const replace_runtime_module_name_1 = require("./replace-runtime-module-name");
11
- class DiffComparator {
12
- constructor(options) {
13
- this.options = options;
14
- }
15
- async compare() {
16
- for (const file of this.options.files) {
17
- try {
18
- const result = (0, compare_1.compareFile)(node_path_1.default.join(this.options.rspackDist, file), node_path_1.default.join(this.options.webpackDist, file), {
19
- modules: this.options.modules,
20
- runtimeModules: this.options.runtimeModules,
21
- format: (0, deepmerge_1.default)({
22
- replacements: {},
23
- ignorePropertyQuotationMark: true,
24
- ignoreModuleId: true,
25
- ignoreModuleArguments: true,
26
- ignoreBlockOnlyStatement: true,
27
- ignoreIfCertainCondition: true,
28
- ignoreSwcHelpersPath: true,
29
- ignoreObjectPropertySequence: true,
30
- ignoreCssFilePath: true
31
- }, this.options.formatOptions || {}),
32
- renameModule: replace_runtime_module_name_1.replaceRuntimeModuleName,
33
- bootstrap: this.options.bootstrap
34
- });
35
- for (const reporter of this.options.reporters) {
36
- reporter.increment(file, result.modules.modules || []);
37
- }
38
- for (const reporter of this.options.reporters) {
39
- reporter.increment(file, result.modules.runtimeModules || []);
40
- }
41
- }
42
- catch (e) {
43
- console.error(e);
44
- for (const reporter of this.options.reporters) {
45
- reporter.failure(file);
46
- }
47
- }
48
- }
49
- await Promise.all(this.options.reporters.map(r => r.output()));
50
- }
51
- }
52
- exports.DiffComparator = DiffComparator;
@@ -1,17 +0,0 @@
1
- import { type TCompareModules, type TCompareResult, type TFileCompareResult, type TModuleCompareResult } from "../type";
2
- import { type IFormatCodeOptions } from "./format-code";
3
- declare global {
4
- var updateSnapshot: boolean;
5
- }
6
- export interface ICompareOptions {
7
- modules?: TCompareModules;
8
- runtimeModules?: TCompareModules;
9
- format: IFormatCodeOptions;
10
- renameModule?: (name: string) => string;
11
- bootstrap?: boolean;
12
- detail?: boolean;
13
- snapshot?: string;
14
- }
15
- export declare function compareFile(sourceFile: string, distFile: string, compareOptions: ICompareOptions): TFileCompareResult;
16
- export declare function compareModules(modules: string[], sourceModules: Record<string, string>, distModules: Record<string, string>, compareOptions: ICompareOptions): TModuleCompareResult[];
17
- export declare function compareContent(sourceContent: string | false, distContent: string | false, compareOptions: ICompareOptions): TCompareResult;