File tree Expand file tree Collapse file tree 3 files changed +32
-16
lines changed
packages/e2e-tests/test-applications/nextjs-app-dir Expand file tree Collapse file tree 3 files changed +32
-16
lines changed Original file line number Diff line number Diff line change 11import { NextResponse } from 'next/server' ;
22import type { NextRequest } from 'next/server' ;
33
4- export function middleware ( ) {
4+ export function middleware ( request : NextRequest ) {
5+ if ( request . headers . has ( 'x-should-throw' ) ) {
6+ throw new Error ( 'Middleware Error' ) ;
7+ }
8+
59 return NextResponse . next ( ) ;
610}
711
Original file line number Diff line number Diff line change 1+ import { test , expect } from '@playwright/test' ;
2+ import { waitForTransaction , waitForError } from '../../../test-utils/event-proxy-server' ;
3+
4+ test ( 'Should create a transaction for middleware' , async ( { request } ) => {
5+ const middlewareTransactionPromise = waitForTransaction ( 'nextjs-13-app-dir' , async transactionEvent => {
6+ return transactionEvent ?. transaction === 'middleware' ;
7+ } ) ;
8+
9+ const response = await request . get ( '/api/endpoint-behind-middleware' ) ;
10+ expect ( await response . json ( ) ) . toStrictEqual ( { name : 'John Doe' } ) ;
11+
12+ const middlewareTransaction = await middlewareTransactionPromise ;
13+
14+ expect ( middlewareTransaction . contexts ?. trace ?. status ) . toBe ( 'ok' ) ;
15+ expect ( middlewareTransaction . contexts ?. trace ?. op ) . toBe ( 'middleware.nextjs' ) ;
16+ expect ( middlewareTransaction . contexts ?. runtime ?. name ) . toBe ( 'edge' ) ;
17+ } ) ;
18+
19+ test ( 'Records exceptions happening in middleware' , async ( { request } ) => {
20+ const errorEventPromise = waitForError ( 'nextjs-13-app-dir' , errorEvent => {
21+ return errorEvent ?. exception ?. values ?. [ 0 ] ?. value === 'Middleware Error' ;
22+ } ) ;
23+
24+ await request . get ( '/api/endpoint-behind-middleware' , { headers : { 'x-should-throw' : '1' } } ) ;
25+
26+ expect ( await errorEventPromise ) . toBeDefined ( ) ;
27+ } ) ;
Original file line number Diff line number Diff line change @@ -112,18 +112,3 @@ if (process.env.TEST_ENV === 'production') {
112112 expect ( ( await serverComponentTransactionPromise ) . contexts ?. trace ?. status ) . toBe ( 'not_found' ) ;
113113 } ) ;
114114}
115-
116- test ( 'Should create a transaction for middleware' , async ( { request } ) => {
117- const middlewareTransactionPromise = waitForTransaction ( 'nextjs-13-app-dir' , async transactionEvent => {
118- return transactionEvent ?. transaction === 'middleware' ;
119- } ) ;
120-
121- const response = await request . get ( '/api/endpoint-behind-middleware' ) ;
122- expect ( await response . json ( ) ) . toStrictEqual ( { name : 'John Doe' } ) ;
123-
124- const middlewareTransaction = await middlewareTransactionPromise ;
125-
126- expect ( middlewareTransaction . contexts ?. trace ?. status ) . toBe ( 'ok' ) ;
127- expect ( middlewareTransaction . contexts ?. trace ?. op ) . toBe ( 'middleware.nextjs' ) ;
128- expect ( middlewareTransaction . contexts ?. runtime ?. name ) . toBe ( 'edge' ) ;
129- } ) ;
You can’t perform that action at this time.
0 commit comments