keep old test case too
This commit is contained in:
parent
8f2c266966
commit
9b08be6d10
|
@ -0,0 +1 @@
|
||||||
|
"./a.json"
|
|
@ -0,0 +1 @@
|
||||||
|
"./b.json"
|
|
@ -0,0 +1 @@
|
||||||
|
"./a.json"
|
|
@ -0,0 +1 @@
|
||||||
|
"./b.json"
|
|
@ -0,0 +1 @@
|
||||||
|
"./a.json"
|
|
@ -0,0 +1 @@
|
||||||
|
"./c.json"
|
|
@ -0,0 +1,31 @@
|
||||||
|
it("should error loadModule when a cycle with 2 modules is requested", () => {
|
||||||
|
expect(require("./loader!./2/a")).toEqual([
|
||||||
|
["./b.json", [
|
||||||
|
["./a.json", "err: There is a circular build dependency, which makes it impossible to create this module"]
|
||||||
|
]]
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
it("should error loadModule when a cycle with 3 modules is requested", () => {
|
||||||
|
expect(require("./loader!./3/a")).toEqual([
|
||||||
|
["./b.json", [
|
||||||
|
["./c.json", [
|
||||||
|
["./a.json", "err: There is a circular build dependency, which makes it impossible to create this module"]
|
||||||
|
]]
|
||||||
|
]]
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
it("should error loadModule when requesting itself", () => {
|
||||||
|
expect(require("./loader!./1/a")).toEqual([
|
||||||
|
["./a.json", "err: There is a circular build dependency, which makes it impossible to create this module"]
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
it("should not report a cycle when loadModule is used twice (https://github.com/webpack/webpack/issues/14379)", () => {
|
||||||
|
expect(require("./loader!./4/a")).toEqual([
|
||||||
|
["./b.json", [
|
||||||
|
["./c.json", []]
|
||||||
|
]],
|
||||||
|
["./b.json", [
|
||||||
|
["./c.json", []]
|
||||||
|
]]
|
||||||
|
]);
|
||||||
|
});
|
|
@ -0,0 +1,30 @@
|
||||||
|
const { promisify } = require("util");
|
||||||
|
|
||||||
|
/** @type {import("../../../../").LoaderDefinitionFunction} */
|
||||||
|
exports.default = function (source) {
|
||||||
|
const content = JSON.parse(source);
|
||||||
|
// content is one reference or an array of references
|
||||||
|
const refs = Array.isArray(content) ? content : [content];
|
||||||
|
const callback = this.async();
|
||||||
|
const loadModulePromise = promisify(this.loadModule.bind(this));
|
||||||
|
|
||||||
|
async function loadReferencedModules() {
|
||||||
|
// Modules are loaded sequentially as the false-positive circular reference
|
||||||
|
// bug from https://github.com/webpack/webpack/issues/14379 doesn't occur if
|
||||||
|
// they are loaded in parallel.
|
||||||
|
const loadedRefs = []
|
||||||
|
for(const ref of refs) {
|
||||||
|
try {
|
||||||
|
const source = await loadModulePromise("../loader!" + ref);
|
||||||
|
loadedRefs.push([ref, JSON.parse(source)]);
|
||||||
|
} catch(err) {
|
||||||
|
loadedRefs.push([ref, `err: ${err && err.message}`]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return loadedRefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadReferencedModules().then((loadResults) => {
|
||||||
|
callback(null, JSON.stringify(loadResults));
|
||||||
|
});
|
||||||
|
};
|
|
@ -1,31 +1,15 @@
|
||||||
it("should error loadModule when a cycle with 2 modules is requested", () => {
|
it("should error loadModule when a cycle with 2 modules is requested", () => {
|
||||||
expect(require("./loader!./2/a")).toEqual([
|
expect(require("./loader!./2/a")).toMatch(
|
||||||
["./b.json", [
|
/^source: err: There is a circular build dependency/
|
||||||
["./a.json", "err: There is a circular build dependency, which makes it impossible to create this module"]
|
);
|
||||||
]]
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
it("should error loadModule when a cycle with 3 modules is requested", () => {
|
it("should error loadModule when a cycle with 3 modules is requested", () => {
|
||||||
expect(require("./loader!./3/a")).toEqual([
|
expect(require("./loader!./3/a")).toMatch(
|
||||||
["./b.json", [
|
/^source: source: err: There is a circular build dependency/
|
||||||
["./c.json", [
|
);
|
||||||
["./a.json", "err: There is a circular build dependency, which makes it impossible to create this module"]
|
|
||||||
]]
|
|
||||||
]]
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
it("should error loadModule when requesting itself", () => {
|
it("should error loadModule when requesting itself", () => {
|
||||||
expect(require("./loader!./1/a")).toEqual([
|
expect(require("./loader!./1/a")).toMatch(
|
||||||
["./a.json", "err: There is a circular build dependency, which makes it impossible to create this module"]
|
/^err: There is a circular build dependency/
|
||||||
]);
|
);
|
||||||
});
|
|
||||||
it("should not report a cycle when loadModule is used twice (https://github.com/webpack/webpack/issues/14379)", () => {
|
|
||||||
expect(require("./loader!./4/a")).toEqual([
|
|
||||||
["./b.json", [
|
|
||||||
["./c.json", []]
|
|
||||||
]],
|
|
||||||
["./b.json", [
|
|
||||||
["./c.json", []]
|
|
||||||
]]
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,30 +1,12 @@
|
||||||
const { promisify } = require("util");
|
|
||||||
|
|
||||||
/** @type {import("../../../../").LoaderDefinitionFunction} */
|
/** @type {import("../../../../").LoaderDefinitionFunction} */
|
||||||
exports.default = function (source) {
|
exports.default = function (source) {
|
||||||
const content = JSON.parse(source);
|
const ref = JSON.parse(source);
|
||||||
// content is one reference or an array of references
|
|
||||||
const refs = Array.isArray(content) ? content : [content];
|
|
||||||
const callback = this.async();
|
const callback = this.async();
|
||||||
const loadModulePromise = promisify(this.loadModule.bind(this));
|
this.loadModule("../loader!" + ref, (err, source, sourceMap, module) => {
|
||||||
|
if (err) {
|
||||||
async function loadReferencedModules() {
|
callback(null, JSON.stringify(`err: ${err && err.message}`));
|
||||||
// Modules are loaded sequentially as the false-positive circular reference
|
} else {
|
||||||
// bug from https://github.com/webpack/webpack/issues/14379 doesn't occur if
|
callback(null, JSON.stringify(`source: ${JSON.parse(source)}`));
|
||||||
// they are loaded in parallel.
|
|
||||||
const loadedRefs = []
|
|
||||||
for(const ref of refs) {
|
|
||||||
try {
|
|
||||||
const source = await loadModulePromise("../loader!" + ref);
|
|
||||||
loadedRefs.push([ref, JSON.parse(source)]);
|
|
||||||
} catch(err) {
|
|
||||||
loadedRefs.push([ref, `err: ${err && err.message}`]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return loadedRefs;
|
|
||||||
}
|
|
||||||
|
|
||||||
loadReferencedModules().then((loadResults) => {
|
|
||||||
callback(null, JSON.stringify(loadResults));
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue