Skip to content

Commit 4632353

Browse files
committed
Add integration tests for duplicate testing
1 parent 583f391 commit 4632353

File tree

4 files changed

+132
-5
lines changed

4 files changed

+132
-5
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
"grunt-contrib-uglify": "^0.11.0",
3535
"grunt-eslint": "^17.3.1",
3636
"grunt-gitinfo": "^0.1.7",
37-
"grunt-mocha": "1.0.2",
37+
"grunt-mocha": "1.0.4",
3838
"grunt-release": "^0.13.0",
3939
"grunt-s3": "0.2.0-alpha.3",
4040
"grunt-sri": "mattrobenolt/grunt-sri#pretty",
4141
"jquery": "^2.1.4",
4242
"lodash": "^3.10.1",
43-
"mocha": "^1.21.5",
43+
"mocha": "2.5.3",
4444
"proxyquireify": "^3.0.2",
4545
"sinon": "1.7.3",
4646
"through2": "^2.0.0",

src/raven.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,9 @@ Raven.prototype = {
14901490
// Try and clean up the packet before sending by truncating long values
14911491
data = this._trimPacket(data);
14921492

1493+
// ideally duplicate error testing should occur *before* dataCallback/shouldSendCallback,
1494+
// but this would require copying an un-truncated copy of the data packet, which can be
1495+
// arbitrarily deep (extra_data) -- could be worthwhile? will revisit
14931496
if (!this._globalOptions.allowDuplicates && this._isRepeatData(data)) {
14941497
this._logDebug('warn', 'Raven dropped repeat event: ', data);
14951498
return;
@@ -1859,9 +1862,11 @@ function htmlElementAsString(elem) {
18591862
return out.join('');
18601863
}
18611864

1862-
1865+
/**
1866+
* Returns true if either a OR b is truthy, but not both
1867+
*/
18631868
function isOnlyOneTruthy(a, b) {
1864-
return a && !b || b && !a;
1869+
return !!(!!a ^ !!b);
18651870
}
18661871

18671872
/**

test/integration/frame.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
function foo() {
7373
bar();
7474
}
75+
76+
function foo2() {
77+
// identical to foo, but meant for testing
78+
// different stack frame fns w/ same stack length
79+
bar();
80+
}
7581
</script>
7682
</head>
7783
<body>

test/integration/test.js

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ describe('integration', function () {
8585
function () {
8686
setTimeout(done);
8787

88-
8988
Raven.captureException({foo:'bar'});
9089
},
9190
function () {
@@ -120,6 +119,123 @@ describe('integration', function () {
120119
}
121120
);
122121
});
122+
123+
it('should reject duplicate, back-to-back errors from captureError', function (done) {
124+
var iframe = this.iframe;
125+
iframeExecute(iframe, done,
126+
function () {
127+
Raven._breadcrumbs = [];
128+
129+
var count = 5;
130+
setTimeout(function invoke() {
131+
// use setTimeout to capture new error objects that have
132+
// identical stack traces (can't call sequentially or callsite
133+
// line number will change)
134+
//
135+
// order:
136+
// Error: foo
137+
// Error: foo (suppressed)
138+
// Error: foo (suppressed)
139+
// Error: bar
140+
// Error: foo
141+
if (count === 2) {
142+
Raven.captureException(new Error('bar'));
143+
}
144+
else {
145+
Raven.captureException(new Error('foo'));
146+
}
147+
148+
if (count-- === 0) return void done();
149+
else setTimeout(invoke);
150+
});
151+
},
152+
function () {
153+
var breadcrumbs = iframe.contentWindow.Raven._breadcrumbs;
154+
// use breadcrumbs to evaluate which errors were sent
155+
// NOTE: can't use ravenData because duplicate error suppression occurs
156+
// AFTER dataCallback/shouldSendCallback (dataCallback will record
157+
// duplicates but they ultimately won't be sent)
158+
assert.equal(breadcrumbs.length, 3);
159+
assert.equal(breadcrumbs[0].message, 'Error: foo');
160+
assert.equal(breadcrumbs[1].message, 'Error: bar');
161+
assert.equal(breadcrumbs[2].message, 'Error: foo');
162+
}
163+
);
164+
});
165+
166+
it('should not reject back-to-back errors with different stack traces', function (done) {
167+
var iframe = this.iframe;
168+
iframeExecute(iframe, done,
169+
function () {
170+
setTimeout(done);
171+
Raven._breadcrumbs = [];
172+
173+
// same error message, but different stacks means that these are considered
174+
// different errors
175+
// NOTE: PhantomJS can't derive function/lineno/colno from evaled frames, must
176+
// use frames declared in frame.html (foo(), bar())
177+
178+
// stack:
179+
// bar
180+
try {
181+
bar(); // declared in frame.html
182+
} catch (e) {
183+
Raven.captureException(e);
184+
}
185+
186+
// stack (different # frames):
187+
// bar
188+
// foo
189+
try {
190+
foo(); // declared in frame.html
191+
} catch (e) {
192+
Raven.captureException(e);
193+
}
194+
195+
// stack (same # frames, different frames):
196+
// bar
197+
// foo2
198+
try {
199+
foo2(); // declared in frame.html
200+
} catch (e) {
201+
Raven.captureException(e);
202+
}
203+
},
204+
function () {
205+
var breadcrumbs = iframe.contentWindow.Raven._breadcrumbs;
206+
assert.equal(breadcrumbs.length, 3);
207+
assert.equal(breadcrumbs[0].message, 'ReferenceError: Can\'t find variable: baz');
208+
assert.equal(breadcrumbs[1].message, 'ReferenceError: Can\'t find variable: baz');
209+
assert.equal(breadcrumbs[2].message, 'ReferenceError: Can\'t find variable: baz');
210+
}
211+
);
212+
});
213+
214+
it('should reject duplicate, back-to-back messages from captureMessage', function (done) {
215+
var iframe = this.iframe;
216+
iframeExecute(iframe, done,
217+
function () {
218+
setTimeout(done);
219+
220+
Raven._breadcrumbs = [];
221+
222+
Raven.captureMessage('this is fine');
223+
Raven.captureMessage('this is fine'); // suppressed
224+
Raven.captureMessage('this is fine', { stacktrace: true });
225+
Raven.captureMessage('i\'m okay with the events that are unfolding currently');
226+
Raven.captureMessage('that\'s okay, things are going to be okay');
227+
},
228+
function () {
229+
var breadcrumbs = iframe.contentWindow.Raven._breadcrumbs;
230+
231+
assert.equal(breadcrumbs.length, 4);
232+
assert.equal(breadcrumbs[0].message, 'this is fine');
233+
assert.equal(breadcrumbs[1].message, 'this is fine'); // with stacktrace
234+
assert.equal(breadcrumbs[2].message, 'i\'m okay with the events that are unfolding currently');
235+
assert.equal(breadcrumbs[3].message, 'that\'s okay, things are going to be okay');
236+
}
237+
);
238+
});
123239
});
124240

125241
describe('window.onerror', function () {

0 commit comments

Comments
 (0)