@@ -56,7 +56,7 @@ test('check if createError creates an Error with the right BaseConstructor, whic
5656} )
5757
5858test ( 'instanceof' , async ( t ) => {
59- const assertsPlanned = 2
59+ const assertsPlanned = 5
6060 t . plan ( assertsPlanned )
6161
6262 const testCwd = path . resolve ( os . tmpdir ( ) )
@@ -88,9 +88,10 @@ test('instanceof', async (t) => {
8888 const { createError } = require('fastify-error')
8989
9090 const Boom = createError('Boom', 'Boom', 500)
91+ const ChildBoom = createError('ChildBoom', 'Boom', 500, Boom)
9192
9293 module.exports.foo = function foo () {
93- throw new Boom ('foo go Boom')
94+ throw new ChildBoom ('foo go Boom')
9495 }
9596 ` )
9697
@@ -112,12 +113,17 @@ test('instanceof', async (t) => {
112113 const { foo } = require('main')
113114
114115 const Boom = createError('Boom', 'Boom', 500)
116+ const ChildBoom = createError('ChildBoom', 'Boom', 500, Boom)
117+ const NotChildBoom = createError('NotChildBoom', 'NotChildBoom', 500, Boom)
115118
116119 try {
117120 foo()
118121 } catch (err) {
122+ process.send(err instanceof Error)
119123 process.send(err instanceof FastifyError)
124+ process.send(err instanceof NotChildBoom)
120125 process.send(err instanceof Boom)
126+ process.send(err instanceof ChildBoom)
121127 }
122128 ` )
123129
@@ -134,7 +140,7 @@ test('instanceof', async (t) => {
134140
135141 const child = cp . fork ( path . resolve ( testCwd , 'index.js' ) , {
136142 cwd : testCwd ,
137- stdio : 'pipe ' ,
143+ stdio : 'inherit ' ,
138144 env : {
139145 ...process . env ,
140146 NODE_OPTIONS : '--no-warnings'
@@ -146,10 +152,19 @@ test('instanceof', async (t) => {
146152 try {
147153 switch ( messageCount ) {
148154 case 0 :
149- t . assert . strictEqual ( message , true , 'instanceof FastifyError ' )
155+ t . assert . strictEqual ( message , true , 'instanceof Error ' )
150156 break
151157 case 1 :
152- t . assert . strictEqual ( message , false , 'instanceof Boom' )
158+ t . assert . strictEqual ( message , true , 'instanceof FastifyError' )
159+ break
160+ case 2 :
161+ t . assert . strictEqual ( message , false , 'instanceof NotChildBoom' )
162+ break
163+ case 3 :
164+ t . assert . strictEqual ( message , true , 'instanceof Boom' )
165+ break
166+ case 4 :
167+ t . assert . strictEqual ( message , true , 'instanceof ChildBoom' )
153168 break
154169 }
155170 if ( ++ messageCount === assertsPlanned ) {
0 commit comments