2017-12-19 22:50:09 +08:00
|
|
|
it("should be able to use eager mode", function() {
|
2017-05-05 00:37:25 +08:00
|
|
|
function load(name) {
|
2017-07-26 20:49:53 +08:00
|
|
|
return import(/* webpackMode: "eager" */ "./dir1/" + name);
|
2017-05-05 00:37:25 +08:00
|
|
|
}
|
2017-12-19 22:50:09 +08:00
|
|
|
return testChunkLoading(load, true, true);
|
2017-05-05 00:37:25 +08:00
|
|
|
});
|
|
|
|
|
2017-12-19 22:50:09 +08:00
|
|
|
it("should be able to use lazy-once mode", function() {
|
2017-05-05 00:37:25 +08:00
|
|
|
function load(name) {
|
2017-07-26 20:49:53 +08:00
|
|
|
return import(/* webpackMode: "lazy-once" */ "./dir2/" + name);
|
2017-05-05 00:37:25 +08:00
|
|
|
}
|
2017-12-19 22:50:09 +08:00
|
|
|
return testChunkLoading(load, false, true);
|
2017-05-05 00:37:25 +08:00
|
|
|
});
|
|
|
|
|
2017-12-19 22:50:09 +08:00
|
|
|
it("should be able to use lazy-once mode with name", function() {
|
2017-05-05 00:37:25 +08:00
|
|
|
function load(name) {
|
2017-07-26 20:49:53 +08:00
|
|
|
return import(/* webpackMode: "lazy-once", webpackChunkName: "name-lazy-once" */ "./dir3/" + name);
|
2017-05-05 00:37:25 +08:00
|
|
|
}
|
2017-12-19 22:50:09 +08:00
|
|
|
return testChunkLoading(load, false, true);
|
2017-05-05 00:37:25 +08:00
|
|
|
});
|
|
|
|
|
2017-12-19 22:50:09 +08:00
|
|
|
it("should be able to use lazy mode", function() {
|
2017-05-05 00:37:25 +08:00
|
|
|
function load(name) {
|
2017-07-26 20:49:53 +08:00
|
|
|
return import(/* webpackMode: "lazy" */ "./dir4/" + name);
|
2017-05-05 00:37:25 +08:00
|
|
|
}
|
2017-12-19 22:50:09 +08:00
|
|
|
return testChunkLoading(load, false, false);
|
2017-05-05 00:37:25 +08:00
|
|
|
});
|
|
|
|
|
2017-12-19 22:50:09 +08:00
|
|
|
it("should be able to use lazy mode with name", function() {
|
2017-05-05 00:37:25 +08:00
|
|
|
function load(name) {
|
2017-07-26 20:49:53 +08:00
|
|
|
return import(/* webpackMode: "lazy", webpackChunkName: "name-lazy" */ "./dir5/" + name);
|
2017-05-05 00:37:25 +08:00
|
|
|
}
|
2017-12-19 22:50:09 +08:00
|
|
|
return testChunkLoading(load, false, false);
|
2017-05-05 00:37:25 +08:00
|
|
|
});
|
|
|
|
|
2017-12-19 22:50:09 +08:00
|
|
|
it("should be able to use lazy mode with name and placeholder", function() {
|
2017-05-05 00:37:25 +08:00
|
|
|
function load(name) {
|
2017-07-26 20:49:53 +08:00
|
|
|
return import(/* webpackMode: "lazy", webpackChunkName: "name-lazy-[request]" */ "./dir6/" + name);
|
2017-05-05 00:37:25 +08:00
|
|
|
}
|
2017-12-19 22:50:09 +08:00
|
|
|
return testChunkLoading(load, false, false);
|
2017-05-05 00:37:25 +08:00
|
|
|
});
|
|
|
|
|
2017-12-19 22:50:09 +08:00
|
|
|
it("should be able to combine chunks by name", function() {
|
2017-05-05 00:37:25 +08:00
|
|
|
function load(name) {
|
|
|
|
switch(name) {
|
|
|
|
case "a":
|
|
|
|
return import(/* webpackMode: "eager" */ "./dir7/a");
|
|
|
|
case "b":
|
|
|
|
return import(/* webpackChunkName: "name-3" */ "./dir7/b");
|
|
|
|
case "c":
|
|
|
|
return import(/* webpackChunkName: "name-3" */ "./dir7/c");
|
|
|
|
case "d":
|
|
|
|
return import(/* webpackChunkName: "name-3" */ "./dir7/d");
|
|
|
|
default:
|
|
|
|
throw new Error("Unexcepted test data");
|
|
|
|
}
|
|
|
|
}
|
2017-12-19 22:50:09 +08:00
|
|
|
return testChunkLoading(load, false, true);
|
2017-05-05 00:37:25 +08:00
|
|
|
});
|
|
|
|
|
2017-12-19 22:50:09 +08:00
|
|
|
it("should be able to use weak mode", function() {
|
2017-07-26 01:21:02 +08:00
|
|
|
function load(name) {
|
2017-07-26 20:49:37 +08:00
|
|
|
return import(/* webpackMode: "weak" */ "./dir8/" + name);
|
2017-07-26 01:21:02 +08:00
|
|
|
}
|
|
|
|
require("./dir8/a") // chunks served manually by the user
|
|
|
|
require("./dir8/b")
|
|
|
|
require("./dir8/c")
|
2017-12-19 22:50:09 +08:00
|
|
|
return testChunkLoading(load, true, true);
|
2017-07-26 01:21:02 +08:00
|
|
|
});
|
|
|
|
|
2017-12-19 22:50:09 +08:00
|
|
|
it("should be able to use weak mode (without context)", function() {
|
2017-07-26 01:21:02 +08:00
|
|
|
function load(name) {
|
|
|
|
switch(name) {
|
|
|
|
case "a":
|
2017-07-26 20:49:37 +08:00
|
|
|
return import(/* webpackMode: "weak" */ "./dir9/a");
|
2017-07-26 01:21:02 +08:00
|
|
|
case "b":
|
2017-07-26 20:49:37 +08:00
|
|
|
return import(/* webpackMode: "weak" */ "./dir9/b");
|
2017-07-26 01:21:02 +08:00
|
|
|
case "c":
|
2017-07-26 20:49:37 +08:00
|
|
|
return import(/* webpackMode: "weak" */ "./dir9/c");
|
2017-07-26 01:21:02 +08:00
|
|
|
default:
|
|
|
|
throw new Error("Unexcepted test data");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require("./dir9/a") // chunks served manually by the user
|
|
|
|
require("./dir9/b")
|
|
|
|
require("./dir9/c")
|
2017-12-19 22:50:09 +08:00
|
|
|
return testChunkLoading(load, true, true);
|
2017-07-26 01:21:02 +08:00
|
|
|
});
|
|
|
|
|
2017-12-19 22:50:09 +08:00
|
|
|
it("should not find module when mode is weak and chunk not served elsewhere", function() {
|
2017-07-26 01:21:02 +08:00
|
|
|
var name = "a";
|
2017-12-19 22:50:09 +08:00
|
|
|
return import(/* webpackMode: "weak" */ "./dir10/" + name)
|
2017-07-26 01:21:02 +08:00
|
|
|
.catch(function(e) {
|
2017-12-19 22:50:09 +08:00
|
|
|
e.should.match({ message: /not available/, code: /MODULE_NOT_FOUND/ });
|
2017-07-26 01:21:02 +08:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-12-19 22:50:09 +08:00
|
|
|
it("should not find module when mode is weak and chunk not served elsewhere (without context)", function() {
|
|
|
|
return import(/* webpackMode: "weak" */ "./dir11/a")
|
2017-07-26 01:21:02 +08:00
|
|
|
.catch(function(e) {
|
2017-12-19 22:50:09 +08:00
|
|
|
e.should.match({ message: /not available/, code: /MODULE_NOT_FOUND/ });
|
2017-07-26 01:21:02 +08:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2017-12-19 22:50:09 +08:00
|
|
|
function testChunkLoading(load, expectedSyncInitial, expectedSyncRequested) {
|
2017-05-05 00:37:25 +08:00
|
|
|
var sync = false;
|
|
|
|
var syncInitial = true;
|
2017-12-19 22:50:09 +08:00
|
|
|
var p = Promise.all([load("a"), load("b")]).then(function() {
|
2018-01-27 05:51:03 +08:00
|
|
|
expect(syncInitial).toBe(expectedSyncInitial);
|
2017-05-05 00:37:25 +08:00
|
|
|
sync = true;
|
2017-12-19 22:50:09 +08:00
|
|
|
var p = Promise.all([
|
2017-05-05 00:37:25 +08:00
|
|
|
load("a").then(function(a) {
|
2018-01-27 05:51:03 +08:00
|
|
|
expect(a).toEqual({ default: "a" });
|
|
|
|
expect(sync).toBe(true);
|
2017-05-05 00:37:25 +08:00
|
|
|
}),
|
|
|
|
load("c").then(function(c) {
|
2018-01-27 05:51:03 +08:00
|
|
|
expect(c).toEqual({ default: "c" });
|
|
|
|
expect(sync).toBe(expectedSyncRequested);
|
2017-05-05 00:37:25 +08:00
|
|
|
})
|
2017-12-19 22:50:09 +08:00
|
|
|
]);
|
2017-05-05 00:37:25 +08:00
|
|
|
Promise.resolve().then(function(){}).then(function(){}).then(function(){}).then(function(){
|
|
|
|
sync = false;
|
|
|
|
});
|
2017-12-19 22:50:09 +08:00
|
|
|
return p;
|
|
|
|
});
|
2017-05-05 00:37:25 +08:00
|
|
|
Promise.resolve().then(function(){}).then(function(){}).then(function(){}).then(function(){
|
|
|
|
syncInitial = false;
|
|
|
|
});
|
2017-12-19 22:50:09 +08:00
|
|
|
return p;
|
2017-05-05 00:37:25 +08:00
|
|
|
}
|