Skip to content

Use options.log, warn and error for compilation messages #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/Shared.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,22 @@ module.exports = function Shared(context) {
options.noInfo)
displayStats = false;
if(displayStats) {
options.log(stats.toString(options.stats));
if(stats.hasErrors()) {
options.error(stats.toString(options.stats));
} else if(stats.hasWarnings()) {
options.warn(stats.toString(options.stats));
} else {
options.log(stats.toString(options.stats));
}
}
if(!options.noInfo && !options.quiet) {
var msg = "Compiled successfully.";
if(stats.hasErrors()) {
msg = "Failed to compile.";
options.error("webpack: Failed to compile.");
} else if(stats.hasWarnings()) {
msg = "Compiled with warnings.";
options.warn("webpack: Compiled with warnings.");
} else {
options.log("webpack: Compiled successfully.");
}
options.log("webpack: " + msg);
}
} else {
options.log("webpack: Compiling...");
Expand Down
22 changes: 16 additions & 6 deletions test/Reporter.test.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,46 @@ describe("Reporter", function() {
beforeEach(function() {
plugins = {};
this.sinon.stub(console, "log");
this.sinon.stub(console, "warn");
this.sinon.stub(console, "error");
});

describe("valid/invalid messages", function() {
it("should show compiled successfully message", function(done) {
describe("compilation messages", function() {
it("should show 'compiled successfully' message", function(done) {
middleware(compiler);

plugins.done(simpleStats);
setTimeout(function() {
should.strictEqual(console.log.callCount, 2);
should.strictEqual(console.warn.callCount, 0);
should.strictEqual(console.error.callCount, 0);
should.strictEqual(console.log.calledWith("webpack: Compiled successfully."), true);
done();
});
});

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

plugins.done(errorStats);
setTimeout(function() {
should.strictEqual(console.log.calledWith("webpack: Failed to compile."), true);
should.strictEqual(console.log.callCount, 0);
should.strictEqual(console.warn.callCount, 0);
should.strictEqual(console.error.callCount, 2);
should.strictEqual(console.error.calledWith("webpack: Failed to compile."), true);
done();
});
});

it("should show compiled with warnings message", function(done) {
it("should show 'Compiled with warnings' message in console.warn", function(done) {
middleware(compiler);

plugins.done(warningStats);
setTimeout(function() {
should.strictEqual(console.log.calledWith("webpack: Compiled with warnings."), true);
should.strictEqual(console.log.callCount, 0);
should.strictEqual(console.warn.callCount, 2);
should.strictEqual(console.error.callCount, 0);
should.strictEqual(console.warn.calledWith("webpack: Compiled with warnings."), true);
done();
});
});
Expand Down