From 01903cb651bfe492c464b275e305c09093ca9eea Mon Sep 17 00:00:00 2001 From: chengjian an Date: Wed, 26 Jun 2019 01:32:08 +0800 Subject: [PATCH 1/2] fix: displayStats only logged --- lib/reporter.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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); } } From a45a86beb3cb1ff950d2cc95543b874dd4950987 Mon Sep 17 00:00:00 2001 From: chengjian an Date: Thu, 27 Jun 2019 00:24:59 +0800 Subject: [PATCH 2/2] test: should not print stats if options.stats without content --- test/reporter.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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;