@@ -7,7 +7,7 @@ import { ReplayContainer } from './../../src/replay';
77import { PerformanceEntryResource } from './../fixtures/performanceEntry/resource' ;
88import { BASE_TIMESTAMP , RecordMock } from './../index' ;
99import { resetSdkMock } from './../mocks' ;
10- import { DomHandler , MockTransportSend } from './../types' ;
10+ import { DomHandler } from './../types' ;
1111import { useFakeTimers } from './../utils/use-fake-timers' ;
1212
1313useFakeTimers ( ) ;
@@ -20,11 +20,10 @@ async function advanceTimers(time: number) {
2020describe ( 'Replay (errorSampleRate)' , ( ) => {
2121 let replay : ReplayContainer ;
2222 let mockRecord : RecordMock ;
23- let mockTransportSend : MockTransportSend ;
2423 let domHandler : DomHandler ;
2524
2625 beforeEach ( async ( ) => {
27- ( { mockRecord, mockTransportSend , domHandler, replay } = await resetSdkMock ( {
26+ ( { mockRecord, domHandler, replay } = await resetSdkMock ( {
2827 replayOptions : {
2928 stickySession : true ,
3029 } ,
@@ -60,6 +59,7 @@ describe('Replay (errorSampleRate)', () => {
6059 await new Promise ( process . nextTick ) ;
6160
6261 expect ( replay ) . toHaveSentReplay ( {
62+ recordingPayloadHeader : { segment_id : 0 } ,
6363 replayEventPayload : expect . objectContaining ( {
6464 tags : expect . objectContaining ( {
6565 errorSampleRate : 1 ,
@@ -87,6 +87,19 @@ describe('Replay (errorSampleRate)', () => {
8787 ] ) ,
8888 } ) ;
8989
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+
90103 jest . runAllTimers ( ) ;
91104 await new Promise ( process . nextTick ) ;
92105
@@ -112,11 +125,11 @@ describe('Replay (errorSampleRate)', () => {
112125 events : JSON . stringify ( [
113126 {
114127 type : 5 ,
115- timestamp : BASE_TIMESTAMP + 15000 + 40 ,
128+ timestamp : BASE_TIMESTAMP + 10000 + 40 ,
116129 data : {
117130 tag : 'breadcrumb' ,
118131 payload : {
119- timestamp : ( BASE_TIMESTAMP + 15000 + 40 ) / 1000 ,
132+ timestamp : ( BASE_TIMESTAMP + 10000 + 40 ) / 1000 ,
120133 type : 'default' ,
121134 category : 'ui.click' ,
122135 message : '<unknown>' ,
@@ -288,7 +301,7 @@ describe('Replay (errorSampleRate)', () => {
288301 jest . runAllTimers ( ) ;
289302 await new Promise ( process . nextTick ) ;
290303
291- expect ( replay ) . toHaveLastSentReplay ( {
304+ expect ( replay ) . toHaveSentReplay ( {
292305 events : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } , TEST_EVENT ] ) ,
293306 replayEventPayload : expect . objectContaining ( {
294307 replay_start_timestamp : BASE_TIMESTAMP / 1000 ,
@@ -319,7 +332,7 @@ describe('Replay (errorSampleRate)', () => {
319332 REPLAY_SESSION_KEY ,
320333 `{"segmentId":0,"id":"fd09adfc4117477abc8de643e5a5798a","sampled":"error","started":${ BASE_TIMESTAMP } ,"lastActivity":${ BASE_TIMESTAMP } }` ,
321334 ) ;
322- ( { mockRecord, mockTransportSend , replay } = await resetSdkMock ( {
335+ ( { mockRecord, replay } = await resetSdkMock ( {
323336 replayOptions : {
324337 stickySession : true ,
325338 } ,
@@ -338,28 +351,14 @@ describe('Replay (errorSampleRate)', () => {
338351 jest . runAllTimers ( ) ;
339352 await new Promise ( process . nextTick ) ;
340353
341- expect ( replay ) . toHaveLastSentReplay ( {
354+ expect ( replay ) . toHaveSentReplay ( {
342355 events : JSON . stringify ( [ { data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } , TEST_EVENT ] ) ,
343356 } ) ;
344357
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)
355360 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 } ] ) ,
363362 } ) ;
364363 } ) ;
365364
@@ -396,7 +395,8 @@ describe('Replay (errorSampleRate)', () => {
396395 expect ( replay . session ?. started ) . toBe ( BASE_TIMESTAMP + ELAPSED + 20 ) ;
397396
398397 // Does not capture mouse click
399- expect ( replay ) . toHaveLastSentReplay ( {
398+ expect ( replay ) . toHaveSentReplay ( {
399+ recordingPayloadHeader : { segment_id : 0 } ,
400400 replayEventPayload : expect . objectContaining ( {
401401 // Make sure the old performance event is thrown out
402402 replay_start_timestamp : ( BASE_TIMESTAMP + ELAPSED + 20 ) / 1000 ,
0 commit comments