|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { waitForError, waitForTransaction } from '@sentry-internal/test-utils'; |
| 3 | + |
| 4 | +test('Should create a transaction for dynamic route handlers', async ({ request }) => { |
| 5 | + const routehandlerTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => { |
| 6 | + return transactionEvent?.transaction === 'GET /route-handlers/[param]'; |
| 7 | + }); |
| 8 | + |
| 9 | + const response = await request.get('/route-handlers/foo'); |
| 10 | + expect(await response.json()).toStrictEqual({ name: 'Beep' }); |
| 11 | + |
| 12 | + const routehandlerTransaction = await routehandlerTransactionPromise; |
| 13 | + |
| 14 | + expect(routehandlerTransaction.contexts?.trace?.status).toBe('ok'); |
| 15 | + expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); |
| 16 | +}); |
| 17 | + |
| 18 | +test('Should create a transaction for static route handlers', async ({ request }) => { |
| 19 | + const routehandlerTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => { |
| 20 | + return transactionEvent?.transaction === 'GET /route-handlers/static'; |
| 21 | + }); |
| 22 | + |
| 23 | + const response = await request.get('/route-handlers/static'); |
| 24 | + expect(await response.json()).toStrictEqual({ name: 'Static' }); |
| 25 | + |
| 26 | + const routehandlerTransaction = await routehandlerTransactionPromise; |
| 27 | + |
| 28 | + expect(routehandlerTransaction.contexts?.trace?.status).toBe('ok'); |
| 29 | + expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); |
| 30 | +}); |
| 31 | + |
| 32 | +test('Should create a transaction for route handlers and correctly set span status depending on http status', async ({ |
| 33 | + request, |
| 34 | +}) => { |
| 35 | + const routehandlerTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => { |
| 36 | + return transactionEvent?.transaction === 'POST /route-handlers/[param]'; |
| 37 | + }); |
| 38 | + |
| 39 | + const response = await request.post('/route-handlers/bar'); |
| 40 | + expect(await response.json()).toStrictEqual({ name: 'Boop' }); |
| 41 | + |
| 42 | + const routehandlerTransaction = await routehandlerTransactionPromise; |
| 43 | + |
| 44 | + expect(routehandlerTransaction.contexts?.trace?.status).toBe('invalid_argument'); |
| 45 | + expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); |
| 46 | +}); |
| 47 | + |
| 48 | +test('Should record exceptions and transactions for faulty route handlers', async ({ request }) => { |
| 49 | + const errorEventPromise = waitForError('nextjs-turbo', errorEvent => { |
| 50 | + return errorEvent?.exception?.values?.[0]?.value === 'Dynamic route handler error'; |
| 51 | + }); |
| 52 | + |
| 53 | + const routehandlerTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => { |
| 54 | + return transactionEvent?.transaction === 'GET /route-handlers/[param]/error'; |
| 55 | + }); |
| 56 | + |
| 57 | + await request.get('/route-handlers/boop/error').catch(() => {}); |
| 58 | + |
| 59 | + const routehandlerTransaction = await routehandlerTransactionPromise; |
| 60 | + const routehandlerError = await errorEventPromise; |
| 61 | + |
| 62 | + expect(routehandlerTransaction.contexts?.trace?.status).toBe('internal_error'); |
| 63 | + expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); |
| 64 | + expect(routehandlerTransaction.contexts?.trace?.origin).toContain('auto'); |
| 65 | + |
| 66 | + expect(routehandlerError.exception?.values?.[0].value).toBe('Dynamic route handler error'); |
| 67 | + |
| 68 | + expect(routehandlerError.request?.method).toBe('GET'); |
| 69 | + // todo: make sure url is attached to request object |
| 70 | + // expect(routehandlerError.request?.url).toContain('/route-handlers/boop/error'); |
| 71 | + |
| 72 | + expect(routehandlerError.transaction).toBe('/route-handlers/[param]/error'); |
| 73 | +}); |
0 commit comments