@rspack-canary/test-tools 1.5.6-canary-e598f284-20250921173624 → 1.5.8-canary-e350b761-20250924173613

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 (122) hide show
  1. package/dist/case/builtin.d.ts +2 -0
  2. package/dist/case/builtin.js +173 -13
  3. package/dist/case/cache.d.ts +1 -1
  4. package/dist/case/cache.js +210 -11
  5. package/dist/case/common.d.ts +10 -0
  6. package/dist/case/common.js +237 -0
  7. package/dist/case/compiler.d.ts +7 -4
  8. package/dist/case/compiler.js +144 -109
  9. package/dist/case/config.d.ts +5 -1
  10. package/dist/case/config.js +102 -16
  11. package/dist/case/defaults.d.ts +12 -4
  12. package/dist/case/defaults.js +67 -12
  13. package/dist/case/diagnostic.d.ts +6 -0
  14. package/dist/case/diagnostic.js +123 -14
  15. package/dist/case/diff.d.ts +17 -1
  16. package/dist/case/diff.js +170 -22
  17. package/dist/case/error.d.ts +14 -4
  18. package/dist/case/error.js +117 -10
  19. package/dist/case/hash.d.ts +1 -1
  20. package/dist/case/hash.js +70 -9
  21. package/dist/case/hook.d.ts +35 -4
  22. package/dist/case/hook.js +210 -21
  23. package/dist/case/hot-step.js +307 -9
  24. package/dist/case/hot.d.ts +8 -1
  25. package/dist/case/hot.js +235 -8
  26. package/dist/case/incremental.d.ts +1 -1
  27. package/dist/case/incremental.js +39 -41
  28. package/dist/case/index.d.ts +20 -20
  29. package/dist/case/index.js +44 -34
  30. package/dist/case/native-watcher.js +10 -23
  31. package/dist/case/normal.js +174 -12
  32. package/dist/case/runner.d.ts +18 -0
  33. package/dist/case/runner.js +108 -0
  34. package/dist/case/serial.d.ts +1 -1
  35. package/dist/case/serial.js +8 -12
  36. package/dist/case/stats-api.d.ts +0 -5
  37. package/dist/case/stats-api.js +71 -10
  38. package/dist/case/stats-output.js +197 -11
  39. package/dist/case/treeshaking.js +34 -7
  40. package/dist/case/watch.d.ts +27 -0
  41. package/dist/case/watch.js +321 -21
  42. package/dist/helper/plugins/hot-update.d.ts +2 -2
  43. package/dist/index.d.ts +0 -2
  44. package/dist/index.js +0 -2
  45. package/dist/runner/index.d.ts +2 -7
  46. package/dist/runner/index.js +2 -7
  47. package/dist/runner/{runner/node → node}/index.d.ts +1 -2
  48. package/dist/runner/{runner/node → node}/index.js +2 -2
  49. package/dist/runner/{runner/web → web}/fake.d.ts +1 -2
  50. package/dist/runner/{runner/web → web}/fake.js +7 -7
  51. package/dist/runner/{runner/web → web}/index.d.ts +2 -2
  52. package/dist/runner/{runner/web → web}/index.js +1 -1
  53. package/dist/runner/{runner/web → web}/jsdom.d.ts +1 -2
  54. package/dist/runner/{runner/web → web}/jsdom.js +4 -4
  55. package/dist/test/context.d.ts +3 -5
  56. package/dist/test/context.js +22 -12
  57. package/dist/test/creator.d.ts +13 -12
  58. package/dist/test/creator.js +52 -43
  59. package/dist/test/tester.js +4 -1
  60. package/dist/type.d.ts +42 -11
  61. package/dist/type.js +7 -1
  62. package/package.json +5 -5
  63. package/dist/processor/basic.d.ts +0 -24
  64. package/dist/processor/basic.js +0 -147
  65. package/dist/processor/builtin.d.ts +0 -9
  66. package/dist/processor/builtin.js +0 -171
  67. package/dist/processor/cache.d.ts +0 -20
  68. package/dist/processor/cache.js +0 -131
  69. package/dist/processor/config.d.ts +0 -11
  70. package/dist/processor/config.js +0 -88
  71. package/dist/processor/defaults.d.ts +0 -30
  72. package/dist/processor/defaults.js +0 -72
  73. package/dist/processor/diagnostic.d.ts +0 -15
  74. package/dist/processor/diagnostic.js +0 -104
  75. package/dist/processor/diff.d.ts +0 -30
  76. package/dist/processor/diff.js +0 -140
  77. package/dist/processor/error.d.ts +0 -23
  78. package/dist/processor/error.js +0 -95
  79. package/dist/processor/hash.d.ts +0 -10
  80. package/dist/processor/hash.js +0 -65
  81. package/dist/processor/hook.d.ts +0 -44
  82. package/dist/processor/hook.js +0 -206
  83. package/dist/processor/hot-incremental.d.ts +0 -14
  84. package/dist/processor/hot-incremental.js +0 -43
  85. package/dist/processor/hot-step.d.ts +0 -18
  86. package/dist/processor/hot-step.js +0 -307
  87. package/dist/processor/hot.d.ts +0 -17
  88. package/dist/processor/hot.js +0 -147
  89. package/dist/processor/index.d.ts +0 -20
  90. package/dist/processor/index.js +0 -36
  91. package/dist/processor/multi.d.ts +0 -17
  92. package/dist/processor/multi.js +0 -73
  93. package/dist/processor/normal.d.ts +0 -12
  94. package/dist/processor/normal.js +0 -170
  95. package/dist/processor/simple.d.ts +0 -24
  96. package/dist/processor/simple.js +0 -51
  97. package/dist/processor/snapshot.d.ts +0 -12
  98. package/dist/processor/snapshot.js +0 -66
  99. package/dist/processor/stats-api.d.ts +0 -18
  100. package/dist/processor/stats-api.js +0 -48
  101. package/dist/processor/stats.d.ts +0 -18
  102. package/dist/processor/stats.js +0 -206
  103. package/dist/processor/treeshaking.d.ts +0 -10
  104. package/dist/processor/treeshaking.js +0 -33
  105. package/dist/processor/watch.d.ts +0 -30
  106. package/dist/processor/watch.js +0 -252
  107. package/dist/runner/basic.d.ts +0 -10
  108. package/dist/runner/basic.js +0 -64
  109. package/dist/runner/cache.d.ts +0 -5
  110. package/dist/runner/cache.js +0 -92
  111. package/dist/runner/hot.d.ts +0 -5
  112. package/dist/runner/hot.js +0 -91
  113. package/dist/runner/multiple.d.ts +0 -11
  114. package/dist/runner/multiple.js +0 -52
  115. package/dist/runner/runner/index.d.ts +0 -2
  116. package/dist/runner/runner/index.js +0 -18
  117. package/dist/runner/type.d.ts +0 -42
  118. package/dist/runner/type.js +0 -9
  119. package/dist/runner/watch.d.ts +0 -7
  120. package/dist/runner/watch.js +0 -71
  121. package/dist/test/simple.d.ts +0 -5
  122. package/dist/test/simple.js +0 -43
