1
1
import type { Envelope , Transport , TransportMakeRequestResponse } from '@sentry/types' ;
2
2
3
- import type { Replay as ReplayIntegration } from '../../src' ;
4
3
import type { ReplayContainer } from '../../src/replay' ;
5
4
import type { ReplayConfiguration } from '../../src/types' ;
6
5
import type { TestClientOptions } from '../utils/TestClient' ;
@@ -46,32 +45,30 @@ class MockTransport implements Transport {
46
45
47
46
export async function mockSdk ( { replayOptions, sentryOptions, autoStart = true } : MockSdkParams = { } ) : Promise < {
48
47
replay : ReplayContainer ;
49
- // eslint-disable-next-line deprecation/deprecation
50
- integration : ReplayIntegration ;
48
+ integration : typeof replayIntegration ;
51
49
} > {
52
- // eslint-disable-next-line deprecation/deprecation
53
- const { Replay } = await import ( '../../src' ) ;
50
+ const { replayIntegration } = await import ( '../../src' ) ;
54
51
55
52
// Scope this to the test, instead of the module
56
53
let _initialized = false ;
57
- class TestReplayIntegration extends Replay {
58
- protected get _isInitialized ( ) : boolean {
59
- return _initialized ;
60
- }
61
- protected set _isInitialized ( value : boolean ) {
62
- _initialized = value ;
63
- }
64
54
65
- public setupOnce ( ) : void {
66
- // do nothing
67
- }
68
-
69
- public initialize ( ) : void {
70
- return super . _initialize ( ) ;
71
- }
55
+ const testReplayIntegration = ( ...args : Parameters < typeof replayIntegration > ) => {
56
+ const replayIntegrationInstance = replayIntegration ( ...args ) ;
57
+ return {
58
+ ...replayIntegrationInstance ,
59
+ get _isInitialized ( ) {
60
+ return _initialized ;
61
+ } ,
62
+ set _isInitialized ( value : boolean ) {
63
+ _initialized = value ;
64
+ } ,
65
+ initialize ( ) {
66
+ replayIntegrationInstance [ '_initialize' ] ( ) ;
67
+ } ,
68
+ } ;
72
69
}
73
70
74
- const replayIntegration = new TestReplayIntegration ( {
71
+ const replayIntegrationInstance = testReplayIntegration ( {
75
72
stickySession : false ,
76
73
minReplayDuration : 0 ,
77
74
...replayOptions ,
@@ -86,18 +83,18 @@ export async function mockSdk({ replayOptions, sentryOptions, autoStart = true }
86
83
replaysSessionSampleRate : 1.0 ,
87
84
replaysOnErrorSampleRate : 0.0 ,
88
85
...sentryOptions ,
89
- integrations : [ replayIntegration ] ,
86
+ integrations : [ replayIntegrationInstance ] ,
90
87
} ) ;
91
88
92
89
// Instead of `setupOnce`, which is tricky to test, we call this manually here
93
- replayIntegration [ '_setup' ] ( ) ;
90
+ replayIntegrationInstance [ '_setup' ] ( ) ;
94
91
95
92
if ( autoStart ) {
96
93
// Only exists in our mock
97
- replayIntegration . initialize ( ) ;
94
+ replayIntegrationInstance . initialize ( ) ;
98
95
}
99
96
100
- const replay = replayIntegration [ '_replay' ] ! ;
97
+ const replay = replayIntegrationInstance [ '_replay' ] ! ;
101
98
102
99
return { replay, integration : replayIntegration } ;
103
100
}
0 commit comments