@@ -26,6 +26,7 @@ type MockFlush = jest.MockedFunction<ReplayContainer['_flush']>;
26
26
type MockRunFlush = jest . MockedFunction < ReplayContainer [ '_runFlush' ] > ;
27
27
28
28
const prevLocation = WINDOW . location ;
29
+ const prevBrowserPerformanceTimeOrigin = SentryUtils . browserPerformanceTimeOrigin ;
29
30
30
31
describe ( 'Integration | flush' , ( ) => {
31
32
let domHandler : ( args : any ) => any ;
@@ -91,6 +92,11 @@ describe('Integration | flush', () => {
91
92
}
92
93
mockEventBufferFinish = replay . eventBuffer ?. finish as MockEventBufferFinish ;
93
94
mockEventBufferFinish . mockClear ( ) ;
95
+
96
+ Object . defineProperty ( SentryUtils , 'browserPerformanceTimeOrigin' , {
97
+ value : BASE_TIMESTAMP ,
98
+ writable : true ,
99
+ } ) ;
94
100
} ) ;
95
101
96
102
afterEach ( async ( ) => {
@@ -102,6 +108,10 @@ describe('Integration | flush', () => {
102
108
value : prevLocation ,
103
109
writable : true ,
104
110
} ) ;
111
+ Object . defineProperty ( SentryUtils , 'browserPerformanceTimeOrigin' , {
112
+ value : prevBrowserPerformanceTimeOrigin ,
113
+ writable : true ,
114
+ } ) ;
105
115
} ) ;
106
116
107
117
afterAll ( ( ) => {
@@ -224,6 +234,7 @@ describe('Integration | flush', () => {
224
234
// flush #5 @ t=25s - debounced flush calls `flush`
225
235
// 20s + `flushMinDelay` which is 5 seconds
226
236
await advanceTimers ( DEFAULT_FLUSH_MIN_DELAY ) ;
237
+
227
238
expect ( mockFlush ) . toHaveBeenCalledTimes ( 5 ) ;
228
239
expect ( mockRunFlush ) . toHaveBeenCalledTimes ( 2 ) ;
229
240
expect ( mockSendReplay ) . toHaveBeenLastCalledWith ( {
@@ -382,4 +393,53 @@ describe('Integration | flush', () => {
382
393
383
394
replay . getOptions ( ) . _experiments . traceInternals = false ;
384
395
} ) ;
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
+ } ) ;
385
445
} ) ;
0 commit comments