Skip to content

Commit

Permalink
test(incremental): enable more webpack watch tests (#9392)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk authored Feb 20, 2025
1 parent f7d50be commit 8b1ebe5
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 51 deletions.
10 changes: 8 additions & 2 deletions packages/rspack-test-tools/etc/test-tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,8 @@ interface IWatchRunnerOptions<T extends ECompilerType = ECompilerType.Rspack> ex
// (undocumented)
isWeb: boolean;
// (undocumented)
state: Record<string, any>;
// (undocumented)
stepName: string;
}

Expand Down Expand Up @@ -1582,7 +1584,7 @@ export type TUpdateOptions = {

// @public (undocumented)
export class WatchProcessor<T extends ECompilerType> extends MultiTaskProcessor<T> {
constructor(_watchOptions: IWatchProcessorOptions<T>);
constructor(_watchOptions: IWatchProcessorOptions<T>, _watchState: Record<string, any>);
// (undocumented)
build(context: ITestContext): Promise<void>;
// (undocumented)
Expand All @@ -1603,6 +1605,8 @@ export class WatchProcessor<T extends ECompilerType> extends MultiTaskProcessor<
run(env: ITestEnv, context: ITestContext): Promise<void>;
// (undocumented)
protected _watchOptions: IWatchProcessorOptions<T>;
// (undocumented)
protected _watchState: Record<string, any>;
}

// @public (undocumented)
Expand All @@ -1626,13 +1630,15 @@ export class WatchRunnerFactory<T extends ECompilerType> extends BasicRunnerFact

// @public (undocumented)
export class WatchStepProcessor<T extends ECompilerType> extends WatchProcessor<T> {
constructor(_watchOptions: IWatchStepProcessorOptions<T>);
constructor(_watchOptions: IWatchStepProcessorOptions<T>, _watchState: Record<string, any>);
// (undocumented)
build(context: ITestContext): Promise<void>;
// (undocumented)
compiler(context: ITestContext): Promise<void>;
// (undocumented)
protected _watchOptions: IWatchStepProcessorOptions<T>;
// (undocumented)
protected _watchState: Record<string, any>;
}

// @public (undocumented)
Expand Down
45 changes: 26 additions & 19 deletions packages/rspack-test-tools/src/case/new-incremental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const watchCreator = new BasicCaseCreator({
},
describe: false,
steps: ({ name, src, temp }) => {
const watchState = {};
const runs = fs
.readdirSync(src)
.sort()
Expand All @@ -74,25 +75,31 @@ const watchCreator = new BasicCaseCreator({

return runs.map((run, index) =>
index === 0
? new WatchProcessor({
name,
stepName: run.name,
tempDir: temp!,
runable: true,
compilerType: ECompilerType.Rspack,
configFiles: ["rspack.config.js", "webpack.config.js"],
experiments: {
incremental: true
}
})
: new WatchStepProcessor({
name,
stepName: run.name,
tempDir: temp!,
runable: true,
compilerType: ECompilerType.Rspack,
configFiles: ["rspack.config.js", "webpack.config.js"]
})
? new WatchProcessor(
{
name,
stepName: run.name,
tempDir: temp!,
runable: true,
compilerType: ECompilerType.Rspack,
configFiles: ["rspack.config.js", "webpack.config.js"],
experiments: {
incremental: true
}
},
watchState
)
: new WatchStepProcessor(
{
name,
stepName: run.name,
tempDir: temp!,
runable: true,
compilerType: ECompilerType.Rspack,
configFiles: ["rspack.config.js", "webpack.config.js"]
},
watchState
)
);
}
});
Expand Down
39 changes: 23 additions & 16 deletions packages/rspack-test-tools/src/case/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const creator = new BasicCaseCreator({
},
describe: false,
steps: ({ name, src, temp }) => {
const watchState = {};
const runs = fs
.readdirSync(src)
.sort()
Expand All @@ -26,22 +27,28 @@ const creator = new BasicCaseCreator({

return runs.map((run, index) =>
index === 0
? new WatchProcessor({
name,
stepName: run.name,
tempDir: temp!,
runable: true,
compilerType: ECompilerType.Rspack,
configFiles: ["rspack.config.js", "webpack.config.js"]
})
: new WatchStepProcessor({
name,
stepName: run.name,
tempDir: temp!,
runable: true,
compilerType: ECompilerType.Rspack,
configFiles: ["rspack.config.js", "webpack.config.js"]
})
? new WatchProcessor(
{
name,
stepName: run.name,
tempDir: temp!,
runable: true,
compilerType: ECompilerType.Rspack,
configFiles: ["rspack.config.js", "webpack.config.js"]
},
watchState
)
: new WatchStepProcessor(
{
name,
stepName: run.name,
tempDir: temp!,
runable: true,
compilerType: ECompilerType.Rspack,
configFiles: ["rspack.config.js", "webpack.config.js"]
},
watchState
)
);
}
});
Expand Down
13 changes: 10 additions & 3 deletions packages/rspack-test-tools/src/processor/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export class WatchProcessor<
protected currentTriggerFilename: string | null = null;
protected lastHash: string | null = null;

constructor(protected _watchOptions: IWatchProcessorOptions<T>) {
constructor(
protected _watchOptions: IWatchProcessorOptions<T>,
protected _watchState: Record<string, any>
) {
super({
overrideOptions: WatchProcessor.overrideOptions<T>(_watchOptions),
findBundle: WatchProcessor.findBundle<T>,
Expand Down Expand Up @@ -79,6 +82,7 @@ export class WatchProcessor<
"watchStepName",
this._watchOptions.stepName
);
context.setValue(this._options.name, "watchState", this._watchState);
await super.run(env, context);
}

Expand Down Expand Up @@ -271,8 +275,11 @@ export interface IWatchStepProcessorOptions<T extends ECompilerType>
export class WatchStepProcessor<
T extends ECompilerType
> extends WatchProcessor<T> {
constructor(protected _watchOptions: IWatchStepProcessorOptions<T>) {
super(_watchOptions);
constructor(
protected _watchOptions: IWatchStepProcessorOptions<T>,
protected _watchState: Record<string, any>
) {
super(_watchOptions, _watchState);
}

async compiler(context: ITestContext): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/src/runner/runner/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ interface IWatchRunnerOptions<T extends ECompilerType = ECompilerType.Rspack>
extends IBasicRunnerOptions<T> {
stepName: string;
isWeb: boolean;
state: Record<string, any>;
}

export class WatchRunner<
T extends ECompilerType = ECompilerType.Rspack
> extends FakeDocumentWebRunner<T> {
private state: Record<string, any> = {};
constructor(protected _watchOptions: IWatchRunnerOptions<T>) {
super(_watchOptions);
}
Expand All @@ -31,7 +31,7 @@ export class WatchRunner<
const moduleScope = super.createModuleScope(requireFn, m, file);
moduleScope.__dirname = path.dirname(file.path);
moduleScope.document = this.globalContext!.document;
moduleScope.STATE = this.state;
moduleScope.STATE = this._watchOptions.state;
moduleScope.WATCH_STEP = this._watchOptions.stepName;
moduleScope.STATS_JSON = this._options.stats;
return moduleScope;
Expand Down
9 changes: 9 additions & 0 deletions packages/rspack-test-tools/src/runner/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ export class WatchRunnerFactory<
throw new Error("Can not get watch step name from context");
}

const state: Record<string, any> | void = this.context.getValue(
this.name,
"watchState"
);
if (!state) {
throw new Error("Can not get watch state from context");
}

const isWeb = Array.isArray(compilerOptions)
? compilerOptions.some(option => {
return option.target === "web" || option.target === "webworker";
Expand All @@ -44,6 +52,7 @@ export class WatchRunnerFactory<
env,
stats,
name: this.name,
state,
stepName,
runInNewContext: isWeb,
isWeb,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ describeByWalk(
},
{
source: path.resolve(__dirname, "../../../tests/webpack-test/watchCases"),
dist: path.resolve(__dirname, `./js/new-incremental/webpack-test/watch`),
exclude: [
/module-concatenation-plugin/,
/missing-module/,
/caching-inner-source/,
/production/,
/warnings-contribute-to-hash/,
/issue-8766/
]
dist: path.resolve(__dirname, `./js/new-incremental/webpack-test/watch`)
}
);

2 comments on commit 8b1ebe5

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏳ Triggered ecosystem ci: Open

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 8b1ebe5 Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2025-02-20 2101c1b) Current Change
10000_big_production-mode_disable-minimize + exec 37.5 s ± 434 ms 37.3 s ± 429 ms -0.64 %
10000_development-mode + exec 1.73 s ± 37 ms 1.72 s ± 16 ms -0.22 %
10000_development-mode_hmr + exec 674 ms ± 4.7 ms 674 ms ± 9 ms -0.06 %
10000_production-mode + exec 2.21 s ± 43 ms 2.18 s ± 44 ms -1.29 %
10000_production-mode_persistent-cold + exec 2.35 s ± 168 ms 2.38 s ± 180 ms +1.40 %
10000_production-mode_persistent-hot + exec 1.59 s ± 22 ms 1.63 s ± 49 ms +2.17 %
arco-pro_development-mode + exec 1.75 s ± 105 ms 1.73 s ± 108 ms -1.06 %
arco-pro_development-mode_hmr + exec 385 ms ± 3.1 ms 385 ms ± 3.1 ms -0.12 %
arco-pro_production-mode + exec 3.57 s ± 201 ms 3.54 s ± 169 ms -0.94 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.65 s ± 103 ms 3.61 s ± 212 ms -0.99 %
arco-pro_production-mode_persistent-cold + exec 3.69 s ± 248 ms 3.61 s ± 207 ms -2.26 %
arco-pro_production-mode_persistent-hot + exec 2.33 s ± 131 ms 2.31 s ± 136 ms -0.94 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.58 s ± 113 ms 3.54 s ± 185 ms -1.21 %
large-dyn-imports_development-mode + exec 1.98 s ± 26 ms 1.99 s ± 34 ms +0.58 %
large-dyn-imports_production-mode + exec 2.04 s ± 53 ms 2.09 s ± 154 ms +2.71 %
threejs_development-mode_10x + exec 1.51 s ± 24 ms 1.52 s ± 19 ms +0.48 %
threejs_development-mode_10x_hmr + exec 776 ms ± 34 ms 780 ms ± 21 ms +0.47 %
threejs_production-mode_10x + exec 5.2 s ± 394 ms 5.13 s ± 85 ms -1.25 %
threejs_production-mode_10x_persistent-cold + exec 5.27 s ± 332 ms 5.19 s ± 81 ms -1.55 %
threejs_production-mode_10x_persistent-hot + exec 4.44 s ± 275 ms 4.4 s ± 31 ms -0.84 %
10000_big_production-mode_disable-minimize + rss memory 8671 MiB ± 16.8 MiB 8666 MiB ± 52.1 MiB -0.06 %
10000_development-mode + rss memory 658 MiB ± 28.2 MiB 652 MiB ± 16.3 MiB -0.88 %
10000_development-mode_hmr + rss memory 1266 MiB ± 241 MiB 1289 MiB ± 284 MiB +1.87 %
10000_production-mode + rss memory 645 MiB ± 23.5 MiB 625 MiB ± 35.3 MiB -3.06 %
10000_production-mode_persistent-cold + rss memory 736 MiB ± 20.5 MiB 731 MiB ± 11.2 MiB -0.67 %
10000_production-mode_persistent-hot + rss memory 728 MiB ± 27.3 MiB 703 MiB ± 36.8 MiB -3.35 %
arco-pro_development-mode + rss memory 580 MiB ± 34.2 MiB 577 MiB ± 26.5 MiB -0.43 %
arco-pro_development-mode_hmr + rss memory 648 MiB ± 49.5 MiB 675 MiB ± 58 MiB +4.17 %
arco-pro_production-mode + rss memory 730 MiB ± 44.8 MiB 706 MiB ± 35.3 MiB -3.32 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 740 MiB ± 22.9 MiB 713 MiB ± 32.4 MiB -3.64 %
arco-pro_production-mode_persistent-cold + rss memory 811 MiB ± 34.9 MiB 806 MiB ± 21.2 MiB -0.67 %
arco-pro_production-mode_persistent-hot + rss memory 671 MiB ± 24 MiB 651 MiB ± 26.6 MiB -2.99 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 736 MiB ± 26.8 MiB 708 MiB ± 17.8 MiB -3.78 %
large-dyn-imports_development-mode + rss memory 652 MiB ± 3.22 MiB 639 MiB ± 5.97 MiB -2.00 %
large-dyn-imports_production-mode + rss memory 537 MiB ± 9.03 MiB 524 MiB ± 5.84 MiB -2.41 %
threejs_development-mode_10x + rss memory 550 MiB ± 25.2 MiB 551 MiB ± 10.4 MiB +0.29 %
threejs_development-mode_10x_hmr + rss memory 1091 MiB ± 142 MiB 1109 MiB ± 134 MiB +1.66 %
threejs_production-mode_10x + rss memory 825 MiB ± 47.2 MiB 825 MiB ± 56.5 MiB +0.03 %
threejs_production-mode_10x_persistent-cold + rss memory 931 MiB ± 39.6 MiB 921 MiB ± 75.3 MiB -1.09 %
threejs_production-mode_10x_persistent-hot + rss memory 811 MiB ± 46.3 MiB 811 MiB ± 46.9 MiB -0.02 %

Please sign in to comment.