Skip to content

Commit 396e59a

Browse files
authored
fix: modify lazy compilation tests (#11349)
* fix: modify lazy-compilation tests * fix: should use specific runtime to get target url
1 parent 614340a commit 396e59a

File tree

22 files changed

+124
-148
lines changed

22 files changed

+124
-148
lines changed

packages/rspack-test-tools/src/plugin/lazy-compilation-test-plugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ export class LazyCompilationTestPlugin {
2222
: `${protocol}://${addr.address}:${addr.port}`;
2323
if (compiler instanceof MultiCompiler) {
2424
for (const c of compiler.compilers) {
25-
if (c.options.experiments.lazyCompilation) {
26-
c.options.experiments.lazyCompilation.serverUrl = urlBase;
25+
if (c.options.lazyCompilation) {
26+
c.options.lazyCompilation.serverUrl = urlBase;
2727
}
2828
}
29-
} else if (compiler.options.experiments.lazyCompilation) {
30-
compiler.options.experiments.lazyCompilation.serverUrl = urlBase;
29+
} else if (compiler.options.lazyCompilation) {
30+
compiler.options.lazyCompilation.serverUrl = urlBase;
3131
}
3232
middleware = experiments.lazyCompilationMiddleware(compiler);
3333

packages/rspack-test-tools/src/processor/hot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class HotProcessor<T extends ECompilerType> extends BasicProcessor<T> {
175175
};
176176
}
177177

178-
if (options.experiments?.lazyCompilation) {
178+
if ((options as TCompilerOptions<ECompilerType.Rspack>).lazyCompilation) {
179179
(options as TCompilerOptions<ECompilerType.Rspack>).plugins!.push(
180180
new LazyCompilationTestPlugin()
181181
);

packages/rspack-test-tools/tests/hotCases/lazy-compilation/context/webpack.config.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
/** @type {import("@rspack/core").Configuration} */
44
module.exports = {
5-
experiments: {
6-
lazyCompilation: {
7-
cacheable: false,
8-
entries: false,
9-
imports: true
10-
}
5+
lazyCompilation: {
6+
cacheable: false,
7+
entries: false,
8+
imports: true
119
}
1210
};

packages/rspack-test-tools/tests/hotCases/lazy-compilation/module-test/webpack.config.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
/** @type {import("@rspack/core").Configuration} */
44
module.exports = {
5-
experiments: {
6-
lazyCompilation: {
7-
entries: false,
8-
cacheable: false,
9-
test: /moduleA/
10-
}
5+
lazyCompilation: {
6+
entries: false,
7+
cacheable: false,
8+
test: /moduleA/
119
}
1210
};

packages/rspack-test-tools/tests/hotCases/lazy-compilation/only-entries/webpack.config.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
/** @type {import("@rspack/core").Configuration} */
44
module.exports = {
5-
experiments: {
6-
lazyCompilation: {
7-
entries: false,
8-
imports: false
9-
}
5+
lazyCompilation: {
6+
entries: false,
7+
imports: false
108
}
119
};

packages/rspack-test-tools/tests/hotCases/lazy-compilation/simple/webpack.config.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
/** @type {import("@rspack/core").Configuration} */
44
module.exports = {
5-
experiments: {
6-
lazyCompilation: {
7-
entries: false,
8-
cacheable: false
9-
}
5+
lazyCompilation: {
6+
entries: false,
7+
cacheable: false
108
}
119
};

packages/rspack-test-tools/tests/hotCases/lazy-compilation/unrelated/webpack.config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
/** @type {import("@rspack/core").Configuration} */
44
module.exports = {
5-
experiments: {
6-
lazyCompilation: {
7-
entries: false
8-
}
5+
lazyCompilation: {
6+
entries: false
97
}
108
};

tests/e2e/cases/lazy-compilation/css-update/rspack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ module.exports = {
1616
plugins: [new rspack.HtmlRspackPlugin(), new rspack.CssExtractRspackPlugin()],
1717
experiments: {
1818
css: false,
19-
lazyCompilation: true
2019
},
20+
lazyCompilation: true,
2121
optimization: {
2222
splitChunks: {
2323
minSize: 0,

tests/e2e/cases/lazy-compilation/custom-prefix/rspack.config.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ module.exports = {
99
stats: "none",
1010
mode: "development",
1111
plugins: [new rspack.HtmlRspackPlugin()],
12-
experiments: {
13-
lazyCompilation: {
14-
entries: true,
15-
imports: true,
16-
// Set custom prefix for lazy compilation
17-
prefix: "/custom-lazy-endpoint-"
18-
}
19-
},
12+
lazyCompilation: {
13+
entries: true,
14+
imports: true,
15+
// Set custom prefix for lazy compilation
16+
prefix: "/custom-lazy-endpoint-"
17+
},
2018
devServer: {
2119
hot: true
2220
}
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
import { expect, test } from "@/fixtures";
22

33
test("should use default prefix for lazy compilation", async ({ page }) => {
4-
// Wait for a request with default prefix
5-
const responsePromise = page.waitForResponse(
6-
response =>
7-
response.url().includes("/lazy-compilation-using-") &&
8-
response.request().method() === "GET",
9-
{ timeout: 5000 }
10-
);
4+
// Wait for a request with default prefix
5+
const responsePromise = page.waitForResponse(
6+
response => {
7+
console.log(`server url: ${response.url()}`)
8+
return response.url().includes("/lazy-compilation-using-") &&
9+
response.request().method() === "GET"
10+
},
11+
{ timeout: 5000 }
12+
);
1113

12-
// Click the button that triggers dynamic import
13-
await page.getByText("Click me").click();
14+
// Click the button that triggers dynamic import
15+
await page.getByText("Click me").click();
1416

15-
// Wait for response with default prefix
16-
const response = await responsePromise;
17-
expect(response.status()).toBe(200);
17+
// Wait for response with default prefix
18+
const response = await responsePromise;
19+
expect(response.status()).toBe(200);
1820

19-
// Wait for the component to appear with a more reliable wait
20-
await page.waitForSelector('div:has-text("Component")', { timeout: 5000 });
21+
// Wait for the component to appear with a more reliable wait
22+
await page.waitForSelector('div:has-text("Component")', { timeout: 5000 });
2123

22-
// Check that the component was loaded and displayed
23-
const component_count = await page.getByText("Component").count();
24-
expect(component_count).toBe(1);
24+
// Check that the component was loaded and displayed
25+
const component_count = await page.getByText("Component").count();
26+
expect(component_count).toBe(1);
2527

26-
// Verify that the request was made using the default prefix
27-
expect(response.url()).toContain("/lazy-compilation-using-");
28+
// Verify that the request was made using the default prefix
29+
expect(response.url()).toContain("/lazy-compilation-using-");
2830
});

0 commit comments

Comments
 (0)