diff --git a/lib/reporter.js b/lib/reporter.js index c3ad186b6..917728a92 100644 --- a/lib/reporter.js +++ b/lib/reporter.js @@ -5,14 +5,16 @@ module.exports = function reporter(middlewareOptions, options) { if (state) { const displayStats = middlewareOptions.stats !== false; + const statsString = stats.toString(middlewareOptions.stats); - if (displayStats) { + // displayStats only logged + if (displayStats && statsString.trim().length) { if (stats.hasErrors()) { - log.error(stats.toString(middlewareOptions.stats)); + log.error(statsString); } else if (stats.hasWarnings()) { - log.warn(stats.toString(middlewareOptions.stats)); + log.warn(statsString); } else { - log.info(stats.toString(middlewareOptions.stats)); + log.info(statsString); } } diff --git a/test/reporter.test.js b/test/reporter.test.js index c4d2cf1da..9ae5ffc15 100644 --- a/test/reporter.test.js +++ b/test/reporter.test.js @@ -165,6 +165,25 @@ describe('Reporter', () => { }); }); + it('should not print stats if options.stats without content', (done) => { + const statsWithoutContent = Object.assign({}, stats, { + toString: () => '', + }); + const instance = middleware( + compiler, + Object.assign(defaults, { stats: statsWithoutContent }) + ); + const { log } = instance.context; + spy(instance); + hooks.done(statsWithoutContent); + + setTimeout(() => { + expect(log.info).toBeCalledTimes(1); + expect(log.info.mock.calls[0][0]).toBe('Compiled successfully.'); + done(); + }); + }); + it('should print: wait until bundle valid', (done) => { const instance = middleware(compiler, defaults); const { log } = instance.context;