Skip to content

Commit 67c5aae

Browse files
authored
test: add configCase for ESM prefetch/preload under neutral target (#20524)
1 parent 4479861 commit 67c5aae

File tree

7 files changed

+101
-0
lines changed

7 files changed

+101
-0
lines changed

test/configCases/target/universal-prefetch-preload/chunk1-a.mjs

Whitespace-only changes.

test/configCases/target/universal-prefetch-preload/chunk1-b.mjs

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default function() {
2+
import(/* webpackPrefetch: true, webpackChunkName: "chunk1-a" */ "./chunk1-a.mjs");
3+
import(/* webpackPreload: true, webpackChunkName: "chunk1-b" */ "./chunk1-b.mjs");
4+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
__webpack_public_path__ = "https://example.com/public/path/";
2+
3+
it("should prefetch and preload child chunks on chunk load", () => {
4+
let link;
5+
const hasBrowser = typeof document !== "undefined";
6+
7+
if (hasBrowser) {
8+
expect(document.head._children).toHaveLength(1);
9+
10+
// Test prefetch from entry chunk
11+
link = document.head._children[0];
12+
expect(link._type).toBe("link");
13+
expect(link.rel).toBe("prefetch");
14+
expect(link.as).toBe("script");
15+
expect(link.href).toBe("https://example.com/public/path/chunk1.mjs");
16+
expect(link.charset).toBe("utf-8");
17+
expect(link.crossOrigin).toBe("anonymous");
18+
}
19+
20+
const promise = import(
21+
/* webpackChunkName: "chunk1", webpackPrefetch: true */ "./chunk1.mjs"
22+
);
23+
24+
if (hasBrowser) {
25+
expect(document.head._children).toHaveLength(2);
26+
27+
// Test preload of chunk1-b
28+
link = document.head._children[1];
29+
expect(link._type).toBe("link");
30+
expect(link.rel).toBe("modulepreload");
31+
expect(link.href).toBe("https://example.com/public/path/chunk1-b.mjs");
32+
expect(link.charset).toBe("utf-8");
33+
expect(link.crossOrigin).toBe("anonymous");
34+
}
35+
36+
return promise.then(() => {
37+
if (hasBrowser) {
38+
expect(document.head._children).toHaveLength(3);
39+
40+
// Test prefetch of chunk1-a
41+
link = document.head._children[2];
42+
expect(link._type).toBe("link");
43+
expect(link.rel).toBe("prefetch");
44+
expect(link.as).toBe("script");
45+
expect(link.href).toBe("https://example.com/public/path/chunk1-a.mjs");
46+
expect(link.crossOrigin).toBe("anonymous");
47+
}
48+
});
49+
});
50+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
3+
module.exports = {
4+
moduleScope(scope, options) {
5+
if (options.name.includes("node")) {
6+
delete scope.window;
7+
delete scope.document;
8+
delete scope.self;
9+
}
10+
},
11+
findBundle() {
12+
return "./bundle0.mjs";
13+
}
14+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
const supportsGlobalThis = require("../../../helpers/supportsGlobalThis");
4+
5+
module.exports = () => supportsGlobalThis();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
3+
const base = {
4+
target: ["web", "node"],
5+
entry: "./index.mjs",
6+
experiments: {
7+
outputModule: true
8+
},
9+
output: {
10+
publicPath: "",
11+
module: true,
12+
filename: "bundle0.mjs",
13+
chunkFilename: "[name].mjs",
14+
crossOriginLoading: "anonymous"
15+
},
16+
performance: {
17+
hints: false
18+
},
19+
optimization: {
20+
minimize: false
21+
}
22+
};
23+
24+
/** @type {import("../../../../").Configuration[]} */
25+
module.exports = [
26+
{ name: "web", ...base },
27+
{ name: "node", ...base }
28+
];

0 commit comments

Comments
 (0)