@rspack/test-tools 1.3.6 → 1.3.8

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 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: "advance"
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
  }
@@ -16,7 +16,7 @@ const creator = new creator_1.BasicCaseCreator({
16
16
  description: (name, index) => {
17
17
  return index === 0
18
18
  ? `${name} should compile`
19
- : `should compile the next step ${index}`;
19
+ : `should compile step ${index}`;
20
20
  },
21
21
  describe: false,
22
22
  steps: ({ name, src, temp }) => {
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);
@@ -67,6 +67,9 @@ class BasicProcessor {
67
67
  return;
68
68
  }
69
69
  for (const bundle of bundles) {
70
+ if (!bundle) {
71
+ continue;
72
+ }
70
73
  const runnerFactory = context.getRunnerFactory(this._options.name);
71
74
  if (!runnerFactory) {
72
75
  throw new Error(`Test case ${this._options.name} is not runable`);
@@ -29,7 +29,7 @@ class HotNewIncrementalProcessor extends hot_1.HotProcessor {
29
29
  if (this._hotOptions.compilerType === type_1.ECompilerType.Rspack) {
30
30
  const rspackOptions = options;
31
31
  rspackOptions.experiments ??= {};
32
- rspackOptions.experiments.incremental ??= true;
32
+ rspackOptions.experiments.incremental ??= "advance";
33
33
  }
34
34
  else {
35
35
  throw new Error("HotNewIncrementalProcessor should only used for Rspack.");
@@ -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;
@@ -79,34 +79,31 @@ class BasicCaseCreator {
79
79
  });
80
80
  const ender = this.registerConcurrentTask(name, starter);
81
81
  const env = this.createConcurrentEnv();
82
- let bailout = false;
83
82
  for (let index = 0; index < tester.total; index++) {
84
83
  let stepSignalResolve = null;
85
- let stepSignalReject = null;
86
84
  const stepSignal = new Promise((resolve, reject) => {
87
85
  stepSignalResolve = resolve;
88
- stepSignalReject = reject;
86
+ }).catch(e => {
87
+ // prevent unhandled rejection
89
88
  });
90
89
  const description = typeof this._options.description === "function"
91
90
  ? this._options.description(name, index)
92
91
  : index
93
92
  ? `step [${index}] should pass`
94
93
  : "should pass";
95
- it(description, async () => {
96
- await stepSignal;
94
+ it(description, cb => {
95
+ stepSignal.then((e) => {
96
+ cb(e);
97
+ });
97
98
  }, this._options.timeout || 180000);
98
99
  chain = chain.then(async () => {
99
100
  try {
100
- if (bailout) {
101
- throw `Case "${name}" step ${index + 1} bailout because ${tester.step + 1} failed`;
102
- }
103
101
  env.clear();
104
102
  await tester.compile();
105
103
  await tester.check(env);
106
104
  await env.run();
107
105
  const context = tester.getContext();
108
106
  if (!tester.next() && context.hasError()) {
109
- bailout = true;
110
107
  const errors = context
111
108
  .getError()
112
109
  .map(i => `${i.stack}`.split("\n").join("\t\n"))
@@ -116,11 +113,21 @@ class BasicCaseCreator {
116
113
  stepSignalResolve();
117
114
  }
118
115
  catch (e) {
119
- stepSignalReject(e);
116
+ stepSignalResolve(e);
117
+ return Promise.reject();
120
118
  }
119
+ }, e => {
120
+ // bailout
121
+ stepSignalResolve();
122
+ return Promise.reject();
121
123
  });
122
124
  }
123
- chain.finally(() => {
125
+ chain
126
+ .catch(e => {
127
+ // bailout error
128
+ // prevent unhandled rejection
129
+ })
130
+ .finally(() => {
124
131
  ender();
125
132
  });
126
133
  afterAll(async () => {
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.8",
4
4
  "license": "MIT",
5
5
  "description": "Test tools for rspack",
6
6
  "main": "dist/index.js",
@@ -54,12 +54,12 @@
54
54
  "source-map": "^0.7.4",
55
55
  "terser-webpack-plugin": "^5.3.14",
56
56
  "webpack": "5.99.6",
57
- "webpack-merge": "5.10.0",
57
+ "webpack-merge": "6.0.1",
58
58
  "webpack-sources": "3.2.3"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@rspack/plugin-preact-refresh": "1.1.2",
62
- "@rspack/plugin-react-refresh": "^1.2.1",
62
+ "@rspack/plugin-react-refresh": "^1.4.1",
63
63
  "@swc/helpers": "0.5.17",
64
64
  "@swc/plugin-remove-console": "^7.0.3",
65
65
  "@types/babel__generator": "7.27.0",
@@ -94,12 +94,12 @@
94
94
  "source-map-loader": "^5.0.0",
95
95
  "style-loader": "^4.0.0",
96
96
  "terser": "5.39.0",
97
- "typescript": "^5.7.3",
97
+ "typescript": "^5.8.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/cli": "1.3.8",
101
+ "@rspack/test-tools": "1.3.8",
102
+ "@rspack/core": "1.3.8"
103
103
  },
104
104
  "peerDependencies": {
105
105
  "@rspack/core": ">=1.0.0"