1
1
'use strict'
2
2
3
- const { test, before } = require ( 'tap ' )
3
+ const { test, before } = require ( 'node:test ' )
4
4
const Fastify = require ( '..' )
5
5
const helper = require ( './helper' )
6
6
@@ -13,69 +13,70 @@ before(async function () {
13
13
14
14
test ( 'listen works without arguments' , async t => {
15
15
const doNotWarn = ( ) => {
16
- t . fail ( 'should not be deprecated' )
16
+ t . assert . fail ( 'should not be deprecated' )
17
17
}
18
18
process . on ( 'warning' , doNotWarn )
19
19
20
20
const fastify = Fastify ( )
21
- t . teardown ( ( ) => {
21
+ t . after ( ( ) => {
22
22
fastify . close ( )
23
23
process . removeListener ( 'warning' , doNotWarn )
24
24
} )
25
25
await fastify . listen ( )
26
26
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 )
29
29
} )
30
30
31
31
test ( 'Async/await listen with arguments' , async t => {
32
32
const doNotWarn = ( ) => {
33
- t . fail ( 'should not be deprecated' )
33
+ t . assert . fail ( 'should not be deprecated' )
34
34
}
35
35
process . on ( 'warning' , doNotWarn )
36
36
37
37
const fastify = Fastify ( )
38
- t . teardown ( ( ) => {
38
+ t . after ( ( ) => {
39
39
fastify . close ( )
40
40
process . removeListener ( 'warning' , doNotWarn )
41
41
} )
42
42
const addr = await fastify . listen ( { port : 0 , host : '0.0.0.0' } )
43
43
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 , {
46
46
address : '0.0.0.0' ,
47
47
family : 'IPv4' ,
48
48
port : address . port
49
49
} )
50
50
} )
51
51
52
- test ( 'listen accepts a callback' , t => {
52
+ test ( 'listen accepts a callback' , ( t , done ) => {
53
53
t . plan ( 2 )
54
54
const doNotWarn = ( ) => {
55
- t . fail ( 'should not be deprecated' )
55
+ t . assert . fail ( 'should not be deprecated' )
56
56
}
57
57
process . on ( 'warning' , doNotWarn )
58
58
59
59
const fastify = Fastify ( )
60
- t . teardown ( ( ) => {
60
+ t . after ( ( ) => {
61
61
fastify . close ( )
62
62
process . removeListener ( 'warning' , doNotWarn )
63
63
} )
64
64
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 ( )
67
68
} )
68
69
} )
69
70
70
- test ( 'listen accepts options and a callback' , t => {
71
+ test ( 'listen accepts options and a callback' , ( t , done ) => {
71
72
t . plan ( 1 )
72
73
const doNotWarn = ( ) => {
73
- t . fail ( 'should not be deprecated' )
74
+ t . assert . fail ( 'should not be deprecated' )
74
75
}
75
76
process . on ( 'warning' , doNotWarn )
76
77
77
78
const fastify = Fastify ( )
78
- t . teardown ( ( ) => {
79
+ t . after ( ( ) => {
79
80
fastify . close ( )
80
81
process . removeListener ( 'warning' , doNotWarn )
81
82
} )
@@ -88,40 +89,42 @@ test('listen accepts options and a callback', t => {
88
89
writableAll : false ,
89
90
ipv6Only : false
90
91
} , ( err ) => {
91
- t . error ( err )
92
+ t . assert . ifError ( err )
93
+ done ( )
92
94
} )
93
95
} )
94
96
95
- test ( 'listen after Promise.resolve()' , t => {
97
+ test ( 'listen after Promise.resolve()' , ( t , done ) => {
96
98
t . plan ( 2 )
97
- const f = Fastify ( )
98
- t . teardown ( f . close . bind ( f ) )
99
+ const fastify = Fastify ( )
100
+ t . after ( ( ) => fastify . close ( ) )
99
101
Promise . resolve ( )
100
102
. 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 ( )
105
108
} )
106
109
} )
107
110
} )
108
111
109
112
test ( 'listen works with undefined host' , async t => {
110
113
const doNotWarn = ( ) => {
111
- t . fail ( 'should not be deprecated' )
114
+ t . assert . fail ( 'should not be deprecated' )
112
115
}
113
116
process . on ( 'warning' , doNotWarn )
114
117
115
118
const fastify = Fastify ( )
116
- t . teardown ( fastify . close . bind ( fastify ) )
117
- t . teardown ( ( ) => {
119
+ t . after ( ( ) => fastify . close ( ) )
120
+ t . after ( ( ) => {
118
121
fastify . close ( )
119
122
process . removeListener ( 'warning' , doNotWarn )
120
123
} )
121
124
await fastify . listen ( { host : undefined , port : 0 } )
122
125
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 )
125
128
} )
126
129
127
130
test ( 'listen works with null host' , async t => {
@@ -131,13 +134,13 @@ test('listen works with null host', async t => {
131
134
process . on ( 'warning' , doNotWarn )
132
135
133
136
const fastify = Fastify ( )
134
- t . teardown ( fastify . close . bind ( fastify ) )
135
- t . teardown ( ( ) => {
137
+ t . after ( ( ) => fastify . close ( ) )
138
+ t . after ( ( ) => {
136
139
fastify . close ( )
137
140
process . removeListener ( 'warning' , doNotWarn )
138
141
} )
139
142
await fastify . listen ( { host : null , port : 0 } )
140
143
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 )
143
146
} )
0 commit comments