@@ -1,4 +1,4 @@
1
- import type { ECompilerType, ITestContext, ITestEnv, ITester, ITestProcessor, TRunnerFactory, TTestConfig } from "../type";
1
+ import type { ECompilerType, ITestContext, ITestEnv, ITester, ITesterConfig, ITestProcessor, TTestConfig, TTestRunnerCreator } from "../type";
2
2
  declare global {
3
3
  var testFilter: string | undefined;
4
4
  }
@@ -19,28 +19,29 @@ export interface IBasicCaseCreatorOptions<T extends ECompilerType> {
19
19
  }) => ITestProcessor[];
20
20
  testConfig?: (testConfig: TTestConfig<T>) => void;
21
21
  description?: (name: string, step: number) => string;
22
- runner?: new (name: string, context: ITestContext) => TRunnerFactory<ECompilerType>;
23
- [key: string]: unknown;
22
+ runner?: TTestRunnerCreator;
23
+ createContext?: (config: ITesterConfig) => ITestContext;
24
24
  concurrent?: boolean | number;
25
+ [key: string]: unknown;
25
26
  }
26
27
  export declare class BasicCaseCreator<T extends ECompilerType> {
27
28
  protected _options: IBasicCaseCreatorOptions<T>;
28
29
  protected currentConcurrent: number;
29
30
  protected tasks: [string, () => void][];
30
31
  constructor(_options: IBasicCaseCreatorOptions<T>);
31
- create(name: string, src: string, dist: string, temp?: string): ITester | undefined;
32
+ create(name: string, src: string, dist: string, temp?: string, caseOptions?: Partial<IBasicCaseCreatorOptions<T>>): ITester | undefined;
32
33
  protected shouldRun(name: string): boolean;
33
- protected describeConcurrent(name: string, tester: ITester, testConfig: TTestConfig<T>): void;
34
- protected describe(name: string, tester: ITester, testConfig: TTestConfig<T>): void;
34
+ protected describeConcurrent(name: string, tester: ITester, testConfig: TTestConfig<T>, options: IBasicCaseCreatorOptions<T>): void;
35
+ protected describe(name: string, tester: ITester, testConfig: TTestConfig<T>, options: IBasicCaseCreatorOptions<T>): void;
35
36
  protected createConcurrentEnv(): ITestEnv & IConcurrentTestEnv;
36
- protected createEnv(testConfig: TTestConfig<T>): ITestEnv;
37
+ protected createEnv(testConfig: TTestConfig<T>, options: IBasicCaseCreatorOptions<T>): ITestEnv;
37
38
  protected clean(folders: string[]): void;
38
39
  protected skip(name: string, reason: string | boolean): void;
39
40
  protected readTestConfig(src: string): TTestConfig<T>;
40
- protected checkSkipped(src: string, testConfig: TTestConfig<T>): boolean | string;
41
- protected createTester(name: string, src: string, dist: string, temp: string | undefined, testConfig: TTestConfig<T>): ITester;
42
- protected tryRunTask(): void;
43
- protected getMaxConcurrent(): number;
44
- protected registerConcurrentTask(name: string, starter: () => void): () => void;
41
+ protected checkSkipped(src: string, testConfig: TTestConfig<T>, options: IBasicCaseCreatorOptions<T>): boolean | string;
42
+ protected createTester(name: string, src: string, dist: string, temp: string | undefined, testConfig: TTestConfig<T>, options: IBasicCaseCreatorOptions<T>): ITester;
43
+ protected tryRunTask(concurrent?: number): void;
44
+ protected getMaxConcurrent(concurrent?: number): number;
45
+ protected registerConcurrentTask(name: string, starter: () => void, concurrent?: number): () => void;
45
46
  }
