@@ -11,7 +11,7 @@ import {
1111 UNSUPPORTED_MEDIA_TYPE
1212} from 'http-errors-enhanced'
1313import t from 'tap'
14- import { handleErrors , plugin as fastifyErrorProperties } from '../src'
14+ import { handleErrors , plugin as fastifyHttpErrorsEnhanced } from '../src'
1515
1616type Test = typeof t
1717type Callback = ( ) => void
@@ -144,11 +144,6 @@ function routes(instance: FastifyInstance, _options: unknown, done: Callback): v
144144}
145145
146146async function buildServer ( options : FastifyPluginOptions = { } ) : Promise < FastifyInstance > {
147- if ( server ) {
148- await server . close ( )
149- server = null
150- }
151-
152147 server = fastify ( {
153148 ajv : {
154149 customOptions : {
@@ -161,19 +156,13 @@ async function buildServer(options: FastifyPluginOptions = {}): Promise<FastifyI
161156 }
162157 } )
163158
164- server . register ( fastifyErrorProperties , options )
159+ server . register ( fastifyHttpErrorsEnhanced , options )
165160 server . register ( routes )
166- await server . listen ( 0 )
167161
168162 return server
169163}
170164
171165async function buildStandaloneServer ( ) : Promise < FastifyInstance > {
172- if ( standaloneServer ) {
173- await standaloneServer . close ( )
174- standaloneServer = null
175- }
176-
177166 standaloneServer = fastify ( )
178167
179168 standaloneServer . setErrorHandler ( handleErrors )
@@ -203,17 +192,11 @@ async function buildStandaloneServer(): Promise<FastifyInstance> {
203192 }
204193 } )
205194
206- await standaloneServer . listen ( 0 )
207-
208195 return standaloneServer
209196}
210197
211198t . test ( 'Plugin' , ( t : Test ) => {
212199 t . test ( 'Handling http-errors' , ( t : Test ) => {
213- t . afterEach ( async ( ) => {
214- await server ! . close ( )
215- } )
216-
217200 t . test ( 'should correctly return client errors' , async ( t : Test ) => {
218201 await buildServer ( )
219202
@@ -327,10 +310,6 @@ t.test('Plugin', (t: Test) => {
327310 } )
328311
329312 t . test ( 'Handling generic errors' , ( t : Test ) => {
330- t . afterEach ( async ( ) => {
331- await server ! . close ( )
332- } )
333-
334313 t . test (
335314 'should correctly return generic errors by wrapping them in a 500 http-error, including headers and properties' ,
336315 async ( t : Test ) => {
@@ -446,10 +425,6 @@ t.test('Plugin', (t: Test) => {
446425 } )
447426
448427 t . test ( 'Handling validation errors' , ( t : Test ) => {
449- t . afterEach ( async ( ) => {
450- await server ! . close ( )
451- } )
452-
453428 t . test ( 'should validate params' , async ( t : Test ) => {
454429 await buildServer ( )
455430
@@ -555,11 +530,7 @@ t.test('Plugin', (t: Test) => {
555530 } )
556531
557532 t . test ( 'Using standalone error handling' , ( t : Test ) => {
558- t . afterEach ( async ( ) => {
559- await standaloneServer ! . close ( )
560- } )
561-
562- t . test ( 'should not return the errorProperties by never masking server side errors' , async ( t : Test ) => {
533+ t . test ( "should not return the error's properties by masking server side errors" , async ( t : Test ) => {
563534 await buildStandaloneServer ( )
564535
565536 const response = await standaloneServer ! . inject ( { method : 'GET' , url : '/error/123' } )
0 commit comments