11import { expect , test } from '@playwright/test' ;
2- import { waitForError } from '@sentry-internal/test-utils' ;
2+ import { waitForError , waitForTransaction } from '@sentry-internal/test-utils' ;
33
44test ( 'Captures manually reported error in microservice handler' , async ( { baseURL } ) => {
55 const errorEventPromise = waitForError ( 'nestjs-microservices' , event => {
@@ -14,11 +14,9 @@ test('Captures manually reported error in microservice handler', async ({ baseUR
1414 expect ( errorEvent . exception ?. values ?. [ 0 ] ?. value ) . toBe ( 'Manually captured microservice error' ) ;
1515} ) ;
1616
17- // There is no good mechanism to verify that an event was NOT sent to Sentry.
18- // The idea here is that we first send a message that triggers an exception which won't be auto-captured,
19- // and then send a message that triggers a manually captured error which will be sent to Sentry.
20- // If the manually captured error arrives, we can deduce that the first exception was not sent,
21- // because both requests go through the same NestJS app and Sentry client, so events are processed in order.
17+ // To verify that an exception is NOT automatically captured, we trigger it,
18+ // wait for the transaction from that request to confirm it completed, flush,
19+ // and then assert no error event was received.
2220test ( 'Does not automatically capture exceptions thrown in microservice handler' , async ( { baseURL } ) => {
2321 let autoCaptureFired = false ;
2422
@@ -29,14 +27,13 @@ test('Does not automatically capture exceptions thrown in microservice handler',
2927 return false ;
3028 } ) ;
3129
32- const manualCapturePromise = waitForError ( 'nestjs-microservices' , event => {
33- return ! event . type && event . exception ?. values ?. [ 0 ] ?. value === 'Manually captured microservice error ' ;
30+ const transactionPromise = waitForTransaction ( 'nestjs-microservices' , transactionEvent => {
31+ return transactionEvent ?. transaction === 'GET /test- microservice-exception/:id ' ;
3432 } ) ;
3533
3634 await fetch ( `${ baseURL } /test-microservice-exception/123` ) ;
37- await fetch ( `${ baseURL } /test-microservice-manual-capture` ) ;
3835
39- await manualCapturePromise ;
36+ await transactionPromise ;
4037
4138 await fetch ( `${ baseURL } /flush` ) ;
4239
0 commit comments