-
-
Notifications
You must be signed in to change notification settings - Fork 591
/
stats-flags.test.js
71 lines (60 loc) · 3.05 KB
/
stats-flags.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
const { run, hyphenToUpperCase } = require('../utils/test-utils');
const { flagsFromCore } = require('../../packages/webpack-cli/lib/utils/cli-flags');
const statsFlags = flagsFromCore.filter(({ name }) => name.startsWith('stats-'));
describe('stats config related flag', () => {
statsFlags.forEach((flag) => {
// extract property name from flag name
const property = flag.name.split('stats-')[1];
const propName = hyphenToUpperCase(property);
if (flag.type === Boolean) {
it(`should config --${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--${flag.name}`]);
expect(stderr).toBeFalsy();
if (flag.name.includes('reset')) {
const option = propName.split('Reset')[0];
expect(stdout).toContain(`stats: { ${option}: [] }`);
} else {
expect(stdout).toContain(`stats: { ${propName}: true }`);
}
});
it(`should config --no-${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--no-${flag.name}`]);
expect(stderr).toBeFalsy();
if (flag.name.includes('reset')) {
expect(stdout).toContain(`stats: {}`);
} else {
expect(stdout).toContain(`stats: { ${propName}: false }`);
}
});
}
if (flag.type === Number) {
it(`should config --${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--${flag.name}`, '10']);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`stats: { ${propName}: 10 }`);
});
}
if (flag.type === String) {
const acceptsSingleValue = ['preset', 'modulesSort', 'logging', 'chunksSort', 'assetsSort'];
it(`should config --${flag.name} correctly`, () => {
let { stderr, stdout } = run(__dirname, [`--${flag.name}`, 'log']);
expect(stderr).toBeFalsy();
if (flag.name.includes('stats-colors')) {
const option = flag.name.split('stats-colors-')[1];
stdout = run(__dirname, [`--${flag.name}`, 'u001b[32m']).stdout;
expect(stdout).toContain(`stats: { colors: { ${option}: 'u001b[32m' } }`);
} else if (acceptsSingleValue.includes(propName)) {
expect(stdout).toContain(`stats: { ${propName}: 'log' }`);
} else if (flag.name === 'stats-context') {
expect(stdout).toContain('log');
} else if (flag.name === 'stats-entrypoints') {
stdout = run(__dirname, [`--${flag.name}`, 'auto']).stdout;
expect(stdout).toContain(`stats: { ${propName}: 'auto' }`);
} else {
expect(stdout).toContain(`stats: { ${propName}: [ 'log' ] }`);
}
});
}
});
});