-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathconsole.test.ts
60 lines (50 loc) · 1.52 KB
/
console.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
import * as SentryCore from '@sentry/core';
import { resetInstrumentationHandlers } from '@sentry/utils';
import { getClient } from '../../src';
import type { NodeClient } from '../../src';
import { consoleIntegration } from '../../src/integrations/console';
const addBreadcrumbSpy = jest.spyOn(SentryCore, 'addBreadcrumb');
jest.spyOn(console, 'log').mockImplementation(() => {
// noop so that we don't spam the logs
});
afterEach(() => {
jest.clearAllMocks();
resetInstrumentationHandlers();
});
describe('Console integration', () => {
it('should add a breadcrumb on console.log', () => {
consoleIntegration().setup?.(getClient() as NodeClient);
// eslint-disable-next-line no-console
console.log('test');
expect(addBreadcrumbSpy).toHaveBeenCalledTimes(1);
expect(addBreadcrumbSpy).toHaveBeenCalledWith(
{
category: 'console',
level: 'log',
message: 'test',
},
{
input: ['test'],
level: 'log',
},
);
});
it('should truncate breadcrumbs with more than 2 KB message size', () => {
consoleIntegration().setup?.(getClient() as NodeClient);
const longMsg = 'A'.repeat(10_000);
// eslint-disable-next-line no-console
console.log(longMsg);
expect(addBreadcrumbSpy).toHaveBeenCalledTimes(1);
expect(addBreadcrumbSpy).toHaveBeenCalledWith(
{
category: 'console',
level: 'log',
message: `${'A'.repeat(2048)}...`,
},
{
input: [longMsg],
level: 'log',
},
);
});
});