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 16, 2020
1 parent a905590 commit fae35b3
Show file tree
Hide file tree
Showing 6 changed files with 36 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
3 changes: 3 additions & 0 deletions test/verbose/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
yarn.lock
package-lock.json
node_modules/
4 changes: 4 additions & 0 deletions test/verbose/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('react');
require('react-dom');
require('redux');
require('react-redux');
8 changes: 8 additions & 0 deletions test/verbose/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": {
"react": "^16.13.0",
"react-dom": "^16.13.0",
"redux": "^4.0.5",
"react-redux": "^7.2.0"
}
}
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 fae35b3

Please sign in to comment.