Skip to content

Commit e3c7291

Browse files
committed
cleanup stop.test.ts
1 parent 099b4f4 commit e3c7291

File tree

1 file changed

+3
-53
lines changed

1 file changed

+3
-53
lines changed

packages/replay-internal/test/integration/stop.test.ts

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
*/
44

55
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';
77

88
import * as SentryBrowserUtils from '@sentry-internal/browser-utils';
99

1010
import { WINDOW } from '../../src/constants';
1111
import type { Replay } from '../../src/integration';
1212
import type { ReplayContainer } from '../../src/replay';
13-
import { clearSession } from '../../src/session/clearSession';
1413
import { addEvent } from '../../src/util/addEvent';
1514
import { createOptionsEvent } from '../../src/util/handleRecordingEmit';
1615
// mock functions need to be imported first
1716
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '../index';
18-
import { getTestEventCheckout, getTestEventIncremental } from '../utils/getTestEvent';
17+
import { getTestEventIncremental } from '../utils/getTestEvent';
1918
import { useFakeTimers } from '../utils/use-fake-timers';
2019

2120
useFakeTimers();
@@ -46,27 +45,15 @@ describe('Integration | stop', () => {
4645
});
4746

4847
afterEach(async () => {
49-
console.log('afterEach');
50-
await vi.runAllTimersAsync();
51-
await new Promise(process.nextTick);
5248
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());
5950
Object.defineProperty(WINDOW, 'location', {
6051
value: prevLocation,
6152
writable: true,
6253
});
6354
vi.clearAllMocks();
6455
});
6556

66-
afterAll(() => {
67-
integration && integration.stop();
68-
});
69-
7057
it('does not upload replay if it was stopped and can resume replays afterwards', async () => {
7158
Object.defineProperty(document, 'visibilityState', {
7259
configurable: true,
@@ -143,13 +130,10 @@ describe('Integration | stop', () => {
143130
});
144131

145132
it('does not buffer new events after being stopped', async function () {
146-
console.log('start test');
147133
expect(replay.eventBuffer?.hasEvents).toBe(false);
148134
expect(mockRunFlush).toHaveBeenCalledTimes(0);
149135
const TEST_EVENT = getTestEventIncremental({ timestamp: BASE_TIMESTAMP });
150-
console.log('hi', replay.eventBuffer);
151136
addEvent(replay, TEST_EVENT, true);
152-
console.log(replay.eventBuffer);
153137
expect(replay.eventBuffer?.hasEvents).toBe(true);
154138
expect(mockRunFlush).toHaveBeenCalledTimes(0);
155139

@@ -160,7 +144,6 @@ describe('Integration | stop', () => {
160144

161145
expect(replay.eventBuffer).toBe(null);
162146

163-
console.log('before blur');
164147
WINDOW.dispatchEvent(new Event('blur'));
165148
await new Promise(process.nextTick);
166149

@@ -179,37 +162,4 @@ describe('Integration | stop', () => {
179162

180163
expect(mockAddDomInstrumentationHandler).not.toHaveBeenCalled();
181164
});
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-
});
215165
});

0 commit comments

Comments
 (0)