Skip to content

Commit

Permalink
tests: add more cases for stats tests (#2178)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Dec 7, 2020
1 parent 12edbe3 commit 988d83d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
14 changes: 14 additions & 0 deletions 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;

Expand Down Expand Up @@ -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);
});
});
});
34 changes: 22 additions & 12 deletions 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, []);
Expand All @@ -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}'`);
}
});
}
});

0 comments on commit 988d83d

Please sign in to comment.