Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webpack-cli): verbose flag functionality #1549

Merged
merged 1 commit into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
snitin315 marked this conversation as resolved.
Show resolved Hide resolved
} 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', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a better test here. i.e. we should test for lines in stdout that are found only in verbose stats.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated 👍, Please take a look.

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