|
| 1 | +const { existsSync } = require("node:fs"); |
| 2 | +const { resolve } = require("node:path"); |
| 3 | + |
1 | 4 | const { run } = require("../../../utils/test-utils"); |
2 | 5 |
|
3 | | -// Regression test for an unsupported config format. |
4 | | -// |
5 | | -// `interpret` lists `.yaml`/`.yml` (via `yaml-hook/register`), but webpack-cli |
6 | | -// only runs `interpret`/`rechoir` for extensions present in |
7 | | -// `interpret.jsVariants`, which contains JS variants only (`.ts`, `.coffee`, |
8 | | -// `.babel.js`, ...) and not data formats such as `.yaml`, `.yml`, `.json5` or |
9 | | -// `.toml`. As a result YAML configs are 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. |
| 6 | +// webpack-cli supports YAML config files through `interpret`/`rechoir`, but it |
| 7 | +// does not ship the parser. The `yaml-hook` package has to be installed by the |
| 8 | +// user (here it is available as a dev dependency) and `yaml-hook/register` is |
| 9 | +// loaded on demand to register the `.yaml`/`.yml` extensions. |
14 | 10 | describe("webpack cli", () => { |
15 | | - it("should not support YAML file as flag", async () => { |
| 11 | + it("should support YAML file as flag", async () => { |
16 | 12 | const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.yaml"]); |
17 | 13 |
|
18 | | - expect(exitCode).toBe(2); |
19 | | - expect(stderr).toContain("Failed to load 'webpack.config.yaml' config"); |
20 | | - expect(stdout).toBeFalsy(); |
| 14 | + expect(exitCode).toBe(0); |
| 15 | + expect(stderr).toBeFalsy(); |
| 16 | + expect(stdout).toBeTruthy(); |
| 17 | + expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy(); |
21 | 18 | }); |
22 | 19 |
|
23 | | - it("should not support YML file as flag", async () => { |
| 20 | + it("should support YML file as flag", async () => { |
24 | 21 | const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.yml"]); |
25 | 22 |
|
26 | | - expect(exitCode).toBe(2); |
27 | | - expect(stderr).toContain("Failed to load 'webpack.config.yml' config"); |
28 | | - expect(stdout).toBeFalsy(); |
| 23 | + expect(exitCode).toBe(0); |
| 24 | + expect(stderr).toBeFalsy(); |
| 25 | + expect(stdout).toBeTruthy(); |
| 26 | + expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy(); |
| 27 | + }); |
| 28 | + |
| 29 | + it("should load YAML file by default", async () => { |
| 30 | + const { exitCode, stderr, stdout } = await run(__dirname, []); |
| 31 | + |
| 32 | + expect(exitCode).toBe(0); |
| 33 | + expect(stderr).toBeFalsy(); |
| 34 | + expect(stdout).toBeTruthy(); |
| 35 | + expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy(); |
29 | 36 | }); |
30 | 37 | }); |
0 commit comments