46
47
  export {};
@@ -16,31 +16,35 @@ class BasicCaseCreator {
16
16
  this.currentConcurrent = 0;
17
17
  this.tasks = [];
18
18
  }
19
- create(name, src, dist, temp) {
19
+ create(name, src, dist, temp, caseOptions) {
20
+ const options = {
21
+ ...this._options,
22
+ ...caseOptions
23
+ };
20
24
  const testConfig = this.readTestConfig(src);
21
- if (typeof this._options.testConfig === "function") {
22
- this._options.testConfig(testConfig);
25
+ if (typeof options.testConfig === "function") {
26
+ options.testConfig(testConfig);
23
27
  }
24
- const skipped = this.checkSkipped(src, testConfig);
28
+ const skipped = this.checkSkipped(src, testConfig, options);
25
29
  if (skipped) {
26
30
  this.skip(name, skipped);
27
31
  return;
28
32
  }
29
- if (this._options.clean) {
33
+ if (options.clean) {
30
34
  this.clean([dist, temp || ""].filter(Boolean));
31
35
  }
32
36
  const run = this.shouldRun(name);
33
- const tester = this.createTester(name, src, dist, temp, testConfig);
37
+ const tester = this.createTester(name, src, dist, temp, testConfig, options);
34
38
  const concurrent = process.env.WASM
35
39
  ? false
36
- : testConfig.concurrent || this._options.concurrent;
37
- if (this._options.describe) {
40
+ : testConfig.concurrent || options.concurrent;
41
+ if (options.describe) {
38
42
  if (run) {
39
43
  if (concurrent) {
40
- describe(name, () => this.describeConcurrent(name, tester, testConfig));
44
+ describe(name, () => this.describeConcurrent(name, tester, testConfig, options));
41
45
  }
42
46
  else {
43
- describe(name, () => this.describe(name, tester, testConfig));
47
+ describe(name, () => this.describe(name, tester, testConfig, options));
44
48
  }
45
49
  }
46
50
  else {
@@ -52,10 +56,10 @@ class BasicCaseCreator {
52
56
  else {
53
57
  if (run) {
54
58
  if (concurrent) {
55
- this.describeConcurrent(name, tester, testConfig);
59
+ this.describeConcurrent(name, tester, testConfig, options);
56
60
  }
57
61
  else {
58
- this.describe(name, tester, testConfig);
62
+ this.describe(name, tester, testConfig, options);
59
63
  }
60
64
  }
61
65
  else {
@@ -71,7 +75,7 @@ class BasicCaseCreator {
71
75
  }
72
76
  return name.includes(global.testFilter);
73
77
  }
74
- describeConcurrent(name, tester, testConfig) {
78
+ describeConcurrent(name, tester, testConfig, options) {
75
79
  beforeAll(async () => {
76
80
  await tester.prepare();
77
81
  });
@@ -79,7 +83,7 @@ class BasicCaseCreator {
79
83
  let chain = new Promise((resolve, reject) => {
80
84
  starter = resolve;
81
85
  });
82
- const ender = this.registerConcurrentTask(name, starter);
86
+ const ender = this.registerConcurrentTask(name, starter, options.concurrent);
83
87
  const env = this.createConcurrentEnv();
84
88
  for (let index = 0; index < tester.total; index++) {
85
89
  let stepSignalResolve = null;
@@ -88,8 +92,8 @@ class BasicCaseCreator {
88
92
  }).catch(() => {
89
93
  // prevent unhandled rejection
90
94
  });
91
- const description = typeof this._options.description === "function"
92
- ? this._options.description(name, index)
95
+ const description = typeof options.description === "function"
96
+ ? options.description(name, index)
93
97
  : index
94
98
  ? `step [${index}] should pass`
95
99
  : "should pass";
@@ -97,7 +101,7 @@ class BasicCaseCreator {
97
101
  stepSignal.then((e) => {
98
102
  cb(e);
99
103
  });
100
- }, this._options.timeout || 180000);
104
+ }, options.timeout || 180000);
101
105
  chain = chain.then(async () => {
102
106
  try {
103
107
  env.clear();
@@ -136,22 +140,28 @@ class BasicCaseCreator {
136
140
  await tester.resume();
137
141
  });
138
142
  }
139
- describe(name, tester, testConfig) {
143
+ describe(name, tester, testConfig, options) {
140
144
  beforeAll(async () => {
141
145
  await tester.prepare();
142
146
  });
143
147
  let bailout = false;
144
148
  for (let index = 0; index < tester.total; index++) {
145
- const description = typeof this._options.description === "function"
146
- ? this._options.description(name, index)
147
- : `step ${index ? `[${index}]` : ""} should pass`;
149
+ const description = typeof options.description === "function"
150
+ ? options.description(name, index)
151
+ : `step [${index}] should pass`;
148
152
  it(description, async () => {
149
153
  if (bailout) {
150
154
  throw `Case "${name}" step ${index + 1} bailout because ${tester.step + 1} failed`;
151
155
  }
152
- await tester.compile();
153
- await tester.check(env);
154
156
  const context = tester.getContext();
157
+ try {
158
+ await tester.compile();
159
+ }
160
+ catch (e) {
161
+ bailout = true;
162
+ context.emitError(name, e);
163
+ }
164
+ await tester.check(env);
155
165
  if (!tester.next() && context.hasError()) {
156
166
  bailout = true;
157
167
  const errors = context
@@ -160,8 +170,8 @@ class BasicCaseCreator {
160
170
  .join("\n\n");
161
171
  throw new Error(`Case "${name}" failed at step ${tester.step + 1}:\n${errors}`);
162
172
  }
163
- }, this._options.timeout || 30000);
164
- const env = this.createEnv(testConfig);
173
+ }, options.timeout || 30000);
174
+ const env = this.createEnv(testConfig, options);
165
175
  }
166
176
  afterAll(async () => {
167
177
  await tester.resume();
@@ -230,8 +240,8 @@ class BasicCaseCreator {
230
240
  jest
231
241
  };
232
242
  }
233
- createEnv(testConfig) {
234
- if (typeof this._options.runner === "function" && !testConfig.noTests) {
243
+ createEnv(testConfig, options) {
244
+ if (options.runner && !testConfig.noTests) {
235
245
  return (0, createLazyTestEnv_1.default)(10000);
236
246
  }
237
247
  return {
@@ -257,30 +267,31 @@ class BasicCaseCreator {
257
267
  const testConfigFile = node_path_1.default.join(src, "test.config.js");
258
268
  return node_fs_1.default.existsSync(testConfigFile) ? require(testConfigFile) : {};
259
269
  }
260
- checkSkipped(src, testConfig) {
270
+ checkSkipped(src, testConfig, options) {
261
271
  const filterPath = node_path_1.default.join(src, "test.filter.js");
262
272
  // no test.filter.js, should not skip
263
273
  if (!node_fs_1.default.existsSync(filterPath)) {
264
274
  return false;
265
275
  }
266
276
  // test.filter.js exists, skip if it returns false|string|array
267
- const filtered = require(filterPath)(this._options, testConfig);
277
+ const filtered = require(filterPath)(options, testConfig);
268
278
  if (typeof filtered === "string" || Array.isArray(filtered)) {
269
279
  return true;
270
280
  }
271
281
  return !filtered;
272
282
  }
273
- createTester(name, src, dist, temp, testConfig) {
283
+ createTester(name, src, dist, temp, testConfig, options) {
274
284
  return new tester_1.Tester({
275
285
  name,
276
286
  src,
277
287
  dist,
278
288
  temp,
279
289
  testConfig,
280
- contextValue: this._options.contextValue,
281
- runnerFactory: this._options.runner,
282
- steps: this._options.steps({
283
- ...this._options,
290
+ contextValue: options.contextValue,
291
+ runnerCreator: options.runner,
292
+ createContext: options.createContext,
293
+ steps: options.steps({
294
+ ...options,
284
295
  name,
285
296
  src,
286
297
  dist,
@@ -288,25 +299,23 @@ class BasicCaseCreator {
288
299
  })
289
300
  });
290
301
  }
291
- tryRunTask() {
302
+ tryRunTask(concurrent) {
292
303
  while (this.tasks.length !== 0 &&
293
- this.currentConcurrent < this.getMaxConcurrent()) {
304
+ this.currentConcurrent < this.getMaxConcurrent(concurrent)) {
294
305
  const [_name, starter] = this.tasks.shift();
295
306
  this.currentConcurrent++;
296
307
  starter();
297
308
  }
298
309
  }
299
- getMaxConcurrent() {
300
- return typeof this._options.concurrent === "number"
301
- ? this._options.concurrent
302
- : DEFAULT_MAX_CONCURRENT;
310
+ getMaxConcurrent(concurrent) {
311
+ return typeof concurrent === "number" ? concurrent : DEFAULT_MAX_CONCURRENT;
303
312
  }
304
- registerConcurrentTask(name, starter) {
313
+ registerConcurrentTask(name, starter, concurrent) {
305
314
  this.tasks.push([name, starter]);
306
- this.tryRunTask();
315
+ this.tryRunTask(concurrent);
307
316
  return () => {
308
317
  this.currentConcurrent--;
309
- this.tryRunTask();
318
+ this.tryRunTask(concurrent);
310
319
  };
311
320
  }
312
321
  }
@@ -12,7 +12,9 @@ class Tester {
12
12
  this.steps = [];
13
13
  this.step = 0;
14
14
  this.total = 0;
15
- this.context = new context_1.TestContext(config);
15
+ this.context = config.createContext
16
+ ? config.createContext(config)
17
+ : new context_1.TestContext(config);
16
18
  this.steps = config.steps || [];
17
19
  this.step = 0;
18
20
  this.total = config.steps?.length || 0;
@@ -69,6 +71,7 @@ class Tester {
69
71
  for (const i of this.steps) {
70
72
  if (typeof i.afterAll === "function") {
71
73
  await i.afterAll(this.context);
74
+ await this.context.closeCompiler(this.config.name);
72
75
  }
73
76
  }
74
77
  }
package/dist/type.d.ts CHANGED
@@ -1,16 +1,14 @@
1
1
  import type EventEmitter from "node:events";
2
2
  import type { Compilation as RspackCompilation, Compiler as RspackCompiler, MultiStats as RspackMultiStats, RspackOptions, Stats as RspackStats, StatsCompilation as RspackStatsCompilation } from "@rspack/core";
3
3
  import type { Compilation as WebpackCompilation, Compiler as WebpackCompiler, MultiStats as WebpackMultiStats, Configuration as WebpackOptions, Stats as WebpackStats, StatsCompilation as WebpackStatsCompilation } from "webpack";
4
- import type { IModuleScope, TRunnerRequirer } from "./runner/type";
5
4
  export interface ITestContext {
6
5
  getSource(sub?: string): string;
7
6
  getDist(sub?: string): string;
8
7
  getTemp(sub?: string): string | null;
9
8
  getCompiler<T extends ECompilerType>(name: string, type: T | void): ITestCompilerManager<T>;
9
+ closeCompiler(name: string): Promise<void>;
10
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;
11
+ getRunner(name: string, file: string, env: ITestEnv): ITestRunner;
14
12
  setValue<T>(name: string, key: string, value: T): void;
15
13
  getValue<T>(name: string, key: string): T | void;
16
14
  getNames(): string[];
@@ -55,7 +53,8 @@ export interface ITesterConfig {
55
53
  testConfig?: TTestConfig<ECompilerType>;
56
54
  compilerFactories?: TCompilerFactories<ECompilerType>;
57
55
  contextValue?: Record<string, unknown>;
58
- runnerFactory?: new (name: string, context: ITestContext) => TRunnerFactory<ECompilerType>;
56
+ runnerCreator?: TTestRunnerCreator;
57
+ createContext?: (config: ITesterConfig) => ITestContext;
59
58
  }
60
59
  export interface ITester {
61
60
  step: number;
@@ -72,11 +71,11 @@ export interface ITestProcessor {
72
71
  afterAll?(context: ITestContext): Promise<void>;
73
72
  before?(context: ITestContext): Promise<void>;
74
73
  after?(context: ITestContext): Promise<void>;
75
- config?(context: ITestContext): Promise<void>;
76
- compiler?(context: ITestContext): Promise<void>;
77
- build?(context: ITestContext): Promise<void>;
78
- run?(env: ITestEnv, context: ITestContext): Promise<void>;
79
- check?(env: ITestEnv, context: ITestContext): Promise<unknown>;
74
+ config(context: ITestContext): Promise<void>;
75
+ compiler(context: ITestContext): Promise<void>;
76
+ build(context: ITestContext): Promise<void>;
77
+ run(env: ITestEnv, context: ITestContext): Promise<void>;
78
+ check(env: ITestEnv, context: ITestContext): Promise<unknown>;
80
79
  }
81
80
  export interface ITestReporter<T> {
82
81
  init(data?: T): Promise<void>;
@@ -163,9 +162,41 @@ export type TCompilerFactory<T extends ECompilerType> = (options: TCompilerOptio
163
162
  export interface TRunnerFactory<T extends ECompilerType> {
164
163
  create(file: string, compilerOptions: TCompilerOptions<T>, env: ITestEnv): ITestRunner;
165
164
  }
166
- export type TUpdateOptions = {
165
+ export type THotUpdateContext = {
167
166
  updateIndex: number;
168
167
  totalUpdates: number;
169
168
  changedFiles: string[];
170
169
  };
171
170
  export type TCompilerFactories<T extends ECompilerType> = Record<T, TCompilerFactory<T>>;
171
+ export type TRunnerRequirer = (currentDirectory: string, modulePath: string[] | string, context?: {
172
+ file?: TRunnerFile;
173
+ esmMode?: EEsmMode;
174
+ }) => Object | Promise<Object>;
175
+ export type TRunnerFile = {
176
+ path: string;
177
+ content: string;
178
+ subPath: string;
179
+ };
180
+ export declare enum EEsmMode {
181
+ Unknown = 0,
182
+ Evaluated = 1,
183
+ Unlinked = 2
184
+ }
185
+ export interface IModuleScope extends ITestEnv {
186
+ console: Record<string, (...args: any[]) => void>;
187
+ expect: jest.Expect;
188
+ [key: string]: any;
189
+ }
190
+ export interface IGlobalContext {
191
+ console: Record<string, (...args: any[]) => void>;
192
+ setTimeout: typeof setTimeout;
193
+ clearTimeout: typeof clearTimeout;
194
+ [key: string]: any;
195
+ }
196
+ export type TModuleObject = {
197
+ exports: unknown;
198
+ };
199
+ export type TTestRunnerCreator = {
200
+ key: (context: ITestContext, name: string, file: string) => string;
201
+ runner: (context: ITestContext, name: string, file: string, env: ITestEnv) => ITestRunner;
202
+ };
package/dist/type.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  /// <reference types="../jest.d.ts" />
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.EDocumentType = exports.ECompareResultType = exports.ECompilerType = void 0;
4
+ exports.EEsmMode = exports.EDocumentType = exports.ECompareResultType = exports.ECompilerType = void 0;
5
5
  var ECompilerType;
6
6
  (function (ECompilerType) {
7
7
  ECompilerType["Rspack"] = "rspack";
@@ -20,3 +20,9 @@ var EDocumentType;
20
20
  EDocumentType["Fake"] = "fake";
21
21
  EDocumentType["JSDOM"] = "jsdom";
22
22
  })(EDocumentType || (exports.EDocumentType = EDocumentType = {}));
23
+ var EEsmMode;
24
+ (function (EEsmMode) {
25
+ EEsmMode[EEsmMode["Unknown"] = 0] = "Unknown";
26
+ EEsmMode[EEsmMode["Evaluated"] = 1] = "Evaluated";
27
+ EEsmMode[EEsmMode["Unlinked"] = 2] = "Unlinked";
28
+ })(EEsmMode || (exports.EEsmMode = EEsmMode = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack-canary/test-tools",
3
- "version": "1.5.6-canary-e598f284-20250921173624",
3
+ "version": "1.5.8-canary-e350b761-20250924173613",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -100,10 +100,10 @@
100
100
  "wast-loader": "^1.14.1",
101
101
  "worker-rspack-loader": "^3.1.2",
102
102
  "exports-loader": "^5.0.0",
103
- "@rspack/cli": "npm:@rspack-canary/cli@1.5.6-canary-e598f284-20250921173624",
104
- "@rspack/core": "npm:@rspack-canary/core@1.5.6-canary-e598f284-20250921173624",
105
- "@rspack/binding-testing": "1.4.1",
106
- "@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.6-canary-e598f284-20250921173624"
103
+ "@rspack/cli": "npm:@rspack-canary/cli@1.5.8-canary-e350b761-20250924173613",
104
+ "@rspack/core": "npm:@rspack-canary/core@1.5.8-canary-e350b761-20250924173613",
105
+ "@rspack/test-tools": "npm:@rspack-canary/test-tools@1.5.8-canary-e350b761-20250924173613",
106
+ "@rspack/binding-testing": "1.4.1"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "@rspack/core": ">=1.0.0"
@@ -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,147 +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.noTests)
42
- return;
43
- if (testConfig.documentType) {
44
- context.setValue(this._options.name, "documentType", testConfig.documentType);
45
- }
46
- const compiler = this.getCompiler(context);
47
- if (typeof testConfig.beforeExecute === "function") {
48
- testConfig.beforeExecute(compiler.getOptions());
49
- }
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(compiler.getOptions());
87
- }
88
- }
89
- async check(env, context) {
90
- const testConfig = context.getTestConfig();
91
- if (testConfig.noTests)
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
- const options = compiler.getOptions();
101
- if (stats) {
102
- if (testConfig.writeStatsOuptut) {
103
- node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.txt"), stats.toString({
104
- preset: "verbose",
105
- colors: false
106
- }), "utf-8");
107
- }
108
- if (testConfig.writeStatsJson) {
109
- const jsonStats = stats.toJson({
110
- errorDetails: true
111
- });
112
- node_fs_1.default.writeFileSync(node_path_1.default.join(context.getDist(), "stats.json"), JSON.stringify(jsonStats, null, 2), "utf-8");
113
- }
114
- if (node_fs_1.default.existsSync(context.getSource("errors.js")) ||
115
- node_fs_1.default.existsSync(context.getSource("warnings.js")) ||
116
- stats.hasErrors() ||
117
- stats.hasWarnings()) {
118
- const statsJson = stats.toJson({
119
- errorDetails: true
120
- });
121
- if (statsJson.errors) {
122
- errors.push(...statsJson.errors);
123
- }
124
- if (statsJson.warnings) {
125
- warnings.push(...statsJson.warnings);
126
- }
127
- }
128
- }
129
- await (0, checkArrayExpectation_1.default)(context.getSource(), { errors }, "error", "errors", "Error", options);
130
- await (0, checkArrayExpectation_1.default)(context.getSource(), { warnings }, "warning", "warnings", "Warning", options);
131
- // clear error if checked
132
- if (node_fs_1.default.existsSync(context.getSource("errors.js"))) {
133
- context.clearError(this._options.name);
134
- }
135
- }
136
- async before(context) { }
137
- async after(context) { }
138
- async beforeAll(context) { }
139
- async afterAll(context) {
140
- const compiler = this.getCompiler(context);
141
- await compiler.close();
142
- }
143
- getCompiler(context) {
144
- return context.getCompiler(this._options.name, this._options.compilerType);
145
- }
146
- }
147
- 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
- }