-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
/
index.js
58 lines (53 loc) · 1.26 KB
/
index.js
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
52
53
54
55
56
57
58
const chunkLoadingSpy = jest.spyOn(__webpack_require__, "e");
it("should not have duplicate chunks in blocks", function (done) {
let i = 0;
const d = () => {
if (i++ >= 3) done();
};
// This split point should contain: a
require.ensure(
[],
function (require) {
expect(require("./a")).toBe("a");
d();
},
"a"
);
// This split point should contain: a and b - we use CommonsChunksPlugin to
// have it only contain b and make chunk a be an async dependency.
require.ensure(
[],
function (require) {
expect(require("./a")).toBe("a");
expect(require("./b")).toBe("b");
d();
},
"a+b"
);
// This split point should contain: a, b and c - we use CommonsChunksPlugin to
// have it only contain c and make chunks a and a+b be async dependencies.
require.ensure(
[],
function (require) {
expect(require("./a")).toBe("a");
expect(require("./b")).toBe("b");
expect(require("./c")).toBe("c");
d();
},
"a+b+c"
);
// Each of the require.ensures above should end up resolving chunks:
// - a
// - a, a+b
// - a, a+b, a+b+c
expect(chunkLoadingSpy.mock.calls.length).toBe(6);
expect(chunkLoadingSpy.mock.calls).toEqual([
["a"],
["a"],
["a+b" /* == b */],
["a"],
["a+b" /* == b */],
["a+b+c" /* == c */]
]);
d();
});