Skip to content

Commit 98deaf4

Browse files
anchengjianhiroppy
authored andcommitted
fix: displayStats only logged (#427)
* fix: displayStats only logged * test: should not print stats if options.stats without content
1 parent dff39a1 commit 98deaf4

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

lib/reporter.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ module.exports = function reporter(middlewareOptions, options) {
55

66
if (state) {
77
const displayStats = middlewareOptions.stats !== false;
8+
const statsString = stats.toString(middlewareOptions.stats);
89

9-
if (displayStats) {
10+
// displayStats only logged
11+
if (displayStats && statsString.trim().length) {
1012
if (stats.hasErrors()) {
11-
log.error(stats.toString(middlewareOptions.stats));
13+
log.error(statsString);
1214
} else if (stats.hasWarnings()) {
13-
log.warn(stats.toString(middlewareOptions.stats));
15+
log.warn(statsString);
1416
} else {
15-
log.info(stats.toString(middlewareOptions.stats));
17+
log.info(statsString);
1618
}
1719
}
1820

test/reporter.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,25 @@ describe('Reporter', () => {
165165
});
166166
});
167167

168+
it('should not print stats if options.stats without content', (done) => {
169+
const statsWithoutContent = Object.assign({}, stats, {
170+
toString: () => '',
171+
});
172+
const instance = middleware(
173+
compiler,
174+
Object.assign(defaults, { stats: statsWithoutContent })
175+
);
176+
const { log } = instance.context;
177+
spy(instance);
178+
hooks.done(statsWithoutContent);
179+
180+
setTimeout(() => {
181+
expect(log.info).toBeCalledTimes(1);
182+
expect(log.info.mock.calls[0][0]).toBe('Compiled successfully.');
183+
done();
184+
});
185+
});
186+
168187
it('should print: wait until bundle valid', (done) => {
169188
const instance = middleware(compiler, defaults);
170189
const { log } = instance.context;

0 commit comments

Comments
 (0)