File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
packages/e2e-tests/test-applications/nextjs-app-dir Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { NextResponse } from 'next/server' ;
2
+ import type { NextRequest } from 'next/server' ;
3
+
4
+ export function middleware ( ) {
5
+ return NextResponse . next ( ) ;
6
+ }
7
+
8
+ // See "Matching Paths" below to learn more
9
+ export const config = {
10
+ matcher : [ '/api/endpoint-behind-middleware' ] ,
11
+ } ;
Original file line number Diff line number Diff line change
1
+ import type { NextApiRequest , NextApiResponse } from 'next' ;
2
+
3
+ type Data = {
4
+ name : string ;
5
+ } ;
6
+
7
+ export default function handler ( req : NextApiRequest , res : NextApiResponse < Data > ) {
8
+ res . status ( 200 ) . json ( { name : 'John Doe' } ) ;
9
+ }
Original file line number Diff line number Diff line change @@ -112,3 +112,18 @@ if (process.env.TEST_ENV === 'production') {
112
112
expect ( ( await serverComponentTransactionPromise ) . contexts ?. trace ?. status ) . toBe ( 'not_found' ) ;
113
113
} ) ;
114
114
}
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