11'use strict'
22
3- const { test, before } = require ( 'tap ' )
3+ const { test, before } = require ( 'node:test ' )
44const Fastify = require ( '..' )
55const helper = require ( './helper' )
66
@@ -13,69 +13,70 @@ before(async function () {
1313
1414test ( 'listen works without arguments' , async t => {
1515 const doNotWarn = ( ) => {
16- t . fail ( 'should not be deprecated' )
16+ t . assert . fail ( 'should not be deprecated' )
1717 }
1818 process . on ( 'warning' , doNotWarn )
1919
2020 const fastify = Fastify ( )
21- t . teardown ( ( ) => {
21+ t . after ( ( ) => {
2222 fastify . close ( )
2323 process . removeListener ( 'warning' , doNotWarn )
2424 } )
2525 await fastify . listen ( )
2626 const address = fastify . server . address ( )
27- t . equal ( address . address , localhost )
28- t . ok ( address . port > 0 )
27+ t . assert . strictEqual ( address . address , localhost )
28+ t . assert . ok ( address . port > 0 )
2929} )
3030
3131test ( 'Async/await listen with arguments' , async t => {
3232 const doNotWarn = ( ) => {
33- t . fail ( 'should not be deprecated' )
33+ t . assert . fail ( 'should not be deprecated' )
3434 }
3535 process . on ( 'warning' , doNotWarn )
3636
3737 const fastify = Fastify ( )
38- t . teardown ( ( ) => {
38+ t . after ( ( ) => {
3939 fastify . close ( )
4040 process . removeListener ( 'warning' , doNotWarn )
4141 } )
4242 const addr = await fastify . listen ( { port : 0 , host : '0.0.0.0' } )
4343 const address = fastify . server . address ( )
44- t . equal ( addr , `http://127.0.0.1:${ address . port } ` )
45- t . same ( address , {
44+ t . assert . strictEqual ( addr , `http://127.0.0.1:${ address . port } ` )
45+ t . assert . deepEqual ( address , {
4646 address : '0.0.0.0' ,
4747 family : 'IPv4' ,
4848 port : address . port
4949 } )
5050} )
5151
52- test ( 'listen accepts a callback' , t => {
52+ test ( 'listen accepts a callback' , ( t , done ) => {
5353 t . plan ( 2 )
5454 const doNotWarn = ( ) => {
55- t . fail ( 'should not be deprecated' )
55+ t . assert . fail ( 'should not be deprecated' )
5656 }
5757 process . on ( 'warning' , doNotWarn )
5858
5959 const fastify = Fastify ( )
60- t . teardown ( ( ) => {
60+ t . after ( ( ) => {
6161 fastify . close ( )
6262 process . removeListener ( 'warning' , doNotWarn )
6363 } )
6464 fastify . listen ( { port : 0 } , ( err ) => {
65- t . equal ( fastify . server . address ( ) . address , localhost )
66- t . error ( err )
65+ t . assert . ifError ( err )
66+ t . assert . strictEqual ( fastify . server . address ( ) . address , localhost )
67+ done ( )
6768 } )
6869} )
6970
70- test ( 'listen accepts options and a callback' , t => {
71+ test ( 'listen accepts options and a callback' , ( t , done ) => {
7172 t . plan ( 1 )
7273 const doNotWarn = ( ) => {
73- t . fail ( 'should not be deprecated' )
74+ t . assert . fail ( 'should not be deprecated' )
7475 }
7576 process . on ( 'warning' , doNotWarn )
7677
7778 const fastify = Fastify ( )
78- t . teardown ( ( ) => {
79+ t . after ( ( ) => {
7980 fastify . close ( )
8081 process . removeListener ( 'warning' , doNotWarn )
8182 } )
@@ -88,40 +89,42 @@ test('listen accepts options and a callback', t => {
8889 writableAll : false ,
8990 ipv6Only : false
9091 } , ( err ) => {
91- t . error ( err )
92+ t . assert . ifError ( err )
93+ done ( )
9294 } )
9395} )
9496
95- test ( 'listen after Promise.resolve()' , t => {
97+ test ( 'listen after Promise.resolve()' , ( t , done ) => {
9698 t . plan ( 2 )
97- const f = Fastify ( )
98- t . teardown ( f . close . bind ( f ) )
99+ const fastify = Fastify ( )
100+ t . after ( ( ) => fastify . close ( ) )
99101 Promise . resolve ( )
100102 . then ( ( ) => {
101- f . listen ( { port : 0 } , ( err , address ) => {
102- f . server . unref ( )
103- t . equal ( address , `http://${ localhostForURL } :${ f . server . address ( ) . port } ` )
104- t . error ( err )
103+ fastify . listen ( { port : 0 } , ( err , address ) => {
104+ fastify . server . unref ( )
105+ t . assert . strictEqual ( address , `http://${ localhostForURL } :${ fastify . server . address ( ) . port } ` )
106+ t . assert . ifError ( err )
107+ done ( )
105108 } )
106109 } )
107110} )
108111
109112test ( 'listen works with undefined host' , async t => {
110113 const doNotWarn = ( ) => {
111- t . fail ( 'should not be deprecated' )
114+ t . assert . fail ( 'should not be deprecated' )
112115 }
113116 process . on ( 'warning' , doNotWarn )
114117
115118 const fastify = Fastify ( )
116- t . teardown ( fastify . close . bind ( fastify ) )
117- t . teardown ( ( ) => {
119+ t . after ( ( ) => fastify . close ( ) )
120+ t . after ( ( ) => {
118121 fastify . close ( )
119122 process . removeListener ( 'warning' , doNotWarn )
120123 } )
121124 await fastify . listen ( { host : undefined , port : 0 } )
122125 const address = fastify . server . address ( )
123- t . equal ( address . address , localhost )
124- t . ok ( address . port > 0 )
126+ t . assert . strictEqual ( address . address , localhost )
127+ t . assert . ok ( address . port > 0 )
125128} )
126129
127130test ( 'listen works with null host' , async t => {
@@ -131,13 +134,13 @@ test('listen works with null host', async t => {
131134 process . on ( 'warning' , doNotWarn )
132135
133136 const fastify = Fastify ( )
134- t . teardown ( fastify . close . bind ( fastify ) )
135- t . teardown ( ( ) => {
137+ t . after ( ( ) => fastify . close ( ) )
138+ t . after ( ( ) => {
136139 fastify . close ( )
137140 process . removeListener ( 'warning' , doNotWarn )
138141 } )
139142 await fastify . listen ( { host : null , port : 0 } )
140143 const address = fastify . server . address ( )
141- t . equal ( address . address , localhost )
142- t . ok ( address . port > 0 )
144+ t . assert . strictEqual ( address . address , localhost )
145+ t . assert . ok ( address . port > 0 )
143146} )
0 commit comments