@rspack/test-tools 1.6.0-beta.0 → 1.6.0

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 (118) hide show
  1. package/dist/case/builtin.d.ts +3 -2
  2. package/dist/case/builtin.js +1 -1
  3. package/dist/case/cache.d.ts +2 -2
  4. package/dist/case/cache.js +13 -9
  5. package/dist/case/common.d.ts +11 -10
  6. package/dist/case/common.js +49 -43
  7. package/dist/case/compiler.d.ts +9 -8
  8. package/dist/case/compiler.js +5 -6
  9. package/dist/case/config.d.ts +6 -5
  10. package/dist/case/config.js +4 -1
  11. package/dist/case/defaults.d.ts +5 -4
  12. package/dist/case/defaults.js +10 -10
  13. package/dist/case/diagnostic.js +5 -6
  14. package/dist/case/error.d.ts +5 -5
  15. package/dist/case/error.js +7 -8
  16. package/dist/case/esm-output.js +30 -9
  17. package/dist/case/example.js +2 -2
  18. package/dist/case/hash.d.ts +2 -2
  19. package/dist/case/hash.js +1 -1
  20. package/dist/case/hook.d.ts +4 -3
  21. package/dist/case/hook.js +3 -2
  22. package/dist/case/hot-step.d.ts +2 -2
  23. package/dist/case/hot-step.js +4 -9
  24. package/dist/case/hot.d.ts +5 -4
  25. package/dist/case/hot.js +37 -49
  26. package/dist/case/incremental.d.ts +2 -2
  27. package/dist/case/incremental.js +1 -20
  28. package/dist/case/index.d.ts +0 -1
  29. package/dist/case/index.js +1 -3
  30. package/dist/case/multi-compiler.d.ts +9 -8
  31. package/dist/case/multi-compiler.js +3 -4
  32. package/dist/case/normal.js +5 -2
  33. package/dist/case/runner.d.ts +5 -4
  34. package/dist/case/runner.js +16 -11
  35. package/dist/case/serial.d.ts +2 -2
  36. package/dist/case/serial.js +1 -1
  37. package/dist/case/stats-api.d.ts +6 -5
  38. package/dist/case/stats-api.js +5 -7
  39. package/dist/case/stats-output.d.ts +3 -2
  40. package/dist/case/stats-output.js +1 -1
  41. package/dist/case/treeshaking.js +1 -1
  42. package/dist/case/watch.d.ts +8 -6
  43. package/dist/case/watch.js +21 -19
  44. package/dist/compiler.d.ts +16 -17
  45. package/dist/compiler.js +116 -16
  46. package/dist/helper/hot-update/loader.d.ts +2 -1
  47. package/dist/helper/hot-update/loader.js +5 -30
  48. package/dist/helper/hot-update/plugin.js +10 -14
  49. package/dist/helper/index.d.ts +1 -0
  50. package/dist/helper/index.js +1 -0
  51. package/dist/helper/legacy/asModule.js +0 -2
  52. package/dist/helper/legacy/checkArrayExpectation.js +1 -1
  53. package/dist/helper/legacy/createLazyTestEnv.d.ts +1 -0
  54. package/dist/helper/legacy/createLazyTestEnv.js +4 -3
  55. package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
  56. package/dist/helper/legacy/supportsTextDecoder.js +9 -0
  57. package/dist/helper/read-config-file.d.ts +3 -2
  58. package/dist/helper/read-config-file.js +12 -2
  59. package/dist/helper/setup-env.js +19 -2
  60. package/dist/helper/stringify-config.d.ts +2 -0
  61. package/dist/helper/stringify-config.js +43 -0
  62. package/dist/helper/util/expectWarningFactory.js +2 -4
  63. package/dist/index.d.ts +0 -1
  64. package/dist/index.js +0 -1
  65. package/dist/plugin/index.d.ts +0 -3
  66. package/dist/plugin/index.js +0 -3
  67. package/dist/runner/node/index.d.ts +13 -8
  68. package/dist/runner/node/index.js +88 -10
  69. package/dist/runner/web/index.d.ts +24 -10
  70. package/dist/runner/web/index.js +286 -18
  71. package/dist/test/context.d.ts +15 -16
  72. package/dist/test/context.js +44 -59
  73. package/dist/test/creator.d.ts +14 -14
  74. package/dist/test/creator.js +17 -12
  75. package/dist/test/debug.d.ts +15 -0
  76. package/dist/test/debug.js +205 -0
  77. package/dist/test/tester.d.ts +1 -0
  78. package/dist/test/tester.js +23 -4
  79. package/dist/type.d.ts +42 -55
  80. package/dist/type.js +1 -11
  81. package/jest.d.ts +2 -0
  82. package/package.json +10 -48
  83. package/dist/case/diff.d.ts +0 -19
  84. package/dist/case/diff.js +0 -274
  85. package/dist/compare/comparator.d.ts +0 -17
  86. package/dist/compare/comparator.js +0 -52
  87. package/dist/compare/compare.d.ts +0 -17
  88. package/dist/compare/compare.js +0 -178
  89. package/dist/compare/format-code.d.ts +0 -16
  90. package/dist/compare/format-code.js +0 -244
  91. package/dist/compare/index.d.ts +0 -5
  92. package/dist/compare/index.js +0 -21
  93. package/dist/compare/replace-module-argument.d.ts +0 -1
  94. package/dist/compare/replace-module-argument.js +0 -8
  95. package/dist/compare/replace-runtime-module-name.d.ts +0 -1
  96. package/dist/compare/replace-runtime-module-name.js +0 -71
  97. package/dist/helper/legacy/FakeDocument.d.ts +0 -54
  98. package/dist/helper/legacy/FakeDocument.js +0 -280
  99. package/dist/helper/legacy/update.d.ts +0 -2
  100. package/dist/helper/legacy/update.esm.d.ts +0 -1
  101. package/dist/helper/legacy/update.esm.js +0 -23
  102. package/dist/helper/legacy/update.js +0 -19
  103. package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
  104. package/dist/helper/legacy/walkCssTokens.js +0 -761
  105. package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
  106. package/dist/plugin/rspack-diff-config-plugin.js +0 -42
  107. package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
  108. package/dist/plugin/webpack-diff-config-plugin.js +0 -41
  109. package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
  110. package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
  111. package/dist/runner/web/fake.d.ts +0 -15
  112. package/dist/runner/web/fake.js +0 -216
  113. package/dist/runner/web/jsdom.d.ts +0 -24
  114. package/dist/runner/web/jsdom.js +0 -224
  115. package/template/diff.bundle.css +0 -1
  116. package/template/diff.bundle.js +0 -144
  117. package/template/diff.html +0 -14
  118. package/template/editor.worker.js +0 -1
