3
3
*/
4
4
5
5
import type { MockInstance , MockedFunction } from 'vitest' ;
6
- import { afterAll , afterEach , beforeAll , beforeEach , describe , expect , it , vi } from 'vitest' ;
6
+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
7
7
8
8
import * as SentryBrowserUtils from '@sentry-internal/browser-utils' ;
9
9
10
10
import { WINDOW } from '../../src/constants' ;
11
11
import type { Replay } from '../../src/integration' ;
12
12
import type { ReplayContainer } from '../../src/replay' ;
13
- import { clearSession } from '../../src/session/clearSession' ;
14
13
import { addEvent } from '../../src/util/addEvent' ;
15
14
import { createOptionsEvent } from '../../src/util/handleRecordingEmit' ;
16
15
// mock functions need to be imported first
17
16
import { BASE_TIMESTAMP , mockRrweb , mockSdk } from '../index' ;
18
- import { getTestEventCheckout , getTestEventIncremental } from '../utils/getTestEvent' ;
17
+ import { getTestEventIncremental } from '../utils/getTestEvent' ;
19
18
import { useFakeTimers } from '../utils/use-fake-timers' ;
20
19
21
20
useFakeTimers ( ) ;
@@ -46,27 +45,15 @@ describe('Integration | stop', () => {
46
45
} ) ;
47
46
48
47
afterEach ( async ( ) => {
49
- console . log ( 'afterEach' ) ;
50
- await vi . runAllTimersAsync ( ) ;
51
- await new Promise ( process . nextTick ) ;
52
48
vi . setSystemTime ( new Date ( BASE_TIMESTAMP ) ) ;
53
- sessionStorage . clear ( ) ;
54
- clearSession ( replay ) ;
55
- replay [ '_initializeSessionForSampling' ] ( ) ;
56
- replay . setInitialState ( ) ;
57
- mockRecord . takeFullSnapshot . mockClear ( ) ;
58
- mockAddDomInstrumentationHandler . mockClear ( ) ;
49
+ integration && ( await integration . stop ( ) ) ;
59
50
Object . defineProperty ( WINDOW , 'location' , {
60
51
value : prevLocation ,
61
52
writable : true ,
62
53
} ) ;
63
54
vi . clearAllMocks ( ) ;
64
55
} ) ;
65
56
66
- afterAll ( ( ) => {
67
- integration && integration . stop ( ) ;
68
- } ) ;
69
-
70
57
it ( 'does not upload replay if it was stopped and can resume replays afterwards' , async ( ) => {
71
58
Object . defineProperty ( document , 'visibilityState' , {
72
59
configurable : true ,
@@ -143,13 +130,10 @@ describe('Integration | stop', () => {
143
130
} ) ;
144
131
145
132
it ( 'does not buffer new events after being stopped' , async function ( ) {
146
- console . log ( 'start test' ) ;
147
133
expect ( replay . eventBuffer ?. hasEvents ) . toBe ( false ) ;
148
134
expect ( mockRunFlush ) . toHaveBeenCalledTimes ( 0 ) ;
149
135
const TEST_EVENT = getTestEventIncremental ( { timestamp : BASE_TIMESTAMP } ) ;
150
- console . log ( 'hi' , replay . eventBuffer ) ;
151
136
addEvent ( replay , TEST_EVENT , true ) ;
152
- console . log ( replay . eventBuffer ) ;
153
137
expect ( replay . eventBuffer ?. hasEvents ) . toBe ( true ) ;
154
138
expect ( mockRunFlush ) . toHaveBeenCalledTimes ( 0 ) ;
155
139
@@ -160,7 +144,6 @@ describe('Integration | stop', () => {
160
144
161
145
expect ( replay . eventBuffer ) . toBe ( null ) ;
162
146
163
- console . log ( 'before blur' ) ;
164
147
WINDOW . dispatchEvent ( new Event ( 'blur' ) ) ;
165
148
await new Promise ( process . nextTick ) ;
166
149
@@ -179,37 +162,4 @@ describe('Integration | stop', () => {
179
162
180
163
expect ( mockAddDomInstrumentationHandler ) . not . toHaveBeenCalled ( ) ;
181
164
} ) ;
182
-
183
- it ( 'does not add replay breadcrumb when stopped due to event buffer limit' , async ( ) => {
184
- const TEST_EVENT = getTestEventIncremental ( { timestamp : BASE_TIMESTAMP } ) ;
185
-
186
- vi . mock ( '../../src/constants' , async requireActual => ( {
187
- ...( await requireActual < any > ( ) ) ,
188
- REPLAY_MAX_EVENT_BUFFER_SIZE : 500 ,
189
- } ) ) ;
190
-
191
- await integration . stop ( ) ;
192
- integration . startBuffering ( ) ;
193
-
194
- await addEvent ( replay , TEST_EVENT ) ;
195
-
196
- expect ( replay . eventBuffer ?. hasEvents ) . toBe ( true ) ;
197
- expect ( replay . eventBuffer ?. [ 'hasCheckout' ] ) . toBe ( true ) ;
198
-
199
- // This should should go over max buffer size
200
- await addEvent ( replay , TEST_EVENT ) ;
201
- // buffer should be cleared and wait for next checkout
202
- expect ( replay . eventBuffer ?. hasEvents ) . toBe ( false ) ;
203
- expect ( replay . eventBuffer ?. [ 'hasCheckout' ] ) . toBe ( false ) ;
204
-
205
- await addEvent ( replay , TEST_EVENT ) ;
206
- expect ( replay . eventBuffer ?. hasEvents ) . toBe ( false ) ;
207
- expect ( replay . eventBuffer ?. [ 'hasCheckout' ] ) . toBe ( false ) ;
208
-
209
- await addEvent ( replay , getTestEventCheckout ( { timestamp : Date . now ( ) } ) , true ) ;
210
- expect ( replay . eventBuffer ?. hasEvents ) . toBe ( true ) ;
211
- expect ( replay . eventBuffer ?. [ 'hasCheckout' ] ) . toBe ( true ) ;
212
-
213
- vi . resetAllMocks ( ) ;
214
- } ) ;
215
165
} ) ;
0 commit comments