Skip to content

Commit 42c2e5d

Browse files
Tarraskshellscape
authored andcommitted
Use options.log, warn and error for compilation messages (#186)
When the compilation fails or has warnings, the compilation messages are outputted in console.log not using the options.error and options.warn functions. This commit change the defaultReporter to output the stats and final message to the options.error when the compilation has errors or the options.warn when it has warnings. The Reporter.test.js test cases are updated accordingly.
1 parent 3833a85 commit 42c2e5d

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

lib/Shared.js

100644100755
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,22 @@ module.exports = function Shared(context) {
4545
options.noInfo)
4646
displayStats = false;
4747
if(displayStats) {
48-
options.log(stats.toString(options.stats));
48+
if(stats.hasErrors()) {
49+
options.error(stats.toString(options.stats));
50+
} else if(stats.hasWarnings()) {
51+
options.warn(stats.toString(options.stats));
52+
} else {
53+
options.log(stats.toString(options.stats));
54+
}
4955
}
5056
if(!options.noInfo && !options.quiet) {
51-
var msg = "Compiled successfully.";
5257
if(stats.hasErrors()) {
53-
msg = "Failed to compile.";
58+
options.error("webpack: Failed to compile.");
5459
} else if(stats.hasWarnings()) {
55-
msg = "Compiled with warnings.";
60+
options.warn("webpack: Compiled with warnings.");
61+
} else {
62+
options.log("webpack: Compiled successfully.");
5663
}
57-
options.log("webpack: " + msg);
5864
}
5965
} else {
6066
options.log("webpack: Compiling...");

test/Reporter.test.js

100644100755
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,46 @@ describe("Reporter", function() {
4848
beforeEach(function() {
4949
plugins = {};
5050
this.sinon.stub(console, "log");
51+
this.sinon.stub(console, "warn");
52+
this.sinon.stub(console, "error");
5153
});
5254

53-
describe("valid/invalid messages", function() {
54-
it("should show compiled successfully message", function(done) {
55+
describe("compilation messages", function() {
56+
it("should show 'compiled successfully' message", function(done) {
5557
middleware(compiler);
5658

5759
plugins.done(simpleStats);
5860
setTimeout(function() {
5961
should.strictEqual(console.log.callCount, 2);
62+
should.strictEqual(console.warn.callCount, 0);
63+
should.strictEqual(console.error.callCount, 0);
6064
should.strictEqual(console.log.calledWith("webpack: Compiled successfully."), true);
6165
done();
6266
});
6367
});
6468

65-
it("should show compiled successfully message", function(done) {
69+
it("should show 'Failed to compile' message in console.error", function(done) {
6670
middleware(compiler);
6771

6872
plugins.done(errorStats);
6973
setTimeout(function() {
70-
should.strictEqual(console.log.calledWith("webpack: Failed to compile."), true);
74+
should.strictEqual(console.log.callCount, 0);
75+
should.strictEqual(console.warn.callCount, 0);
76+
should.strictEqual(console.error.callCount, 2);
77+
should.strictEqual(console.error.calledWith("webpack: Failed to compile."), true);
7178
done();
7279
});
7380
});
7481

75-
it("should show compiled with warnings message", function(done) {
82+
it("should show 'Compiled with warnings' message in console.warn", function(done) {
7683
middleware(compiler);
7784

7885
plugins.done(warningStats);
7986
setTimeout(function() {
80-
should.strictEqual(console.log.calledWith("webpack: Compiled with warnings."), true);
87+
should.strictEqual(console.log.callCount, 0);
88+
should.strictEqual(console.warn.callCount, 2);
89+
should.strictEqual(console.error.callCount, 0);
90+
should.strictEqual(console.warn.calledWith("webpack: Compiled with warnings."), true);
8191
done();
8292
});
8393
});

0 commit comments

Comments
 (0)