Skip to content

Commit

Permalink
tests: add tests for --no-stats
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jun 27, 2020
1 parent 7eb768b commit 525f556
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/no-stats/with-config/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('url');
require('path');

console.log('--no-stats with config test');
29 changes: 29 additions & 0 deletions test/no-stats/with-config/no-stats-with-config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';
// eslint-disable-next-line node/no-unpublished-require
const { run } = require('../../utils/test-utils');
// eslint-disable-next-line node/no-extraneous-require
const { version } = require('webpack');

describe('stats flag', () => {
it(`should use stats detailed as defined in webpack config`, () => {
const { stderr, stdout } = run(__dirname, []);

expect(stderr).toBeFalsy();
if (version.startsWith('5')) {
expect(stdout).toContain(`stats: { preset: 'detailed' }`);
} else {
expect(stdout).toContain(`stats: 'detailed'`);
}
});

it(`should use --no-stats and override value config`, () => {
const { stderr, stdout } = run(__dirname, ['--no-stats']);

expect(stderr).toBeFalsy();
if (version.startsWith('5')) {
expect(stdout).toContain(`stats: { preset: 'none' }`);
} else {
expect(stdout).toContain(`stats: false`);
}
});
});
9 changes: 9 additions & 0 deletions test/no-stats/with-config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// eslint-disable-next-line node/no-unpublished-require
const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin');

module.exports = {
mode: 'development',
entry: './main.js',
stats: 'detailed',
plugins: [new WebpackCLITestPlugin()],
};
4 changes: 4 additions & 0 deletions test/no-stats/with-flags/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('url');
require('path');

console.log('--no-stats test');
51 changes: 51 additions & 0 deletions test/no-stats/with-flags/no-stats.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict';
// eslint-disable-next-line node/no-unpublished-require
const { run } = require('../../utils/test-utils');
// eslint-disable-next-line node/no-extraneous-require
const { version } = require('webpack');

describe('stats flag', () => {
it('should accept --no-stats as boolean', () => {
const { stderr, stdout } = run(__dirname, ['--no-stats']);

expect(stderr).toBeFalsy();
if (version.startsWith('5')) {
expect(stdout).toContain(`stats: { preset: 'none' }`);
} else {
expect(stdout).toContain('stats: false');
}
});

it('should warn and use --no-stats when stats and no-stats both are provided', () => {
const { stderr, stdout } = run(__dirname, ['--stats', 'verbose', '--no-stats']);

expect(stderr).toContain(`You provided both --stats and --no-stats. We will use only the last of these flags`);
if (version.startsWith('5')) {
expect(stdout).toContain(`stats: { preset: 'none' }`);
} else {
expect(stdout).toContain('stats: false');
}
});

it('should warn and use --stats when stats and no-stats both are provided', () => {
const { stderr, stdout } = run(__dirname, ['--no-stats', '--stats', 'verbose']);

expect(stderr).toContain(`You provided both --stats and --no-stats. We will use only the last of these flags`);
if (version.startsWith('5')) {
expect(stdout).toContain(`stats: { preset: 'verbose' }`);
} else {
expect(stdout).toContain(`stats: 'verbose'`);
}
});

it('should use --verbose over --no-stats', () => {
const { stderr, stdout } = run(__dirname, ['--no-stats', '--verbose']);

expect(stderr).toBeFalsy();
if (version.startsWith('5')) {
expect(stdout).toContain(`stats: { preset: 'verbose' }`);
} else {
expect(stdout).toContain(`stats: 'verbose'`);
}
});
});
8 changes: 8 additions & 0 deletions test/no-stats/with-flags/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// eslint-disable-next-line node/no-unpublished-require
const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin');

module.exports = {
mode: 'development',
entry: './main.js',
plugins: [new WebpackCLITestPlugin()],
};

0 comments on commit 525f556

Please sign in to comment.