/
colors.test.js
145 lines (113 loc) · 6.32 KB
/
colors.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
'use strict';
const { run, isWebpack5 } = require('../utils/test-utils');
const { resolve } = require('path');
const { options: coloretteOptions } = require('colorette');
describe('colorts', () => {
it('should output by default', () => {
const { stderr, stdout, exitCode } = run(__dirname);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(exitCode).toBe(0);
});
it('should work with the "stats" option from flags', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--stats=verbose']);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(exitCode).toBe(0);
});
it('should work with the "stats" option from flags and from configuration', () => {
const { stderr, stdout, exitCode } = run(__dirname, [
'--stats=verbose',
`--config=${resolve(__dirname, './no-stats.webpack.config.js')}`,
]);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(exitCode).toBe(0);
});
it('should work with the "stats" option from flags and from configuration #2', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--stats=verbose', '--config=stats-string.webpack.config.js']);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(exitCode).toBe(0);
});
it('should disable colored output with --no-color', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--stats=verbose', '--no-color']);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).not.toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
expect(stdout).toContain(output);
expect(exitCode).toBe(0);
});
it('should work with the "stats" option and --color flags', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--stats=verbose', '--color']);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
expect(exitCode).toBe(0);
});
it('should work with the "stats" option from the configuration', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--config=stats-string.webpack.config.js']);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(exitCode).toBe(0);
});
it('should work with the "stats" option from the configuration #1', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--config=stats-boolean.webpack.config.js']);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(exitCode).toBe(0);
});
it('should work with the "stats" option from the configuration #2', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--config=no-stats.webpack.config.js']);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(exitCode).toBe(0);
});
it('should work with the "stats" option from the configuration #3', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--config=colors-true.webpack.config.js']);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(coloretteOptions.enabled ? `\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m` : output);
expect(exitCode).toBe(0);
});
it('should work with the "stats" option from the configuration #4', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--config=colors-false.webpack.config.js']);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).not.toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
expect(stdout).toContain(output);
expect(exitCode).toBe(0);
});
it('should prioritize --color over colors in config', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--config=colors-false.webpack.config.js', '--color']);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
expect(exitCode).toBe(0);
});
it('should prioratize --no-color over colors in config', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--config=colors-true.webpack.config.js', '--no-color']);
expect(stderr).toBeFalsy();
const output = isWebpack5 ? 'successfully' : 'main.js';
expect(stdout).not.toContain(`\u001b[1m\u001b[32m${output}\u001b[39m\u001b[22m`);
expect(stdout).toContain(output);
expect(exitCode).toBe(0);
});
it('should work in multicompiler mode', () => {
const { stderr, stdout, exitCode } = run(__dirname, ['--config=multiple-configs.js', '--color']);
expect(stderr).toBeFalsy();
expect(exitCode).toBe(0);
if (isWebpack5) {
expect(stdout).toContain(`\u001b[1mfirst-config`);
expect(stdout).toContain(`\u001b[1msecond-config`);
expect(stdout).toContain(`\u001b[1m\u001b[32msuccessfully\u001b[39m\u001b[22m`);
}
});
});