Skip to content

Commit

Permalink
add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed May 28, 2018
1 parent 7708471 commit 023d4ca
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 6 deletions.
61 changes: 61 additions & 0 deletions test/cases/json/import-lazy/index.js
@@ -0,0 +1,61 @@

it("should be possible to import json data async", function() {
return Promise.all([
import("../data/a.json"),
import("../data/b.json"),
import("../data/c.json"),
import("../data/d.json"),
import("../data/e.json"),
import("../data/f.json"),
import("../data/g.json")
]).then(([a, b, c, d, e, f, g]) => {
expect(a).toEqual({
default: null,
[Symbol.toStringTag]: "Module"
});
expect(b).toEqual({
default: 123,
[Symbol.toStringTag]: "Module"
});
expect(c).toEqual({
0: 1,
1: 2,
2: 3,
3: 4,
default: [1, 2, 3, 4],
[Symbol.toStringTag]: "Module"
});
expect(d).toEqual({
default: {},
[Symbol.toStringTag]: "Module"
});
expect(e).toEqual({
aa: 1,
bb: 2,
1: "x",
default: {
aa: 1,
bb: 2,
"1": "x"
},
[Symbol.toStringTag]: "Module"
});
expect(f).toEqual({
named: "named",
default: {
named: "named",
"default": "default",
__esModule: true
},
[Symbol.toStringTag]: "Module"
});
expect(g).toEqual({
named: {},
default: {
named: {}
},
[Symbol.toStringTag]: "Module"
});
expect(g.named).toBe(g.default.named);
});
});
4 changes: 4 additions & 0 deletions test/cases/mjs/namespace-object-lazy/dir-mixed/json.json
@@ -0,0 +1,4 @@
{
"default": "default",
"named": "named"
}
11 changes: 6 additions & 5 deletions test/cases/mjs/namespace-object-lazy/index.mjs
Expand Up @@ -40,11 +40,11 @@ function contextHarmony(name) {

function contextMixed(name) {
return Promise.all([
import(`./dir-mixed/${name}.js`),
import(/* webpackMode: "lazy-once" */`./dir-mixed?1/${name}.js`),
import(/* webpackMode: "eager" */`./dir-mixed?2/${name}.js`)
import(`./dir-mixed/${name}`),
import(/* webpackMode: "lazy-once" */`./dir-mixed?1/${name}`),
import(/* webpackMode: "eager" */`./dir-mixed?2/${name}`)
]).then(function(results) {
return import(/* webpackMode: "weak" */`./dir-mixed/${name}.js`).then(function(r) {
return import(/* webpackMode: "weak" */`./dir-mixed/${name}`).then(function(r) {
results.push(r);
return results;
});
Expand Down Expand Up @@ -80,6 +80,7 @@ it("should receive a namespace object when importing mixed content via context",
promiseTest(contextMixed("one"), { default: { named: "named", default: "default" }, [Symbol.toStringTag]: "Module" }),
promiseTest(contextMixed("two"), { default: { __esModule: true, named: "named", default: "default" }, [Symbol.toStringTag]: "Module" }),
promiseTest(contextMixed("three"), { named: "named", default: "default", [Symbol.toStringTag]: "Module" }),
promiseTest(contextMixed("null"), { default: null, [Symbol.toStringTag]: "Module" })
promiseTest(contextMixed("null"), { default: null, [Symbol.toStringTag]: "Module" }),
promiseTest(contextMixed("json.json"), { named: "named", default: { named: "named", default: "default" }, [Symbol.toStringTag]: "Module" })
]);
});
@@ -0,0 +1,4 @@
{
"default": "default",
"named": "named"
}
3 changes: 2 additions & 1 deletion test/cases/mjs/non-mjs-namespace-object-lazy/index.js
Expand Up @@ -80,6 +80,7 @@ it("should receive a namespace object when importing mixed content via context",
promiseTest(contextMixed("one"), { named: "named", default: { named: "named", default: "default" }, [Symbol.toStringTag]: "Module" }),
promiseTest(contextMixed("two"), { __esModule: true, named: "named", default: "default" }),
promiseTest(contextMixed("three"), { named: "named", default: "default", [Symbol.toStringTag]: "Module" }),
promiseTest(contextMixed("null"), { default: null, [Symbol.toStringTag]: "Module" })
promiseTest(contextMixed("null"), { default: null, [Symbol.toStringTag]: "Module" }),
promiseTest(contextMixed("json.json"), { named: "named", default: { named: "named", default: "default" }, [Symbol.toStringTag]: "Module" })
]);
});

0 comments on commit 023d4ca

Please sign in to comment.