Skip to content

Commit

Permalink
fix: should run watch cases test in build assets (#7897)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk authored Sep 13, 2024
1 parent 5ea4a16 commit 0325a3d
Show file tree
Hide file tree
Showing 21 changed files with 86 additions and 103 deletions.
4 changes: 4 additions & 0 deletions packages/rspack-test-tools/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1496,8 +1496,12 @@ export class WatchProcessor<T extends ECompilerType> extends MultiTaskProcessor<
// (undocumented)
compiler(context: ITestContext): Promise<void>;
// (undocumented)
config(context: ITestContext): Promise<void>;
// (undocumented)
protected currentTriggerFilename: string | null;
// (undocumented)
static findBundle<T extends ECompilerType>(index: number, context: ITestContext, options: TCompilerOptions<T>): string | string[];
// (undocumented)
protected lastHash: string | null;
// (undocumented)
static overrideOptions<T extends ECompilerType>({ tempDir, name, experiments, optimization }: IWatchProcessorOptions<T>): (index: number, context: ITestContext, options: TCompilerOptions<ECompilerType>) => void;
Expand Down
52 changes: 50 additions & 2 deletions packages/rspack-test-tools/src/processor/watch.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import fs from "node:fs";
import path from "node:path";
import { merge } from "webpack-merge";

import { ECompilerEvent } from "../compiler";
import { readConfigFile } from "../helper";
import copyDiff from "../helper/legacy/copyDiff";
import type {
ECompilerType,
ITestContext,
ITestEnv,
TCompilerOptions
} from "../type";
import { ConfigProcessor } from "./config";
import { type IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi";

// This file is used to port step number to rspack.config.js/webpack.config.js
Expand Down Expand Up @@ -38,7 +39,7 @@ export class WatchProcessor<
constructor(protected _watchOptions: IWatchProcessorOptions<T>) {
super({
overrideOptions: WatchProcessor.overrideOptions<T>(_watchOptions),
findBundle: ConfigProcessor.findBundle<T>,
findBundle: WatchProcessor.findBundle<T>,
..._watchOptions
});
}
Expand Down Expand Up @@ -93,6 +94,39 @@ export class WatchProcessor<
);
}

async config(context: ITestContext) {
this.multiCompilerOptions = [];
const caseOptions: TCompilerOptions<T>[] = Array.isArray(
this._multiOptions.configFiles
)
? readConfigFile(
this._multiOptions.configFiles!.map(i => context.getSource(i))
)
: [{}];

for (const [index, options] of caseOptions.entries()) {
const compilerOptions = merge(
typeof this._multiOptions.defaultOptions === "function"
? this._multiOptions.defaultOptions!(index, context)
: {},
options
);

if (typeof this._multiOptions.overrideOptions === "function") {
this._multiOptions.overrideOptions!(index, context, compilerOptions);
}

this.multiCompilerOptions.push(compilerOptions);
}

const compilerOptions =
this.multiCompilerOptions.length === 1
? this.multiCompilerOptions[0]
: this.multiCompilerOptions;
const compiler = this.getCompiler(context);
compiler.setOptions(compilerOptions as any);
}

static overrideOptions<T extends ECompilerType>({
tempDir,
name,
Expand All @@ -108,6 +142,7 @@ export class WatchProcessor<
if (!options.context) options.context = tempDir;
if (!options.entry) options.entry = "./index.js";
if (!options.target) options.target = "async-node";
if (!options.devtool) options.devtool = false;
if (!options.output) options.output = {};
if (!options.output.path) options.output.path = context.getDist();
if (typeof options.output.pathinfo === "undefined")
Expand Down Expand Up @@ -151,6 +186,19 @@ export class WatchProcessor<
).experiments!.rspackFuture!.bundlerInfo!.force ??= false;
};
}

static findBundle<T extends ECompilerType>(
index: number,
context: ITestContext,
options: TCompilerOptions<T>
) {
const testConfig = context.getTestConfig();

if (typeof testConfig.findBundle === "function") {
return testConfig.findBundle!(index, options);
}
return "./bundle.js";
}
}

export interface IWatchStepProcessorOptions<T extends ECompilerType>
Expand Down
1 change: 1 addition & 0 deletions packages/rspack-test-tools/src/runner/runner/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class WatchRunner<
moduleScope.document = this.globalContext!.document;
moduleScope.STATE = this.state;
moduleScope.WATCH_STEP = this._watchOptions.stepName;
moduleScope.STATS_JSON = this._options.stats;
return moduleScope;
}

