@@ -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