2
2
3
3
import fastify , { type FastifyError , type FastifyInstance , type FastifyPluginOptions } from 'fastify'
4
4
import { INTERNAL_SERVER_ERROR } from 'http-errors-enhanced'
5
- import t from 'tap'
5
+ import { deepStrictEqual , match } from 'node:assert'
6
+ import { test } from 'node:test'
6
7
import { plugin as fastifyHttpErrorsEnhanced } from '../src/index.js'
7
8
8
9
async function buildServer ( options : FastifyPluginOptions = { } ) : Promise < FastifyInstance > {
@@ -31,7 +32,7 @@ async function buildServer(options: FastifyPluginOptions = {}): Promise<FastifyI
31
32
return server
32
33
}
33
34
34
- t . test ( 'should correctly allow preprocessing of error before executing the handler' , async t => {
35
+ test ( 'should correctly allow preprocessing of error before executing the handler' , async t => {
35
36
const server = await buildServer ( {
36
37
preHandler ( error : FastifyError | Error ) {
37
38
Object . defineProperty ( error , 'preHandlerExecuted' , { enumerable : true , value : true } )
@@ -41,14 +42,14 @@ t.test('should correctly allow preprocessing of error before executing the handl
41
42
42
43
const response = await server . inject ( { method : 'GET' , url : '/error' } )
43
44
44
- t . equal ( response . statusCode , INTERNAL_SERVER_ERROR )
45
- t . equal ( response . headers [ 'x-custom-header' ] , 'Custom-Value' )
45
+ deepStrictEqual ( response . statusCode , INTERNAL_SERVER_ERROR )
46
+ deepStrictEqual ( response . headers [ 'x-custom-header' ] , 'Custom-Value' )
46
47
47
48
const payload = JSON . parse ( response . payload )
48
- t . match ( payload . stack [ 0 ] , / ^ O b j e c t \. h a n d l e r \( (?: f i l e : \/ \/ ) ? \$ R O O T \/ t e s t \/ h o o k s \. t e s t \. t s : \d + : \d + \) $ / )
49
+ match ( payload . stack [ 0 ] as string , / ^ O b j e c t \. h a n d l e r \( (?: f i l e : \/ \/ ) ? \$ R O O T \/ t e s t \/ h o o k s \. t e s t \. t s : \d + : \d + \) $ / )
49
50
delete payload . stack
50
51
51
- t . same ( payload , {
52
+ deepStrictEqual ( payload , {
52
53
error : 'Internal Server Error' ,
53
54
message : '[Error] This was a generic message.' ,
54
55
statusCode : INTERNAL_SERVER_ERROR ,
0 commit comments