This commit is contained in:
Leah 2022-10-21 01:46:26 +02:00 committed by GitHub
parent d87b96bb49
commit 276c844152
5 changed files with 79 additions and 49 deletions

View file

@ -1 +1 @@
export { default } from "../node.js"
export { default } from "../node.js";

View file

@ -1 +1 @@
throw new Error("This is node.js only")
throw new Error("This is node.js only");

View file

@ -14,7 +14,10 @@ it("should be able to use lazy-once mode", function () {
it("should be able to use lazy-once mode with name", function () {
function load(name) {
return import(/* webpackMode: "lazy-once", webpackChunkName: "name-lazy-once" */ "./dir3/" + name);
return import(
/* webpackMode: "lazy-once", webpackChunkName: "name-lazy-once" */ "./dir3/" +
name
);
}
return testChunkLoading(load, false, true);
});
@ -28,14 +31,19 @@ it("should be able to use lazy mode", function () {
it("should be able to use lazy mode with name", function () {
function load(name) {
return import(/* webpackMode: "lazy", webpackChunkName: "name-lazy" */ "./dir5/" + name);
return import(
/* webpackMode: "lazy", webpackChunkName: "name-lazy" */ "./dir5/" + name
);
}
return testChunkLoading(load, false, false);
});
it("should be able to use lazy mode with name and placeholder", function () {
function load(name) {
return import(/* webpackMode: "lazy", webpackChunkName: "name-lazy-[request]" */ "./dir6/" + name);
return import(
/* webpackMode: "lazy", webpackChunkName: "name-lazy-[request]" */ "./dir6/" +
name
);
}
return testChunkLoading(load, false, false);
});
@ -89,7 +97,9 @@ it("should be able to use weak mode (without context)", function () {
it("should not find module when mode is weak and chunk not served elsewhere", function () {
var name = "a";
return import(/* webpackMode: "weak" */ "./dir10/" + name).catch(function (e) {
return import(/* webpackMode: "weak" */ "./dir10/" + name).catch(function (
e
) {
expect(e).toMatchObject({
message: /not available/,
code: /MODULE_NOT_FOUND/,
@ -108,13 +118,17 @@ it("should not find module when mode is weak and chunk not served elsewhere (wit
if (process.env.NODE_ENV === "production") {
it("should contain only one export from webpackExports from module", function () {
return import(/* webpackExports: "usedExports" */ "./dir12/a?1").then((module) => {
expect(module.usedExports).toEqual(["usedExports"]);
});
return import(/* webpackExports: "usedExports" */ "./dir12/a?1").then(
(module) => {
expect(module.usedExports).toEqual(["usedExports"]);
}
);
});
it("should contain only webpackExports from module", function () {
return import(/* webpackExports: ["a", "usedExports", "b"] */ "./dir12/a?2").then((module) => {
return import(
/* webpackExports: ["a", "usedExports", "b"] */ "./dir12/a?2"
).then((module) => {
expect(module.usedExports).toEqual(["a", "b", "usedExports"]);
});
});
@ -143,22 +157,28 @@ if (process.env.NODE_ENV === "production") {
});
it("should not mangle webpackExports from module", function () {
return import(/* webpackExports: "longnameforexport" */ "./dir12/a?5").then((module) => {
expect(module).toHaveProperty("longnameforexport");
});
return import(/* webpackExports: "longnameforexport" */ "./dir12/a?5").then(
(module) => {
expect(module).toHaveProperty("longnameforexport");
}
);
});
it("should not mangle default webpackExports from module", function () {
return import(/* webpackExports: "default" */ "./dir12/a?6").then((module) => {
expect(module).toHaveProperty("default");
});
return import(/* webpackExports: "default" */ "./dir12/a?6").then(
(module) => {
expect(module).toHaveProperty("default");
}
);
});
it("should contain only webpackExports from module in context mode", function () {
const x = "b";
return import(/* webpackExports: "usedExports" */ `./dir13/${x}`).then((module) => {
expect(module.usedExports).toEqual(["usedExports"]);
});
return import(/* webpackExports: "usedExports" */ `./dir13/${x}`).then(
(module) => {
expect(module.usedExports).toEqual(["usedExports"]);
}
);
});
}

View file

@ -108,9 +108,13 @@ it("should handle empty named chunks when there is an error callback", function
it("should be able to use named chunks in import()", function (done) {
var sync = false;
import("./empty?import1-in-chunk1" /* webpackChunkName: "import-named-chunk-1" */).then(function (result) {
import(
"./empty?import1-in-chunk1" /* webpackChunkName: "import-named-chunk-1" */
).then(function (result) {
var i = 0;
import("./empty?import2-in-chunk1" /* webpackChunkName: "import-named-chunk-1" */)
import(
"./empty?import2-in-chunk1" /* webpackChunkName: "import-named-chunk-1" */
)
.then(function (result) {
expect(sync).toBeTruthy();
if (i++ > 0) done();
@ -118,7 +122,9 @@ it("should be able to use named chunks in import()", function (done) {
.catch(function (err) {
done(err);
});
import("./empty?import3-in-chunk2" /* webpackChunkName: "import-named-chunk-2" */)
import(
"./empty?import3-in-chunk2" /* webpackChunkName: "import-named-chunk-2" */
)
.then(function (result) {
expect(sync).toBeFalsy();
if (i++ > 0) done();
@ -140,30 +146,32 @@ it("should be able to use named chunk in context import()", function (done) {
// cspell:ignore mpty
var mpty = "mpty";
var sync = false;
import("./e" + mpty + "2" /* webpackChunkName: "context-named-chunk" */).then(function (result) {
var i = 0;
import("./e" + mpty + "3" /* webpackChunkName: "context-named-chunk" */)
.then(function (result) {
expect(sync).toBeTruthy();
if (i++ > 0) done();
})
.catch(function (err) {
done(err);
});
import("./e" + mpty + "4" /* webpackChunkName: "context-named-chunk-2" */)
.then(function (result) {
expect(sync).toBeFalsy();
if (i++ > 0) done();
})
.catch(function (err) {
done(err);
});
sync = true;
Promise.resolve()
.then(function () {})
.then(function () {})
.then(function () {
sync = false;
});
});
import("./e" + mpty + "2" /* webpackChunkName: "context-named-chunk" */).then(
function (result) {
var i = 0;
import("./e" + mpty + "3" /* webpackChunkName: "context-named-chunk" */)
.then(function (result) {
expect(sync).toBeTruthy();
if (i++ > 0) done();
})
.catch(function (err) {
done(err);
});
import("./e" + mpty + "4" /* webpackChunkName: "context-named-chunk-2" */)
.then(function (result) {
expect(sync).toBeFalsy();
if (i++ > 0) done();
})
.catch(function (err) {
done(err);
});
sync = true;
Promise.resolve()
.then(function () {})
.then(function () {})
.then(function () {
sync = false;
});
}
);
});

View file

@ -1,3 +1,5 @@
module.exports = [
[/It's not allowed to load an initial chunk on demand\. The chunk name "main" is already used by an entrypoint\./],
[
/It's not allowed to load an initial chunk on demand\. The chunk name "main" is already used by an entrypoint\./,
],
];