Skip to content

Commit f12c7a0

Browse files
test(errors): cover the case-conflict warning on a case-sensitive disk
The existing case has it backwards by necessity: it runs only where `FILE.js` resolves to the committed `file.js`, so the warning is exercised on a case-insensitive filesystem and the Linux branch asserts the module-not-found error instead. Every coverage uploader is ubuntu-latest, so `CaseSensitiveModulesWarning` read 21% -- its message builder never ran in a run that reported. Write the colliding pair to a temporary directory instead, which a checkout cannot hold, and assert the warning a real build emits. Where the two names are one file the case above already covers it, so the test returns. Statements, lines and functions go 21% -> 100%.
1 parent f0b3540 commit f12c7a0

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

‎test/unitCases/Errors.unittest.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require("../helpers/warmup-webpack");
44

5+
const os = require("os");
56
const path = require("path");
67
const testDirectory = path.resolve(__dirname, "..");
78
const fs = require("graceful-fs");
@@ -334,6 +335,46 @@ describe("Errors", () => {
334335
});
335336
}
336337

338+
// WHY: the warning needs two modules whose names differ only in case, which a
339+
// checkout cannot hold on a case-insensitive filesystem — so the pair is
340+
// written to a temporary directory, and only a case-sensitive one keeps them
341+
// apart. The branch above covers the other filesystem.
342+
it("should emit warning for modules differing only in casing", async () => {
343+
const directory = fs.mkdtempSync(
344+
path.join(os.tmpdir(), "webpack-case-conflict-")
345+
);
346+
try {
347+
fs.writeFileSync(path.join(directory, "file.js"), "module.exports = 1;\n");
348+
fs.writeFileSync(path.join(directory, "FILE.js"), "module.exports = 2;\n");
349+
const keptApart =
350+
fs.readFileSync(path.join(directory, "file.js"), "utf8") ===
351+
"module.exports = 1;\n";
352+
if (!keptApart) return;
353+
fs.writeFileSync(
354+
path.join(directory, "index.js"),
355+
'require("./file");\nrequire("./FILE");\n'
356+
);
357+
const { errors, warnings } = await compile({
358+
context: directory,
359+
mode: "development",
360+
entry: "./index"
361+
});
362+
expect(errors).toHaveLength(0);
363+
expect(warnings).toHaveLength(1);
364+
const { message } = warnings[0];
365+
expect(message).toContain(
366+
"There are multiple modules with names that only differ in casing."
367+
);
368+
// The list names a representative importer for each module.
369+
expect(message).toContain("module(s), i. e.");
370+
expect(message.indexOf("FILE.js")).toBeLessThan(
371+
message.lastIndexOf("file.js")
372+
);
373+
} finally {
374+
fs.rmSync(directory, { recursive: true, force: true });
375+
}
376+
});
377+
337378
it("should emit warning for undef mode", async () => {
338379
await expect(compile({ mode: undefined, entry: "./entry-point" })).resolves
339380
.toMatchInlineSnapshot(`

0 commit comments

Comments
 (0)