Skip to content

Commit b1c8af5

Browse files
test: fix
1 parent d04ffe9 commit b1c8af5

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed

packages/webpack-cli/src/webpack-cli.ts

+17-13
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import { type stringifyChunked } from "@discoveryjs/json-ext";
5555
import { type Help, type ParseOptions } from "commander";
5656

5757
import { type CLIPlugin as CLIPluginClass } from "./plugins/cli-plugin";
58-
import * as console from "node:console";
58+
5959
const fs = require("fs");
6060
const { Readable } = require("stream");
6161
const path = require("path");
@@ -1933,19 +1933,23 @@ class WebpackCLI implements IWebpackCLI {
19331933
),
19341934
);
19351935

1936-
config.options = [];
1937-
1938-
loadedConfigs.forEach((loadedConfig) => {
1939-
if (Array.isArray(loadedConfig.options)) {
1940-
for (const item of loadedConfig.options) {
1941-
(config.options as WebpackConfiguration[]).push(item);
1942-
config.path.set(options, [loadedConfig.path]);
1936+
if (loadedConfigs.length === 1) {
1937+
config.options = loadedConfigs[0].options;
1938+
config.path.set(loadedConfigs[0].options, [loadedConfigs[0].path]);
1939+
} else {
1940+
config.options = [];
1941+
loadedConfigs.forEach((loadedConfig) => {
1942+
if (Array.isArray(loadedConfig.options)) {
1943+
for (const item of loadedConfig.options) {
1944+
(config.options as WebpackConfiguration[]).push(item);
1945+
config.path.set(options, [loadedConfig.path]);
1946+
}
1947+
} else {
1948+
(config.options as WebpackConfiguration[]).push(loadedConfig.options);
1949+
config.path.set(loadedConfig.options, [loadedConfig.path]);
19431950
}
1944-
} else {
1945-
(config.options as WebpackConfiguration[]).push(loadedConfig.options);
1946-
config.path.set(loadedConfig.options, [loadedConfig.path]);
1947-
}
1948-
});
1951+
});
1952+
}
19491953
} else {
19501954
// Prioritize popular extensions first to avoid unnecessary fs calls
19511955
const extensions = new Set([

test/api/CLI.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ describe("CLI API", () => {
44
let cli;
55

66
beforeEach(() => {
7+
jest.spyOn(console, "error").mockImplementation(() => {});
8+
79
cli = new CLI();
810
});
911

12+
afterAll(() => {
13+
console.error.mockRestore();
14+
});
15+
1016
describe("makeCommand", () => {
1117
it("should make command", async () => {
1218
expect.assertions(1);

test/api/get-default-package-manager.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ describe("getPackageManager", () => {
101101
});
102102

103103
it("should throw error if no package manager is found", () => {
104+
cwdSpy.mockReturnValue(noLockPath);
104105
syncMock.mockImplementation(() => {
105106
throw new Error();
106107
});

test/build/cache/cache.test.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ describe("cache", () => {
3131

3232
it("should work in multi compiler mode", async () => {
3333
fs.rmSync(
34-
path.join(__dirname, "../../../node_modules/.cache/webpack/cache-test-first-development"),
34+
path.join(
35+
__dirname,
36+
"../../../node_modules/.cache/webpack/cache-test-first-development__compiler1__",
37+
),
3538
{ recursive: true, force: true },
3639
);
3740
fs.rmSync(
38-
path.join(__dirname, "../../../node_modules/.cache/webpack/cache-test-second-development"),
41+
path.join(
42+
__dirname,
43+
"../../../node_modules/.cache/webpack/cache-test-second-development__compiler2__",
44+
),
3945
{ recursive: true, force: true },
4046
);
4147

@@ -59,7 +65,10 @@ describe("cache", () => {
5965

6066
it("should work in multi compiler mode with the `--config-name` argument", async () => {
6167
fs.rmSync(
62-
path.join(__dirname, "../../../node_modules/.cache/webpack/cache-test-third-development"),
68+
path.join(
69+
__dirname,
70+
"../../../node_modules/.cache/webpack/cache-test-third-development__compiler1__",
71+
),
6372
{ recursive: true, force: true },
6473
);
6574

test/build/config-name/config-name.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ describe("--config-name flag", () => {
120120
false,
121121
);
122122

123+
console.log(stdout);
124+
console.log(stderr);
125+
123126
expect(exitCode).toBe(0);
124127
expect(stderr).toBeFalsy();
125128
expect(stdout).toContain("first");

0 commit comments

Comments
 (0)