Repository navigation
Expand file tree
/
Copy pathdebug.test.ts
More file actions
79 lines (62 loc) · 2.97 KB
/
Copy pathdebug.test.ts
File metadata and controls
79 lines (62 loc) · 2.97 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
import type { EventProcessor, Integration } from '@sentry/types';
import { Debug } from '../src/debug';
const mockGetCurrentHub = (getIntegrationResult: Integration) => ({
getIntegration: jest.fn(() => getIntegrationResult),
});
// Replace console log with a mock so we can check for invocations
const mockConsoleLog = jest.fn();
// eslint-disable-next-line @typescript-eslint/unbound-method
const originalConsoleLog = global.console.log;
global.console.log = mockConsoleLog;
describe('Debug integration setup should register an event processor that', () => {
afterAll(() => {
// Reset mocked console log to original one
global.console.log = originalConsoleLog;
});
afterEach(() => {
jest.clearAllMocks();
});
it('logs an event', () => {
const debugIntegration = new Debug();
const captureEventProcessor = (eventProcessor: EventProcessor) => {
const testEvent = { event_id: 'some event' };
void eventProcessor(testEvent, {});
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
expect(mockConsoleLog).toBeCalledWith(testEvent);
};
debugIntegration.setupOnce(captureEventProcessor, () => mockGetCurrentHub(debugIntegration) as any);
});
it('logs an event hint if available', () => {
const debugIntegration = new Debug();
const captureEventProcessor = (eventProcessor: EventProcessor) => {
const testEvent = { event_id: 'some event' };
const testEventHint = { event_id: 'some event hint' };
void eventProcessor(testEvent, testEventHint);
expect(mockConsoleLog).toHaveBeenCalledTimes(2);
expect(mockConsoleLog).toBeCalledWith(testEvent);
expect(mockConsoleLog).toBeCalledWith(testEventHint);
};
debugIntegration.setupOnce(captureEventProcessor, () => mockGetCurrentHub(debugIntegration) as any);
});
it('logs events in stringified format when `stringify` option was set', () => {
const debugIntegration = new Debug({ stringify: true });
const captureEventProcessor = (eventProcessor: EventProcessor) => {
const testEvent = { event_id: 'some event' };
void eventProcessor(testEvent, {});
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
expect(mockConsoleLog).toBeCalledWith(JSON.stringify(testEvent, null, 2));
};
debugIntegration.setupOnce(captureEventProcessor, () => mockGetCurrentHub(debugIntegration) as any);
});
it('logs event hints in stringified format when `stringify` option was set', () => {
const debugIntegration = new Debug({ stringify: true });
const captureEventProcessor = (eventProcessor: EventProcessor) => {
const testEvent = { event_id: 'some event' };
const testEventHint = { event_id: 'some event hint' };
void eventProcessor(testEvent, testEventHint);
expect(mockConsoleLog).toHaveBeenCalledTimes(2);
expect(mockConsoleLog).toBeCalledWith(JSON.stringify(testEventHint, null, 2));
};
debugIntegration.setupOnce(captureEventProcessor, () => mockGetCurrentHub(debugIntegration) as any);
});
});