@@ -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;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Tester = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const context_1 = require("./context");
9
+ const debug_1 = require("./debug");
9
10
  class Tester {
10
11
  constructor(config) {
11
12
  this.config = config;
@@ -20,7 +21,7 @@ class Tester {
20
21
  this.total = config.steps?.length || 0;
21
22
  if (config.contextValue) {
22
23
  for (const [key, value] of Array.from(Object.entries(config.contextValue))) {
23
- this.context.setValue(config.name, key, value);
24
+ this.context.setValue(key, value);
24
25
  }
25
26
  }
26
27
  }
@@ -55,6 +56,11 @@ class Tester {
55
56
  if (!currentStep)
56
57
  return;
57
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;
58
64
  await this.runStepMethods(currentStep, ["after"], true);
59
65
  }
60
66
  next() {
@@ -73,7 +79,20 @@ class Tester {
73
79
  await i.afterAll(this.context);
74
80
  }
75
81
  }
76
- await this.context.closeCompiler(this.config.name);
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
+ }
77
96
  }
78
97
  async runStepMethods(step, methods, force = false) {
79
98
  for (const i of methods) {
@@ -84,7 +103,7 @@ class Tester {
84
103
  await step[i](this.context);
85
104
  }
86
105
  catch (e) {
87
- this.context.emitError(this.config.name, e);
106
+ this.context.emitError(e);
88
107
  }
89
108
  }
90
109
  }
@@ -98,7 +117,7 @@ class Tester {
98
117
  }
99
118
  }
100
119
  catch (e) {
101
- const errors = this.context.getError(this.config.name);
120
+ const errors = this.context.getError();
102
121
  console.error(new Error([...errors, e].map(e => e.message).join("\n")));
103
122
  throw e;
104
123
  }
package/dist/type.d.ts CHANGED
@@ -1,42 +1,30 @@
1
1
  import type EventEmitter from "node:events";
