2018-05-07 21:26:04 +08:00
|
|
|
const chunkLoadingSpy = jest.spyOn(__webpack_require__, "e");
|
2017-05-31 11:56:34 +08:00
|
|
|
|
2021-07-08 18:16:14 +08:00
|
|
|
it("should not have duplicate chunks in blocks", function (done) {
|
|
|
|
let i = 0;
|
|
|
|
const d = () => {
|
|
|
|
if (i++ >= 3) done();
|
|
|
|
};
|
|
|
|
|
2018-06-20 00:21:09 +08:00
|
|
|
// This split point should contain: a
|
|
|
|
require.ensure(
|
|
|
|
[],
|
2021-07-08 18:16:14 +08:00
|
|
|
function (require) {
|
2018-06-20 00:21:09 +08:00
|
|
|
expect(require("./a")).toBe("a");
|
2021-07-08 18:16:14 +08:00
|
|
|
d();
|
2018-06-20 00:21:09 +08:00
|
|
|
},
|
|
|
|
"a"
|
|
|
|
);
|
2017-05-31 11:56:34 +08:00
|
|
|
|
2018-06-20 00:21:09 +08:00
|
|
|
// 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(
|
|
|
|
[],
|
2021-07-08 18:16:14 +08:00
|
|
|
function (require) {
|
2018-06-20 00:21:09 +08:00
|
|
|
expect(require("./a")).toBe("a");
|
|
|
|
expect(require("./b")).toBe("b");
|
2021-07-08 18:16:14 +08:00
|
|
|
d();
|
2018-06-20 00:21:09 +08:00
|
|
|
},
|
|
|
|
"a+b"
|
|
|
|
);
|
2017-05-31 11:56:34 +08:00
|
|
|
|
2018-06-20 00:21:09 +08:00
|
|
|
// 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(
|
|
|
|
[],
|
2021-07-08 18:16:14 +08:00
|
|
|
function (require) {
|
2018-06-20 00:21:09 +08:00
|
|
|
expect(require("./a")).toBe("a");
|
|
|
|
expect(require("./b")).toBe("b");
|
|
|
|
expect(require("./c")).toBe("c");
|
2021-07-08 18:16:14 +08:00
|
|
|
d();
|
2018-06-20 00:21:09 +08:00
|
|
|
},
|
|
|
|
"a+b+c"
|
|
|
|
);
|
2017-05-31 11:56:34 +08:00
|
|
|
|
2018-06-20 00:21:09 +08:00
|
|
|
// Each of the require.ensures above should end up resolving chunks:
|
|
|
|
// - a
|
|
|
|
// - a, a+b
|
|
|
|
// - a, a+b, a+b+c
|
2018-05-07 21:26:04 +08:00
|
|
|
expect(chunkLoadingSpy.mock.calls.length).toBe(6);
|
2018-06-20 00:21:09 +08:00
|
|
|
expect(chunkLoadingSpy.mock.calls).toEqual([
|
|
|
|
["a"],
|
|
|
|
["a"],
|
|
|
|
["a+b" /* == b */],
|
|
|
|
["a"],
|
|
|
|
["a+b" /* == b */],
|
|
|
|
["a+b+c" /* == c */]
|
|
|
|
]);
|
2021-07-08 18:16:14 +08:00
|
|
|
d();
|
2017-05-31 11:56:34 +08:00
|
|
|
});
|