@@ -3,7 +3,7 @@ import { waitForTransaction, waitForError } from '../../../test-utils/event-prox
3
3
4
4
test ( 'Should create a transaction for middleware' , async ( { request } ) => {
5
5
const middlewareTransactionPromise = waitForTransaction ( 'nextjs-13-app-dir' , async transactionEvent => {
6
- return transactionEvent ?. transaction === 'middleware' ;
6
+ return transactionEvent ?. transaction === 'middleware' && transactionEvent ?. contexts ?. trace ?. status === 'ok' ;
7
7
} ) ;
8
8
9
9
const response = await request . get ( '/api/endpoint-behind-middleware' ) ;
@@ -16,12 +16,28 @@ test('Should create a transaction for middleware', async ({ request }) => {
16
16
expect ( middlewareTransaction . contexts ?. runtime ?. name ) . toBe ( 'edge' ) ;
17
17
} ) ;
18
18
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
+
19
35
test ( 'Records exceptions happening in middleware' , async ( { request } ) => {
20
36
const errorEventPromise = waitForError ( 'nextjs-13-app-dir' , errorEvent => {
21
37
return errorEvent ?. exception ?. values ?. [ 0 ] ?. value === 'Middleware Error' ;
22
38
} ) ;
23
39
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' } } ) ;
25
41
26
42
expect ( await errorEventPromise ) . toBeDefined ( ) ;
27
43
} ) ;
0 commit comments