Skip to content

Commit 3fa009a

Browse files
test: cover async loading of chunks initial for another entry with a shared runtime (#22673)
1 parent f16c5fb commit 3fa009a

56 files changed

Lines changed: 662 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as styles from "./shared.module.css";
2+
3+
export const value = styles.title;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
it("should load a css modules chunk that is initial for another entry", async () => {
2+
const { value } = await import("./feature.js");
3+
expect(value).toMatch(/title/);
4+
if (typeof document !== "undefined") {
5+
const links = document.getElementsByTagName("link");
6+
expect(links).toHaveLength(1);
7+
expect(links[0].rel).toBe("stylesheet");
8+
expect(links[0].href).toContain("shared.");
9+
await import("./feature.js");
10+
expect(document.getElementsByTagName("link")).toHaveLength(1);
11+
}
12+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.title {
2+
color: red;
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
module.exports = {
4+
evaluateScriptOnAttached: true,
5+
findBundle(index, options) {
6+
const extension = options.output.module ? "mjs" : "js";
7+
return [`runtime.${index}.${extension}`, `main.${index}.${extension}`];
8+
}
9+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration[]} */
4+
module.exports = [
5+
{ target: "web", output: { module: false } },
6+
{ target: "web", output: { module: true } },
7+
{ target: ["web", "node"], output: { module: true } }
8+
].map((options, index) => ({
9+
...options,
10+
mode: "development",
11+
devtool: false,
12+
entry: {
13+
main: "./index.js",
14+
other: "./feature.js"
15+
},
16+
experiments: { css: true },
17+
output: {
18+
...options.output,
19+
filename: `[name].${index}.${options.output.module ? "mjs" : "js"}`,
20+
chunkFilename: `[name].${index}.${options.output.module ? "mjs" : "js"}`,
21+
cssFilename: `[name].${index}.css`,
22+
cssChunkFilename: `[name].${index}.css`,
23+
publicPath: ""
24+
},
25+
optimization: {
26+
runtimeChunk: "single",
27+
splitChunks: {
28+
cacheGroups: {
29+
default: false,
30+
defaultVendors: false,
31+
shared: {
32+
test: /shared\.module\.css$/,
33+
name: "shared",
34+
chunks: "all",
35+
enforce: true
36+
}
37+
}
38+
}
39+
}
40+
}));
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { shared } from "./shared.js";
2+
3+
export const value = `${shared}-feature`;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
it("should load a stylesheet that is initial for a dependOn entry", async () => {
2+
const { value } = await import("./feature.js");
3+
expect(value).toBe("shared-feature");
4+
if (typeof document !== "undefined") {
5+
const links = document.getElementsByTagName("link");
6+
expect(links).toHaveLength(1);
7+
expect(links[0].href).toContain("shared.");
8+
expect(getComputedStyle(document.body).getPropertyValue("color")).toBe(
9+
" red"
10+
);
11+
await import("./feature.js");
12+
expect(document.getElementsByTagName("link")).toHaveLength(1);
13+
}
14+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
color: red;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./shared.css";
2+
3+
export const shared = "shared";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
module.exports = {
4+
evaluateScriptOnAttached: true,
5+
findBundle(index, options) {
6+
const extension = options.output.module ? "mjs" : "js";
7+
return [`runtime.${index}.${extension}`, `main.${index}.${extension}`];
8+
}
9+
};

0 commit comments

Comments
 (0)