diff --git a/packages/webpack-cli/__tests__/resolveArgs.test.js b/packages/webpack-cli/__tests__/resolveArgs.test.js index f199870cfb3..1eff36c414f 100644 --- a/packages/webpack-cli/__tests__/resolveArgs.test.js +++ b/packages/webpack-cli/__tests__/resolveArgs.test.js @@ -1,7 +1,13 @@ const { resolve } = require('path'); +const { version } = require('webpack'); const webpackCLI = require('../lib/webpack-cli'); const targetValues = ['web', 'webworker', 'node', 'async-node', 'node-webkit', 'electron-main', 'electron-renderer', 'electron-preload']; +const statsPresets = ['normal', 'detailed', 'errors-only', 'errors-warnings', 'minimal', 'verbose', 'none']; + +if (version.startsWith('5')) { + statsPresets.push('summary'); +} const basicResolver = new webpackCLI().resolveArguments; @@ -83,4 +89,12 @@ describe('BasicResolver', () => { expect(result.options.target).toEqual(option); }); }); + + statsPresets.map((preset) => { + it(`should handle ${preset} preset`, async () => { + const result = await basicResolver({ options: {} }, { stats: preset }); + + expect(result.options.stats).toEqual(preset); + }); + }); }); diff --git a/test/stats/config/stats.test.js b/test/stats/config/stats.test.js index 932e57f56ab..2eeb66671c7 100644 --- a/test/stats/config/stats.test.js +++ b/test/stats/config/stats.test.js @@ -1,9 +1,16 @@ /* eslint-disable node/no-extraneous-require */ 'use strict'; // eslint-disable-next-line node/no-unpublished-require -const { run } = require('../../utils/test-utils'); +const { run, isWebpack5 } = require('../../utils/test-utils'); const { version } = require('webpack'); +// 'normal' is used in webpack.config.js +const statsPresets = ['detailed', 'errors-only', 'errors-warnings', 'minimal', 'verbose', 'none']; + +if (isWebpack5) { + statsPresets.push('summary'); +} + describe('stats flag with config', () => { it('should compile without stats flag', () => { const { exitCode, stderr, stdout } = run(__dirname, []); @@ -18,17 +25,20 @@ describe('stats flag with config', () => { expect(stdout).toContain(`stats: 'normal'`); } }); - it('should compile with stats flag', () => { - const { exitCode, stderr, stdout } = run(__dirname, ['--stats', 'errors-warnings']); - expect(exitCode).toBe(0); - expect(stderr).toContain('Compilation starting...'); - expect(stderr).toContain('Compilation finished'); + for (const preset of statsPresets) { + it(`should override 'noramal' value in config with "${preset}"`, () => { + const { exitCode, stderr, stdout } = run(__dirname, ['--stats', `${preset}`]); - if (version.startsWith('5')) { - expect(stdout).toContain(`stats: { preset: 'errors-warnings' }`); - } else { - expect(stdout).toContain(`stats: 'errors-warnings'`); - } - }); + expect(exitCode).toBe(0); + expect(stderr).toContain('Compilation starting...'); + expect(stderr).toContain('Compilation finished'); + + if (isWebpack5) { + expect(stdout).toContain(`stats: { preset: '${preset}' }`); + } else { + expect(stdout).toContain(`stats: '${preset}'`); + } + }); + } });