Skip to content

Commit

Permalink
fix: displayStats only logged (#427)
Browse files Browse the repository at this point in the history
* fix: displayStats only logged

* test: should not print stats if options.stats without content
  • Loading branch information
anchengjian authored and hiroppy committed Jul 8, 2019
1 parent dff39a1 commit 98deaf4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/reporter.js
Expand Up @@ -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);
}
}

Expand Down
19 changes: 19 additions & 0 deletions test/reporter.test.js
Expand Up @@ -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;
Expand Down

0 comments on commit 98deaf4

Please sign in to comment.