Skip to content

Commit 9403f01

Browse files
committed
First pass at tests
1 parent 7fbf87b commit 9403f01

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/raven.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ Raven.prototype = {
363363
ex = ex1;
364364
}
365365

366+
console.log(ex.stack);
367+
366368
// null exception name so `Error` isn't prefixed to msg
367369
ex.name = null;
368370

@@ -1084,15 +1086,15 @@ Raven.prototype = {
10841086

10851087
// e.g. frames captured via captureMessage throw
10861088
var j;
1087-
if (options && options.trimHeadFrames) {
1088-
for (j = 0; j < options.trimHeadFrames && j < frames.length; j++) {
1089+
if (options && options.trimTailFrames) {
1090+
for (j = 0; j < options.trimTailFrames && j < frames.length; j++) {
10891091
frames[j].in_app = false;
10901092
}
10911093
}
10921094

10931095
// e.g. try/catch (wrapper) frames
1094-
if (options && options.trimTailFrames) {
1095-
for (j = options.trimTailFrames; j < frames.length; j++) {
1096+
if (options && options.trimHeadFrames) {
1097+
for (j = frames.length - options.trimHeadFrames; j < frames.length; j++) {
10961098
frames[j].in_app = false;
10971099
}
10981100
}

test/raven.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,29 @@ describe('Raven (public API)', function() {
19101910
});
19111911
});
19121912

1913+
it('should include a synthetic stacktrace if stacktrace:true is passed', function () {
1914+
this.sinon.stub(Raven, 'isSetup').returns(true);
1915+
this.sinon.stub(Raven, '_send');
1916+
1917+
function foo() {
1918+
Raven.captureMessage('foo', {
1919+
stacktrace: true
1920+
});
1921+
}
1922+
1923+
foo();
1924+
var frames = Raven._send.lastCall.args[0].stacktrace.frames;
1925+
1926+
// Raven.captureMessage
1927+
var last = frames[frames.length - 1];
1928+
console.log(last.function);
1929+
assert.isTrue(/captureMessage/.test(last.function)); // loose equality check because differs per-browser
1930+
assert.equal(last.in_app, false);
1931+
1932+
var secondLast = frames[frames.length - 2];
1933+
assert.equal(secondLast.function, 'foo');
1934+
assert.equal(secondLast.in_app, true);
1935+
});
19131936
});
19141937

19151938
describe('.captureException', function() {

0 commit comments

Comments
 (0)