@@ -26,6 +26,7 @@ type MockFlush = jest.MockedFunction<ReplayContainer['_flush']>;
2626type MockRunFlush = jest . MockedFunction < ReplayContainer [ '_runFlush' ] > ;
2727
2828const prevLocation = WINDOW . location ;
29+ const prevBrowserPerformanceTimeOrigin = SentryUtils . browserPerformanceTimeOrigin ;
2930
3031describe ( 'Integration | flush' , ( ) => {
3132 let domHandler : ( args : any ) => any ;
@@ -91,6 +92,11 @@ describe('Integration | flush', () => {
9192 }
9293 mockEventBufferFinish = replay . eventBuffer ?. finish as MockEventBufferFinish ;
9394 mockEventBufferFinish . mockClear ( ) ;
95+
96+ Object . defineProperty ( SentryUtils , 'browserPerformanceTimeOrigin' , {
97+ value : BASE_TIMESTAMP ,
98+ writable : true ,
99+ } ) ;
94100 } ) ;
95101
96102 afterEach ( async ( ) => {
@@ -102,6 +108,10 @@ describe('Integration | flush', () => {
102108 value : prevLocation ,
103109 writable : true ,
104110 } ) ;
111+ Object . defineProperty ( SentryUtils , 'browserPerformanceTimeOrigin' , {
112+ value : prevBrowserPerformanceTimeOrigin ,
113+ writable : true ,
114+ } ) ;
105115 } ) ;
106116
107117 afterAll ( ( ) => {
@@ -224,6 +234,7 @@ describe('Integration | flush', () => {
224234 // flush #5 @ t=25s - debounced flush calls `flush`
225235 // 20s + `flushMinDelay` which is 5 seconds
226236 await advanceTimers ( DEFAULT_FLUSH_MIN_DELAY ) ;
237+
227238 expect ( mockFlush ) . toHaveBeenCalledTimes ( 5 ) ;
228239 expect ( mockRunFlush ) . toHaveBeenCalledTimes ( 2 ) ;
229240 expect ( mockSendReplay ) . toHaveBeenLastCalledWith ( {
@@ -382,4 +393,53 @@ describe('Integration | flush', () => {
382393
383394 replay . getOptions ( ) . _experiments . traceInternals = false ;
384395 } ) ;
396+
397+ it ( 'logs warning if adding event that is after maxSessionLife' , async ( ) => {
398+ replay . getOptions ( ) . _experiments . traceInternals = true ;
399+
400+ sessionStorage . clear ( ) ;
401+ clearSession ( replay ) ;
402+ replay [ '_loadAndCheckSession' ] ( ) ;
403+ await new Promise ( process . nextTick ) ;
404+ jest . setSystemTime ( BASE_TIMESTAMP ) ;
405+
406+ replay . eventBuffer ! . clear ( ) ;
407+
408+ // We do not care about this warning here
409+ replay . eventBuffer ! . hasCheckout = true ;
410+
411+ // Add event that is too long after session start
412+ const TEST_EVENT = { data : { } , timestamp : BASE_TIMESTAMP + MAX_SESSION_LIFE + 100 , type : 2 } ;
413+ mockRecord . _emitter ( TEST_EVENT ) ;
414+
415+ // no checkout!
416+ await advanceTimers ( DEFAULT_FLUSH_MIN_DELAY ) ;
417+
418+ expect ( mockFlush ) . toHaveBeenCalledTimes ( 1 ) ;
419+ expect ( mockSendReplay ) . toHaveBeenCalledTimes ( 1 ) ;
420+
421+ const replayData = mockSendReplay . mock . calls [ 0 ] [ 0 ] ;
422+
423+ expect ( JSON . parse ( replayData . recordingData ) ) . toEqual ( [
424+ {
425+ type : 5 ,
426+ timestamp : BASE_TIMESTAMP ,
427+ data : {
428+ tag : 'breadcrumb' ,
429+ payload : {
430+ timestamp : BASE_TIMESTAMP / 1000 ,
431+ type : 'default' ,
432+ category : 'console' ,
433+ data : { logger : 'replay' } ,
434+ level : 'info' ,
435+ message : `[Replay] Skipping event with timestamp ${
436+ BASE_TIMESTAMP + MAX_SESSION_LIFE + 100
437+ } because it is after maxSessionLife`,
438+ } ,
439+ } ,
440+ } ,
441+ ] ) ;
442+
443+ replay . getOptions ( ) . _experiments . traceInternals = false ;
444+ } ) ;
385445} ) ;
0 commit comments