Skip to content

Commit

Permalink
fix: verbose flag functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed May 17, 2020
1 parent a905590 commit e01fd20
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/webpack-cli/lib/groups/StatsGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ class StatsGroup extends GroupHelper {
}

resolveOptions() {
if (this.args.verbose && this.args.stats) {
if (this.args.verbose && process.argv.includes('--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
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');
11 changes: 11 additions & 0 deletions test/verbose/verbose-flag.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'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();
});
});

0 comments on commit e01fd20

Please sign in to comment.