Skip to content

Commit 1df1c94

Browse files
committed
First pass at tests
1 parent df508d4 commit 1df1c94

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
@@ -384,6 +384,8 @@ Raven.prototype = {
384384
ex = ex1;
385385
}
386386

387+
console.log(ex.stack);
388+
387389
// null exception name so `Error` isn't prefixed to msg
388390
ex.name = null;
389391

@@ -1132,15 +1134,15 @@ Raven.prototype = {
11321134

11331135
// e.g. frames captured via captureMessage throw
11341136
var j;
1135-
if (options && options.trimHeadFrames) {
1136-
for (j = 0; j < options.trimHeadFrames && j < frames.length; j++) {
1137+
if (options && options.trimTailFrames) {
1138+
for (j = 0; j < options.trimTailFrames && j < frames.length; j++) {
11371139
frames[j].in_app = false;
11381140
}
11391141
}
11401142

11411143
// e.g. try/catch (wrapper) frames
1142-
if (options && options.trimTailFrames) {
1143-
for (j = options.trimTailFrames; j < frames.length; j++) {
1144+
if (options && options.trimHeadFrames) {
1145+
for (j = frames.length - options.trimHeadFrames; j < frames.length; j++) {
11441146
frames[j].in_app = false;
11451147
}
11461148
}

test/raven.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,29 @@ describe('Raven (public API)', function() {
20272027
});
20282028
});
20292029

2030+
it('should include a synthetic stacktrace if stacktrace:true is passed', function () {
2031+
this.sinon.stub(Raven, 'isSetup').returns(true);
2032+
this.sinon.stub(Raven, '_send');
2033+
2034+
function foo() {
2035+
Raven.captureMessage('foo', {
2036+
stacktrace: true
2037+
});
2038+
}
2039+
2040+
foo();
2041+
var frames = Raven._send.lastCall.args[0].stacktrace.frames;
2042+
2043+
// Raven.captureMessage
2044+
var last = frames[frames.length - 1];
2045+
console.log(last.function);
2046+
assert.isTrue(/captureMessage/.test(last.function)); // loose equality check because differs per-browser
2047+
assert.equal(last.in_app, false);
2048+
2049+
var secondLast = frames[frames.length - 2];
2050+
assert.equal(secondLast.function, 'foo');
2051+
assert.equal(secondLast.in_app, true);
2052+
});
20302053
});
20312054

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

0 commit comments

Comments
 (0)