@@ -5,7 +5,8 @@ import * as SentryUtils from '@sentry/utils';
55import type { Replay } from '../../src' ;
66import type { ReplayContainer } from '../../src/replay' ;
77import { clearSession } from '../../src/session/clearSession' ;
8- import type { EventType } from '../../src/types' ;
8+ import { createPerformanceEntries } from '../../src/util/createPerformanceEntries' ;
9+ import { createPerformanceSpans } from '../../src/util/createPerformanceSpans' ;
910import * as SendReplayRequest from '../../src/util/sendReplayRequest' ;
1011import { BASE_TIMESTAMP , mockRrweb , mockSdk } from '../index' ;
1112import { useFakeTimers } from '../utils/use-fake-timers' ;
@@ -40,6 +41,10 @@ describe('Integration | beforeAddRecordingEvent', () => {
4041 beforeAddRecordingEvent : event => {
4142 const eventData = event . data ;
4243
44+ if ( eventData . tag === 'performanceSpan' ) {
45+ throw new Error ( 'test error in callback' ) ;
46+ }
47+
4348 if ( eventData . tag === 'breadcrumb' && eventData . payload . category === 'ui.click' ) {
4449 return {
4550 ...event ,
@@ -53,12 +58,6 @@ describe('Integration | beforeAddRecordingEvent', () => {
5358 } ;
5459 }
5560
56- // This should not do anything because callback should not be called
57- // for `event.type != 5` - but we guard anyhow to be safe
58- if ( ( event . type as EventType ) === 2 ) {
59- return null ;
60- }
61-
6261 if ( eventData . tag === 'options' ) {
6362 return null ;
6463 }
@@ -143,4 +142,42 @@ describe('Integration | beforeAddRecordingEvent', () => {
143142 recordingData : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } ] ) ,
144143 } ) ;
145144 } ) ;
145+
146+ it ( 'handles error in callback' , async ( ) => {
147+ createPerformanceSpans (
148+ replay ,
149+ createPerformanceEntries ( [
150+ {
151+ name : 'https://sentry.io/foo.js' ,
152+ entryType : 'resource' ,
153+ startTime : 176.59999990463257 ,
154+ duration : 5.600000023841858 ,
155+ initiatorType : 'link' ,
156+ nextHopProtocol : 'h2' ,
157+ workerStart : 177.5 ,
158+ redirectStart : 0 ,
159+ redirectEnd : 0 ,
160+ fetchStart : 177.69999992847443 ,
161+ domainLookupStart : 177.69999992847443 ,
162+ domainLookupEnd : 177.69999992847443 ,
163+ connectStart : 177.69999992847443 ,
164+ connectEnd : 177.69999992847443 ,
165+ secureConnectionStart : 177.69999992847443 ,
166+ requestStart : 177.5 ,
167+ responseStart : 181 ,
168+ responseEnd : 182.19999992847443 ,
169+ transferSize : 0 ,
170+ encodedBodySize : 0 ,
171+ decodedBodySize : 0 ,
172+ serverTiming : [ ] ,
173+ } as unknown as PerformanceResourceTiming ,
174+ ] ) ,
175+ ) ;
176+
177+ jest . runAllTimers ( ) ;
178+ await new Promise ( process . nextTick ) ;
179+
180+ expect ( replay ) . not . toHaveLastSentReplay ( ) ;
181+ expect ( replay . isEnabled ( ) ) . toBe ( true ) ;
182+ } ) ;
146183} ) ;
0 commit comments