@@ -7,7 +7,7 @@ import { ReplayContainer } from './../../src/replay';
7
7
import { PerformanceEntryResource } from './../fixtures/performanceEntry/resource' ;
8
8
import { BASE_TIMESTAMP , RecordMock } from './../index' ;
9
9
import { resetSdkMock } from './../mocks' ;
10
- import { DomHandler , MockTransportSend } from './../types' ;
10
+ import { DomHandler } from './../types' ;
11
11
import { useFakeTimers } from './../utils/use-fake-timers' ;
12
12
13
13
useFakeTimers ( ) ;
@@ -20,11 +20,10 @@ async function advanceTimers(time: number) {
20
20
describe ( 'Replay (errorSampleRate)' , ( ) => {
21
21
let replay : ReplayContainer ;
22
22
let mockRecord : RecordMock ;
23
- let mockTransportSend : MockTransportSend ;
24
23
let domHandler : DomHandler ;
25
24
26
25
beforeEach ( async ( ) => {
27
- ( { mockRecord, mockTransportSend , domHandler, replay } = await resetSdkMock ( {
26
+ ( { mockRecord, domHandler, replay } = await resetSdkMock ( {
28
27
replayOptions : {
29
28
stickySession : true ,
30
29
} ,
@@ -60,6 +59,7 @@ describe('Replay (errorSampleRate)', () => {
60
59
await new Promise ( process . nextTick ) ;
61
60
62
61
expect ( replay ) . toHaveSentReplay ( {
62
+ recordingPayloadHeader : { segment_id : 0 } ,
63
63
replayEventPayload : expect . objectContaining ( {
64
64
tags : expect . objectContaining ( {
65
65
errorSampleRate : 1 ,
@@ -87,6 +87,19 @@ describe('Replay (errorSampleRate)', () => {
87
87
] ) ,
88
88
} ) ;
89
89
90
+ // This is from when we stop recording and start a session recording
91
+ expect ( replay ) . toHaveLastSentReplay ( {
92
+ recordingPayloadHeader : { segment_id : 1 } ,
93
+ replayEventPayload : expect . objectContaining ( {
94
+ tags : expect . objectContaining ( {
95
+ errorSampleRate : 1 ,
96
+ replayType : 'error' ,
97
+ sessionSampleRate : 0 ,
98
+ } ) ,
99
+ } ) ,
100
+ events : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP + 5020 , type : 2 } ] ) ,
101
+ } ) ;
102
+
90
103
jest . runAllTimers ( ) ;
91
104
await new Promise ( process . nextTick ) ;
92
105
@@ -112,11 +125,11 @@ describe('Replay (errorSampleRate)', () => {
112
125
events : JSON . stringify ( [
113
126
{
114
127
type : 5 ,
115
- timestamp : BASE_TIMESTAMP + 15000 + 40 ,
128
+ timestamp : BASE_TIMESTAMP + 10000 + 40 ,
116
129
data : {
117
130
tag : 'breadcrumb' ,
118
131
payload : {
119
- timestamp : ( BASE_TIMESTAMP + 15000 + 40 ) / 1000 ,
132
+ timestamp : ( BASE_TIMESTAMP + 10000 + 40 ) / 1000 ,
120
133
type : 'default' ,
121
134
category : 'ui.click' ,
122
135
message : '<unknown>' ,
@@ -288,7 +301,7 @@ describe('Replay (errorSampleRate)', () => {
288
301
jest . runAllTimers ( ) ;
289
302
await new Promise ( process . nextTick ) ;
290
303
291
- expect ( replay ) . toHaveLastSentReplay ( {
304
+ expect ( replay ) . toHaveSentReplay ( {
292
305
events : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } , TEST_EVENT ] ) ,
293
306
replayEventPayload : expect . objectContaining ( {
294
307
replay_start_timestamp : BASE_TIMESTAMP / 1000 ,
@@ -319,7 +332,7 @@ describe('Replay (errorSampleRate)', () => {
319
332
REPLAY_SESSION_KEY ,
320
333
`{"segmentId":0,"id":"fd09adfc4117477abc8de643e5a5798a","sampled":"error","started":${ BASE_TIMESTAMP } ,"lastActivity":${ BASE_TIMESTAMP } }` ,
321
334
) ;
322
- ( { mockRecord, mockTransportSend , replay } = await resetSdkMock ( {
335
+ ( { mockRecord, replay } = await resetSdkMock ( {
323
336
replayOptions : {
324
337
stickySession : true ,
325
338
} ,
@@ -338,28 +351,14 @@ describe('Replay (errorSampleRate)', () => {
338
351
jest . runAllTimers ( ) ;
339
352
await new Promise ( process . nextTick ) ;
340
353
341
- expect ( replay ) . toHaveLastSentReplay ( {
354
+ expect ( replay ) . toHaveSentReplay ( {
342
355
events : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } , TEST_EVENT ] ) ,
343
356
} ) ;
344
357
345
- mockTransportSend . mockClear ( ) ;
346
- expect ( replay ) . not . toHaveLastSentReplay ( ) ;
347
-
348
- jest . runAllTimers ( ) ;
349
- await new Promise ( process . nextTick ) ;
350
- jest . runAllTimers ( ) ;
351
- await new Promise ( process . nextTick ) ;
352
-
353
- // New checkout when we call `startRecording` again after uploading segment
354
- // after an error occurs
358
+ // Latest checkout when we call `startRecording` again after uploading segment
359
+ // after an error occurs (e.g. when we switch to session replay recording)
355
360
expect ( replay ) . toHaveLastSentReplay ( {
356
- events : JSON . stringify ( [
357
- {
358
- data : { isCheckout : true } ,
359
- timestamp : BASE_TIMESTAMP + 10000 + 20 ,
360
- type : 2 ,
361
- } ,
362
- ] ) ,
361
+ events : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP + 5020 , type : 2 } ] ) ,
363
362
} ) ;
364
363
} ) ;
365
364
@@ -396,7 +395,8 @@ describe('Replay (errorSampleRate)', () => {
396
395
expect ( replay . session ?. started ) . toBe ( BASE_TIMESTAMP + ELAPSED + 20 ) ;
397
396
398
397
// Does not capture mouse click
399
- expect ( replay ) . toHaveLastSentReplay ( {
398
+ expect ( replay ) . toHaveSentReplay ( {
399
+ recordingPayloadHeader : { segment_id : 0 } ,
400
400
replayEventPayload : expect . objectContaining ( {
401
401
// Make sure the old performance event is thrown out
402
402
replay_start_timestamp : ( BASE_TIMESTAMP + ELAPSED + 20 ) / 1000 ,
0 commit comments