Skip to content

Commit

Permalink
fix: reduce spammy logs (#2206)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 8, 2020
1 parent fd8f3d5 commit 9b3cc28
Show file tree
Hide file tree
Showing 114 changed files with 375 additions and 749 deletions.
6 changes: 2 additions & 4 deletions packages/webpack-cli/__tests__/serve/serve.test.js
Expand Up @@ -14,17 +14,15 @@ describe('Serve', () => {
it('should run with cli', async () => {
const { stderr, stdout } = await runServe([], __dirname);

expect(stderr).toContain('Compilation starting...');
expect(stderr).toContain('Compilation finished');
expect(stderr).toBeFalsy();
expect(stdout).toContain('main.js');
expect(stdout).not.toContain('HotModuleReplacementPlugin');
});

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

expect(stderr).toContain('Compilation starting...');
expect(stderr).toContain('Compilation finished');
expect(stderr).toBeFalsy();
expect(stdout).toContain('main.js');
expect(stdout).toContain('HotModuleReplacementPlugin');
});
Expand Down
16 changes: 8 additions & 8 deletions packages/webpack-cli/lib/plugins/CLIPlugin.js
Expand Up @@ -42,10 +42,10 @@ class CLIPlugin {

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

compiler.hooks.run.tap(pluginName, (compiler) => {
this.logger.info(`Compilation${getCompilationName(compiler)} starting...`);
compiler.hooks.run.tap(pluginName, () => {
this.logger.log(`Compilation${getCompilationName()} starting...`);
});

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

this.logger.info(`Compilation${getCompilationName(compiler)} starting...`);
this.logger.log(`Compilation${getCompilationName()} starting...`);
});

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

this.logger.info(`File '${filename}' was modified`);
this.logger.log(`File '${filename}' was modified`);
this.logger.log(`Changed time is ${date} (timestamp is ${changeTime})`);
});

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

process.nextTick(() => {
if (compiler.watchMode) {
this.logger.info(`Compiler${getCompilationName(stats.compilation)} is watching files for updates...`);
this.logger.log(`Compiler${getCompilationName()} is watching files for updates...`);
}
});
});
Expand Down
3 changes: 1 addition & 2 deletions test/analyze/analyze-flag.test.js
Expand Up @@ -22,8 +22,7 @@ describe('--analyze flag', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['-c', './analyze.config.js', '--analyze']);

expect(exitCode).toBe(0);
expect(stderr).toContain('Compilation starting...');
expect(stderr).toContain('Compilation finished');
expect(stderr).toBeFalsy();
expect(stdout).toContain('Webpack Bundle Analyzer saved report to');
expect(stdout.match(/Webpack Bundle Analyzer saved report to/g)).toHaveLength(1);
});
Expand Down
39 changes: 7 additions & 32 deletions test/bail/bail.test.js
Expand Up @@ -7,81 +7,56 @@ describe('bail and watch warning', () => {
const { exitCode, stderr, stdout } = await run(__dirname, ['-c', 'bail-webpack.config.js']);

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

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

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

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

expect(stderr).toContain('Compilation starting...');
expect(stderr).toContain('Compilation finished');
expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

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

expect(stderr).toContain('Compilation starting...');
expect(stderr).toContain('Compilation finished');
expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

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

expect(stderr).toContain('Compilation starting...');
expect(stderr).toContain('Compilation finished');
expect(stderr).not.toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});

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

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

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

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

