diff --git a/src/raven.js b/src/raven.js index 5cab24d91c79..6e48e542addf 100644 --- a/src/raven.js +++ b/src/raven.js @@ -363,11 +363,13 @@ Raven.prototype = { return; } + options = options || {}; + var data = objectMerge({ message: msg + '' // Make sure it's actually a string }, options); - if (options && options.stacktrace) { + if (this._globalOptions.stacktrace || (options && options.stacktrace)) { var ex; // create a stack trace from this point; just trim // off extra frames so they don't include this function call (or diff --git a/test/raven.test.js b/test/raven.test.js index e3537dcffa27..a002cb467fde 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -2045,28 +2045,48 @@ describe('Raven (public API)', function() { }); }); - it('should include a synthetic stacktrace if stacktrace:true is passed', function () { - this.sinon.stub(Raven, 'isSetup').returns(true); - this.sinon.stub(Raven, '_send'); - function foo() { - Raven.captureMessage('foo', { - stacktrace: true - }); + describe('synthetic traces', function () { + function assertSynthetic(frames) { + // Raven.captureMessage + var last = frames[frames.length - 1]; + assert.isTrue(/(captureMessage|^\?)$/.test(last.function)); // loose equality check because differs per-browser + assert.equal(last.in_app, false); + + // foo + var secondLast = frames[frames.length - 2]; + assert.equal(secondLast.function, 'foo'); + assert.equal(secondLast.in_app, true); } - foo(); - var frames = Raven._send.lastCall.args[0].stacktrace.frames; + it('should get collected if stacktrace:true is passed via options', function () { + this.sinon.stub(Raven, 'isSetup').returns(true); + this.sinon.stub(Raven, '_send'); + + function foo() { + Raven.captureMessage('foo', { + stacktrace: true + }); + } + + foo(); + var frames = Raven._send.lastCall.args[0].stacktrace.frames; + assertSynthetic(frames); + }); + + it('should get collected if stacktrace:true is set via globalOptions', function () { + this.sinon.stub(Raven, 'isSetup').returns(true); + this.sinon.stub(Raven, '_send'); - // Raven.captureMessage - var last = frames[frames.length - 1]; - assert.isTrue(/(captureMessage|^\?)$/.test(last.function)); // loose equality check because differs per-browser - assert.equal(last.in_app, false); + Raven._globalOptions.stacktrace = true; + function foo() { + Raven.captureMessage('foo'); + } - // foo - var secondLast = frames[frames.length - 2]; - assert.equal(secondLast.function, 'foo'); - assert.equal(secondLast.in_app, true); + foo(); + var frames = Raven._send.lastCall.args[0].stacktrace.frames; + assertSynthetic(frames); + }); }); });