-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy patherrors.test.ts
More file actions
75 lines (55 loc) · 2.55 KB
/
errors.test.ts
File metadata and controls
75 lines (55 loc) · 2.55 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
import { expect, test } from '@playwright/test';
import { waitForError } from '@sentry-internal/test-utils';
import { io } from 'socket.io-client';
test('Captures manually reported error in WebSocket gateway handler', async ({ baseURL }) => {
const errorPromise = waitForError('nestjs-websockets', event => {
return event.exception?.values?.[0]?.value === 'Manually captured WebSocket error';
});
const socket = io(baseURL!);
await new Promise<void>(resolve => socket.on('connect', resolve));
socket.emit('test-manual-capture', {});
const error = await errorPromise;
expect(error.exception?.values?.[0]).toMatchObject({
type: 'Error',
value: 'Manually captured WebSocket error',
});
socket.disconnect();
});
test('Automatically captures exceptions in WebSocket gateway handler', async ({ baseURL }) => {
const errorPromise = waitForError('nestjs-websockets', event => {
return event.exception?.values?.[0]?.value === 'This is an exception in a WebSocket handler';
});
const socket = io(baseURL!);
await new Promise<void>(resolve => socket.on('connect', resolve));
socket.emit('test-exception', {});
const error = await errorPromise;
expect(error.exception?.values?.[0]).toMatchObject({
type: 'Error',
value: 'This is an exception in a WebSocket handler',
});
socket.disconnect();
});
// There is no good mechanism to verify that an event was NOT sent to Sentry.
// The idea here is that we first send a message that triggers a WsException which should not be auto-captured,
// and then send a message that triggers a manually captured error which will be sent to Sentry.
// If the manually captured error arrives, we can deduce that the WsException was not sent,
// because Socket.IO guarantees message ordering: https://socket.io/docs/v4/delivery-guarantees
test('Does not capture WsException in WebSocket gateway handler', async ({ baseURL }) => {
let errorEventOccurred = false;
waitForError('nestjs-websockets', event => {
if (!event.type && event.exception?.values?.[0]?.value === 'Expected WS exception') {
errorEventOccurred = true;
}
return false;
});
const manualCapturePromise = waitForError('nestjs-websockets', event => {
return event.exception?.values?.[0]?.value === 'Manually captured WebSocket error';
});
const socket = io(baseURL!);
await new Promise<void>(resolve => socket.on('connect', resolve));
socket.emit('test-ws-exception', {});
socket.emit('test-manual-capture', {});
await manualCapturePromise;
expect(errorEventOccurred).toBe(false);
socket.disconnect();
});