it('should log warning in case of multiple compilers', async () => {
const { stderr, stdout } = await runWatch(
__dirname,
['-c', 'multi-webpack.config.js'],
true,
"Compiler 'second' is watching files for updates...",
);

expect(stderr).toContain("Compilation 'first' starting...");
expect(stderr).toContain("Compilation 'first' finished");
expect(stderr).toContain("Compiler 'first' is watching files for updates...");
expect(stderr).toContain("Compilation 'second' starting...");
expect(stderr).toContain("Compilation 'second' finished");
expect(stderr).toContain("Compiler 'second' is watching files for updates...");
const { stderr, stdout } = await runWatch(__dirname, ['-c', 'multi-webpack.config.js'], true);

expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
expect(stdout).toBeTruthy();
});
Expand Down
9 changes: 3 additions & 6 deletions test/build-errors/errors.test.js
Expand Up @@ -8,8 +8,7 @@ describe('errors', () => {
const { exitCode, stderr, stdout } = run(__dirname);

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

expect(exitCode).toBe(1);
expect(stderr).not.toContain('Compilation starting...');
expect(stderr).not.toContain('Compilation finished');
expect(stderr).toBeFalsy();
expect(() => JSON.parse(stdout)).not.toThrow();

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

expect(exitCode).toBe(1);
expect(stderr).not.toContain('Compilation starting...');
expect(stderr).not.toContain('Compilation finished');
expect(stderr).toBeFalsy();
expect(stdout).toContain('stats are successfully stored as json to stats.json');

readFile(resolve(__dirname, 'stats.json'), 'utf-8', (error, data) => {
Expand Down
9 changes: 3 additions & 6 deletions test/build-warnings/warnings.test.js
Expand Up @@ -8,8 +8,7 @@ describe('warnings', () => {
const { exitCode, stderr, stdout } = run(__dirname);

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

expect(exitCode).toBe(0);
expect(stderr).not.toContain('Compilation starting...');
expect(stderr).not.toContain('Compilation finished');
expect(stderr).toBeFalsy();

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

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

expect(exitCode).toBe(0);
expect(stderr).not.toContain('Compilation starting...');
expect(stderr).not.toContain('Compilation finished');
expect(stderr).toBeFalsy();
expect(stdout).toContain('stats are successfully stored as json to stats.json');

expect(existsSync(resolve(__dirname, './stats.json'))).toBeTruthy();
Expand Down
44 changes: 15 additions & 29 deletions test/cache/cache.test.js
Expand Up @@ -13,10 +13,9 @@ describe('cache', () => {
expect(exitCode).toEqual(0);

if (isWebpack5) {
expect(stderr).toContain("Compilation 'cache-test-default' starting...");
expect(stderr).toContain("Compilation 'cache-test-default' finished");
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
}

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

if (isWebpack5) {
expect(stderr).toContain("Compilation 'cache-test-default' starting...");
expect(stderr).toContain("Compilation 'cache-test-default' finished");
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
}
});

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

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

expect(exitCode).toEqual(0);

if (isWebpack5) {
expect(stderr).toContain("Compilation 'cache-test-first' starting...");
expect(stderr).toContain("Compilation 'cache-test-first' finished");
expect(stderr).toContain("Compilation 'cache-test-second' starting...");
expect(stderr).toContain("Compilation 'cache-test-second' finished");
console.log(stderr);
expect(stderr.match(/No pack exists at/g)).toHaveLength(2);
expect(stderr.match(/Stored pack/g)).toHaveLength(2);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
}

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

if (isWebpack5) {
expect(stderr).toContain("Compilation 'cache-test-first' starting...");
expect(stderr).toContain("Compilation 'cache-test-first' finished");
expect(stderr).toContain("Compilation 'cache-test-second' starting...");
expect(stderr).toContain("Compilation 'cache-test-second' finished");
expect(stderr.match(/restore cache container:/g)).toHaveLength(2);
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(2);
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(2);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
}
});
Expand All @@ -79,10 +73,9 @@ describe('cache', () => {
expect(exitCode).toEqual(0);

if (isWebpack5) {
expect(stderr).toContain("Compilation 'cache-test-third' starting...");
expect(stderr).toContain("Compilation 'cache-test-third' finished");
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
}

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

if (isWebpack5) {
expect(stderr).toContain("Compilation 'cache-test-third' starting...");
expect(stderr).toContain("Compilation 'cache-test-third' finished");
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
}
});
Expand All @@ -116,10 +108,9 @@ describe('cache', () => {
expect(exitCode).toEqual(0);

if (isWebpack5) {
expect(stderr).toContain("Compilation 'cache-test-fourth' starting...");
expect(stderr).toContain("Compilation 'cache-test-fourth' finished");
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
}

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

if (isWebpack5) {
expect(stderr).toContain("Compilation 'cache-test-fourth' starting...");
expect(stderr).toContain("Compilation 'cache-test-fourth' finished");
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
}
});
Expand Down Expand Up @@ -165,10 +155,9 @@ describe('cache', () => {
expect(exitCode).toEqual(0);

if (isWebpack5) {
expect(stderr).toContain("Compilation 'cache-test-fifth' starting...");
expect(stderr).toContain("Compilation 'cache-test-fifth' finished");
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
}

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

if (isWebpack5) {
expect(stderr).toContain("Compilation 'cache-test-fifth' starting...");
expect(stderr).toContain("Compilation 'cache-test-fifth' finished");
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
}
});
Expand All @@ -210,10 +198,9 @@ describe('cache', () => {
expect(exitCode).toEqual(0);

if (isWebpack5) {
expect(stderr).toContain("Compilation 'cache-test-autoloading' starting...");
expect(stderr).toContain("Compilation 'cache-test-autoloading' finished");
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
}

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

if (isWebpack5) {
expect(stderr).toContain("Compilation 'cache-test-autoloading' starting...");
expect(stderr).toContain("Compilation 'cache-test-autoloading' finished");
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
}
});
Expand Down

0 comments on commit 9b3cc28

Please sign in to comment.