@@ -35,34 +35,51 @@ test('Sends correct error event', async ({ baseURL }) => {
3535} ) ;
3636
3737test ( 'Does not send error when shouldHandleError returns false' , async ( { baseURL } ) => {
38- const errorEventPromise = waitForError ( 'node-fastify-5' , event => {
39- return ! event . type && event . exception ?. values ?. [ 0 ] ?. value === 'This is an error that will not be captured' ;
38+ let errorEventOccurred = false ;
39+
40+ waitForError ( 'node-fastify-5' , event => {
41+ if ( ! event . type && event . exception ?. values ?. [ 0 ] ?. value === 'This is an error that will not be captured' ) {
42+ errorEventOccurred = true ;
43+ }
44+ return event ?. transaction === 'GET /test-error-not-captured' ;
4045 } ) ;
4146
42- errorEventPromise . then ( ( ) => {
43- throw new Error ( 'This error should not be captured') ;
47+ const transactionEventPromise = waitForTransaction ( 'node-fastify-5' , transactionEvent => {
48+ return transactionEvent ?. transaction === 'GET /test- error- not- captured';
4449 } ) ;
4550
4651 await fetch ( `${ baseURL } /test-error-not-captured` ) ;
4752
48- // wait for a short time to ensure the error is not captured
49- await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
53+ await transactionEventPromise ;
54+
55+ await fetch ( `${ baseURL } /flush` ) ;
56+
57+ expect ( errorEventOccurred ) . toBe ( false ) ;
5058} ) ;
5159
5260// Regression test for https://github.com/fastify/fastify/issues/6409
5361// The error diagnostic channel was always sending 200 unless explicitly changed.
5462// This was fixed in Fastify 5.7.0
5563test ( 'Error in child plugin with rethrown error handler reports correct 500 status' , async ( { baseURL } ) => {
56- const errorEventPromise = waitForError ( 'node-fastify-5' , event => {
57- return ! event . type && event . exception ?. values ?. [ 0 ] ?. value === 'This is an error that will not be captured' ;
64+ let errorEventOccurred = false ;
65+
66+ waitForError ( 'node-fastify-5' , event => {
67+ if ( ! event . type && event . exception ?. values ?. [ 0 ] ?. value === 'This is an error that will not be captured' ) {
68+ errorEventOccurred = true ;
69+ }
70+ return event ?. transaction === 'GET /test-error-ignored' ;
5871 } ) ;
5972
60- errorEventPromise . then ( ( ) => {
61- throw new Error ( 'This error should not be captured' ) ;
73+ const transactionEventPromise = waitForTransaction ( 'node-fastify-5' , transactionEvent => {
74+ return transactionEvent ?. transaction === 'GET /test- error-ignored' ;
6275 } ) ;
6376
77+
6478 await fetch ( `${ baseURL } /test-error-ignored` ) ;
6579
66- // wait for a short time to ensure the error is not captured
67- await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
80+ await transactionEventPromise ;
81+
82+ await fetch ( `${ baseURL } /flush` ) ;
83+
84+ expect ( errorEventOccurred ) . toBe ( false ) ;
6885} ) ;
0 commit comments