/
modulePreloadPolyfill.spec.ts.snap
51 lines (49 loc) · 1.52 KB
/
modulePreloadPolyfill.spec.ts.snap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`load > doesn't load modulepreload polyfill when format is cjs 1`] = `
"\\"use strict\\";
"
`;
exports[`load > loads modulepreload polyfill 1`] = `
"(function polyfill() {
const relList = document.createElement(\\"link\\").relList;
if (relList && relList.supports && relList.supports(\\"modulepreload\\")) {
return;
}
for (const link of document.querySelectorAll('link[rel=\\"modulepreload\\"]')) {
processPreload(link);
}
new MutationObserver((mutations) => {
for (const mutation of mutations) {
if (mutation.type !== \\"childList\\") {
continue;
}
for (const node of mutation.addedNodes) {
if (node.tagName === \\"LINK\\" && node.rel === \\"modulepreload\\")
processPreload(node);
}
}
}).observe(document, { childList: true, subtree: true });
function getFetchOpts(link) {
const fetchOpts = {};
if (link.integrity)
fetchOpts.integrity = link.integrity;
if (link.referrerPolicy)
fetchOpts.referrerPolicy = link.referrerPolicy;
if (link.crossOrigin === \\"use-credentials\\")
fetchOpts.credentials = \\"include\\";
else if (link.crossOrigin === \\"anonymous\\")
fetchOpts.credentials = \\"omit\\";
else
fetchOpts.credentials = \\"same-origin\\";
return fetchOpts;
}
function processPreload(link) {
if (link.ep)
return;
link.ep = true;
const fetchOpts = getFetchOpts(link);
fetch(link.href, fetchOpts);
}
})();
"
`;