mirror of https://github.com/webpack/webpack.git
test: improve logic
This commit is contained in:
parent
a49a5eaa51
commit
aa27e75e6a
|
@ -107,7 +107,10 @@ class ChunkPrefetchPreloadPlugin {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
chunksFetchPriorityMap[c.id] &&
|
chunksFetchPriorityMap[c.id] &&
|
||||||
prefetchOrder > chunksFetchPriorityMap[c.id].prefetchOrder
|
prefetchOrder &&
|
||||||
|
(chunksFetchPriorityMap[c.id].prefetchOrder === undefined ||
|
||||||
|
prefetchOrder >
|
||||||
|
chunksFetchPriorityMap[c.id].prefetchOrder)
|
||||||
) {
|
) {
|
||||||
chunksFetchPriorityMap[c.id] = {
|
chunksFetchPriorityMap[c.id] = {
|
||||||
fetchPriority,
|
fetchPriority,
|
||||||
|
@ -116,7 +119,7 @@ class ChunkPrefetchPreloadPlugin {
|
||||||
} else if (!chunksFetchPriorityMap[c.id]) {
|
} else if (!chunksFetchPriorityMap[c.id]) {
|
||||||
chunksFetchPriorityMap[c.id] = {
|
chunksFetchPriorityMap[c.id] = {
|
||||||
fetchPriority,
|
fetchPriority,
|
||||||
prefetchOrder: prefetchOrder || 0
|
prefetchOrder: prefetchOrder
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
export default function test() {
|
||||||
|
import("./d1");
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
export default function test() {
|
||||||
|
import("./d2");
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
export default function test() {
|
||||||
|
import(/* webpackFetchPriority: "high" */ "./d3");
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
export default "d3";
|
|
@ -1,18 +1,28 @@
|
||||||
it("should set fetchPriority", () => {
|
it("should set fetchPriority", () => {
|
||||||
import("./a");
|
import(/* webpackFetchPriority: "high" */ "./a");
|
||||||
expect(document.head._children).toHaveLength(3);
|
|
||||||
const script1 = document.head._children[1];
|
|
||||||
expect(script1._attributes.fetchpriority).toBe("low");
|
|
||||||
|
|
||||||
import("./b");
|
|
||||||
expect(document.head._children).toHaveLength(4);
|
expect(document.head._children).toHaveLength(4);
|
||||||
const script2 = document.head._children[3];
|
const script1 = document.head._children[2];
|
||||||
|
expect(script1._attributes.fetchpriority).toBe("high");
|
||||||
|
|
||||||
|
import(/* webpackFetchPriority: "low" */ "./b");
|
||||||
|
expect(document.head._children).toHaveLength(5);
|
||||||
|
const script2 = document.head._children[4];
|
||||||
expect(script2._attributes.fetchpriority).toBe("low");
|
expect(script2._attributes.fetchpriority).toBe("low");
|
||||||
|
|
||||||
import( "./c");
|
import(/* webpackFetchPriority: "low" */ "./c");
|
||||||
expect(document.head._children).toHaveLength(5);
|
expect(document.head._children).toHaveLength(6);
|
||||||
const script3 = document.head._children[4];
|
const script3 = document.head._children[5];
|
||||||
expect(script3._attributes.fetchpriority).toBe("auto");
|
expect(script3._attributes.fetchpriority).toBe("auto");
|
||||||
|
|
||||||
import(/* webpackPrefetch: 20, webpackFetchPriority: "auto" */ "./c");
|
import(/* webpackPrefetch: 20, webpackFetchPriority: "auto" */ "./c");
|
||||||
|
|
||||||
|
import("./d")
|
||||||
|
expect(document.head._children).toHaveLength(7);
|
||||||
|
const script4 = document.head._children[6];
|
||||||
|
expect(script4._attributes.fetchpriority).toBeUndefined();
|
||||||
|
|
||||||
|
import(/* webpackPrefetch: -20 */ "./d3");
|
||||||
|
expect(document.head._children).toHaveLength(8);
|
||||||
|
const script5 = document.head._children[7];
|
||||||
|
expect(script5._attributes.fetchpriority).toBe("high");
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,10 +12,15 @@ module.exports = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /d\.js$/,
|
||||||
parser: {
|
parser: {
|
||||||
javascript: {
|
javascript: {
|
||||||
dynamicImportFetchPriority: "low"
|
dynamicImportFetchPriority: "low"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue