Skip to content

Commit 42cf33b

Browse files
1 parent be2f4f1 commit 42cf33b

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎test/build/config/basic/basic-config.test.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"use strict";
22

3+
const fs = require("node:fs");
4+
const os = require("node:os");
5+
const path = require("node:path");
36
const { resolve } = require("node:path");
47
const { pathToFileURL } = require("node:url");
58
const { cleanStderr, run } = require("../../../utils/test-utils");
@@ -40,6 +43,24 @@ describe("basic config file", () => {
4043
expect(stdout).toBeTruthy();
4144
});
4245

46+
it("should load a configuration path as a module specifier and not run it as code", async () => {
47+
const marker = path.join(
48+
fs.mkdtempSync(path.join(os.tmpdir(), "webpack-cli-config-path-")),
49+
"executed",
50+
);
51+
const configPath = `file:///webpack.config.js"),require("node:fs").writeFileSync(${JSON.stringify(marker)},""),import("file:///webpack.config.js`;
52+
53+
try {
54+
const { exitCode, stderr } = await run(__dirname, ["-c", configPath]);
55+
56+
expect(exitCode).toBe(2);
57+
expect(stderr).toContain("Failed to load");
58+
expect(fs.existsSync(marker)).toBe(false);
59+
} finally {
60+
fs.rmSync(path.dirname(marker), { recursive: true, force: true });
61+
}
62+
});
63+
4364
it("should build and not throw error with a basic using weird path", async () => {
4465
const { exitCode, stderr, stdout } = await run(__dirname, [
4566
"-c",

0 commit comments

Comments
 (0)