Skip to content

Commit eff73c1

Browse files
committed
test(webpack-cli): add config format coverage for json, json5, yaml and toml
Add test cases covering data-style config formats so the planned move away from `interpret` (towards Node.js' built-in loaders/`import`) cannot silently change which formats are accepted. - `json`: asserts JSON configs load (Node.js loads JSON natively), both via the `-c` flag and default config resolution. - `json5`, `yaml`, `yml`, `toml`: regression tests pinning the current behavior. These extensions are listed by `interpret` but are absent from `interpret.jsVariants`, which is what webpack-cli uses to gate `interpret`/`rechoir`, so they are not loadable today and fail with exit code 2. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013AushhUmU7F2dKWRE94XCg
1 parent a5af401 commit eff73c1

13 files changed

Lines changed: 130 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { existsSync } = require("node:fs");
2+
const { resolve } = require("node:path");
3+
4+
const { run } = require("../../../utils/test-utils");
5+
6+
describe("webpack cli", () => {
7+
it("should support JSON file as flag", async () => {
8+
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.json"]);
9+
10+
expect(exitCode).toBe(0);
11+
expect(stderr).toBeFalsy();
12+
expect(stdout).toBeTruthy();
13+
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
14+
});
15+
16+
it("should load JSON file by default", async () => {
17+
const { exitCode, stderr, stdout } = await run(__dirname, []);
18+
19+
expect(exitCode).toBe(0);
20+
expect(stderr).toBeFalsy();
21+
expect(stdout).toBeTruthy();
22+
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
23+
});
24+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hoshiumi Shoyo");
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"mode": "development",
3+
"entry": "./main.js",
4+
"output": {
5+
"filename": "foo.bundle.js"
6+
}
7+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { run } = require("../../../utils/test-utils");
2+
3+
// Regression test for an unsupported config format.
4+
//
5+
// `interpret` lists `.json5` (via `json5/lib/register`), but webpack-cli only
6+
// runs `interpret`/`rechoir` for extensions present in `interpret.jsVariants`,
7+
// which contains JS variants only (`.ts`, `.coffee`, `.babel.js`, ...) and not
8+
// data formats such as `.json5`, `.yaml` or `.toml`. As a result a `.json5`
9+
// config is not loadable today, even when `json5` is installed.
10+
//
11+
// This test locks in that behavior so the planned move away from `interpret`
12+
// (towards Node.js' built-in loaders/`import`) does not silently change which
13+
// formats are accepted without a deliberate decision.
14+
describe("webpack cli", () => {
15+
it("should not support JSON5 file as flag", async () => {
16+
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.json5"]);
17+
18+
expect(exitCode).toBe(2);
19+
expect(stderr).toContain("Failed to load 'webpack.config.json5' config");
20+
expect(stdout).toBeFalsy();
21+
});
22+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Kageyama Tobio");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
// JSON5 allows comments, unquoted keys and trailing commas
3+
mode: "development",
4+
entry: "./main.js",
5+
output: {
6+
filename: "foo.bundle.js",
7+
},
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Tanjiro");
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { run } = require("../../../utils/test-utils");
2+
3+
// Regression test for an unsupported config format.
4+
//
5+
// `interpret` lists `.toml` (via `toml-require`), but webpack-cli only runs
6+
// `interpret`/`rechoir` for extensions present in `interpret.jsVariants`, which
7+
// contains JS variants only (`.ts`, `.coffee`, `.babel.js`, ...) and not data
8+
// formats such as `.toml`, `.yaml` or `.json5`. As a result a `.toml` config is
9+
// not loadable today.
10+
//
11+
// This test locks in that behavior so the planned move away from `interpret`
12+
// (towards Node.js' built-in loaders/`import`) does not silently change which
13+
// formats are accepted without a deliberate decision.
14+
describe("webpack cli", () => {
15+
it("should not support TOML file as flag", async () => {
16+
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.toml"]);
17+
18+
expect(exitCode).toBe(2);
19+
expect(stderr).toContain("Failed to load 'webpack.config.toml' config");
20+
expect(stdout).toBeFalsy();
21+
});
22+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mode = "development"
2+
entry = "./main.js"
3+
4+
[output]
5+
filename = "foo.bundle.js"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Nishinoya Yu");

0 commit comments

Comments
 (0)