Skip to content

Commit 732dbb8

Browse files
committed
chore: enable modulepreload unit test
1 parent 8fa30e3 commit 732dbb8

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

packages/vite/src/node/__tests__/plugins/modulePreloadPolyfill/__snapshots__/modulePreloadPolyfill.spec.ts.snap

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,28 @@ exports[`load > doesn't load modulepreload polyfill when format is cjs 1`] = `""
55
exports[`load > loads modulepreload polyfill 1`] = `
66
"(function polyfill() {
77
const relList = document.createElement("link").relList;
8-
if (relList && relList.supports && relList.supports("modulepreload")) {
9-
return;
10-
}
11-
for (const link of document.querySelectorAll('link[rel="modulepreload"]')) {
12-
processPreload(link);
13-
}
8+
if (relList && relList.supports && relList.supports("modulepreload")) return;
9+
for (const link of document.querySelectorAll('link[rel="modulepreload"]')) processPreload(link);
1410
new MutationObserver((mutations) => {
1511
for (const mutation of mutations) {
16-
if (mutation.type !== "childList") {
17-
continue;
18-
}
19-
for (const node of mutation.addedNodes) {
20-
if (node.tagName === "LINK" && node.rel === "modulepreload")
21-
processPreload(node);
22-
}
12+
if (mutation.type !== "childList") continue;
13+
for (const node of mutation.addedNodes) if (node.tagName === "LINK" && node.rel === "modulepreload") processPreload(node);
2314
}
24-
}).observe(document, { childList: true, subtree: true });
15+
}).observe(document, {
16+
childList: true,
17+
subtree: true
18+
});
2519
function getFetchOpts(link) {
2620
const fetchOpts = {};
2721
if (link.integrity) fetchOpts.integrity = link.integrity;
2822
if (link.referrerPolicy) fetchOpts.referrerPolicy = link.referrerPolicy;
29-
if (link.crossOrigin === "use-credentials")
30-
fetchOpts.credentials = "include";
23+
if (link.crossOrigin === "use-credentials") fetchOpts.credentials = "include";
3124
else if (link.crossOrigin === "anonymous") fetchOpts.credentials = "omit";
3225
else fetchOpts.credentials = "same-origin";
3326
return fetchOpts;
3427
}
3528
function processPreload(link) {
36-
if (link.ep)
37-
return;
29+
if (link.ep) return;
3830
link.ep = true;
3931
const fetchOpts = getFetchOpts(link);
4032
fetch(link.href, fetchOpts);

packages/vite/src/node/__tests__/plugins/modulePreloadPolyfill/modulePreloadPolyfill.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ const buildProject = ({ format = 'es' as ModuleFormat } = {}) =>
3737
}) as Promise<RollupOutput>
3838

3939
describe('load', () => {
40-
// NOTE: due to https://github.com/rolldown/rolldown/issues/2828
41-
it.skip('loads modulepreload polyfill', async ({ expect }) => {
40+
it('loads modulepreload polyfill', async ({ expect }) => {
4241
const { output } = await buildProject()
4342
expect(output).toHaveLength(1)
4443
expect(output[0].code).toMatchSnapshot()

0 commit comments

Comments
 (0)