Skip to content

Commit

Permalink
fix: allow to disable stats color via --no-color
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Nov 5, 2020
1 parent a786301 commit 2faaaa1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -235,6 +235,10 @@ class WebpackCLI {
}
}

if (!coloretteOptions.enabled && args.color) {
coloretteOptions.enabled = args.color;
}

stats.colors = typeof stats.colors !== 'undefined' ? stats.colors : coloretteOptions.enabled;

return stats;
Expand Down
19 changes: 19 additions & 0 deletions test/colors/colors.test.js
Expand Up @@ -43,6 +43,25 @@ describe('colorts', () => {
expect(exitCode).toBe(0);
});

it('should disable colored output with --no-color', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--stats=verbose', '--no-color']);

expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).not.toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
expect(stdout).toContain(output);
expect(exitCode).toBe(0);
});

it('should work with the "stats" option and --color flags', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--stats=verbose', '--color']);

expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
expect(exitCode).toBe(0);
});

it('should work with the "stats" option from the configuration', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--config=stats-string.webpack.config.js']);

Expand Down

0 comments on commit 2faaaa1

Please sign in to comment.