Skip to content

Commit 9b3cc28

Browse files
fix: reduce spammy logs (#2206)
1 parent fd8f3d5 commit 9b3cc28

File tree

114 files changed

+375
-749
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+375
-749
lines changed

packages/webpack-cli/__tests__/serve/serve.test.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ describe('Serve', () => {
1414
it('should run with cli', async () => {
1515
const { stderr, stdout } = await runServe([], __dirname);
1616

17-
expect(stderr).toContain('Compilation starting...');
18-
expect(stderr).toContain('Compilation finished');
17+
expect(stderr).toBeFalsy();
1918
expect(stdout).toContain('main.js');
2019
expect(stdout).not.toContain('HotModuleReplacementPlugin');
2120
});
2221

2322
it('should work with flags', async () => {
2423
const { stderr, stdout } = await runServe(['--hot'], __dirname);
2524

26-
expect(stderr).toContain('Compilation starting...');
27-
expect(stderr).toContain('Compilation finished');
25+
expect(stderr).toBeFalsy();
2826
expect(stdout).toContain('main.js');
2927
expect(stdout).toContain('HotModuleReplacementPlugin');
3028
});

packages/webpack-cli/lib/plugins/CLIPlugin.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ class CLIPlugin {
4242

4343
setupHelpfulOutput(compiler) {
4444
const pluginName = 'webpack-cli';
45-
const getCompilationName = (compilation) => (compilation.name ? ` '${compilation.name}'` : '');
45+
const getCompilationName = () => (compiler.name ? ` '${compiler.name}'` : '');
4646

47-
compiler.hooks.run.tap(pluginName, (compiler) => {
48-
this.logger.info(`Compilation${getCompilationName(compiler)} starting...`);
47+
compiler.hooks.run.tap(pluginName, () => {
48+
this.logger.log(`Compilation${getCompilationName()} starting...`);
4949
});
5050

5151
compiler.hooks.watchRun.tap(pluginName, (compiler) => {
@@ -55,22 +55,22 @@ class CLIPlugin {
5555
this.logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.');
5656
}
5757

58-
this.logger.info(`Compilation${getCompilationName(compiler)} starting...`);
58+
this.logger.log(`Compilation${getCompilationName()} starting...`);
5959
});
6060

6161
compiler.hooks.invalid.tap(pluginName, (filename, changeTime) => {
6262
const date = new Date(changeTime * 1000);
6363

64-
this.logger.info(`File '${filename}' was modified`);
64+
this.logger.log(`File '${filename}' was modified`);
6565
this.logger.log(`Changed time is ${date} (timestamp is ${changeTime})`);
6666
});
6767

68-
(compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap(pluginName, (stats) => {
69-
this.logger.info(`Compilation${getCompilationName(stats.compilation)} finished`);
68+
(compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap(pluginName, () => {
69+
this.logger.log(`Compilation${getCompilationName()} finished`);
7070

7171
process.nextTick(() => {
7272
if (compiler.watchMode) {
73-
this.logger.info(`Compiler${getCompilationName(stats.compilation)} is watching files for updates...`);
73+
this.logger.log(`Compiler${getCompilationName()} is watching files for updates...`);
7474
}
7575
});
7676
});

test/analyze/analyze-flag.test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ describe('--analyze flag', () => {
2222
const { exitCode, stderr, stdout } = run(__dirname, ['-c', './analyze.config.js', '--analyze']);
2323

2424
expect(exitCode).toBe(0);
25-
expect(stderr).toContain('Compilation starting...');
26-
expect(stderr).toContain('Compilation finished');
25+
expect(stderr).toBeFalsy();
2726
expect(stdout).toContain('Webpack Bundle Analyzer saved report to');
2827
expect(stdout.match(/Webpack Bundle Analyzer saved report to/g)).toHaveLength(1);
2928
});

test/bail/bail.test.js

+7-32
Original file line numberDiff line numberDiff line change
@@ -7,81 +7,56 @@ describe('bail and watch warning', () => {
77
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'bail-webpack.config.js']);
88

99
expect(exitCode).toEqual(0);
10-
expect(stderr).toContain('Compilation starting...');
11-
expect(stderr).toContain('Compilation finished');
12-
expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
10+
expect(stderr).toBeFalsy();
1311
expect(stdout).toBeTruthy();
1412
});
1513

1614
it('should not log warning in not watch mode without the "bail" option', async () => {
1715
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'no-bail-webpack.config.js']);
1816

1917
expect(exitCode).toEqual(0);
20-
expect(stderr).toContain('Compilation starting...');
21-
expect(stderr).toContain('Compilation finished');
22-
expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
18+
expect(stderr).toBeFalsy();
2319
expect(stdout).toBeTruthy();
2420
});
2521

2622
it('should not log warning in not watch mode without the "watch" option', async () => {
2723
const { stderr, stdout } = await runWatch(__dirname, ['-c', 'watch-webpack.config.js']);
2824

29-
expect(stderr).toContain('Compilation starting...');
30-
expect(stderr).toContain('Compilation finished');
31-
expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
25+
expect(stderr).toBeFalsy();
3226
expect(stdout).toBeTruthy();
3327
});
3428

3529
it('should not log warning without the "bail" option', async () => {
3630
const { stderr, stdout } = await runWatch(__dirname, ['-c', 'no-bail-webpack.config.js', '--watch']);
3731

38-
expect(stderr).toContain('Compilation starting...');
39-
expect(stderr).toContain('Compilation finished');
40-
expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
32+
expect(stderr).toBeFalsy();
4133
expect(stdout).toBeTruthy();
4234
});
4335

4436
it('should not log warning without the "bail" option', async () => {
4537
const { stderr, stdout } = await runWatch(__dirname, ['-c', 'no-bail-webpack.config.js', '--watch']);
4638

47-
expect(stderr).toContain('Compilation starting...');
48-
expect(stderr).toContain('Compilation finished');
49-
expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
39+
expect(stderr).toBeFalsy();
5040
expect(stdout).toBeTruthy();
5141
});
5242

5343
it('should log warning in watch mode', async () => {
5444
const { stderr, stdout } = await runWatch(__dirname, ['-c', 'bail-webpack.config.js', '--watch']);
5545

56-
expect(stderr).toContain('Compilation starting...');
57-
expect(stderr).toContain('Compilation finished');
5846
expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
5947
expect(stdout).toBeTruthy();
6048
});
6149

6250
it('should log warning in watch mode', async () => {
6351
const { stderr, stdout } = await runWatch(__dirname, ['-c', 'bail-and-watch-webpack.config.js']);
6452

65-
expect(stderr).toContain('Compilation starting...');
66-
expect(stderr).toContain('Compilation finished');
6753
expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
6854
expect(stdout).toBeTruthy();
6955
});
7056

7157
it('should log warning in case of multiple compilers', async () => {
72-
const { stderr, stdout } = await runWatch(
73-
__dirname,
74-
['-c', 'multi-webpack.config.js'],
75-
true,
76-
"Compiler 'second' is watching files for updates...",
77-
);
78-
79-
expect(stderr).toContain("Compilation 'first' starting...");
80-
expect(stderr).toContain("Compilation 'first' finished");
81-
expect(stderr).toContain("Compiler 'first' is watching files for updates...");
82-
expect(stderr).toContain("Compilation 'second' starting...");
83-
expect(stderr).toContain("Compilation 'second' finished");
84-
expect(stderr).toContain("Compiler 'second' is watching files for updates...");
58+
const { stderr, stdout } = await runWatch(__dirname, ['-c', 'multi-webpack.config.js'], true);
59+
8560
expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
8661
expect(stdout).toBeTruthy();
8762
});

test/build-errors/errors.test.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ describe('errors', () => {
88
const { exitCode, stderr, stdout } = run(__dirname);
99

1010
expect(exitCode).toBe(1);
11-
expect(stderr).toContain('Compilation starting...');
12-
expect(stderr).toContain('Compilation finished');
11+
expect(stderr).toBeFalsy();
1312
expect(stdout).toMatch(/ERROR/);
1413
expect(stdout).toMatch(/Error: Can't resolve/);
1514
});
@@ -18,8 +17,7 @@ describe('errors', () => {
1817
const { exitCode, stderr, stdout } = run(__dirname, ['--json']);
1918

2019
expect(exitCode).toBe(1);
21-
expect(stderr).not.toContain('Compilation starting...');
22-
expect(stderr).not.toContain('Compilation finished');
20+
expect(stderr).toBeFalsy();
2321
expect(() => JSON.parse(stdout)).not.toThrow();
2422

2523
const json = JSON.parse(stdout);
@@ -34,8 +32,7 @@ describe('errors', () => {
3432
const { exitCode, stderr, stdout } = run(__dirname, ['--json', 'stats.json']);
3533

3634
expect(exitCode).toBe(1);
37-
expect(stderr).not.toContain('Compilation starting...');
38-
expect(stderr).not.toContain('Compilation finished');
35+
expect(stderr).toBeFalsy();
3936
expect(stdout).toContain('stats are successfully stored as json to stats.json');
4037

4138
readFile(resolve(__dirname, 'stats.json'), 'utf-8', (error, data) => {

test/build-warnings/warnings.test.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ describe('warnings', () => {
88
const { exitCode, stderr, stdout } = run(__dirname);
99

1010
expect(exitCode).toBe(0);
11-
expect(stderr).toContain('Compilation starting...');
12-
expect(stderr).toContain('Compilation finished');
11+
expect(stderr).toBeFalsy();
1312
expect(stdout).toMatch(/WARNING/);
1413
expect(stdout).toMatch(/Error: Can't resolve/);
1514
});
@@ -18,8 +17,7 @@ describe('warnings', () => {
1817
const { exitCode, stderr, stdout } = run(__dirname, ['--json']);
1918

2019
expect(exitCode).toBe(0);
21-
expect(stderr).not.toContain('Compilation starting...');
22-
expect(stderr).not.toContain('Compilation finished');
20+
expect(stderr).toBeFalsy();
2321

2422
expect(() => JSON.parse(stdout)).not.toThrow();
2523

@@ -35,8 +33,7 @@ describe('warnings', () => {
3533
const { exitCode, stderr, stdout } = run(__dirname, ['--json', 'stats.json']);
3634

3735
expect(exitCode).toBe(0);
38-
expect(stderr).not.toContain('Compilation starting...');
39-
expect(stderr).not.toContain('Compilation finished');
36+
expect(stderr).toBeFalsy();
4037
expect(stdout).toContain('stats are successfully stored as json to stats.json');
4138

4239
expect(existsSync(resolve(__dirname, './stats.json'))).toBeTruthy();

test/cache/cache.test.js

+15-29
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ describe('cache', () => {
1313
expect(exitCode).toEqual(0);
1414

1515
if (isWebpack5) {
16-
expect(stderr).toContain("Compilation 'cache-test-default' starting...");
17-
expect(stderr).toContain("Compilation 'cache-test-default' finished");
1816
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
1917
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
18+
expect(stderr).toBeTruthy();
2019
expect(stdout).toBeTruthy();
2120
}
2221

@@ -25,29 +24,27 @@ describe('cache', () => {
2524
expect(exitCode).toEqual(0);
2625

2726
if (isWebpack5) {
28-
expect(stderr).toContain("Compilation 'cache-test-default' starting...");
29-
expect(stderr).toContain("Compilation 'cache-test-default' finished");
3027
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
3128
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
3229
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
30+
expect(stderr).toBeTruthy();
3331
expect(stdout).toBeTruthy();
3432
}
3533
});
3634

3735
it('should work in multi compiler mode', () => {
38-
rimraf.sync(path.join(__dirname, '../../node_modules/.cache/webpack/cache-test-{first,second}-development'));
36+
rimraf.sync(path.join(__dirname, '../../node_modules/.cache/webpack/cache-test-first-development'));
37+
rimraf.sync(path.join(__dirname, '../../node_modules/.cache/webpack/cache-test-second-development'));
3938

4039
let { exitCode, stderr, stdout } = run(__dirname, ['-c', './multi.config.js'], false);
4140

4241
expect(exitCode).toEqual(0);
4342

4443
if (isWebpack5) {
45-
expect(stderr).toContain("Compilation 'cache-test-first' starting...");
46-
expect(stderr).toContain("Compilation 'cache-test-first' finished");
47-
expect(stderr).toContain("Compilation 'cache-test-second' starting...");
48-
expect(stderr).toContain("Compilation 'cache-test-second' finished");
44+
console.log(stderr);
4945
expect(stderr.match(/No pack exists at/g)).toHaveLength(2);
5046
expect(stderr.match(/Stored pack/g)).toHaveLength(2);
47+
expect(stderr).toBeTruthy();
5148
expect(stdout).toBeTruthy();
5249
}
5350

@@ -56,13 +53,10 @@ describe('cache', () => {
5653
expect(exitCode).toEqual(0);
5754

5855
if (isWebpack5) {
59-
expect(stderr).toContain("Compilation 'cache-test-first' starting...");
60-
expect(stderr).toContain("Compilation 'cache-test-first' finished");
61-
expect(stderr).toContain("Compilation 'cache-test-second' starting...");
62-
expect(stderr).toContain("Compilation 'cache-test-second' finished");
6356
expect(stderr.match(/restore cache container:/g)).toHaveLength(2);
6457
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(2);
6558
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(2);
59+
expect(stderr).toBeTruthy();
6660
expect(stdout).toBeTruthy();
6761
}
6862
});
@@ -79,10 +73,9 @@ describe('cache', () => {
7973
expect(exitCode).toEqual(0);
8074

8175
if (isWebpack5) {
82-
expect(stderr).toContain("Compilation 'cache-test-third' starting...");
83-
expect(stderr).toContain("Compilation 'cache-test-third' finished");
8476
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
8577
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
78+
expect(stderr).toBeTruthy();
8679
expect(stdout).toBeTruthy();
8780
}
8881

@@ -95,11 +88,10 @@ describe('cache', () => {
9588
expect(exitCode).toEqual(0);
9689

9790
if (isWebpack5) {
98-
expect(stderr).toContain("Compilation 'cache-test-third' starting...");
99-
expect(stderr).toContain("Compilation 'cache-test-third' finished");
10091
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
10192
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
10293
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
94+
expect(stderr).toBeTruthy();
10395
expect(stdout).toBeTruthy();
10496
}
10597
});
@@ -116,10 +108,9 @@ describe('cache', () => {
116108
expect(exitCode).toEqual(0);
117109

118110
if (isWebpack5) {
119-
expect(stderr).toContain("Compilation 'cache-test-fourth' starting...");
120-
expect(stderr).toContain("Compilation 'cache-test-fourth' finished");
121111
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
122112
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
113+
expect(stderr).toBeTruthy();
123114
expect(stdout).toBeTruthy();
124115
}
125116

@@ -132,11 +123,10 @@ describe('cache', () => {
132123
expect(exitCode).toEqual(0);
133124

134125
if (isWebpack5) {
135-
expect(stderr).toContain("Compilation 'cache-test-fourth' starting...");
136-
expect(stderr).toContain("Compilation 'cache-test-fourth' finished");
137126
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
138127
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
139128
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
129+
expect(stderr).toBeTruthy();
140130
expect(stdout).toBeTruthy();
141131
}
142132
});
@@ -165,10 +155,9 @@ describe('cache', () => {
165155
expect(exitCode).toEqual(0);
166156

167157
if (isWebpack5) {
168-
expect(stderr).toContain("Compilation 'cache-test-fifth' starting...");
169-
expect(stderr).toContain("Compilation 'cache-test-fifth' finished");
170158
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
171159
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
160+
expect(stderr).toBeTruthy();
172161
expect(stdout).toBeTruthy();
173162
}
174163

@@ -193,11 +182,10 @@ describe('cache', () => {
193182
expect(exitCode).toEqual(0);
194183

195184
if (isWebpack5) {
196-
expect(stderr).toContain("Compilation 'cache-test-fifth' starting...");
197-
expect(stderr).toContain("Compilation 'cache-test-fifth' finished");
198185
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
199186
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
200187
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
188+
expect(stderr).toBeTruthy();
201189
expect(stdout).toBeTruthy();
202190
}
203191
});
@@ -210,10 +198,9 @@ describe('cache', () => {
210198
expect(exitCode).toEqual(0);
211199

212200
if (isWebpack5) {
213-
expect(stderr).toContain("Compilation 'cache-test-autoloading' starting...");
214-
expect(stderr).toContain("Compilation 'cache-test-autoloading' finished");
215201
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
216202
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
203+
expect(stderr).toBeTruthy();
217204
expect(stdout).toBeTruthy();
218205
}
219206

@@ -222,11 +209,10 @@ describe('cache', () => {
222209
expect(exitCode).toEqual(0);
223210

224211
if (isWebpack5) {
225-
expect(stderr).toContain("Compilation 'cache-test-autoloading' starting...");
226-
expect(stderr).toContain("Compilation 'cache-test-autoloading' finished");
227212
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
228213
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
229214
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
215+
expect(stderr).toBeTruthy();
230216
expect(stdout).toBeTruthy();
231217
}
232218
});

0 commit comments

Comments
 (0)