Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Fix autoNotifyUnhandledRejection option
Browse files Browse the repository at this point in the history
  • Loading branch information
bengourley committed Oct 23, 2017
1 parent 508925d commit cc02caa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var Configuration = {
Configuration.releaseStage = options.releaseStage || Configuration.releaseStage;
Configuration.appVersion = options.appVersion || Configuration.appVersion;
Configuration.autoNotifyUncaught = options.autoNotify != null ? options.autoNotify : Configuration.autoNotifyUncaught;
Configuration.autoNotifyUnhandledRejection = options.autoNotify != null ? options.autoNotify : Configuration.autoNotifyUnhandledRejection;
Configuration.autoNotifyUnhandledRejection = options.autoNotifyUnhandledRejection === false ? false : (options.autoNotify != null ? options.autoNotify : Configuration.autoNotifyUnhandledRejection);
Configuration.useSSL = options.useSSL != null ? options.useSSL : Configuration.useSSL;
Configuration.filters = options.filters || Configuration.filters;
Configuration.notifyReleaseStages = options.notifyReleaseStages || Configuration.notifyReleaseStages;
Expand Down
4 changes: 3 additions & 1 deletion test/lib/process-unhandled-rejection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ var bugsnag = require("../../"),
Notification = require("../../lib/notification"),
sinon = require("sinon");

bugsnag.register("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
bugsnag.register("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", {
autoNotifyUnhandledRejection: process.env.NOTIFY_UNHANDLED_REJECTION !== 'no'
});

var deliverStub = sinon.stub(Notification.prototype, "_deliver").yields(null, {});
process.on("exit", function (code) {
Expand Down
26 changes: 22 additions & 4 deletions test/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,13 @@ describe("Notification", function() {
var payload;
p.on("message", function (msg) {
deliverCalled = msg.deliverCalled;
payload = msg.payload
payload = msg.payload;
});
p.on("exit", function (code) {
try {
code.should.equal(1);
deliverCalled.should.equal(true);
var event = payload.events[0]
var event = payload.events[0];
event.severity.should.equal("error");
event.unhandled.should.equal(true);
event.severityReason.should.eql({ type: "unhandledException" });
Expand All @@ -446,13 +446,13 @@ describe("Notification", function() {
var payload;
p.on("message", function (msg) {
deliverCalled = msg.deliverCalled;
payload = msg.payload
payload = msg.payload;
});
p.on("exit", function (code) {
try {
code.should.equal(1);
deliverCalled.should.equal(true);
var event = payload.events[0]
var event = payload.events[0];
event.severity.should.equal("error");
event.unhandled.should.equal(true);
event.severityReason.should.eql({ type: "unhandledPromiseRejection" });
Expand All @@ -462,6 +462,24 @@ describe("Notification", function() {
}
});
});

it("should support autoNotifyUnhandledRejection=false", function (done) {
var p = child_process.fork(__dirname + "/lib/process-unhandled-rejection.js", { env: { NOTIFY_UNHANDLED_REJECTION: 'no' } });
var deliverCalled = false;
var payload;
p.on("message", function (msg) {
deliverCalled = msg.deliverCalled;
});
p.on("exit", function (code) {
try {
code.should.equal(0);
deliverCalled.should.equal(false);
done();
} catch (e) {
done(e);
}
});
});
});

describe("handledState properties", function (done) {
Expand Down

0 comments on commit cc02caa

Please sign in to comment.