-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathearlyEvents.test.ts
More file actions
113 lines (93 loc) · 3.12 KB
/
earlyEvents.test.ts
File metadata and controls
113 lines (93 loc) · 3.12 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* @vitest-environment jsdom
*/
import '../utils/mock-internal-setTimeout';
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import { BASE_TIMESTAMP } from '..';
import { resetSdkMock } from '../mocks/resetSdkMock';
describe('Integration | early events', () => {
beforeAll(() => {
vi.useFakeTimers();
});
beforeEach(() => {
vi.clearAllMocks();
});
it('updates initialTimestamp for early performance entries', async () => {
const earlyTimeStampSeconds = BASE_TIMESTAMP / 1000 - 10;
const { replay } = await resetSdkMock({
replayOptions: {
stickySession: true,
},
sentryOptions: {
replaysSessionSampleRate: 0,
replaysOnErrorSampleRate: 1.0,
},
});
expect(replay.session).toBeDefined();
expect(replay['_requiresManualStart']).toBe(false);
const initialTimestamp = replay.getContext().initialTimestamp;
expect(initialTimestamp).not.toEqual(earlyTimeStampSeconds * 1000);
// A performance entry that happened before should not extend the session when we manually started
replay.replayPerformanceEntries.push({
type: 'largest-contentful-paint',
name: 'largest-contentful-paint',
start: earlyTimeStampSeconds,
end: earlyTimeStampSeconds,
data: {
value: 100,
size: 100,
nodeId: undefined,
},
});
// _too_ early events are always thrown away
replay.replayPerformanceEntries.push({
type: 'largest-contentful-paint',
name: 'largest-contentful-paint',
start: earlyTimeStampSeconds - 999999,
end: earlyTimeStampSeconds - 99999,
data: {
value: 100,
size: 100,
nodeId: undefined,
},
});
await replay.flushImmediate();
vi.runAllTimers();
expect(replay.getContext().initialTimestamp).toEqual(earlyTimeStampSeconds * 1000);
});
it('does not change initialTimestamp when replay is manually started', async () => {
const earlyTimeStampSeconds = Date.now() / 1000 - 5;
const { replay } = await resetSdkMock({
replayOptions: {
stickySession: true,
},
sentryOptions: {
replaysSessionSampleRate: 0.0,
replaysOnErrorSampleRate: 0.0,
},
});
expect(replay.session).toBe(undefined);
expect(replay['_requiresManualStart']).toBe(true);
replay.start();
vi.runAllTimers();
const initialTimestamp = replay.getContext().initialTimestamp;
expect(initialTimestamp).not.toEqual(earlyTimeStampSeconds * 1000);
expect(replay.session).toBeDefined();
expect(replay['_requiresManualStart']).toBe(true);
// A performance entry that happened before should not extend the session when we manually started
replay.replayPerformanceEntries.push({
type: 'largest-contentful-paint',
name: 'largest-contentful-paint',
start: earlyTimeStampSeconds,
end: earlyTimeStampSeconds,
data: {
value: 100,
size: 100,
nodeId: undefined,
},
});
await replay.flushImmediate();
vi.runAllTimers();
expect(replay.getContext().initialTimestamp).toEqual(initialTimestamp);
});
});