-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathhandleBeforeSendEvent.test.ts
More file actions
91 lines (79 loc) · 2.56 KB
/
handleBeforeSendEvent.test.ts
File metadata and controls
91 lines (79 loc) · 2.56 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
/**
* @vitest-environment jsdom
*/
import '../../utils/mock-internal-setTimeout';
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
import { handleBeforeSendEvent } from '../../../src/coreHandlers/handleBeforeSendEvent';
import type { ReplayContainer } from '../../../src/replay';
import { Error } from '../../fixtures/error';
import { resetSdkMock } from '../../mocks/resetSdkMock';
let replay: ReplayContainer;
describe('Integration | coreHandlers | handleBeforeSendEvent', () => {
beforeAll(() => {
vi.useFakeTimers();
});
afterEach(() => {
replay.stop();
});
it('adds a hydration breadcrumb on development hydration error', async () => {
({ replay } = await resetSdkMock({
replayOptions: {
stickySession: false,
},
sentryOptions: {
replaysSessionSampleRate: 0.0,
replaysOnErrorSampleRate: 1.0,
},
}));
const handler = handleBeforeSendEvent(replay);
const addBreadcrumbSpy = vi.spyOn(replay, 'throttledAddEvent');
const error = Error();
error.exception.values[0]!.value =
'Text content does not match server-rendered HTML. Warning: Text content did not match.';
handler(error);
expect(addBreadcrumbSpy).toHaveBeenCalledTimes(1);
expect(addBreadcrumbSpy).toHaveBeenCalledWith({
data: {
payload: {
category: 'replay.hydrate-error',
data: { url: 'http://localhost:3000/' },
timestamp: expect.any(Number),
type: 'default',
},
tag: 'breadcrumb',
},
timestamp: expect.any(Number),
type: 5,
});
});
it('adds a hydration breadcrumb on production hydration error', async () => {
({ replay } = await resetSdkMock({
replayOptions: {
stickySession: false,
},
sentryOptions: {
replaysSessionSampleRate: 0.0,
replaysOnErrorSampleRate: 1.0,
},
}));
const handler = handleBeforeSendEvent(replay);
const addBreadcrumbSpy = vi.spyOn(replay, 'throttledAddEvent');
const error = Error();
error.exception.values[0]!.value = 'https://reactjs.org/docs/error-decoder.html?invariant=423';
handler(error);
expect(addBreadcrumbSpy).toHaveBeenCalledTimes(1);
expect(addBreadcrumbSpy).toHaveBeenCalledWith({
data: {
payload: {
category: 'replay.hydrate-error',
data: { url: 'http://localhost:3000/' },
timestamp: expect.any(Number),
type: 'default',
},
tag: 'breadcrumb',
},
timestamp: expect.any(Number),
type: 5,
});
});
});