Skip to content

Commit

Permalink
fix(webpack-cli): verbose flag functionality (#1549)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 authored May 21, 2020
1 parent 3f1d7c0 commit e15d9cd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
8 changes: 2 additions & 6 deletions packages/webpack-cli/lib/groups/StatsGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ class StatsGroup extends GroupHelper {
resolveOptions() {
if (this.args.verbose && this.args.stats) {
logger.warn('Conflict between "verbose" and "stats" options. Using verbose.');
this.opts.option.stats = {
verbose: true,
};
this.opts.options.stats = 'verbose';
} else {
if (this.args.verbose) {
this.opts.option.stats = {
verbose: true,
};
this.opts.options.stats = 'verbose';
} else if (!StatsGroup.validOptions().includes(this.args.stats)) {
logger.warn(`'${this.args.stats}' is invalid value for stats. Using 'normal' option for stats`);
this.opts.options.stats = 'normal';
Expand Down
1 change: 0 additions & 1 deletion packages/webpack-cli/lib/utils/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ module.exports = {
name: 'stats',
usage: '--stats verbose',
type: String,
defaultValue: 'normal',
group: DISPLAY_GROUP,
description: 'It instructs webpack on how to treat the stats',
link: 'https://webpack.js.org/configuration/stats/#stats',
Expand Down
7 changes: 7 additions & 0 deletions test/stats/stats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ describe('stats flag', () => {
expect(stdout).toBeTruthy();
});

it('should warn when --verbose & --stats are passed together', () => {
const { stderr, stdout } = run(__dirname, ['--verbose', '--stats', 'normal']);
expect(stderr).toBeTruthy();
expect(stderr).toContain('Conflict between "verbose" and "stats" options');
expect(stdout).toBeTruthy();
});

it('should warn when an unknown flag stats value is passed', () => {
const { stderr, stdout } = run(__dirname, ['--stats', 'foo']);
expect(stderr).toBeTruthy();
Expand Down
1 change: 1 addition & 0 deletions test/verbose/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('test');
12 changes: 12 additions & 0 deletions test/verbose/verbose-flag.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';
// eslint-disable-next-line node/no-unpublished-require
const { run } = require('../utils/test-utils');

describe('verbose flag', () => {
it('should accept --verbose', () => {
const { stderr, stdout } = run(__dirname, ['--verbose']);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).toContain('LOG from webpack');
});
});

0 comments on commit e15d9cd

Please sign in to comment.