4
4
5
5
import '../utils/mock-internal-setTimeout' ;
6
6
import { captureException , getClient } from '@sentry/core' ;
7
+ import type { MockInstance } from 'vitest' ;
7
8
import { afterEach , beforeAll , beforeEach , describe , expect , it , vi } from 'vitest' ;
8
9
import {
9
10
BUFFER_CHECKOUT_TIME ,
@@ -34,15 +35,15 @@ async function waitForFlush() {
34
35
}
35
36
36
37
describe ( 'Integration | errorSampleRate' , ( ) => {
38
+ beforeAll ( ( ) => {
39
+ vi . useFakeTimers ( ) ;
40
+ } ) ;
41
+
37
42
describe ( 'basic' , ( ) => {
38
43
let replay : ReplayContainer ;
39
44
let mockRecord : RecordMock ;
40
45
let domHandler : DomHandler ;
41
46
42
- beforeAll ( ( ) => {
43
- vi . useFakeTimers ( ) ;
44
- } ) ;
45
-
46
47
beforeEach ( async ( ) => {
47
48
( { mockRecord, domHandler, replay } = await resetSdkMock ( {
48
49
replayOptions : {
@@ -163,14 +164,14 @@ describe('Integration | errorSampleRate', () => {
163
164
const ADVANCED_TIME = 86400000 ;
164
165
const optionsEvent = createOptionsEvent ( replay ) ;
165
166
166
- expect ( replay . session . started ) . toBe ( BASE_TIMESTAMP ) ;
167
+ expect ( replay . session ? .started ) . toBe ( BASE_TIMESTAMP ) ;
167
168
168
169
// advance time to make sure replay duration is invalid
169
170
vi . advanceTimersByTime ( ADVANCED_TIME ) ;
170
171
171
172
// full snapshot should update session start time
172
173
mockRecord . takeFullSnapshot ( true ) ;
173
- expect ( replay . session . started ) . toBe ( BASE_TIMESTAMP + ADVANCED_TIME ) ;
174
+ expect ( replay . session ? .started ) . toBe ( BASE_TIMESTAMP + ADVANCED_TIME ) ;
174
175
expect ( replay . recordingMode ) . toBe ( 'buffer' ) ;
175
176
176
177
// advance so we can flush
@@ -253,7 +254,7 @@ describe('Integration | errorSampleRate', () => {
253
254
254
255
await vi . advanceTimersToNextTimerAsync ( ) ;
255
256
256
- expect ( replay ) . toHaveSentReplay ( {
257
+ expect ( replay ) . toHaveLastSentReplay ( {
257
258
recordingPayloadHeader : { segment_id : 0 } ,
258
259
replayEventPayload : expect . objectContaining ( {
259
260
replay_type : 'buffer' ,
@@ -339,7 +340,7 @@ describe('Integration | errorSampleRate', () => {
339
340
340
341
await vi . advanceTimersToNextTimerAsync ( ) ;
341
342
342
- expect ( replay ) . toHaveSentReplay ( {
343
+ expect ( replay ) . toHaveLastSentReplay ( {
343
344
recordingPayloadHeader : { segment_id : 0 } ,
344
345
replayEventPayload : expect . objectContaining ( {
345
346
replay_type : 'buffer' ,
@@ -364,24 +365,6 @@ describe('Integration | errorSampleRate', () => {
364
365
} ,
365
366
] ) ,
366
367
} ) ;
367
-
368
- vi . advanceTimersByTime ( DEFAULT_FLUSH_MIN_DELAY ) ;
369
- // Check that click will not get captured
370
- domHandler ( {
371
- name : 'click' ,
372
- event : new Event ( 'click' ) ,
373
- } ) ;
374
-
375
- await waitForFlush ( ) ;
376
-
377
- // This is still the last replay sent since we passed `continueRecording:
378
- // false`.
379
- expect ( replay ) . toHaveLastSentReplay ( {
380
- recordingPayloadHeader : { segment_id : 1 } ,
381
- replayEventPayload : expect . objectContaining ( {
382
- replay_type : 'buffer' ,
383
- } ) ,
384
- } ) ;
385
368
} ) ;
386
369
387
370
// This tests a regression where we were calling flush indiscriminantly in `stop()`
@@ -672,7 +655,7 @@ describe('Integration | errorSampleRate', () => {
672
655
expect ( replay . session ?. id ) . toBe ( oldSessionId ) ;
673
656
674
657
// buffered events
675
- expect ( replay ) . toHaveSentReplay ( {
658
+ expect ( replay ) . toHaveLastSentReplay ( {
676
659
recordingPayloadHeader : { segment_id : 0 } ,
677
660
replayEventPayload : expect . objectContaining ( {
678
661
replay_type : 'buffer' ,
@@ -709,7 +692,7 @@ describe('Integration | errorSampleRate', () => {
709
692
vi . advanceTimersByTime ( DEFAULT_FLUSH_MIN_DELAY ) ;
710
693
await vi . advanceTimersToNextTimerAsync ( ) ;
711
694
712
- expect ( replay ) . toHaveSentReplay ( {
695
+ expect ( replay ) . toHaveLastSentReplay ( {
713
696
recordingData : JSON . stringify ( [
714
697
{ data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } ,
715
698
optionsEvent ,
@@ -762,7 +745,7 @@ describe('Integration | errorSampleRate', () => {
762
745
expect ( replay . session ?. started ) . toBe ( BASE_TIMESTAMP + ELAPSED ) ;
763
746
764
747
// Does not capture mouse click
765
- expect ( replay ) . toHaveSentReplay ( {
748
+ expect ( replay ) . toHaveLastSentReplay ( {
766
749
recordingPayloadHeader : { segment_id : 0 } ,
767
750
replayEventPayload : expect . objectContaining ( {
768
751
// Make sure the old performance event is thrown out
@@ -846,7 +829,7 @@ describe('Integration | errorSampleRate', () => {
846
829
await waitForFlush ( ) ;
847
830
848
831
expect ( replay . session ?. id ) . toBe ( sessionId ) ;
849
- expect ( replay ) . toHaveSentReplay ( {
832
+ expect ( replay ) . toHaveLastSentReplay ( {
850
833
recordingPayloadHeader : { segment_id : 0 } ,
851
834
} ) ;
852
835
@@ -1047,7 +1030,7 @@ describe('Integration | errorSampleRate', () => {
1047
1030
await vi . advanceTimersToNextTimerAsync ( ) ;
1048
1031
1049
1032
// Buffered events before error
1050
- expect ( replay ) . toHaveSentReplay ( {
1033
+ expect ( replay ) . toHaveLastSentReplay ( {
1051
1034
recordingPayloadHeader : { segment_id : 0 } ,
1052
1035
recordingData : JSON . stringify ( [
1053
1036
{ data : { isCheckout : true } , timestamp : BASE_TIMESTAMP , type : 2 } ,
0 commit comments