Skip to content

Commit faa931e

Browse files
committed
Add tests for checking onerror doesn't catch same error twice
1 parent 2973fc6 commit faa931e

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

test/integration/frame.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@
4545
// making "clean" stack traces that don't originate from mocha)
4646
window.origSetTimeout = setTimeout;
4747

48+
window.ravenData = [];
4849
Raven.config('https://[email protected]/1', {
4950
dataCallback: function (data) {
50-
window.ravenData = data;
51+
ravenData.push(data);
5152
}
5253
}).install();
5354

test/integration/test.js

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('integration', function () {
4343
done();
4444
},
4545
function () {
46-
var ravenData = iframe.contentWindow.ravenData;
46+
var ravenData = iframe.contentWindow.ravenData[0];
4747
assert.equal(ravenData.message, 'Hello');
4848
}
4949
);
@@ -62,7 +62,7 @@ describe('integration', function () {
6262
}
6363
},
6464
function () {
65-
var ravenData = iframe.contentWindow.ravenData;
65+
var ravenData = iframe.contentWindow.ravenData[0];
6666
assert.isAbove(ravenData.exception.values[0].stacktrace.frames.length, 1);
6767
}
6868
);
@@ -79,12 +79,51 @@ describe('integration', function () {
7979
eval('foo{};');
8080
},
8181
function () {
82-
var ravenData = iframe.contentWindow.ravenData;
82+
var ravenData = iframe.contentWindow.ravenData[0];
8383
assert.isTrue(/SyntaxError/.test(ravenData.message)); // full message differs per-browser
8484
assert.equal(ravenData.exception.values[0].stacktrace.frames.length, 1); // just one frame
8585
}
8686
);
8787
});
88+
89+
it('should NOT catch an exception already caught via Raven.wrap', function (done) {
90+
var iframe = this.iframe;
91+
92+
iframeExecute(iframe, done,
93+
function () {
94+
setTimeout(done);
95+
Raven.wrap(function () {
96+
foo();
97+
})();
98+
},
99+
function () {
100+
var ravenData = iframe.contentWindow.ravenData;
101+
assert.equal(ravenData.length, 1); // one caught error
102+
}
103+
);
104+
});
105+
106+
it('should catch an exception already caught [but rethrown] via Raven.captureException', function (done) {
107+
// unlike Raven.wrap which ALWAYS re-throws, we don't know if the user will
108+
// re-throw an exception passed to Raven.captureException, and so we cannot
109+
// automatically suppress the next error caught through window.onerror
110+
var iframe = this.iframe;
111+
iframeExecute(iframe, done,
112+
function () {
113+
setTimeout(done, 50);
114+
try {
115+
foo();
116+
} catch (e) {
117+
Raven.captureException(e);
118+
throw e; // intentionally re-throw
119+
}
120+
},
121+
function () {
122+
var ravenData = iframe.contentWindow.ravenData;
123+
assert.equal(ravenData.length, 2);
124+
}
125+
);
126+
});
88127
});
89128

90129
describe('wrapped built-ins', function () {
@@ -111,7 +150,7 @@ describe('integration', function () {
111150
}
112151
},
113152
function () {
114-
var ravenData = iframe.contentWindow.ravenData;
153+
var ravenData = iframe.contentWindow.ravenData[0];
115154
assert.isAbove(ravenData.exception.values[0].stacktrace.frames.length, 2);
116155
}
117156
);
@@ -140,7 +179,7 @@ describe('integration', function () {
140179
}
141180
},
142181
function () {
143-
var ravenData = iframe.contentWindow.ravenData;
182+
var ravenData = iframe.contentWindow.ravenData[0];
144183
assert.equal(ravenData, null); // should never trigger error
145184
}
146185
);
@@ -157,7 +196,7 @@ describe('integration', function () {
157196
}, 10);
158197
},
159198
function () {
160-
var ravenData = iframe.contentWindow.ravenData;
199+
var ravenData = iframe.contentWindow.ravenData[0];
161200
assert.isAbove(ravenData.exception.values[0].stacktrace.frames.length, 2);
162201
}
163202
);
@@ -175,7 +214,7 @@ describe('integration', function () {
175214
}, 10);
176215
},
177216
function () {
178-
var ravenData = iframe.contentWindow.ravenData;
217+
var ravenData = iframe.contentWindow.ravenData[0];
179218
assert.isAbove(ravenData.exception.values[0].stacktrace.frames.length, 2);
180219
}
181220
);
@@ -194,7 +233,7 @@ describe('integration', function () {
194233
});
195234
},
196235
function () {
197-
var ravenData = iframe.contentWindow.ravenData;
236+
var ravenData = iframe.contentWindow.ravenData[0];
198237
assert.isAbove(ravenData.exception.values[0].stacktrace.frames.length, 2);
199238
}
200239
);
@@ -214,7 +253,7 @@ describe('integration', function () {
214253
xhr.send();
215254
},
216255
function () {
217-
var ravenData = iframe.contentWindow.ravenData;
256+
var ravenData = iframe.contentWindow.ravenData[0];
218257
// # of frames alter significantly between chrome/firefox & safari
219258
assert.isAbove(ravenData.exception.values[0].stacktrace.frames.length, 2);
220259
}

0 commit comments

Comments
 (0)