1
1
jest . mock ( './../../src/util/isInternal' , ( ) => ( {
2
2
isInternal : jest . fn ( ( ) => true ) ,
3
3
} ) ) ;
4
+ import { WINDOW } from '@sentry/browser' ;
4
5
import { BASE_TIMESTAMP , RecordMock } from '@test' ;
5
6
import { PerformanceEntryResource } from '@test/fixtures/performanceEntry/resource' ;
6
7
import { resetSdkMock } from '@test/mocks' ;
@@ -23,7 +24,7 @@ describe('Replay', () => {
23
24
let mockTransportSend : MockTransportSend ;
24
25
let domHandler : DomHandler ;
25
26
let spyCaptureException : jest . MockedFunction < any > ;
26
- const prevLocation = window . location ;
27
+ const prevLocation = WINDOW . location ;
27
28
28
29
type MockSendReplayRequest = jest . MockedFunction < typeof replay . sendReplayRequest > ;
29
30
let mockSendReplayRequest : MockSendReplayRequest ;
@@ -56,9 +57,7 @@ describe('Replay', () => {
56
57
afterEach ( async ( ) => {
57
58
jest . runAllTimers ( ) ;
58
59
await new Promise ( process . nextTick ) ;
59
- // @ts -ignore: The operand of a 'delete' operator must be optional.ts(2790)
60
- delete window . location ;
61
- Object . defineProperty ( window , 'location' , {
60
+ Object . defineProperty ( WINDOW , 'location' , {
62
61
value : prevLocation ,
63
62
writable : true ,
64
63
} ) ;
@@ -97,7 +96,7 @@ describe('Replay', () => {
97
96
98
97
it ( 'clears session' , ( ) => {
99
98
replay . clearSession ( ) ;
100
- expect ( window . sessionStorage . getItem ( REPLAY_SESSION_KEY ) ) . toBe ( null ) ;
99
+ expect ( WINDOW . sessionStorage . getItem ( REPLAY_SESSION_KEY ) ) . toBe ( null ) ;
101
100
expect ( replay . session ) . toBe ( undefined ) ;
102
101
} ) ;
103
102
@@ -133,7 +132,7 @@ describe('Replay', () => {
133
132
134
133
jest . advanceTimersByTime ( VISIBILITY_CHANGE_TIMEOUT + 1 ) ;
135
134
136
- window . dispatchEvent ( new Event ( 'focus' ) ) ;
135
+ WINDOW . dispatchEvent ( new Event ( 'focus' ) ) ;
137
136
138
137
expect ( mockRecord . takeFullSnapshot ) . toHaveBeenLastCalledWith ( true ) ;
139
138
@@ -169,7 +168,7 @@ describe('Replay', () => {
169
168
expect ( replay ) . toHaveSameSession ( initialSession ) ;
170
169
} ) ;
171
170
172
- it ( 'uploads a replay event when window is blurred' , async ( ) => {
171
+ it ( 'uploads a replay event when WINDOW is blurred' , async ( ) => {
173
172
Object . defineProperty ( document , 'visibilityState' , {
174
173
configurable : true ,
175
174
get : function ( ) {
@@ -196,7 +195,7 @@ describe('Replay', () => {
196
195
} ;
197
196
198
197
replay . addEvent ( TEST_EVENT ) ;
199
- window . dispatchEvent ( new Event ( 'blur' ) ) ;
198
+ WINDOW . dispatchEvent ( new Event ( 'blur' ) ) ;
200
199
await new Promise ( process . nextTick ) ;
201
200
expect ( mockRecord . takeFullSnapshot ) . not . toHaveBeenCalled ( ) ;
202
201
expect ( replay ) . toHaveSentReplay ( {
@@ -303,7 +302,7 @@ describe('Replay', () => {
303
302
) ;
304
303
305
304
const url = 'http://dummy/' ;
306
- Object . defineProperty ( window , 'location' , {
305
+ Object . defineProperty ( WINDOW , 'location' , {
307
306
value : new URL ( url ) ,
308
307
} ) ;
309
308
@@ -391,7 +390,7 @@ describe('Replay', () => {
391
390
) ;
392
391
393
392
const url = 'http://dummy/' ;
394
- Object . defineProperty ( window , 'location' , {
393
+ Object . defineProperty ( WINDOW , 'location' , {
395
394
value : new URL ( url ) ,
396
395
} ) ;
397
396
@@ -419,7 +418,7 @@ describe('Replay', () => {
419
418
return true ;
420
419
} ) ;
421
420
422
- window . dispatchEvent ( new Event ( 'blur' ) ) ;
421
+ WINDOW . dispatchEvent ( new Event ( 'blur' ) ) ;
423
422
await advanceTimers ( 5000 ) ;
424
423
425
424
expect ( mockRecord . takeFullSnapshot ) . not . toHaveBeenCalled ( ) ;
@@ -639,15 +638,15 @@ describe('Replay', () => {
639
638
const TEST_EVENT = { data : { } , timestamp : BASE_TIMESTAMP , type : 2 } ;
640
639
641
640
replay . addEvent ( TEST_EVENT ) ;
642
- window . dispatchEvent ( new Event ( 'blur' ) ) ;
641
+ WINDOW . dispatchEvent ( new Event ( 'blur' ) ) ;
643
642
await new Promise ( process . nextTick ) ;
644
643
expect ( replay ) . toHaveSentReplay ( {
645
644
recordingPayloadHeader : { segment_id : 0 } ,
646
645
} ) ;
647
646
expect ( replay . session ?. segmentId ) . toBe ( 1 ) ;
648
647
649
648
replay . addEvent ( TEST_EVENT ) ;
650
- window . dispatchEvent ( new Event ( 'blur' ) ) ;
649
+ WINDOW . dispatchEvent ( new Event ( 'blur' ) ) ;
651
650
jest . runAllTimers ( ) ;
652
651
await new Promise ( process . nextTick ) ;
653
652
expect ( replay . session ?. segmentId ) . toBe ( 2 ) ;
@@ -679,7 +678,7 @@ describe('Replay', () => {
679
678
} ;
680
679
681
680
replay . addEvent ( TEST_EVENT ) ;
682
- window . dispatchEvent ( new Event ( 'blur' ) ) ;
681
+ WINDOW . dispatchEvent ( new Event ( 'blur' ) ) ;
683
682
await new Promise ( process . nextTick ) ;
684
683
685
684
expect ( replay ) . toHaveSentReplay ( {
@@ -773,7 +772,7 @@ describe('Replay', () => {
773
772
type : 5 ,
774
773
} ) ;
775
774
776
- window . dispatchEvent ( new Event ( 'blur' ) ) ;
775
+ WINDOW . dispatchEvent ( new Event ( 'blur' ) ) ;
777
776
await new Promise ( process . nextTick ) ;
778
777
expect ( replay ) . toHaveSentReplay ( {
779
778
replayEventPayload : expect . objectContaining ( {
@@ -816,7 +815,7 @@ describe('Replay', () => {
816
815
817
816
replay . addEvent ( TEST_EVENT ) ;
818
817
// This event will trigger a flush
819
- window . dispatchEvent ( new Event ( 'blur' ) ) ;
818
+ WINDOW . dispatchEvent ( new Event ( 'blur' ) ) ;
820
819
jest . runAllTimers ( ) ;
821
820
await new Promise ( process . nextTick ) ;
822
821
0 commit comments