Skip to content

Commit

Permalink
test: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jul 19, 2022
1 parent 06c700a commit 47f5a03
Show file tree
Hide file tree
Showing 9 changed files with 450 additions and 424 deletions.
20 changes: 17 additions & 3 deletions packages/webpack-cli/src/webpack-cli.ts
Expand Up @@ -13,10 +13,8 @@ import {
WebpackCLICommandOptions,
WebpackCLIMainOption,
WebpackCLILogger,
WebpackV4LegacyStats,
WebpackDevServerOptions,
WebpackRunOptions,
WebpackV4Compiler,
WebpackCompiler,
WebpackConfiguration,
Argv,
Expand All @@ -34,7 +32,6 @@ import {
Instantiable,
JsonExt,
ModuleName,
MultipleCompilerStatsOptions,
PackageInstallOptions,
PackageManager,
Path,
Expand Down Expand Up @@ -2092,6 +2089,23 @@ class WebpackCLI implements IWebpackCLI {
item.stats = { preset: item.stats };
}

let colors;

// From arguments
if (typeof this.isColorSupportChanged !== "undefined") {
colors = Boolean(this.isColorSupportChanged);
}
// From stats
else if (typeof (item.stats as StatsOptions).colors !== "undefined") {
colors = (item.stats as StatsOptions).colors;
}
// Default
else {
colors = Boolean(this.colors.isColorSupported);
}

item.stats.colors = colors;

// Apply CLI plugin
if (!item.plugins) {
item.plugins = [];
Expand Down
6 changes: 4 additions & 2 deletions test/build/core-flags/core-flags.test.js
Expand Up @@ -239,15 +239,17 @@ describe("core flags", () => {
expect(stdout).toContain(`devtool: 'source-map'`);
});

it("should allow string value devtool option using alias", async () => {
// TODO: Enable alias with webpack 5
it.skip("should allow string value devtool option using alias", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["-d", "source-map"]);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`devtool: 'source-map'`);
});

it("should allow string value devtool option using alias #1", async () => {
// TODO: Enable alias with webpack 5
it.skip("should allow string value devtool option using alias #1", async () => {
// cSpell:ignore dsource
const { exitCode, stderr, stdout } = await run(__dirname, ["-dsource-map"]);

Expand Down
2 changes: 1 addition & 1 deletion test/build/defaults/output-defaults.test.js
Expand Up @@ -38,7 +38,7 @@ describe("output flag defaults", () => {
]);

expect(exitCode).toBe(2);
expect(stderr).toContain("Error: Option '-o, --output-path <value>' argument missing");
expect(stderr).toContain("Error: Option '--output-path <value>' argument missing");
expect(stdout).toBeFalsy();
});
});
4 changes: 2 additions & 2 deletions test/build/devtool/object/source-map-object.test.js
Expand Up @@ -34,7 +34,7 @@ describe("source-map object", () => {
it("should override config with source-map", async () => {
const { exitCode, stderr, stdout } = await run(
__dirname,
["-c", "./webpack.eval.config.js", "--devtool", "source-map", "-o", "./binary"],
["-c", "./webpack.eval.config.js", "--devtool", "source-map", "--output-path", "./binary"],
false,
);

Expand All @@ -47,7 +47,7 @@ describe("source-map object", () => {
it("should override config with devtool false", async () => {
const { exitCode, stderr, stdout } = await run(
__dirname,
["-c", "./webpack.eval.config.js", "--no-devtool", "-o", "./binary"],
["-c", "./webpack.eval.config.js", "--no-devtool", "--output-path", "./binary"],
false,
);

Expand Down
7 changes: 1 addition & 6 deletions test/build/entry/flag-entry/entry-with-flag.test.js
Expand Up @@ -6,12 +6,7 @@ const { resolve } = require("path");

describe("entry flag", () => {
it("should resolve the path to src/index.cjs", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"--entry",
"./src/index.cjs",
"-o",
"./dist/",
]);
const { exitCode, stderr, stdout } = await run(__dirname, ["--entry", "./src/index.cjs"]);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
Expand Down
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`output flag named bundles should output file in bin directory using default webpack config with warning for empty output value: stderr 1`] = `
"[webpack-cli] Error: Option '-o, --output-path <value>' argument missing
"[webpack-cli] Error: Option '--output-path <value>' argument missing
[webpack-cli] Run 'webpack --help' to see available commands and options"
`;

Expand Down
3 changes: 2 additions & 1 deletion test/build/target/flag-test/target-flag.test.js
Expand Up @@ -22,7 +22,8 @@ describe("--target flag", () => {
expect(stdout).toContain(`target: [ '${val}' ]`);
});

it(`should accept ${val} with -t alias`, async () => {
// TODO: Enable aliases with webpack 5
it.skip(`should accept ${val} with -t alias`, async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["-t", `${val}`]);

expect(exitCode).toBe(0);
Expand Down
1 change: 0 additions & 1 deletion test/build/target/flag-test/webpack.config.js
Expand Up @@ -3,6 +3,5 @@ const WebpackCLITestPlugin = require("../../../utils/webpack-cli-test-plugin");
module.exports = {
entry: "./index.js",
mode: "development",
target: "node",
plugins: [new WebpackCLITestPlugin()],
};

0 comments on commit 47f5a03

Please sign in to comment.