Skip to content

Commit e1afcd4

Browse files
test: stability and avoid extra output (#19974)
1 parent d45073a commit e1afcd4

7 files changed

Lines changed: 62 additions & 32 deletions

File tree

test/configCases/parsing/bom/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as style from "./style.css";
33
import * as text1 from "./text-with-bom.txt";
44
import * as text2 from "./test-without-bom.text";
55

6-
it("should remove BOM", function() {
6+
it("should remove BOM", async function() {
77
const url = new URL("./resource-with-bom.ext", import.meta.url);
88

99
expect(mod).toBeDefined();
@@ -13,7 +13,7 @@ it("should remove BOM", function() {
1313
expect(url).toBeDefined();
1414

1515
const module = "module.js"
16-
const modules = import("./dir/" + module);
16+
const modules = await import("./dir/" + module);
1717

1818
expect(modules).toBeDefined();
1919
});

test/configCases/parsing/bom/test.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const fs = require("fs");
44
const path = require("path");
55

66
module.exports = {
7+
findBundle() {
8+
return ["dir_module_js.bundle0.js", "bundle0.js"];
9+
},
710
afterExecute(options) {
811
const outputPath = options.output.path;
912
const files = fs.readdirSync(outputPath);

test/configCases/parsing/bom/webpack.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ module.exports = {
66
output: {
77
assetModuleFilename: "[name][ext]"
88
},
9+
optimization: {
10+
chunkIds: "named"
11+
},
912
module: {
1013
rules: [
1114
{

test/configCases/web/fetch-priority-2/index.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,52 @@
1-
it("should set fetchPriority", () => {
2-
import(/* webpackFetchPriority: "high" */ "./a");
1+
function abortable(fn) {
2+
return new Promise((resolve) => {
3+
const timeoutId = setTimeout(() => {
4+
fn = undefined;
5+
resolve('Promise resolved after delay');
6+
clearTimeout(timeoutId);
7+
}, 1000);
8+
9+
return fn();
10+
});
11+
}
12+
13+
it("should set fetchPriority", async () => {
14+
abortable(() => import(/* webpackFetchPriority: "high" */ "./a"));
315
expect(document.head._children).toHaveLength(4);
416
const script1 = document.head._children[2];
517
expect(script1._attributes.fetchpriority).toBe("high");
618

7-
import(/* webpackFetchPriority: "low" */ "./b");
19+
abortable(() => import(/* webpackFetchPriority: "low" */ "./b"));
820
expect(document.head._children).toHaveLength(5);
921
const script2 = document.head._children[4];
1022
expect(script2._attributes.fetchpriority).toBe("low");
1123

12-
import(/* webpackFetchPriority: "low" */ "./c");
24+
abortable(() => import(/* webpackFetchPriority: "low" */ "./c"));
1325
expect(document.head._children).toHaveLength(6);
1426
const script3 = document.head._children[5];
1527
expect(script3._attributes.fetchpriority).toBe("low");
1628

17-
import(/* webpackPrefetch: 20, webpackFetchPriority: "auto" */ "./c");
29+
abortable(() => import(/* webpackPrefetch: 20, webpackFetchPriority: "auto" */ "./c"));
1830

19-
import("./d")
31+
abortable(() => import("./d"))
2032
expect(document.head._children).toHaveLength(7);
2133
const script4 = document.head._children[6];
2234
expect(script4._attributes.fetchpriority).toBeUndefined();
2335

24-
import(/* webpackPrefetch: -20 */ "./d3");
36+
abortable(() => import(/* webpackPrefetch: -20 */ "./d3"));
2537
expect(document.head._children).toHaveLength(8);
2638
const script5 = document.head._children[7];
2739
expect(script5._attributes.fetchpriority).toBeUndefined();
2840

2941
const condition = true;
3042

3143
if (!condition) {
32-
import(/* webpackFetchPriority: "high", webpackChunkName: "one" */ "./e");
44+
abortable( () => import(/* webpackFetchPriority: "high", webpackChunkName: "one" */ "./e"));
3345
expect(document.head._children).toHaveLength(9);
3446
const script6 = document.head._children[8];
3547
expect(script6._attributes.fetchpriority).toBe("high");
3648
} else {
37-
import(/* webpackFetchPriority: "low", webpackChunkName: "two" */ "./e");
49+
abortable(() => import(/* webpackFetchPriority: "low", webpackChunkName: "two" */ "./e"));
3850
expect(document.head._children).toHaveLength(9);
3951
const script6 = document.head._children[8];
4052
expect(script6._attributes.fetchpriority).toBe("low");

test/configCases/web/fetch-priority/index.js

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1+
function abortable(fn) {
2+
return new Promise((resolve) => {
3+
const timeoutId = setTimeout(() => {
4+
fn = undefined;
5+
resolve('Promise resolved after delay');
6+
clearTimeout(timeoutId);
7+
}, 1000);
8+
9+
return fn();
10+
});
11+
}
12+
113
it("should set fetchPriority", () => {
214
// Single Chunk
3-
import(/* webpackFetchPriority: "high" */ "./a");
15+
abortable(() => import(/* webpackFetchPriority: "high" */ "./a"));
416
expect(document.head._children).toHaveLength(1);
517
const script1 = document.head._children[0];
618
expect(script1._attributes.fetchpriority).toBe("high");
719

820
// Multiple Chunks
9-
import(/* webpackFetchPriority: "high" */ "./b");
10-
import(/* webpackFetchPriority: "high" */ "./b2");
21+
abortable(() => import(/* webpackFetchPriority: "high" */ "./b"));
22+
abortable(() => import(/* webpackFetchPriority: "high" */ "./b2"));
1123
expect(document.head._children).toHaveLength(4);
1224
const script2 = document.head._children[1];
1325
const script3 = document.head._children[2];
@@ -17,19 +29,19 @@ it("should set fetchPriority", () => {
1729
expect(script4._attributes.fetchpriority).toBe("high");
1830

1931
// Single Chunk, low
20-
import(/* webpackFetchPriority: "low" */ "./c");
32+
abortable(() => import(/* webpackFetchPriority: "low" */ "./c"));
2133
expect(document.head._children).toHaveLength(5);
2234
const script5 = document.head._children[4];
2335
expect(script5._attributes.fetchpriority).toBe("low");
2436

2537
// Single Chunk, auto
26-
import(/* webpackFetchPriority: "auto" */ "./d");
38+
abortable(() => import(/* webpackFetchPriority: "auto" */ "./d"));
2739
expect(document.head._children).toHaveLength(6);
2840
const script6 = document.head._children[5];
2941
expect(script6._attributes.fetchpriority).toBe("auto");
3042

3143
// No fetch priority
32-
import("./e");
44+
abortable(() => import("./e"));
3345
expect(document.head._children).toHaveLength(7);
3446
const script7 = document.head._children[6];
3547
expect(script7._attributes.fetchpriority).toBeUndefined();
@@ -44,49 +56,49 @@ it("should set fetchPriority", () => {
4456
const script8 = document.head._children[7];
4557
expect(script8._attributes.fetchpriority).toBeUndefined();
4658

47-
import(/* webpackFetchPriority: "auto" */ "./g");
59+
abortable(() => import(/* webpackFetchPriority: "auto" */ "./g"));
4860
expect(document.head._children).toHaveLength(9);
4961
const script9 = document.head._children[8];
5062
expect(script9._attributes.fetchpriority).toBe("auto");
5163

52-
import(/* webpackFetchPriority: "unknown" */ "./h.js");
64+
abortable(() => import(/* webpackFetchPriority: "unknown" */ "./h.js"));
5365
expect(document.head._children).toHaveLength(10);
5466
const script10 = document.head._children[9];
5567
expect(script10._attributes.fetchpriority).toBeUndefined();
5668

57-
import(/* webpackFetchPriority: "high" */ "./i");
58-
import(/* webpackFetchPriority: "low" */ "./i");
69+
abortable(() => import(/* webpackFetchPriority: "high" */ "./i"));
70+
abortable(() => import(/* webpackFetchPriority: "low" */ "./i"));
5971
expect(document.head._children).toHaveLength(11);
6072
const script11 = document.head._children[10];
6173
expect(script11._attributes.fetchpriority).toBe("high");
6274

63-
import(/* webpackFetchPriority: "low" */ "./j");
64-
import(/* webpackFetchPriority: "high" */ "./j");
75+
abortable(() => import(/* webpackFetchPriority: "low" */ "./j"));
76+
abortable(() => import(/* webpackFetchPriority: "high" */ "./j"));
6577
expect(document.head._children).toHaveLength(12);
6678
const script12 = document.head._children[11];
6779

6880
expect(script12._attributes.fetchpriority).toBe("low");
69-
import(/* webpackFetchPriority: "low" */ "./k");
70-
import("./e");
71-
import(/* webpackFetchPriority: "high" */ "./k");
72-
expect(document.head._children).toHaveLength(13);
81+
abortable(() => import(/* webpackFetchPriority: "low" */ "./k"));
82+
abortable(() => import("./e"));
83+
abortable(() => import(/* webpackFetchPriority: "high" */ "./k"));
84+
abortable(() => expect(document.head._children).toHaveLength(13));
7385
const script13 = document.head._children[12];
7486
expect(script13._attributes.fetchpriority).toBe("low");
7587

7688
__non_webpack_require__("./125.js");
77-
import(/* webpackFetchPriority: "high" */ "./style.css");
89+
abortable(() => import(/* webpackFetchPriority: "high" */ "./style.css"));
7890
expect(document.head._children).toHaveLength(14);
7991
const link1 = document.head._children[13];
8092
expect(link1._attributes.fetchpriority).toBe("high");
8193

8294
__non_webpack_require__("./499.js");
83-
import("./style-1.css");
95+
abortable(() => import("./style-1.css"));
8496
expect(document.head._children).toHaveLength(15);
8597
const link2 = document.head._children[14];
8698
expect(link2._attributes.fetchpriority).toBeUndefined();
8799

88100
__non_webpack_require__("./616.js");
89-
import(/* webpackFetchPriority: "low" */ "./style-2.css");
101+
abortable(() => import(/* webpackFetchPriority: "low" */ "./style-2.css"));
90102
expect(document.head._children).toHaveLength(16);
91103
const link3 = document.head._children[15];
92104
expect(link3._attributes.fetchpriority).toBe("low");

test/watchCases/cache/loader-import-module-progress/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717
]
1818
},
1919
plugins: [
20-
new webpack.ProgressPlugin(),
20+
new webpack.ProgressPlugin(() => {}),
2121
{
2222
apply(compiler) {
2323
compiler.hooks.done.tapPromise("CacheTest", async () => {

test/watchCases/cache/loader-load-module-progress/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
]
1717
},
1818
plugins: [
19-
new webpack.ProgressPlugin(),
19+
new webpack.ProgressPlugin(() => {}),
2020
{
2121
apply(compiler) {
2222
compiler.hooks.done.tapPromise("CacheTest", async () => {

0 commit comments

Comments
 (0)