@rspack/test-tools 1.0.0 → 1.0.2

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.
@@ -1,3 +1,3 @@
1
- import { ECompilerType, type TCompilerOptions } from "../type";
2
- export declare function createHotNewIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
1
+ import { ECompilerType, type EDocumentType, type TCompilerOptions } from "../type";
2
+ export declare function createHotNewIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], documentType: EDocumentType): void;
3
3
  export declare function createWatchNewIncrementalCase(name: string, src: string, dist: string, temp: string): void;
@@ -12,9 +12,10 @@ const runner_1 = require("../runner");
12
12
  const creator_1 = require("../test/creator");
13
13
  const type_1 = require("../type");
14
14
  const hotCreators = new Map();
15
- function getHotCreator(target) {
16
- if (!hotCreators.has(target)) {
17
- hotCreators.set(target, new creator_1.BasicCaseCreator({
15
+ function getHotCreator(target, documentType) {
16
+ const key = JSON.stringify({ target, documentType });
17
+ if (!hotCreators.has(key)) {
18
+ hotCreators.set(key, new creator_1.BasicCaseCreator({
18
19
  clean: true,
19
20
  describe: true,
20
21
  target,
@@ -23,16 +24,17 @@ function getHotCreator(target) {
23
24
  name,
24
25
  target: target,
25
26
  compilerType: type_1.ECompilerType.Rspack,
26
- configFiles: ["rspack.config.js", "webpack.config.js"]
27
+ configFiles: ["rspack.config.js", "webpack.config.js"],
28
+ documentType
27
29
  })
28
30
  ],
29
31
  runner: runner_1.HotRunnerFactory
30
32
  }));
31
33
  }
32
- return hotCreators.get(target);
34
+ return hotCreators.get(key);
33
35
  }
34
- function createHotNewIncrementalCase(name, src, dist, target) {
35
- const creator = getHotCreator(target);
36
+ function createHotNewIncrementalCase(name, src, dist, target, documentType) {
37
+ const creator = getHotCreator(target, documentType);
36
38
  creator.create(name, src, dist);
37
39
  }
38
40
  exports.createHotNewIncrementalCase = createHotNewIncrementalCase;
@@ -1,11 +1,14 @@
1
- import { ECompilerType, type ITestContext, type TCompilerOptions } from "../type";
1
+ import { ECompilerType, EDocumentType, type ITestContext, type ITestEnv, type TCompilerOptions } from "../type";
2
2
  import type { IBasicProcessorOptions } from "./basic";
3
3
  import { HotProcessor } from "./hot";
4
4
  export interface IHotNewIncrementalProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
5
5
  target: TCompilerOptions<T>["target"];
6
+ documentType?: EDocumentType;
6
7
  }
7
8
  export declare class HotNewIncrementalProcessor<T extends ECompilerType> extends HotProcessor<T> {
8
9
  protected _hotOptions: IHotNewIncrementalProcessorOptions<T>;
9
10
  constructor(_hotOptions: IHotNewIncrementalProcessorOptions<T>);
11
+ run(env: ITestEnv, context: ITestContext): Promise<void>;
12
+ afterAll(context: ITestContext): Promise<void>;
10
13
  static defaultOptions<T extends ECompilerType>(this: HotNewIncrementalProcessor<T>, context: ITestContext): TCompilerOptions<T>;
11
14
  }
@@ -8,6 +8,22 @@ class HotNewIncrementalProcessor extends hot_1.HotProcessor {
8
8
  super(_hotOptions);
9
9
  this._hotOptions = _hotOptions;
10
10
  }
11
+ async run(env, context) {
12
+ context.setValue(this._options.name, "documentType", this._hotOptions.documentType);
13
+ await super.run(env, context);
14
+ }
15
+ async afterAll(context) {
16
+ try {
17
+ await super.afterAll(context);
18
+ }
19
+ catch (e) {
20
+ const isFake = context.getValue(this._options.name, "documentType") ===
21
+ type_1.EDocumentType.Fake;
22
+ if (isFake && /Should run all hot steps/.test(e.message))
23
+ return;
24
+ throw e;
25
+ }
26
+ }
11
27
  static defaultOptions(context) {
12
28
  const options = super.defaultOptions(context);
13
29
  if (this._hotOptions.compilerType === type_1.ECompilerType.Rspack) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/test-tools",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -100,8 +100,8 @@
100
100
  "terser": "5.27.2",
101
101
  "typescript": "5.0.2",
102
102
  "wast-loader": "^1.12.1",
103
- "@rspack/cli": "1.0.0",
104
- "@rspack/core": "1.0.0"
103
+ "@rspack/cli": "1.0.2",
104
+ "@rspack/core": "1.0.2"
105
105
  },
106
106
  "peerDependencies": {
107
107
  "@rspack/core": ">=0.7.0"