diff --git a/packages/e2e-tests/test-applications/nextjs-app-dir/tests/middleware.test.ts b/packages/e2e-tests/test-applications/nextjs-app-dir/tests/middleware.test.ts index 019b25af9893..2cf7d066625b 100644 --- a/packages/e2e-tests/test-applications/nextjs-app-dir/tests/middleware.test.ts +++ b/packages/e2e-tests/test-applications/nextjs-app-dir/tests/middleware.test.ts @@ -3,7 +3,7 @@ import { waitForTransaction, waitForError } from '../../../test-utils/event-prox test('Should create a transaction for middleware', async ({ request }) => { const middlewareTransactionPromise = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { - return transactionEvent?.transaction === 'middleware'; + return transactionEvent?.transaction === 'middleware' && transactionEvent?.contexts?.trace?.status === 'ok'; }); const response = await request.get('/api/endpoint-behind-middleware'); @@ -16,12 +16,28 @@ test('Should create a transaction for middleware', async ({ request }) => { expect(middlewareTransaction.contexts?.runtime?.name).toBe('edge'); }); +test('Should create a transaction with error status for faulty middleware', async ({ request }) => { + const middlewareTransactionPromise = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { + return ( + transactionEvent?.transaction === 'middleware' && transactionEvent?.contexts?.trace?.status === 'internal_error' + ); + }); + + request.get('/api/endpoint-behind-middleware', { headers: { 'x-should-throw': '1' } }); + + const middlewareTransaction = await middlewareTransactionPromise; + + expect(middlewareTransaction.contexts?.trace?.status).toBe('internal_error'); + expect(middlewareTransaction.contexts?.trace?.op).toBe('middleware.nextjs'); + expect(middlewareTransaction.contexts?.runtime?.name).toBe('edge'); +}); + test('Records exceptions happening in middleware', async ({ request }) => { const errorEventPromise = waitForError('nextjs-13-app-dir', errorEvent => { return errorEvent?.exception?.values?.[0]?.value === 'Middleware Error'; }); - await request.get('/api/endpoint-behind-middleware', { headers: { 'x-should-throw': '1' } }); + request.get('/api/endpoint-behind-middleware', { headers: { 'x-should-throw': '1' } }); expect(await errorEventPromise).toBeDefined(); });