|
1 | 1 | import { expect, test } from '@playwright/test';
|
2 | 2 | import { waitForError } from '@sentry-internal/test-utils';
|
| 3 | +import {WebSocket} from 'ws' |
3 | 4 |
|
4 | 5 | test('Index page', async ({ baseURL }) => {
|
5 | 6 | const result = await fetch(baseURL!);
|
@@ -35,3 +36,47 @@ test('Request processed by DurableObject\'s fetch is recorded', async ({baseURL}
|
35 | 36 | const event = await eventWaiter;
|
36 | 37 | expect(event.exception?.values?.[0]?.value).toBe('Should be recorded in Sentry.');
|
37 | 38 | });
|
| 39 | +test('Websocket.webSocketMessage', async ({baseURL}) => { |
| 40 | + const eventWaiter = waitForError('cloudflare-workers', (event) => { |
| 41 | + return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare_durableobject'; |
| 42 | + }); |
| 43 | + const url = new URL('/pass-to-object/ws', baseURL); |
| 44 | + url.protocol = url.protocol.replace('http', 'ws'); |
| 45 | + const socket = new WebSocket(url.toString()); |
| 46 | + socket.addEventListener('open', () => { |
| 47 | + socket.send('throwException') |
| 48 | + }); |
| 49 | + const event = await eventWaiter; |
| 50 | + socket.close(); |
| 51 | + expect(event.exception?.values?.[0]?.value).toBe('Should be recorded in Sentry: webSocketMessage'); |
| 52 | +}) |
| 53 | + |
| 54 | +test('Websocket.webSocketClose', async ({baseURL}) => { |
| 55 | + const eventWaiter = waitForError('cloudflare-workers', (event) => { |
| 56 | + return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare_durableobject'; |
| 57 | + }); |
| 58 | + const url = new URL('/pass-to-object/ws', baseURL); |
| 59 | + url.protocol = url.protocol.replace('http', 'ws'); |
| 60 | + const socket = new WebSocket(url.toString()); |
| 61 | + socket.addEventListener('open', () => { |
| 62 | + socket.send('throwOnExit') |
| 63 | + socket.close() |
| 64 | + }); |
| 65 | + const event = await eventWaiter; |
| 66 | + expect(event.exception?.values?.[0]?.value).toBe('Should be recorded in Sentry: webSocketClose'); |
| 67 | +}) |
| 68 | + |
| 69 | +test('Websocket.webSocketClose', async ({baseURL}) => { |
| 70 | + const eventWaiter = waitForError('cloudflare-workers', (event) => { |
| 71 | + return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare_durableobject'; |
| 72 | + }); |
| 73 | + const url = new URL('/pass-to-object/ws', baseURL); |
| 74 | + url.protocol = url.protocol.replace('http', 'ws'); |
| 75 | + const socket = new WebSocket(url.toString()); |
| 76 | + socket.addEventListener('open', () => { |
| 77 | + socket.send('throwOnExit') |
| 78 | + socket.close() |
| 79 | + }); |
| 80 | + const event = await eventWaiter; |
| 81 | + expect(event.exception?.values?.[0]?.value).toBe('Should be recorded in Sentry: webSocketClose'); |
| 82 | +}) |
0 commit comments