2
- import type { Compilation as RspackCompilation, Compiler as RspackCompiler, MultiStats as RspackMultiStats, RspackOptions, Stats as RspackStats, StatsCompilation as RspackStatsCompilation } from "@rspack/core";
3
- import type { Compilation as WebpackCompilation, Compiler as WebpackCompiler, MultiStats as WebpackMultiStats, Configuration as WebpackOptions, Stats as WebpackStats, StatsCompilation as WebpackStatsCompilation } from "webpack";
2
+ import type { Compiler, MultiStats, RspackOptions, Stats, StatsCompilation } from "@rspack/core";
4
3
  export interface ITestContext {
5
4
  getSource(sub?: string): string;
6
5
  getDist(sub?: string): string;
7
6
  getTemp(sub?: string): string | null;
8
- getCompiler<T extends ECompilerType>(name: string, type: T | void): ITestCompilerManager<T>;
9
- closeCompiler(name: string): Promise<void>;
10
- getTestConfig<T extends ECompilerType>(): TTestConfig<T>;
11
- getRunner(name: string, file: string, env: ITestEnv): ITestRunner;
12
- setValue<T>(name: string, key: string, value: T): void;
13
- getValue<T>(name: string, key: string): T | void;
14
- getNames(): string[];
15
- hasError(name?: string): boolean;
16
- emitError(name: string, err: Error | string): void;
17
- getError(name?: string): Error[];
18
- clearError(name?: string): void;
19
- }
20
- export declare enum ECompilerType {
21
- Rspack = "rspack",
22
- Webpack = "webpack"
23
- }
24
- export type TCompilerOptions<T> = T extends ECompilerType.Rspack ? RspackOptions : WebpackOptions;
25
- export type TCompiler<T> = T extends ECompilerType.Rspack ? RspackCompiler : WebpackCompiler;
26
- export type TCompilation<T> = T extends ECompilerType.Rspack ? RspackCompilation : WebpackCompilation;
27
- export type TCompilerStats<T> = T extends ECompilerType.Rspack ? RspackStats : WebpackStats;
28
- export type TCompilerMultiStats<T> = T extends ECompilerType.Rspack ? RspackMultiStats : WebpackMultiStats;
29
- export type TCompilerStatsCompilation<T> = T extends ECompilerType.Rspack ? RspackStatsCompilation : WebpackStatsCompilation;
30
- export interface ITestCompilerManager<T extends ECompilerType> {
31
- getOptions(): TCompilerOptions<T>;
32
- setOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
33
- mergeOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
34
- getCompiler(): TCompiler<T> | null;
35
- createCompiler(): TCompiler<T>;
36
- createCompilerWithCallback(callback: (error: Error | null, stats: TCompilerStats<T> | null) => void): TCompiler<T>;
37
- build(): Promise<TCompilerStats<T>>;
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;
17
+ }
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,8 +38,7 @@ export interface ITesterConfig {
50
38
  dist: string;
51
39
  temp?: string;
52
40
  steps?: ITestProcessor[];
53
- testConfig?: TTestConfig<ECompilerType>;
54
- compilerFactories?: TCompilerFactories<ECompilerType>;
41
+ testConfig?: TTestConfig;
55
42
  contextValue?: Record<string, unknown>;
56
43
  runnerCreator?: TTestRunnerCreator;
57
44
  createContext?: (config: ITesterConfig) => ITestContext;
@@ -63,6 +50,7 @@ export interface ITester {
63
50
  prepare(): Promise<void>;
64
51
  compile(): Promise<void>;
65
52
  check(env: ITestEnv): Promise<void>;
53
+ after(): Promise<void>;
66
54
  next(): boolean;
67
55
  resume(): Promise<void>;
68
56
  }
@@ -77,9 +65,9 @@ export interface ITestProcessor {
77
65
  run(env: ITestEnv, context: ITestContext): Promise<void>;
78
66
  check(env: ITestEnv, context: ITestContext): Promise<unknown>;
79
67
  }
80
- export interface ITestReporter<T> {
81
- init(data?: T): Promise<void>;
82
- 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>;
83
71
  failure(id: string): Promise<void>;
84
72
  output(): Promise<void>;
85
73
  }
@@ -129,21 +117,17 @@ export interface ITestEnv {
129
117
  afterEach: (...args: any[]) => void;
130
118
  [key: string]: unknown;
131
119
  }
132
- export declare enum EDocumentType {
133
- Fake = "fake",
134
- JSDOM = "jsdom"
135
- }
136
- export type TTestConfig<T extends ECompilerType> = {
137
- documentType?: EDocumentType;
138
- validate?: (stats: TCompilerStats<T> | TCompilerMultiStats<T>, stderr?: string) => void;
120
+ export type TTestConfig = {
121
+ location?: string;
122
+ validate?: (stats: Stats | MultiStats, stderr?: string) => void;
139
123
  noTests?: boolean;
140
124
  writeStatsOuptut?: boolean;
141
125
  writeStatsJson?: boolean;
142
- beforeExecute?: (options: TCompilerOptions<T>) => void;
143
- afterExecute?: (options: TCompilerOptions<T>) => void;
144
- moduleScope?: (ms: IModuleScope, stats?: TCompilerStatsCompilation<T>, options?: TCompilerOptions<T>) => IModuleScope;
145
- checkStats?: (stepName: string, jsonStats: TCompilerStatsCompilation<T> | undefined, stringStats: String) => boolean;
146
- 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[];
147
131
  bundlePath?: string[];
148
132
  nonEsmThis?: (p: string | string[]) => Object;
149
133
  modules?: Record<string, Object>;
@@ -152,23 +136,25 @@ export type TTestConfig<T extends ECompilerType> = {
152
136
  snapshotContent?(content: string): string;
153
137
  checkSteps?: boolean;
154
138
  ignoreNotFriendlyForIncrementalWarnings?: boolean;
139
+ esmLibPluginOptions?: {
140
+ preserveModules?: string;
141
+ };
155
142
  };
156
- export type TTestFilter<T extends ECompilerType> = (creatorConfig: Record<string, unknown>, testConfig: TTestConfig<T>) => boolean | string;
143
+ export type TTestFilter = (creatorConfig: Record<string, unknown>, testConfig: TTestConfig) => boolean | string;
157
144
  export interface ITestRunner {
158
145
  run(file: string): Promise<unknown>;
159
146
  getRequire(): TRunnerRequirer;
160
147
  getGlobal(name: string): unknown;
161
148
  }
162
- export type TCompilerFactory<T extends ECompilerType> = (options: TCompilerOptions<T> | TCompilerOptions<T>[], callback?: (error: Error | null, stats: TCompilerStats<T> | null) => void) => TCompiler<T>;
163
- export interface TRunnerFactory<T extends ECompilerType> {
164
- create(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
149
+ export type TCompilerFactory = (options: RspackOptions | RspackOptions[], callback?: (error: Error | null, stats: Stats | null) => void) => Compiler;
150
+ export interface TRunnerFactory {
151
+ create(file: string, compilerOptions: RspackOptions, env: ITestEnv): ITestRunner;
165
152
  }
166
153
  export type THotUpdateContext = {
167
154
  updateIndex: number;
168
155
  totalUpdates: number;
169
156
  changedFiles: string[];
170
157
  };
171
- export type TCompilerFactories<T extends ECompilerType> = Record<T, TCompilerFactory<T>>;
172
158
  export type TRunnerRequirer = (currentDirectory: string, modulePath: string[] | string, context?: {
173
159
  file?: TRunnerFile;
174
160
  esmMode?: EEsmMode;
@@ -202,6 +188,7 @@ export type TTestRunnerCreator = {
202
188
  runner: (context: ITestContext, name: string, file: string, env: ITestEnv) => ITestRunner;
203
189
  };
204
190
  declare global {
191
+ var __DEBUG__: boolean;
205
192
  var __TEST_PATH__: string;
206
193
  var __TEST_FIXTURES_PATH__: string;
207
194
  var __TEST_DIST_PATH__: string;
package/dist/type.js CHANGED
@@ -1,12 +1,7 @@
1
1
  "use strict";
2
2
  /// <reference types="../jest.d.ts" />
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.EEsmMode = 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,11 +10,6 @@ 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 = {}));
23
13
  var EEsmMode;
24
14
  (function (EEsmMode) {
25
15
  EEsmMode[EEsmMode["Unknown"] = 0] = "Unknown";
package/jest.d.ts CHANGED
@@ -22,4 +22,6 @@ declare global {
22
22
  ) => void;
23
23
  }
24
24
  }
25
+
26
+ var rstest = jest;
25
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/test-tools",
3
- "version": "1.6.0-beta.0",
3
+ "version": "1.6.0",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -36,77 +36,39 @@
36
36
  "directory": "packages/rspack-test-tools"
37
37
  },
38
38
  "dependencies": {
39
- "@babel/generator": "7.28.3",
40
- "@babel/parser": "7.28.4",
41
- "@babel/traverse": "7.28.4",
42
- "@babel/types": "7.28.4",
39
+ "@babel/generator": "7.28.5",
40
+ "@babel/parser": "7.28.5",
41
+ "@babel/traverse": "7.28.5",
42
+ "@babel/types": "7.28.5",
43
43
  "@jest/reporters": "29.7.0",
44
44
  "cross-env": "^10.1.0",
45
- "csv-to-markdown-table": "1.5.0",
46
- "deepmerge": "^4.3.1",
47
45
  "filenamify": "4.3.0",
48
46
  "fs-extra": "^11.3.2",
49
- "glob": "^11.0.3",
50
- "graceful-fs": "^4.2.11",
51
47
  "iconv-lite": "^0.6.3",
48
+ "javascript-stringify": "^2.1.0",
52
49
  "jest-diff": "^29.7.0",
53
50
  "jest-snapshot": "29.7.0",
54
51
  "jest-environment-node": "29.7.0",
55
52
  "jsdom": "^26.1.0",
56
53
  "memfs": "4.48.1",
57
- "loader-utils": "^2.0.4",
58
54
  "path-serializer": "0.5.1",
59
55
  "pretty-format": "29.7.0",
60
56
  "rimraf": "^5.0.10",
61
57
  "source-map": "^0.7.6",
62
58
  "terser-webpack-plugin": "^5.3.14",
63
- "webpack": "5.99.9",
59
+ "webpack": "5.102.1",
64
60
  "webpack-merge": "6.0.1",
65
- "webpack-sources": "3.3.3"
61
+ "webpack-sources": "3.3.3",
62
+ "chalk": "^4.1.2"
66
63
  },
67
64
  "devDependencies": {
68
- "@rspack/plugin-preact-refresh": "1.1.3",
69
- "@rspack/plugin-react-refresh": "^1.5.1",
70
- "@swc/helpers": "0.5.17",
71
- "@swc/plugin-remove-console": "^9.1.0",
72
65
  "@types/babel__generator": "7.27.0",
73
66
  "@types/babel__traverse": "7.28.0",
74
67
  "@types/fs-extra": "11.0.4",
75
68
  "@types/jsdom": "^21.1.7",
76
- "@types/react": "^19.1.13",
77
- "@types/react-dom": "^19.1.9",
78
- "@webdiscus/pug-loader": "^2.11.1",
79
- "acorn": "^8.15.0",
80
- "babel-loader": "^10.0.0",
81
- "babel-plugin-import": "^1.13.8",
82
- "chalk": "^4.1.2",
83
- "core-js": "3.45.1",
84
- "css-loader": "^7.1.2",
85
- "file-loader": "^6.2.0",
86
- "graceful-fs": "^4.2.11",
87
- "html-loader": "^5.1.0",
88
- "html-webpack-plugin": "^5.6.4",
89
- "less-loader": "^12.3.0",
90
- "lodash": "^4.17.21",
91
- "postcss-loader": "^8.2.0",
92
- "postcss-pxtorem": "^6.1.0",
93
- "raw-loader": "^4.0.2",
94
- "react": "^19.1.1",
95
- "react-dom": "^19.1.1",
96
- "react-refresh": "^0.17.0",
97
- "sass-loader": "^16.0.5",
98
- "source-map": "^0.7.6",
99
- "source-map-loader": "^5.0.0",
100
- "style-loader": "^4.0.0",
101
- "terser": "5.43.1",
102
69
  "typescript": "^5.9.3",
103
70
  "wast-loader": "^1.14.1",
104
- "worker-rspack-loader": "^3.1.2",
105
- "exports-loader": "^5.0.0",
106
- "@rspack/core": "1.6.0-beta.0",
107
- "@rspack/cli": "1.6.0-beta.0",
108
- "@rspack/binding-testing": "1.4.1",
109
- "@rspack/test-tools": "1.6.0-beta.0"
71
+ "@rspack/core": "1.6.0"
110
72
  },
111
73
  "peerDependencies": {
112
74
  "@rspack/core": ">=1.0.0"
@@ -1,19 +0,0 @@
1
- import { type IFormatCodeOptions, type IFormatCodeReplacement } from "../compare";
2
- import { type TCompareModules, type TFileCompareResult, type TModuleCompareResult } from "../type";
3
- export type TDiffCaseConfig = IDiffProcessorOptions;
4
- export declare function createDiffCase(name: string, src: string, dist: string): void;
5
- export interface IDiffProcessorOptions extends IFormatCodeOptions {
6
- webpackPath: string;
7
- rspackPath: string;
8
- files?: string[];
9
- modules?: TCompareModules;
10
- runtimeModules?: TCompareModules;
11
- bootstrap?: boolean;
12
- detail?: boolean;
13
- errors?: boolean;
14
- replacements?: IFormatCodeReplacement[];
15
- renameModule?: (file: string) => string;
16
- onCompareFile?: (file: string, result: TFileCompareResult) => void;
17
- onCompareModules?: (file: string, results: TModuleCompareResult[]) => void;
18
- onCompareRuntimeModules?: (file: string, results: TModuleCompareResult[]) => void;
19
- }