2017-12-04 19:07:43 +08:00
|
|
|
it("should receive a namespace object when importing commonjs", function(done) {
|
|
|
|
import("./cjs.js").then(function(result) {
|
2018-07-10 18:18:34 +08:00
|
|
|
expect(result).toEqual(nsObj({ default: { named: "named", default: "default" } }));
|
2017-12-04 19:07:43 +08:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should receive a namespace object when importing commonjs with __esModule", function(done) {
|
|
|
|
import("./cjs-esmodule.js").then(function(result) {
|
2018-07-10 18:18:34 +08:00
|
|
|
expect(result).toEqual(nsObj({ default: { __esModule: true, named: "named", default: "default" } }));
|
2017-12-04 19:07:43 +08:00
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
function contextCJS(name) {
|
|
|
|
return Promise.all([
|
|
|
|
import(`./dir-cjs/${name}.js`),
|
|
|
|
import(/* webpackMode: "lazy-once" */`./dir-cjs?1/${name}.js`),
|
|
|
|
import(/* webpackMode: "eager" */`./dir-cjs?2/${name}.js`)
|
|
|
|
]).then(function(results) {
|
|
|
|
return import(/* webpackMode: "weak" */`./dir-cjs/${name}.js`).then(function(r) {
|
|
|
|
results.push(r);
|
|
|
|
return results;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextHarmony(name) {
|
|
|
|
return Promise.all([
|
|
|
|
import(`./dir-harmony/${name}.js`),
|
|
|
|
import(/* webpackMode: "lazy-once" */`./dir-harmony?1/${name}.js`),
|
|
|
|
import(/* webpackMode: "eager" */`./dir-harmony?2/${name}.js`)
|
|
|
|
]).then(function(results) {
|
|
|
|
return import(/* webpackMode: "weak" */`./dir-harmony/${name}.js`).then(function(r) {
|
|
|
|
results.push(r);
|
|
|
|
return results;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextMixed(name) {
|
|
|
|
return Promise.all([
|
2018-05-29 06:45:39 +08:00
|
|
|
import(`./dir-mixed/${name}`),
|
|
|
|
import(/* webpackMode: "lazy-once" */`./dir-mixed?1/${name}`),
|
|
|
|
import(/* webpackMode: "eager" */`./dir-mixed?2/${name}`)
|
2017-12-04 19:07:43 +08:00
|
|
|
]).then(function(results) {
|
2018-05-29 06:45:39 +08:00
|
|
|
return import(/* webpackMode: "weak" */`./dir-mixed/${name}`).then(function(r) {
|
2017-12-04 19:07:43 +08:00
|
|
|
results.push(r);
|
|
|
|
return results;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function promiseTest(promise, equalsTo) {
|
|
|
|
return promise.then(function(results) {
|
2019-12-05 05:54:26 +08:00
|
|
|
expect(results).toEqual(results.map(() => equalsTo));
|
2017-12-04 19:07:43 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
it("should receive a namespace object when importing commonjs via context", function() {
|
|
|
|
return Promise.all([
|
2018-07-10 18:18:34 +08:00
|
|
|
promiseTest(contextCJS("one"), nsObj({ default: { named: "named", default: "default" } })),
|
|
|
|
promiseTest(contextCJS("two"), nsObj({ default: { __esModule: true, named: "named", default: "default" } })),
|
|
|
|
promiseTest(contextCJS("three"), nsObj({ default: { named: "named", default: "default" } })),
|
|
|
|
promiseTest(contextCJS("null"), nsObj({ default: null }))
|
2017-12-04 19:07:43 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should receive a namespace object when importing harmony via context", function() {
|
|
|
|
return Promise.all([
|
2018-07-10 18:18:34 +08:00
|
|
|
promiseTest(contextHarmony("one"), nsObj({ named: "named", default: "default" })),
|
|
|
|
promiseTest(contextHarmony("two"), nsObj({ named: "named", default: "default" })),
|
|
|
|
promiseTest(contextHarmony("three"), nsObj({ named: "named", default: "default" }))
|
2017-12-04 19:07:43 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should receive a namespace object when importing mixed content via context", function() {
|
|
|
|
return Promise.all([
|
2018-07-10 18:18:34 +08:00
|
|
|
promiseTest(contextMixed("one"), nsObj({ default: { named: "named", default: "default" } })),
|
|
|
|
promiseTest(contextMixed("two"), nsObj({ default: { __esModule: true, named: "named", default: "default" } })),
|
|
|
|
promiseTest(contextMixed("three"), nsObj({ named: "named", default: "default" })),
|
|
|
|
promiseTest(contextMixed("null"), nsObj({ default: null })),
|
2019-11-20 17:06:16 +08:00
|
|
|
promiseTest(contextMixed("json.json"), nsObj({ default: { named: "named", default: "default" } }))
|
2017-12-04 19:07:43 +08:00
|
|
|
]);
|
|
|
|
});
|