Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Jun 19, 2023
1 parent cd705b7 commit a5ef5b8
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();
});

0 comments on commit a5ef5b8

Please sign in to comment.