@@ -3,7 +3,7 @@ import { waitForTransaction, waitForError } from '../../../test-utils/event-prox
33
44test ( 'Should create a transaction for middleware' , async ( { request } ) => {
55 const middlewareTransactionPromise = waitForTransaction ( 'nextjs-13-app-dir' , async transactionEvent => {
6- return transactionEvent ?. transaction === 'middleware' ;
6+ return transactionEvent ?. transaction === 'middleware' && transactionEvent ?. contexts ?. trace ?. status === 'ok' ;
77 } ) ;
88
99 const response = await request . get ( '/api/endpoint-behind-middleware' ) ;
@@ -16,12 +16,28 @@ test('Should create a transaction for middleware', async ({ request }) => {
1616 expect ( middlewareTransaction . contexts ?. runtime ?. name ) . toBe ( 'edge' ) ;
1717} ) ;
1818
19+ test ( 'Should create a transaction with error status for faulty middleware' , async ( { request } ) => {
20+ const middlewareTransactionPromise = waitForTransaction ( 'nextjs-13-app-dir' , async transactionEvent => {
21+ return (
22+ transactionEvent ?. transaction === 'middleware' && transactionEvent ?. contexts ?. trace ?. status === 'internal_error'
23+ ) ;
24+ } ) ;
25+
26+ request . get ( '/api/endpoint-behind-middleware' , { headers : { 'x-should-throw' : '1' } } ) ;
27+
28+ const middlewareTransaction = await middlewareTransactionPromise ;
29+
30+ expect ( middlewareTransaction . contexts ?. trace ?. status ) . toBe ( 'internal_error' ) ;
31+ expect ( middlewareTransaction . contexts ?. trace ?. op ) . toBe ( 'middleware.nextjs' ) ;
32+ expect ( middlewareTransaction . contexts ?. runtime ?. name ) . toBe ( 'edge' ) ;
33+ } ) ;
34+
1935test ( 'Records exceptions happening in middleware' , async ( { request } ) => {
2036 const errorEventPromise = waitForError ( 'nextjs-13-app-dir' , errorEvent => {
2137 return errorEvent ?. exception ?. values ?. [ 0 ] ?. value === 'Middleware Error' ;
2238 } ) ;
2339
24- await request . get ( '/api/endpoint-behind-middleware' , { headers : { 'x-should-throw' : '1' } } ) ;
40+ request . get ( '/api/endpoint-behind-middleware' , { headers : { 'x-should-throw' : '1' } } ) ;
2541
2642 expect ( await errorEventPromise ) . toBeDefined ( ) ;
2743} ) ;
0 commit comments