-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathclientreport.test.ts
62 lines (52 loc) · 1.94 KB
/
clientreport.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
import type { ClientReport } from '../../src/types-hoist';
import { describe, expect, it } from 'vitest';
import { createClientReportEnvelope } from '../../src/utils-hoist/clientreport';
import { parseEnvelope, serializeEnvelope } from '../../src/utils-hoist/envelope';
const DEFAULT_DISCARDED_EVENTS: ClientReport['discarded_events'] = [
{
reason: 'before_send',
category: 'error',
quantity: 30,
},
{
reason: 'network_error',
category: 'transaction',
quantity: 23,
},
];
const MOCK_DSN = 'https://public@example.com/1';
describe('createClientReportEnvelope', () => {
const testTable: Array<
[string, Parameters<typeof createClientReportEnvelope>[0], Parameters<typeof createClientReportEnvelope>[1]]
> = [
['with no discard reasons', [], undefined],
['with a dsn', [], MOCK_DSN],
['with discard reasons', DEFAULT_DISCARDED_EVENTS, MOCK_DSN],
];
it.each(testTable)('%s', (_: string, discardedEvents, dsn) => {
const env = createClientReportEnvelope(discardedEvents, dsn);
expect(env[0]).toEqual(dsn ? { dsn } : {});
const items = env[1];
expect(items).toHaveLength(1);
const clientReportItem = items[0]!;
expect(clientReportItem[0]).toEqual({ type: 'client_report' });
expect(clientReportItem[1]).toEqual({ timestamp: expect.any(Number), discarded_events: discardedEvents });
});
it('serializes an envelope', () => {
const env = createClientReportEnvelope(DEFAULT_DISCARDED_EVENTS, MOCK_DSN, 123456);
const [headers, items] = parseEnvelope(serializeEnvelope(env));
expect(headers).toEqual({ dsn: 'https://public@example.com/1' });
expect(items).toEqual([
[
{ type: 'client_report' },
{
timestamp: 123456,
discarded_events: [
{ reason: 'before_send', category: 'error', quantity: 30 },
{ reason: 'network_error', category: 'transaction', quantity: 23 },
],
},
],
]);
});
});