From 98deaf43bcb5f1ddf4e776cd59b4951cbe5ca9f4 Mon Sep 17 00:00:00 2001 From: anchengjian Date: Tue, 9 Jul 2019 03:48:17 +0800 Subject: [PATCH] fix: displayStats only logged (#427) * fix: displayStats only logged * test: should not print stats if options.stats without content --- lib/reporter.js | 10 ++++++---- test/reporter.test.js | 19 +++++++++++++++++++ 2 files changed, 25 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); } } 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;