forked from getsentry/sentry-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhint.test.ts
96 lines (75 loc) · 3.03 KB
/
hint.test.ts
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
import { captureEvent, configureScope } from '@sentry/hub';
import { GLOBAL_OBJ } from '@sentry/utils';
import { initAndBind } from '../../src/sdk';
import { getDefaultTestClientOptions, TestClient } from '../mocks/client';
import { AddAttachmentTestIntegration } from '../mocks/integration';
const PUBLIC_DSN = 'https://username@domain/123';
const sendEvent = jest.spyOn(TestClient.prototype, 'sendEvent');
describe('Hint', () => {
beforeEach(() => {
TestClient.sendEventCalled = undefined;
TestClient.instance = undefined;
});
afterEach(() => {
jest.clearAllMocks();
delete GLOBAL_OBJ.__SENTRY__;
});
describe('attachments', () => {
test('can be mutated in beforeSend', () => {
expect.assertions(1);
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
beforeSend: (event, hint) => {
hint.attachments = [...(hint.attachments || []), { filename: 'another.file', data: 'more text' }];
return event;
},
});
const client = new TestClient(options);
client.captureEvent({});
const [, hint] = sendEvent.mock.calls[0];
expect(hint).toEqual({ attachments: [{ filename: 'another.file', data: 'more text' }] });
});
test('gets passed through to beforeSend and can be further mutated', () => {
expect.assertions(1);
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
beforeSend: (event, hint) => {
hint.attachments = [...(hint.attachments || []), { filename: 'another.file', data: 'more text' }];
return event;
},
});
const client = new TestClient(options);
client.captureEvent({}, { attachments: [{ filename: 'some-file.txt', data: 'Hello' }] });
const [, hint] = sendEvent.mock.calls[0];
expect(hint).toEqual({
attachments: [
{ filename: 'some-file.txt', data: 'Hello' },
{ filename: 'another.file', data: 'more text' },
],
});
});
test('can be mutated by an integration via event processor', () => {
expect.assertions(1);
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
integrations: [new AddAttachmentTestIntegration()],
});
initAndBind(TestClient, options);
captureEvent({});
const [, hint] = sendEvent.mock.calls[0];
expect(hint?.attachments).toEqual([{ filename: 'integration.file', data: 'great content!' }]);
});
test('get copied from scope to hint', () => {
expect.assertions(1);
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN });
initAndBind(TestClient, options);
configureScope(scope => scope.addAttachment({ filename: 'scope.file', data: 'great content!' }));
captureEvent({}, { attachments: [{ filename: 'some-file.txt', data: 'Hello' }] });
const [, hint] = sendEvent.mock.calls[0];
expect(hint?.attachments).toEqual([
{ filename: 'some-file.txt', data: 'Hello' },
{ filename: 'scope.file', data: 'great content!' },
]);
});
});
});