1
- import { captureException , getCurrentHub } from '@sentry/core' ;
1
+ import { captureException } from '@sentry/core' ;
2
2
3
3
import { REPLAY_SESSION_KEY , VISIBILITY_CHANGE_TIMEOUT , WINDOW } from '../../src/constants' ;
4
4
import { addEvent } from '../../src/util/addEvent' ;
@@ -19,7 +19,6 @@ async function advanceTimers(time: number) {
19
19
describe ( 'Replay (errorSampleRate)' , ( ) => {
20
20
let replay : ReplayContainer ;
21
21
let mockRecord : RecordMock ;
22
-
23
22
let domHandler : DomHandler ;
24
23
25
24
beforeEach ( async ( ) => {
@@ -59,6 +58,7 @@ describe('Replay (errorSampleRate)', () => {
59
58
await new Promise ( process . nextTick ) ;
60
59
61
60
expect ( replay ) . toHaveSentReplay ( {
61
+ recordingPayloadHeader : { segment_id : 0 } ,
62
62
replayEventPayload : expect . objectContaining ( {
63
63
tags : expect . objectContaining ( {
64
64
errorSampleRate : 1 ,
@@ -86,6 +86,19 @@ describe('Replay (errorSampleRate)', () => {
86
86
] ) ,
87
87
} ) ;
88
88
89
+ // This is from when we stop recording and start a session recording
90
+ expect ( replay ) . toHaveLastSentReplay ( {
91
+ recordingPayloadHeader : { segment_id : 1 } ,
92
+ replayEventPayload : expect . objectContaining ( {
93
+ tags : expect . objectContaining ( {
94
+ errorSampleRate : 1 ,
95
+ replayType : 'error' ,
96
+ sessionSampleRate : 0 ,
97
+ } ) ,
98
+ } ) ,
99
+ events : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP + 5020 , type : 2 } ] ) ,
100
+ } ) ;
101
+
89
102
jest . runAllTimers ( ) ;
90
103
await new Promise ( process . nextTick ) ;
91
104
@@ -111,11 +124,11 @@ describe('Replay (errorSampleRate)', () => {
111
124
events : JSON . stringify ( [
112
125
{
113
126
type : 5 ,
114
- timestamp : BASE_TIMESTAMP + 15000 + 40 ,
127
+ timestamp : BASE_TIMESTAMP + 10000 + 40 ,
115
128
data : {
116
129
tag : 'breadcrumb' ,
117
130
payload : {
118
- timestamp : ( BASE_TIMESTAMP + 15000 + 40 ) / 1000 ,
131
+ timestamp : ( BASE_TIMESTAMP + 10000 + 40 ) / 1000 ,
119
132
type : 'default' ,
120
133
category : 'ui.click' ,
121
134
message : '<unknown>' ,
@@ -287,7 +300,7 @@ describe('Replay (errorSampleRate)', () => {
287
300
jest . runAllTimers ( ) ;
288
301
await new Promise ( process . nextTick ) ;
289
302
290
- expect ( replay ) . toHaveLastSentReplay ( {
303
+ expect ( replay ) . toHaveSentReplay ( {
291
304
events : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } , TEST_EVENT ] ) ,
292
305
replayEventPayload : expect . objectContaining ( {
293
306
replay_start_timestamp : BASE_TIMESTAMP / 1000 ,
@@ -338,7 +351,8 @@ describe('Replay (errorSampleRate)', () => {
338
351
expect ( replay . session ?. started ) . toBe ( BASE_TIMESTAMP + ELAPSED + 20 ) ;
339
352
340
353
// Does not capture mouse click
341
- expect ( replay ) . toHaveLastSentReplay ( {
354
+ expect ( replay ) . toHaveSentReplay ( {
355
+ recordingPayloadHeader : { segment_id : 0 } ,
342
356
replayEventPayload : expect . objectContaining ( {
343
357
// Make sure the old performance event is thrown out
344
358
replay_start_timestamp : ( BASE_TIMESTAMP + ELAPSED + 20 ) / 1000 ,
@@ -373,12 +387,6 @@ it('sends a replay after loading the session multiple times', async () => {
373
387
} ,
374
388
autoStart : false ,
375
389
} ) ;
376
-
377
- const fn = getCurrentHub ( ) ?. getClient ( ) ?. getTransport ( ) ?. send ;
378
- const mockTransportSend = fn
379
- ? ( jest . spyOn ( getCurrentHub ( ) . getClient ( ) ! . getTransport ( ) ! , 'send' ) as jest . MockedFunction < any > )
380
- : jest . fn ( ) ;
381
-
382
390
replay . start ( ) ;
383
391
384
392
jest . runAllTimers ( ) ;
@@ -393,27 +401,13 @@ it('sends a replay after loading the session multiple times', async () => {
393
401
jest . runAllTimers ( ) ;
394
402
await new Promise ( process . nextTick ) ;
395
403
396
- expect ( replay ) . toHaveLastSentReplay ( {
404
+ expect ( replay ) . toHaveSentReplay ( {
397
405
events : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } , TEST_EVENT ] ) ,
398
406
} ) ;
399
407
400
- mockTransportSend . mockClear ( ) ;
401
- expect ( replay ) . not . toHaveLastSentReplay ( ) ;
402
-
403
- jest . runAllTimers ( ) ;
404
- await new Promise ( process . nextTick ) ;
405
- jest . runAllTimers ( ) ;
406
- await new Promise ( process . nextTick ) ;
407
-
408
- // New checkout when we call `startRecording` again after uploading segment
409
- // after an error occurs
408
+ // Latest checkout when we call `startRecording` again after uploading segment
409
+ // after an error occurs (e.g. when we switch to session replay recording)
410
410
expect ( replay ) . toHaveLastSentReplay ( {
411
- events : JSON . stringify ( [
412
- {
413
- data : { isCheckout : true } ,
414
- timestamp : BASE_TIMESTAMP + 10000 + 20 ,
415
- type : 2 ,
416
- } ,
417
- ] ) ,
411
+ events : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP + 5020 , type : 2 } ] ) ,
418
412
} ) ;
419
413
} ) ;
0 commit comments