Skip to content

Commit faa2d54

Browse files
committed
add eventBuffer integration test
1 parent e3c7291 commit faa2d54

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

packages/replay-internal/src/eventBuffer/EventBufferProxy.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export class EventBufferProxy implements EventBuffer {
5959

6060
/** @inheritdoc */
6161
public clear(): void {
62-
this.waitForCheckout = true;
6362
return this._used.clear();
6463
}
6564

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
5+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6+
7+
import { WINDOW } from '../../src/constants';
8+
import type { Replay } from '../../src/integration';
9+
import type { ReplayContainer } from '../../src/replay';
10+
import { addEvent } from '../../src/util/addEvent';
11+
12+
// mock functions need to be imported first
13+
import { BASE_TIMESTAMP, mockSdk } from '../index';
14+
import { getTestEventCheckout, getTestEventIncremental } from '../utils/getTestEvent';
15+
import { useFakeTimers } from '../utils/use-fake-timers';
16+
17+
useFakeTimers();
18+
19+
describe('Integration | eventBuffer | Event Buffer Max Size', () => {
20+
let replay: ReplayContainer;
21+
let integration: Replay;
22+
const prevLocation = WINDOW.location;
23+
24+
beforeEach(async () => {
25+
vi.setSystemTime(new Date(BASE_TIMESTAMP));
26+
27+
({ replay, integration } = await mockSdk());
28+
29+
await vi.runAllTimersAsync();
30+
vi.clearAllMocks();
31+
});
32+
33+
afterEach(async () => {
34+
vi.setSystemTime(new Date(BASE_TIMESTAMP));
35+
integration && (await integration.stop());
36+
Object.defineProperty(WINDOW, 'location', {
37+
value: prevLocation,
38+
writable: true,
39+
});
40+
vi.clearAllMocks();
41+
});
42+
43+
it('does not add replay breadcrumb when stopped due to event buffer limit', async () => {
44+
const TEST_EVENT = getTestEventIncremental({ timestamp: BASE_TIMESTAMP });
45+
46+
vi.mock('../../src/constants', async requireActual => ({
47+
...(await requireActual<any>()),
48+
REPLAY_MAX_EVENT_BUFFER_SIZE: 500,
49+
}));
50+
51+
await integration.stop();
52+
integration.startBuffering();
53+
54+
await addEvent(replay, TEST_EVENT);
55+
56+
expect(replay.eventBuffer?.hasEvents).toBe(true);
57+
expect(replay.eventBuffer?.['hasCheckout']).toBe(true);
58+
59+
// This should should go over max buffer size
60+
await addEvent(replay, TEST_EVENT);
61+
// buffer should be cleared and wait for next checkout
62+
expect(replay.eventBuffer?.hasEvents).toBe(false);
63+
expect(replay.eventBuffer?.['hasCheckout']).toBe(false);
64+
65+
await addEvent(replay, TEST_EVENT);
66+
expect(replay.eventBuffer?.hasEvents).toBe(false);
67+
expect(replay.eventBuffer?.['hasCheckout']).toBe(false);
68+
69+
await addEvent(replay, getTestEventCheckout({ timestamp: Date.now() }), true);
70+
expect(replay.eventBuffer?.hasEvents).toBe(true);
71+
expect(replay.eventBuffer?.['hasCheckout']).toBe(true);
72+
73+
vi.resetAllMocks();
74+
});
75+
});

0 commit comments

Comments
 (0)