1- import type { BrowserOptions } from '@sentry/browser' ;
1+ import { BrowserOptions , init } from '@sentry/browser' ;
22import { Envelope , Transport } from '@sentry/types' ;
33
44import { Replay as ReplayIntegration } from '../../src' ;
@@ -39,10 +39,24 @@ export async function mockSdk({ replayOptions, sentryOptions }: MockSdkParams =
3939 replay : ReplayContainer ;
4040 integration : ReplayIntegration ;
4141} > {
42- const { init } = jest . requireActual ( '@sentry/browser' ) ;
43-
4442 const { Replay } = await import ( '../../src' ) ;
45- const replayIntegration = new Replay ( {
43+
44+ // Scope this to the test, instead of the module
45+ let _initialized = false ;
46+ class TestReplayIntegration extends Replay {
47+ protected get _isInitialized ( ) : boolean {
48+ return _initialized ;
49+ }
50+ protected set _isInitialized ( value : boolean ) {
51+ _initialized = value ;
52+ }
53+
54+ public setupOnce ( ) : void {
55+ // do nothing
56+ }
57+ }
58+
59+ const replayIntegration = new TestReplayIntegration ( {
4660 stickySession : false ,
4761 ...replayOptions ,
4862 } ) ;
@@ -54,18 +68,14 @@ export async function mockSdk({ replayOptions, sentryOptions }: MockSdkParams =
5468 transport : ( ) => new MockTransport ( ) ,
5569 replaysSessionSampleRate : 1.0 ,
5670 replaysOnErrorSampleRate : 0.0 ,
71+ defaultIntegrations : false ,
5772 ...sentryOptions ,
5873 integrations : [ replayIntegration ] ,
5974 } ) ;
6075
61- // setupOnce is only called the first time, so we ensure to manually run setup in subsequent calls
62- if ( replayIntegration [ '_hasCalledSetupOnce' ] ) {
63- // The first time the integration is used, `start()` is called (in setupOnce)
64- // For consistency, we want to stop that
65- replayIntegration . stop ( ) ;
66- } else {
67- replayIntegration [ '_setup' ] ( ) ;
68- }
76+ // Instead of `setupOnce`, which is tricky to test, we call this manually here
77+ replayIntegration [ '_setup' ] ( ) ;
78+ replayIntegration . start ( ) ;
6979
7080 const replay = replayIntegration [ '_replay' ] ! ;
7181
0 commit comments