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