-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcatcher.addons.test.ts
More file actions
96 lines (76 loc) · 3.52 KB
/
catcher.addons.test.ts
File metadata and controls
96 lines (76 loc) · 3.52 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
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { BreadcrumbManager } from '../src/addons/breadcrumbs';
import { wait, createTransport, getLastPayload, createCatcher } from './catcher.helpers';
const mockParse = vi.hoisted(() => vi.fn().mockResolvedValue([]));
vi.mock('@hawk.so/core', async (importOriginal) => {
const actual = await importOriginal<typeof import('@hawk.so/core')>();
return { ...actual, StackParser: class { parse = mockParse; } };
});
describe('Catcher', () => {
beforeEach(() => {
localStorage.clear();
mockParse.mockResolvedValue([]);
(BreadcrumbManager as any).instance = null;
});
// ── Environment addons ────────────────────────────────────────────────────
//
// Browser-specific data collected from window (URL, GET params, debug info).
describe('environment addons', () => {
it('should include GET parameters when the URL has a query string', async () => {
vi.stubGlobal('location', {
...window.location,
search: '?foo=bar&baz=qux',
href: 'http://localhost/?foo=bar&baz=qux',
});
const { sendSpy, transport } = createTransport();
createCatcher(transport).send(new Error('e'));
await wait();
expect(getLastPayload(sendSpy).addons.get).toEqual({ foo: 'bar', baz: 'qux' });
vi.unstubAllGlobals();
});
it('should include raw error data in debug mode', async () => {
const { sendSpy, transport } = createTransport();
const error = new Error('debug error');
createCatcher(transport, { debug: true }).send(error);
await wait();
expect(getLastPayload(sendSpy).addons.RAW_EVENT_DATA).toMatchObject({
name: 'Error',
message: 'debug error',
stack: expect.any(String),
});
});
it('should not include raw error data for string errors even in debug mode', async () => {
const { sendSpy, transport } = createTransport();
createCatcher(transport, { debug: true }).send('string reason');
await wait();
expect(getLastPayload(sendSpy).addons.RAW_EVENT_DATA).toBeUndefined();
});
});
// ── Integration addons ────────────────────────────────────────────────────
//
// Framework integrations (Vue, Nuxt, etc.) attach extra addons when
// reporting errors via captureError(). These are merged into the payload
// alongside the standard browser addons.
describe('integration addons via captureError()', () => {
it('should merge integration-specific addons', async () => {
const { sendSpy, transport } = createTransport();
createCatcher(transport).captureError(new Error('e'), {
vue: { component: '<App />', props: {}, lifecycle: 'mounted' },
});
await wait();
expect(getLastPayload(sendSpy).addons).toMatchObject({
vue: { component: '<App />', props: {}, lifecycle: 'mounted' },
});
});
it('should preserve standard browser addons when integration addons are merged', async () => {
const { sendSpy, transport } = createTransport();
createCatcher(transport).captureError(new Error('e'), {
vue: { component: '<Foo />', props: {}, lifecycle: 'mounted' },
});
await wait();
const addons = getLastPayload(sendSpy).addons;
expect(addons.userAgent).toBeDefined();
expect(addons.url).toBeDefined();
});
});
});