@rspack/test-tools 1.3.6 → 1.3.7

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,6 @@
1
1
  import { ECompilerType, type EDocumentType, type TCompilerOptions } from "../type";
2
2
  export declare function createHotNewIncrementalCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], documentType: EDocumentType): void;
3
- export declare function createWatchNewIncrementalCase(name: string, src: string, dist: string, temp: string): void;
3
+ export type WatchNewIncrementalOptions = {
4
+ ignoreNotFriendlyForIncrementalWarnings?: boolean;
5
+ };
6
+ export declare function createWatchNewIncrementalCase(name: string, src: string, dist: string, temp: string, options?: WatchNewIncrementalOptions): void;
@@ -39,47 +39,62 @@ function createHotNewIncrementalCase(name, src, dist, target, documentType) {
39
39
  const creator = getHotCreator(target, documentType);
40
40
  creator.create(name, src, dist);
41
41
  }
42
- const watchCreator = new creator_1.BasicCaseCreator({
43
- clean: true,
44
- runner: runner_1.WatchRunnerFactory,
45
- description: (name, index) => {
46
- return index === 0
47
- ? `${name} should compile`
48
- : `should compile the next step ${index}`;
49
- },
50
- describe: false,
51
- steps: ({ name, src, temp }) => {
52
- const watchState = {};
53
- const runs = node_fs_1.default
54
- .readdirSync(src)
55
- .sort()
56
- .filter(name => {
57
- return node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory();
58
- })
59
- .map(name => ({ name }));
60
- return runs.map((run, index) => index === 0
61
- ? new watch_1.WatchProcessor({
62
- name,
63
- stepName: run.name,
64
- tempDir: temp,
65
- runable: true,
66
- compilerType: type_1.ECompilerType.Rspack,
67
- configFiles: ["rspack.config.js", "webpack.config.js"],
68
- experiments: {
69
- incremental: true
70
- }
71
- }, watchState)
72
- : new watch_1.WatchStepProcessor({
73
- name,
74
- stepName: run.name,
75
- tempDir: temp,
76
- runable: true,
77
- compilerType: type_1.ECompilerType.Rspack,
78
- configFiles: ["rspack.config.js", "webpack.config.js"]
79
- }, watchState));
80
- },
81
- concurrent: true
82
- });
83
- function createWatchNewIncrementalCase(name, src, dist, temp) {
84
- watchCreator.create(name, src, dist, temp);
42
+ const watchCreators = new Map();
43
+ function getWatchCreator(options) {
44
+ const key = JSON.stringify(options);
45
+ if (!watchCreators.has(key)) {
46
+ watchCreators.set(key, new creator_1.BasicCaseCreator({
47
+ clean: true,
48
+ runner: runner_1.WatchRunnerFactory,
49
+ description: (name, index) => {
50
+ return index === 0
51
+ ? `${name} should compile`
52
+ : `should compile the next step ${index}`;
53
+ },
54
+ describe: false,
55
+ steps: ({ name, src, temp }) => {
56
+ const watchState = {};
57
+ const runs = node_fs_1.default
58
+ .readdirSync(src)
59
+ .sort()
60
+ .filter(name => {
61
+ return node_fs_1.default.statSync(node_path_1.default.join(src, name)).isDirectory();
62
+ })
63
+ .map(name => ({ name }));
64
+ return runs.map((run, index) => index === 0
65
+ ? new watch_1.WatchProcessor({
66
+ name,
67
+ stepName: run.name,
68
+ tempDir: temp,
69
+ runable: true,
70
+ compilerType: type_1.ECompilerType.Rspack,
71
+ configFiles: ["rspack.config.js", "webpack.config.js"],
72
+ defaultOptions(index, context) {
73
+ return {
74
+ experiments: {
75
+ incremental: true
76
+ },
77
+ ignoreWarnings: options.ignoreNotFriendlyForIncrementalWarnings
78
+ ? [/is not friendly for incremental/]
79
+ : undefined
80
+ };
81
+ }
82
+ }, watchState)
83
+ : new watch_1.WatchStepProcessor({
84
+ name,
85
+ stepName: run.name,
86
+ tempDir: temp,
87
+ runable: true,
88
+ compilerType: type_1.ECompilerType.Rspack,
89
+ configFiles: ["rspack.config.js", "webpack.config.js"]
90
+ }, watchState));
91
+ },
92
+ concurrent: true
93
+ }));
94
+ }
95
+ return watchCreators.get(key);
96
+ }
97
+ function createWatchNewIncrementalCase(name, src, dist, temp, options = {}) {
98
+ const creator = getWatchCreator(options);
99
+ creator.create(name, src, dist, temp);
85
100
  }
package/dist/compiler.js CHANGED
@@ -74,6 +74,9 @@ class TestCompilerManager {
74
74
  // This is a workaround for the issue that watchpack cannot detect the file change in time
75
75
  // so we set the poll to 300ms to make it more sensitive to the file change
76
76
  poll: 300,
77
+ // Rspack ignored node_modules and .git by default for better performance, but for tests we
78
+ // want to watch all files, which aligns with webpack's default behavior
79
+ ignored: [],
77
80
  aggregateTimeout: timeout
78
81
  }, (error, newStats) => {
79
82
  this.emitter.emit(ECompilerEvent.Build, error, newStats);
@@ -1,12 +1,8 @@
1
1
  import type { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type";
2
2
  import { type IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";
3
- type TRspackExperiments = TCompilerOptions<ECompilerType>["experiments"];
4
- type TRspackOptimization = TCompilerOptions<ECompilerType>["optimization"];
5
3
  export interface IWatchProcessorOptions<T extends ECompilerType> extends IMultiTaskProcessorOptions<T> {
6
4
  stepName: string;
7
5
  tempDir: string;
8
- experiments?: TRspackExperiments;
9
- optimization?: TRspackOptimization;
10
6
  }
11
7
  export declare class WatchProcessor<T extends ECompilerType> extends MultiTaskProcessor<T> {
12
8
  protected _watchOptions: IWatchProcessorOptions<T>;
@@ -19,7 +15,7 @@ export declare class WatchProcessor<T extends ECompilerType> extends MultiTaskPr
19
15
  run(env: ITestEnv, context: ITestContext): Promise<void>;
20
16
  check(env: ITestEnv, context: ITestContext): Promise<void>;
21
17
  config(context: ITestContext): Promise<void>;
22
- static overrideOptions<T extends ECompilerType>({ tempDir, name, experiments, optimization }: IWatchProcessorOptions<T>): (index: number, context: ITestContext, options: TCompilerOptions<ECompilerType>) => void;
18
+ static overrideOptions<T extends ECompilerType>({ tempDir, name }: IWatchProcessorOptions<T>): (index: number, context: ITestContext, options: TCompilerOptions<ECompilerType>) => void;
23
19
  static findBundle<T extends ECompilerType>(this: IWatchProcessorOptions<T>, index: number, context: ITestContext, options: TCompilerOptions<T>): string | string[];
24
20
  }
25
21
  export interface IWatchStepProcessorOptions<T extends ECompilerType> extends Omit<IWatchProcessorOptions<T>, "experiments" | "optimization"> {
@@ -31,4 +27,3 @@ export declare class WatchStepProcessor<T extends ECompilerType> extends WatchPr
31
27
  compiler(context: ITestContext): Promise<void>;
32
28
  build(context: ITestContext): Promise<void>;
33
29
  }
34
- export {};
@@ -159,7 +159,7 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
159
159
  const compiler = this.getCompiler(context);
160
160
  compiler.setOptions(compilerOptions);
161
161
  }
162
- static overrideOptions({ tempDir, name, experiments, optimization }) {
162
+ static overrideOptions({ tempDir, name }) {
163
163
  return (index, context, options) => {
164
164
  if (!options.mode)
165
165
  options.mode = "development";
@@ -184,25 +184,9 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
184
184
  options.cache.cacheDirectory = cacheDirectory;
185
185
  options.cache.name = `config-${index}`;
186
186
  }
187
- if (experiments) {
188
- if (!options.experiments)
189
- options.experiments = {};
190
- for (const key of Object.keys(experiments)) {
191
- if (options.experiments[key] === undefined)
192
- options.experiments[key] = experiments[key];
193
- }
194
- }
195
- if (optimization) {
196
- if (!options.optimization)
197
- options.optimization = {};
198
- for (const key of Object.keys(optimization)) {
199
- if (options.optimization[key] === undefined)
200
- options.optimization[key] = optimization[key];
201
- }
202
- }
187
+ options.optimization ??= {};
203
188
  options.experiments ??= {};
204
- options.experiments.css ??=
205
- true;
189
+ options.experiments.css ??= true;
206
190
  options.experiments.rspackFuture ??= {};
207
191
  options.experiments.rspackFuture.bundlerInfo ??= {};
208
192
  options.experiments.rspackFuture.bundlerInfo.force ??= false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/test-tools",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -97,9 +97,9 @@
97
97
  "typescript": "^5.7.3",
98
98
  "wast-loader": "^1.14.1",
99
99
  "worker-rspack-loader": "^3.1.2",
100
- "@rspack/cli": "1.3.6",
101
- "@rspack/core": "1.3.6",
102
- "@rspack/test-tools": "1.3.6"
100
+ "@rspack/test-tools": "1.3.7",
101
+ "@rspack/core": "1.3.7",
102
+ "@rspack/cli": "1.3.7"
103
103
  },
104
104
  "peerDependencies": {
105
105
  "@rspack/core": ">=1.0.0"