Skip to content

Commit

Permalink
test: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 18, 2024
1 parent d04ffe9 commit b1c8af5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
30 changes: 17 additions & 13 deletions packages/webpack-cli/src/webpack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { type stringifyChunked } from "@discoveryjs/json-ext";
import { type Help, type ParseOptions } from "commander";

import { type CLIPlugin as CLIPluginClass } from "./plugins/cli-plugin";
import * as console from "node:console";

const fs = require("fs");
const { Readable } = require("stream");
const path = require("path");
Expand Down Expand Up @@ -1933,19 +1933,23 @@ class WebpackCLI implements IWebpackCLI {
),
);

config.options = [];

loadedConfigs.forEach((loadedConfig) => {
if (Array.isArray(loadedConfig.options)) {
for (const item of loadedConfig.options) {
(config.options as WebpackConfiguration[]).push(item);
config.path.set(options, [loadedConfig.path]);
if (loadedConfigs.length === 1) {
config.options = loadedConfigs[0].options;
config.path.set(loadedConfigs[0].options, [loadedConfigs[0].path]);
} else {
config.options = [];
loadedConfigs.forEach((loadedConfig) => {
if (Array.isArray(loadedConfig.options)) {
for (const item of loadedConfig.options) {
(config.options as WebpackConfiguration[]).push(item);
config.path.set(options, [loadedConfig.path]);
}
} else {
(config.options as WebpackConfiguration[]).push(loadedConfig.options);
config.path.set(loadedConfig.options, [loadedConfig.path]);
}
} else {
(config.options as WebpackConfiguration[]).push(loadedConfig.options);
config.path.set(loadedConfig.options, [loadedConfig.path]);
}
});
});
}
} else {
// Prioritize popular extensions first to avoid unnecessary fs calls
const extensions = new Set([
Expand Down
6 changes: 6 additions & 0 deletions test/api/CLI.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ describe("CLI API", () => {
let cli;

beforeEach(() => {
jest.spyOn(console, "error").mockImplementation(() => {});

cli = new CLI();
});

afterAll(() => {
console.error.mockRestore();
});

describe("makeCommand", () => {
it("should make command", async () => {
expect.assertions(1);
Expand Down
1 change: 1 addition & 0 deletions test/api/get-default-package-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ describe("getPackageManager", () => {
});

it("should throw error if no package manager is found", () => {
cwdSpy.mockReturnValue(noLockPath);
syncMock.mockImplementation(() => {
throw new Error();
});
Expand Down
15 changes: 12 additions & 3 deletions test/build/cache/cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ describe("cache", () => {

it("should work in multi compiler mode", async () => {
fs.rmSync(
path.join(__dirname, "../../../node_modules/.cache/webpack/cache-test-first-development"),
path.join(
__dirname,
"../../../node_modules/.cache/webpack/cache-test-first-development__compiler1__",
),
{ recursive: true, force: true },
);
fs.rmSync(
path.join(__dirname, "../../../node_modules/.cache/webpack/cache-test-second-development"),
path.join(
__dirname,
"../../../node_modules/.cache/webpack/cache-test-second-development__compiler2__",
),
{ recursive: true, force: true },
);

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

it("should work in multi compiler mode with the `--config-name` argument", async () => {
fs.rmSync(
path.join(__dirname, "../../../node_modules/.cache/webpack/cache-test-third-development"),
path.join(
__dirname,
"../../../node_modules/.cache/webpack/cache-test-third-development__compiler1__",
),
{ recursive: true, force: true },
);

Expand Down
3 changes: 3 additions & 0 deletions test/build/config-name/config-name.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ describe("--config-name flag", () => {
false,
);

console.log(stdout);
console.log(stderr);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain("first");
Expand Down

0 comments on commit b1c8af5

Please sign in to comment.