Expand Down
1 change: 1 addition & 0 deletions packages/rspack-test-tools/tests/NewIncremental.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@ describeByWalk(v("watch (webpack-test)"), (name, src, dist) => {
/caching-inner-source/,
/production/,
/warnings-contribute-to-hash/,
/issue-8766/,
]
});

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import module from "./file";

it("should watch for multiply compiler", function () {
it("should watch for multiply compiler (entry1)", function () {
expect(module).toBe(WATCH_STEP);
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import module from "./file";

it("should watch for multiply compiler", function () {
it("should watch for multiply compiler (entry2)", function () {
expect(module).toBe(WATCH_STEP);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ module.exports = [
{
entry: {
entry1: "./entry1.js"
},
output: {
filename: "./bundle1.js",
}
},
{
entry: {
entry2: "./entry2.js"
},
output: {
filename: "./bundle2.js",
}
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
findBundle(i) {
switch (i) {
case 0:
return `bundle1.js`
case 1:
return `bundle2.js`
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
documentType: 'fake',
findBundle() {
return ['bundle.css', 'bundle.js']
findBundle(i) {
return ["bundle.css", "bundle.js"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {value} from "./module";

it("should have correct export from re-exports", function () {
expect(value).toBe("foo");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {v} from './reexports'
// ...
export const value = '' + v;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import {v} from './reexports'
export const value = '' + v;
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@ module.exports = {
optimization: {
sideEffects: true,
providedExports: true,
},
experiments: {
rspackFuture: {
newIncremental: true
}
}
};

4 comments on commit 0325a3d

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rslib ✅ success
rsbuild ❌ failure
examples ✅ success

@rspack-bot
Copy link

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 (2024-09-13 56a30b4) Current Change
10000_development-mode + exec 2.24 s ± 49 ms 2.22 s ± 35 ms -0.97 %
10000_development-mode_hmr + exec 692 ms ± 15 ms 690 ms ± 10 ms -0.23 %
10000_production-mode + exec 2.84 s ± 28 ms 2.84 s ± 33 ms +0.01 %
arco-pro_development-mode + exec 1.85 s ± 66 ms 1.85 s ± 88 ms -0.44 %
arco-pro_development-mode_hmr + exec 435 ms ± 2 ms 435 ms ± 3.6 ms +0.16 %
arco-pro_production-mode + exec 3.23 s ± 46 ms 3.26 s ± 63 ms +0.96 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.31 s ± 61 ms 3.31 s ± 95 ms -0.11 %
threejs_development-mode_10x + exec 1.7 s ± 12 ms 1.67 s ± 12 ms -1.69 %
threejs_development-mode_10x_hmr + exec 802 ms ± 11 ms 785 ms ± 6.8 ms -2.09 %
threejs_production-mode_10x + exec 5.18 s ± 26 ms 5.2 s ± 30 ms +0.27 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rslib ✅ success
rsbuild ❌ failure
examples ✅ success

@rspack-bot
Copy link

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 (2024-09-13 56a30b4) Current Change
10000_development-mode + exec 2.24 s ± 49 ms 2.23 s ± 40 ms -0.53 %
10000_development-mode_hmr + exec 692 ms ± 15 ms 695 ms ± 21 ms +0.52 %
10000_production-mode + exec 2.84 s ± 28 ms 2.82 s ± 35 ms -0.59 %
arco-pro_development-mode + exec 1.85 s ± 66 ms 1.83 s ± 82 ms -1.33 %
arco-pro_development-mode_hmr + exec 435 ms ± 2 ms 434 ms ± 4.1 ms -0.03 %
arco-pro_production-mode + exec 3.23 s ± 46 ms 3.26 s ± 75 ms +0.96 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.31 s ± 61 ms 3.31 s ± 87 ms 0.00 %
threejs_development-mode_10x + exec 1.7 s ± 12 ms 1.68 s ± 7.1 ms -1.14 %
threejs_development-mode_10x_hmr + exec 802 ms ± 11 ms 781 ms ± 13 ms -2.62 %
threejs_production-mode_10x + exec 5.18 s ± 26 ms 5.17 s ± 21 ms -0.25 %

Please sign in to comment.