1
1
'use strict'
2
2
3
- const t = require ( 'tap' )
4
- const test = t . test
3
+ const { test } = require ( 'node:test' )
5
4
const sget = require ( 'simple-get' ) . concat
6
5
const errors = require ( 'http-errors' )
7
6
const JSONStream = require ( 'JSONStream' )
@@ -10,7 +9,7 @@ const split = require('split2')
10
9
const Fastify = require ( '..' )
11
10
const { kDisableRequestLogging } = require ( '../lib/symbols.js' )
12
11
13
- test ( 'Destroying streams prematurely should call abort method' , t => {
12
+ test ( 'Destroying streams prematurely should call abort method' , ( t , testDone ) => {
14
13
t . plan ( 7 )
15
14
16
15
let fastify = null
@@ -23,21 +22,22 @@ test('Destroying streams prematurely should call abort method', t => {
23
22
}
24
23
} )
25
24
} catch ( e ) {
26
- t . fail ( )
25
+ t . assert . fail ( )
27
26
}
28
27
const stream = require ( 'node:stream' )
29
28
const http = require ( 'node:http' )
30
29
31
30
// Test that "premature close" errors are logged with level warn
32
31
logStream . on ( 'data' , line => {
33
32
if ( line . res ) {
34
- t . equal ( line . msg , 'stream closed prematurely' )
35
- t . equal ( line . level , 30 )
33
+ t . assert . strictEqual ( line . msg , 'stream closed prematurely' )
34
+ t . assert . strictEqual ( line . level , 30 )
35
+ testDone ( )
36
36
}
37
37
} )
38
38
39
39
fastify . get ( '/' , function ( request , reply ) {
40
- t . pass ( 'Received request' )
40
+ t . assert . ok ( 'Received request' )
41
41
42
42
let sent = false
43
43
const reallyLongStream = new stream . Readable ( {
@@ -50,30 +50,30 @@ test('Destroying streams prematurely should call abort method', t => {
50
50
} )
51
51
reallyLongStream . destroy = undefined
52
52
reallyLongStream . close = undefined
53
- reallyLongStream . abort = ( ) => t . ok ( 'called' )
53
+ reallyLongStream . abort = ( ) => t . assert . ok ( 'called' )
54
54
reply . send ( reallyLongStream )
55
55
} )
56
56
57
57
fastify . listen ( { port : 0 } , err => {
58
- t . error ( err )
59
- t . teardown ( ( ) => { fastify . close ( ) } )
58
+ t . assert . ifError ( err )
59
+ t . after ( ( ) => { fastify . close ( ) } )
60
60
61
61
const port = fastify . server . address ( ) . port
62
62
63
63
http . get ( `http://localhost:${ port } ` , function ( response ) {
64
- t . equal ( response . statusCode , 200 )
64
+ t . assert . strictEqual ( response . statusCode , 200 )
65
65
response . on ( 'readable' , function ( ) {
66
66
response . destroy ( )
67
67
} )
68
68
// Node bug? Node never emits 'close' here.
69
69
response . on ( 'aborted' , function ( ) {
70
- t . pass ( 'Response closed' )
70
+ t . assert . ok ( 'Response closed' )
71
71
} )
72
72
} )
73
73
} )
74
74
} )
75
75
76
- test ( 'Destroying streams prematurely, log is disabled' , t => {
76
+ test ( 'Destroying streams prematurely, log is disabled' , ( t , testDone ) => {
77
77
t . plan ( 4 )
78
78
79
79
let fastify = null
@@ -82,7 +82,7 @@ test('Destroying streams prematurely, log is disabled', t => {
82
82
logger : false
83
83
} )
84
84
} catch ( e ) {
85
- t . fail ( )
85
+ t . assert . fail ( )
86
86
}
87
87
const stream = require ( 'node:stream' )
88
88
const http = require ( 'node:http' )
@@ -100,30 +100,33 @@ test('Destroying streams prematurely, log is disabled', t => {
100
100
}
101
101
} )
102
102
reallyLongStream . destroy = true
103
- reallyLongStream . close = ( ) => t . ok ( 'called' )
103
+ reallyLongStream . close = ( ) => {
104
+ t . assert . ok ( 'called' )
105
+ testDone ( )
106
+ }
104
107
reply . send ( reallyLongStream )
105
108
} )
106
109
107
110
fastify . listen ( { port : 0 } , err => {
108
- t . error ( err )
109
- t . teardown ( ( ) => { fastify . close ( ) } )
111
+ t . assert . ifError ( err )
112
+ t . after ( ( ) => { fastify . close ( ) } )
110
113
111
114
const port = fastify . server . address ( ) . port
112
115
113
116
http . get ( `http://localhost:${ port } ` , function ( response ) {
114
- t . equal ( response . statusCode , 200 )
117
+ t . assert . strictEqual ( response . statusCode , 200 )
115
118
response . on ( 'readable' , function ( ) {
116
119
response . destroy ( )
117
120
} )
118
121
// Node bug? Node never emits 'close' here.
119
122
response . on ( 'aborted' , function ( ) {
120
- t . pass ( 'Response closed' )
123
+ t . assert . ok ( 'Response closed' )
121
124
} )
122
125
} )
123
126
} )
124
127
} )
125
128
126
- test ( 'should respond with a stream1' , t => {
129
+ test ( 'should respond with a stream1' , ( t , testDone ) => {
127
130
t . plan ( 5 )
128
131
const fastify = Fastify ( )
129
132
@@ -135,25 +138,26 @@ test('should respond with a stream1', t => {
135
138
} )
136
139
137
140
fastify . listen ( { port : 0 } , err => {
138
- t . error ( err )
139
- t . teardown ( ( ) => { fastify . close ( ) } )
141
+ t . assert . ifError ( err )
142
+ t . after ( ( ) => { fastify . close ( ) } )
140
143
141
144
sget ( `http://localhost:${ fastify . server . address ( ) . port } ` , function ( err , response , body ) {
142
- t . error ( err )
143
- t . equal ( response . headers [ 'content-type' ] , 'application/json' )
144
- t . equal ( response . statusCode , 200 )
145
- t . same ( JSON . parse ( body ) , [ { hello : 'world' } , { a : 42 } ] )
145
+ t . assert . ifError ( err )
146
+ t . assert . strictEqual ( response . headers [ 'content-type' ] , 'application/json' )
147
+ t . assert . strictEqual ( response . statusCode , 200 )
148
+ t . assert . deepStrictEqual ( JSON . parse ( body ) , [ { hello : 'world' } , { a : 42 } ] )
149
+ testDone ( )
146
150
} )
147
151
} )
148
152
} )
149
153
150
- test ( 'return a 404 if the stream emits a 404 error' , t => {
154
+ test ( 'return a 404 if the stream emits a 404 error' , ( t , testDone ) => {
151
155
t . plan ( 5 )
152
156
153
157
const fastify = Fastify ( )
154
158
155
159
fastify . get ( '/' , function ( request , reply ) {
156
- t . pass ( 'Received request' )
160
+ t . assert . ok ( 'Received request' )
157
161
158
162
const reallyLongStream = new Readable ( {
159
163
read : function ( ) {
@@ -167,15 +171,16 @@ test('return a 404 if the stream emits a 404 error', t => {
167
171
} )
168
172
169
173
fastify . listen ( { port : 0 } , err => {
170
- t . error ( err )
171
- t . teardown ( ( ) => { fastify . close ( ) } )
174
+ t . assert . ifError ( err )
175
+ t . after ( ( ) => { fastify . close ( ) } )
172
176
173
177
const port = fastify . server . address ( ) . port
174
178
175
179
sget ( `http://localhost:${ port } ` , function ( err , response ) {
176
- t . error ( err )
177
- t . equal ( response . headers [ 'content-type' ] , 'application/json; charset=utf-8' )
178
- t . equal ( response . statusCode , 404 )
180
+ t . assert . ifError ( err )
181
+ t . assert . strictEqual ( response . headers [ 'content-type' ] , 'application/json; charset=utf-8' )
182
+ t . assert . strictEqual ( response . statusCode , 404 )
183
+ testDone ( )
179
184
} )
180
185
} )
181
186
} )
0 commit comments