/
stats.test.js
51 lines (45 loc) · 1.81 KB
/
stats.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* eslint-disable node/no-unpublished-require */
'use strict';
const { run, isWebpack5, isWindows } = require('../../utils/test-utils');
const presets = ['normal', 'detailed', 'errors-only', 'errors-warnings', 'minimal', 'verbose', 'none'];
if (isWebpack5) {
presets.push('summary');
}
describe('stats flag', () => {
for (const preset of presets) {
it(`should accept --stats "${preset}"`, () => {
const { stderr, stdout } = run(__dirname, ['--stats', `${preset}`]);
expect(stderr).toBeFalsy();
if (isWebpack5) {
expect(stdout).toContain(`stats: { preset: '${preset}' }`);
} else {
expect(stdout).toContain(`stats: '${preset}'`);
}
});
}
it('should accept stats as boolean', () => {
const { stderr, stdout } = run(__dirname, ['--stats']);
expect(stderr).toBeFalsy();
if (isWebpack5) {
expect(stdout).toContain(`stats: { preset: 'normal' }`);
} else {
expect(stdout).toContain('stats: true');
}
});
it('should warn when an unknown flag stats value is passed', () => {
const { stderr, exitCode } = run(__dirname, ['--stats', 'foo']);
expect(stderr).toBeTruthy();
expect(stderr).toContain('* configuration.stats should be one of these:');
if (isWebpack5) {
expect(stderr).toContain(
`"none" | "summary" | "errors-only" | "errors-warnings" | "minimal" | "normal" | "detailed" | "verbose"`,
);
} else {
expect(stderr).toContain('"none" | "errors-only" | "minimal" | "normal" | "detailed" | "verbose" | "errors-warnings"');
}
// TODO - Fix exitcode check on windows
if (!isWindows) {
expect(exitCode).toEqual(2);
}
});
});