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 a5ef5b8 commit 3f7dc52
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { test, expect } from '@playwright/test';
import { waitForTransaction, waitForError } from '../../../test-utils/event-proxy-server';

test('Should create a transaction for middleware', async ({ request }) => {
test.skip(process.env.TEST_ENV === 'development', "Doesn't work in dev mode.");

const middlewareTransactionPromise = waitForTransaction('nextjs-13-app-dir', async transactionEvent => {
return transactionEvent?.transaction === 'middleware' && transactionEvent?.contexts?.trace?.status === 'ok';
});
Expand All @@ -17,13 +19,17 @@ test('Should create a transaction for middleware', async ({ request }) => {
});

test('Should create a transaction with error status for faulty middleware', async ({ request }) => {
test.skip(process.env.TEST_ENV === 'development', "Doesn't work in dev mode.");

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' } });
request.get('/api/endpoint-behind-middleware', { headers: { 'x-should-throw': '1' } }).catch(() => {
// Noop
});

const middlewareTransaction = await middlewareTransactionPromise;

Expand All @@ -33,11 +39,15 @@ test('Should create a transaction with error status for faulty middleware', asyn
});

test('Records exceptions happening in middleware', async ({ request }) => {
test.skip(process.env.TEST_ENV === 'development', "Doesn't work in dev mode.");

const errorEventPromise = waitForError('nextjs-13-app-dir', errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Middleware Error';
});

request.get('/api/endpoint-behind-middleware', { headers: { 'x-should-throw': '1' } });
request.get('/api/endpoint-behind-middleware', { headers: { 'x-should-throw': '1' } }).catch(() => {
// Noop
});

expect(await errorEventPromise).toBeDefined();
});

0 comments on commit 3f7dc52

Please sign in to comment.