fastify 5.3.2 → 5.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/.vscode/settings.json +22 -0
  2. package/docs/Guides/Ecosystem.md +7 -2
  3. package/docs/Guides/Serverless.md +28 -69
  4. package/docs/Reference/Errors.md +0 -2
  5. package/docs/Reference/Server.md +17 -1
  6. package/eslint.config.js +17 -9
  7. package/fastify.js +6 -2
  8. package/lib/decorate.js +2 -2
  9. package/lib/errors.js +0 -8
  10. package/lib/logger-factory.js +1 -1
  11. package/lib/logger-pino.js +2 -2
  12. package/lib/reply.js +2 -2
  13. package/lib/request.js +1 -1
  14. package/lib/server.js +30 -51
  15. package/package.json +4 -4
  16. package/test/close-pipelining.test.js +5 -4
  17. package/test/decorator.test.js +422 -341
  18. package/test/helper.js +107 -69
  19. package/test/hooks.on-listen.test.js +255 -239
  20. package/test/hooks.on-ready.test.js +110 -92
  21. package/test/inject.test.js +114 -97
  22. package/test/input-validation.js +63 -53
  23. package/test/internals/errors.test.js +1 -11
  24. package/test/internals/hooks.test.js +17 -0
  25. package/test/issue-4959.test.js +2 -2
  26. package/test/logger/response.test.js +19 -20
  27. package/test/options.error-handler.test.js +1 -1
  28. package/test/options.test.js +1 -1
  29. package/test/output-validation.test.js +49 -70
  30. package/test/patch.error-handler.test.js +1 -1
  31. package/test/patch.test.js +1 -1
  32. package/test/plugin.1.test.js +71 -60
  33. package/test/promises.test.js +36 -30
  34. package/test/put.error-handler.test.js +1 -1
  35. package/test/put.test.js +1 -1
  36. package/test/reply-error.test.js +169 -148
  37. package/test/reply-trailers.test.js +119 -108
  38. package/test/schema-feature.test.js +309 -238
  39. package/test/schema-validation.test.js +44 -2
  40. package/test/stream.1.test.js +30 -27
  41. package/test/stream.2.test.js +20 -10
  42. package/test/stream.3.test.js +37 -31
  43. package/test/types/errors.test-d.ts +0 -1
  44. package/test/types/plugin.test-d.ts +1 -1
  45. package/test/types/register.test-d.ts +1 -1
  46. package/test/use-semicolon-delimiter.test.js +1 -1
  47. package/types/errors.d.ts +0 -1
  48. package/test/http2/missing-http2-module.test.js +0 -17
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { test, before } = require('tap')
3
+ const { test, before } = require('node:test')
4
4
  const Fastify = require('../fastify')
5
5
  const fp = require('fastify-plugin')
6
6
  const split = require('split2')
@@ -15,60 +15,63 @@ before(async function () {
15
15
  [localhost] = await helper.getLoopbackHost()
16
16
  })
17
17
 
18
- test('onListen should not be processed when .ready() is called', t => {
18
+ test('onListen should not be processed when .ready() is called', (t, testDone) => {
19
19
  t.plan(1)
20
20
  const fastify = Fastify()
21
- t.teardown(fastify.close.bind(fastify))
21
+ t.after(() => fastify.close())
22
22
 
23
23
  fastify.addHook('onListen', function (done) {
24
- t.fail()
24
+ t.assert.fail()
25
25
  done()
26
26
  })
27
27
 
28
- fastify.ready(err => t.error(err))
28
+ fastify.ready(err => {
29
+ t.assert.ifError(err)
30
+ testDone()
31
+ })
29
32
  })
30
33
 
31
- test('localhost onListen should be called in order', t => {
34
+ test('localhost onListen should be called in order', (t, testDone) => {
32
35
  t.plan(2)
33
36
  const fastify = Fastify()
34
- t.teardown(fastify.close.bind(fastify))
37
+ t.after(() => fastify.close())
35
38
  let order = 0
36
39
 
37
40
  fastify.addHook('onListen', function (done) {
38
- t.equal(++order, 1, '1st called in root')
41
+ t.assert.strictEqual(++order, 1, '1st called in root')
39
42
  done()
40
43
  })
41
44
 
42
45
  fastify.addHook('onListen', function (done) {
43
- t.equal(++order, 2, '2nd called in root')
46
+ t.assert.strictEqual(++order, 2, '2nd called in root')
44
47
  done()
45
48
  })
46
49
 
47
50
  fastify.listen({
48
51
  host: 'localhost',
49
52
  port: 0
50
- })
53
+ }, testDone)
51
54
  })
52
55
 
53
56
  test('localhost async onListen should be called in order', async t => {
54
57
  t.plan(3)
55
58
  const fastify = Fastify()
56
- t.teardown(fastify.close.bind(fastify))
59
+ t.after(() => fastify.close())
57
60
  let order = 0
58
61
 
59
62
  fastify.addHook('onListen', async function () {
60
- t.equal(++order, 1, '1st async called in root')
63
+ t.assert.strictEqual(++order, 1, '1st async called in root')
61
64
  })
62
65
 
63
66
  fastify.addHook('onListen', async function () {
64
- t.equal(++order, 2, '2nd async called in root')
67
+ t.assert.strictEqual(++order, 2, '2nd async called in root')
65
68
  })
66
69
 
67
70
  await fastify.listen({
68
71
  host: 'localhost',
69
72
  port: 0
70
73
  })
71
- t.equal(order, 2, 'the onListen hooks are awaited')
74
+ t.assert.strictEqual(order, 2, 'the onListen hooks are awaited')
72
75
  })
73
76
 
74
77
  test('localhost onListen sync should log errors as warnings and continue /1', async t => {
@@ -82,30 +85,30 @@ test('localhost onListen sync should log errors as warnings and continue /1', as
82
85
  level: 'info'
83
86
  }
84
87
  })
85
- t.teardown(fastify.close.bind(fastify))
88
+ t.after(() => fastify.close())
86
89
 
87
90
  stream.on('data', message => {
88
91
  if (message.msg.includes('FAIL ON LISTEN')) {
89
- t.equal(order, 2)
90
- t.pass('Logged Error Message')
92
+ t.assert.strictEqual(order, 2)
93
+ t.assert.ok('Logged Error Message')
91
94
  }
92
95
  })
93
96
 
94
97
  fastify.addHook('onListen', function (done) {
95
- t.equal(++order, 1, '1st call')
96
- t.pass('called in root')
98
+ t.assert.strictEqual(++order, 1, '1st call')
99
+ t.assert.ok('called in root')
97
100
  done()
98
101
  })
99
102
 
100
103
  fastify.addHook('onListen', function (done) {
101
- t.equal(++order, 2, '2nd call')
102
- t.pass('called onListen error')
104
+ t.assert.strictEqual(++order, 2, '2nd call')
105
+ t.assert.ok('called onListen error')
103
106
  throw new Error('FAIL ON LISTEN')
104
107
  })
105
108
 
106
109
  fastify.addHook('onListen', function (done) {
107
- t.equal(++order, 3, '3rd call')
108
- t.pass('onListen hooks continue after error')
110
+ t.assert.strictEqual(++order, 3, '3rd call')
111
+ t.assert.ok('onListen hooks continue after error')
109
112
  done()
110
113
  })
111
114
 
@@ -115,7 +118,7 @@ test('localhost onListen sync should log errors as warnings and continue /1', as
115
118
  })
116
119
  })
117
120
 
118
- test('localhost onListen sync should log errors as warnings and continue /2', t => {
121
+ test('localhost onListen sync should log errors as warnings and continue /2', (t, testDone) => {
119
122
  t.plan(7)
120
123
  const stream = split(JSON.parse)
121
124
  const fastify = Fastify({
@@ -125,38 +128,38 @@ test('localhost onListen sync should log errors as warnings and continue /2', t
125
128
  level: 'info'
126
129
  }
127
130
  })
128
- t.teardown(fastify.close.bind(fastify))
131
+ t.after(() => fastify.close())
129
132
 
130
133
  let order = 0
131
134
 
132
135
  stream.on('data', message => {
133
136
  if (message.msg.includes('FAIL ON LISTEN')) {
134
- t.pass('Logged Error Message')
137
+ t.assert.ok('Logged Error Message')
135
138
  }
136
139
  })
137
140
 
138
141
  fastify.addHook('onListen', function (done) {
139
- t.equal(++order, 1, '1st call')
140
- t.pass('called in root')
142
+ t.assert.strictEqual(++order, 1, '1st call')
143
+ t.assert.ok('called in root')
141
144
  done()
142
145
  })
143
146
 
144
147
  fastify.addHook('onListen', function (done) {
145
- t.equal(++order, 2, '2nd call')
146
- t.pass('called onListen error')
148
+ t.assert.strictEqual(++order, 2, '2nd call')
149
+ t.assert.ok('called onListen error')
147
150
  done(new Error('FAIL ON LISTEN'))
148
151
  })
149
152
 
150
153
  fastify.addHook('onListen', function (done) {
151
- t.equal(++order, 3, '3rd call')
152
- t.pass('onListen hooks continue after error')
154
+ t.assert.strictEqual(++order, 3, '3rd call')
155
+ t.assert.ok('onListen hooks continue after error')
153
156
  done()
154
157
  })
155
158
 
156
159
  fastify.listen({
157
160
  host: 'localhost',
158
161
  port: 0
159
- })
162
+ }, testDone)
160
163
  })
161
164
 
162
165
  test('localhost onListen async should log errors as warnings and continue', async t => {
@@ -169,25 +172,25 @@ test('localhost onListen async should log errors as warnings and continue', asyn
169
172
  level: 'info'
170
173
  }
171
174
  })
172
- t.teardown(fastify.close.bind(fastify))
175
+ t.after(() => fastify.close())
173
176
 
174
177
  stream.on('data', message => {
175
178
  if (message.msg.includes('FAIL ON LISTEN')) {
176
- t.pass('Logged Error Message')
179
+ t.assert.ok('Logged Error Message')
177
180
  }
178
181
  })
179
182
 
180
183
  fastify.addHook('onListen', async function () {
181
- t.pass('called in root')
184
+ t.assert.ok('called in root')
182
185
  })
183
186
 
184
187
  fastify.addHook('onListen', async function () {
185
- t.pass('called onListen error')
188
+ t.assert.ok('called onListen error')
186
189
  throw new Error('FAIL ON LISTEN')
187
190
  })
188
191
 
189
192
  fastify.addHook('onListen', async function () {
190
- t.pass('onListen hooks continue after error')
193
+ t.assert.ok('onListen hooks continue after error')
191
194
  })
192
195
 
193
196
  await fastify.listen({
@@ -196,14 +199,14 @@ test('localhost onListen async should log errors as warnings and continue', asyn
196
199
  })
197
200
  })
198
201
 
199
- test('localhost Register onListen hook after a plugin inside a plugin', t => {
202
+ test('localhost Register onListen hook after a plugin inside a plugin', (t, testDone) => {
200
203
  t.plan(3)
201
204
  const fastify = Fastify()
202
- t.teardown(fastify.close.bind(fastify))
205
+ t.after(() => fastify.close())
203
206
 
204
207
  fastify.register(fp(function (instance, opts, done) {
205
208
  instance.addHook('onListen', function (done) {
206
- t.pass('called')
209
+ t.assert.ok('called')
207
210
  done()
208
211
  })
209
212
  done()
@@ -211,12 +214,12 @@ test('localhost Register onListen hook after a plugin inside a plugin', t => {
211
214
 
212
215
  fastify.register(fp(function (instance, opts, done) {
213
216
  instance.addHook('onListen', function (done) {
214
- t.pass('called')
217
+ t.assert.ok('called')
215
218
  done()
216
219
  })
217
220
 
218
221
  instance.addHook('onListen', function (done) {
219
- t.pass('called')
222
+ t.assert.ok('called')
220
223
  done()
221
224
  })
222
225
 
@@ -226,10 +229,10 @@ test('localhost Register onListen hook after a plugin inside a plugin', t => {
226
229
  fastify.listen({
227
230
  host: 'localhost',
228
231
  port: 0
229
- })
232
+ }, testDone)
230
233
  })
231
234
 
232
- test('localhost Register onListen hook after a plugin inside a plugin should log errors as warnings and continue', t => {
235
+ test('localhost Register onListen hook after a plugin inside a plugin should log errors as warnings and continue', (t, testDone) => {
233
236
  t.plan(6)
234
237
  const stream = split(JSON.parse)
235
238
  const fastify = Fastify({
@@ -239,17 +242,17 @@ test('localhost Register onListen hook after a plugin inside a plugin should log
239
242
  level: 'info'
240
243
  }
241
244
  })
242
- t.teardown(fastify.close.bind(fastify))
245
+ t.after(() => fastify.close())
243
246
 
244
247
  stream.on('data', message => {
245
248
  if (message.msg.includes('Plugin Error')) {
246
- t.pass('Logged Error Message')
249
+ t.assert.ok('Logged Error Message')
247
250
  }
248
251
  })
249
252
 
250
253
  fastify.register(fp(function (instance, opts, done) {
251
254
  instance.addHook('onListen', function () {
252
- t.pass('called')
255
+ t.assert.ok('called')
253
256
  throw new Error('Plugin Error')
254
257
  })
255
258
  done()
@@ -257,12 +260,12 @@ test('localhost Register onListen hook after a plugin inside a plugin should log
257
260
 
258
261
  fastify.register(fp(function (instance, opts, done) {
259
262
  instance.addHook('onListen', function () {
260
- t.pass('called')
263
+ t.assert.ok('called')
261
264
  throw new Error('Plugin Error')
262
265
  })
263
266
 
264
267
  instance.addHook('onListen', function () {
265
- t.pass('called')
268
+ t.assert.ok('called')
266
269
  throw new Error('Plugin Error')
267
270
  })
268
271
 
@@ -272,40 +275,40 @@ test('localhost Register onListen hook after a plugin inside a plugin should log
272
275
  fastify.listen({
273
276
  host: 'localhost',
274
277
  port: 0
275
- })
278
+ }, testDone)
276
279
  })
277
280
 
278
281
  test('localhost onListen encapsulation should be called in order', async t => {
279
282
  t.plan(8)
280
283
  const fastify = Fastify()
281
- t.teardown(fastify.close.bind(fastify))
284
+ t.after(() => fastify.close())
282
285
 
283
286
  let order = 0
284
287
 
285
288
  fastify.addHook('onListen', function (done) {
286
- t.equal(++order, 1, 'called in root')
287
- t.equal(this.pluginName, fastify.pluginName, 'the this binding is the right instance')
289
+ t.assert.strictEqual(++order, 1, 'called in root')
290
+ t.assert.strictEqual(this.pluginName, fastify.pluginName, 'the this binding is the right instance')
288
291
  done()
289
292
  })
290
293
 
291
294
  await fastify.register(async (childOne, o) => {
292
295
  childOne.addHook('onListen', function (done) {
293
- t.equal(++order, 2, 'called in childOne')
294
- t.equal(this.pluginName, childOne.pluginName, 'the this binding is the right instance')
296
+ t.assert.strictEqual(++order, 2, 'called in childOne')
297
+ t.assert.strictEqual(this.pluginName, childOne.pluginName, 'the this binding is the right instance')
295
298
  done()
296
299
  })
297
300
 
298
301
  await childOne.register(async (childTwo, o) => {
299
302
  childTwo.addHook('onListen', async function () {
300
- t.equal(++order, 3, 'called in childTwo')
301
- t.equal(this.pluginName, childTwo.pluginName, 'the this binding is the right instance')
303
+ t.assert.strictEqual(++order, 3, 'called in childTwo')
304
+ t.assert.strictEqual(this.pluginName, childTwo.pluginName, 'the this binding is the right instance')
302
305
  })
303
306
  })
304
307
 
305
308
  await childOne.register(async (childTwoPeer, o) => {
306
309
  childTwoPeer.addHook('onListen', async function () {
307
- t.equal(++order, 4, 'called second in childTwo')
308
- t.equal(this.pluginName, childTwoPeer.pluginName, 'the this binding is the right instance')
310
+ t.assert.strictEqual(++order, 4, 'called second in childTwo')
311
+ t.assert.strictEqual(this.pluginName, childTwoPeer.pluginName, 'the this binding is the right instance')
309
312
  })
310
313
  })
311
314
  })
@@ -318,12 +321,12 @@ test('localhost onListen encapsulation should be called in order', async t => {
318
321
  test('localhost onListen encapsulation with only nested hook', async t => {
319
322
  t.plan(1)
320
323
  const fastify = Fastify()
321
- t.teardown(fastify.close.bind(fastify))
324
+ t.after(() => fastify.close())
322
325
 
323
326
  await fastify.register(async (child) => {
324
327
  await child.register(async (child2) => {
325
328
  child2.addHook('onListen', function (done) {
326
- t.pass()
329
+ t.assert.ok()
327
330
  done()
328
331
  })
329
332
  })
@@ -338,19 +341,19 @@ test('localhost onListen encapsulation with only nested hook', async t => {
338
341
  test('localhost onListen peer encapsulations with only nested hooks', async t => {
339
342
  t.plan(2)
340
343
  const fastify = Fastify()
341
- t.teardown(fastify.close.bind(fastify))
344
+ t.after(() => fastify.close())
342
345
 
343
346
  await fastify.register(async (child) => {
344
347
  await child.register(async (child2) => {
345
348
  child2.addHook('onListen', function (done) {
346
- t.pass()
349
+ t.assert.ok()
347
350
  done()
348
351
  })
349
352
  })
350
353
 
351
354
  await child.register(async (child2) => {
352
355
  child2.addHook('onListen', function (done) {
353
- t.pass()
356
+ t.assert.ok()
354
357
  done()
355
358
  })
356
359
  })
@@ -362,7 +365,7 @@ test('localhost onListen peer encapsulations with only nested hooks', async t =>
362
365
  })
363
366
  })
364
367
 
365
- test('localhost onListen encapsulation should be called in order and should log errors as warnings and continue', t => {
368
+ test('localhost onListen encapsulation should be called in order and should log errors as warnings and continue', (t, testDone) => {
366
369
  t.plan(7)
367
370
  const stream = split(JSON.parse)
368
371
  const fastify = Fastify({
@@ -372,32 +375,32 @@ test('localhost onListen encapsulation should be called in order and should log
372
375
  level: 'info'
373
376
  }
374
377
  })
375
- t.teardown(fastify.close.bind(fastify))
378
+ t.after(() => fastify.close())
376
379
 
377
380
  stream.on('data', message => {
378
381
  if (message.msg.includes('Error in onListen hook of childTwo')) {
379
- t.pass('Logged Error Message')
382
+ t.assert.ok('Logged Error Message')
380
383
  }
381
384
  })
382
385
 
383
386
  let order = 0
384
387
 
385
388
  fastify.addHook('onListen', function (done) {
386
- t.equal(++order, 1, 'called in root')
387
- t.equal(this.pluginName, fastify.pluginName, 'the this binding is the right instance')
389
+ t.assert.strictEqual(++order, 1, 'called in root')
390
+ t.assert.strictEqual(this.pluginName, fastify.pluginName, 'the this binding is the right instance')
388
391
  done()
389
392
  })
390
393
 
391
394
  fastify.register(async (childOne, o) => {
392
395
  childOne.addHook('onListen', function (done) {
393
- t.equal(++order, 2, 'called in childOne')
394
- t.equal(this.pluginName, childOne.pluginName, 'the this binding is the right instance')
396
+ t.assert.strictEqual(++order, 2, 'called in childOne')
397
+ t.assert.strictEqual(this.pluginName, childOne.pluginName, 'the this binding is the right instance')
395
398
  done()
396
399
  })
397
400
  childOne.register(async (childTwo, o) => {
398
401
  childTwo.addHook('onListen', async function () {
399
- t.equal(++order, 3, 'called in childTwo')
400
- t.equal(this.pluginName, childTwo.pluginName, 'the this binding is the right instance')
402
+ t.assert.strictEqual(++order, 3, 'called in childTwo')
403
+ t.assert.strictEqual(this.pluginName, childTwo.pluginName, 'the this binding is the right instance')
401
404
  throw new Error('Error in onListen hook of childTwo')
402
405
  })
403
406
  })
@@ -405,44 +408,44 @@ test('localhost onListen encapsulation should be called in order and should log
405
408
  fastify.listen({
406
409
  host: 'localhost',
407
410
  port: 0
408
- })
411
+ }, testDone)
409
412
  })
410
413
 
411
- test('non-localhost onListen should be called in order', { skip: isIPv6Missing }, t => {
414
+ test('non-localhost onListen should be called in order', { skip: isIPv6Missing }, (t, testDone) => {
412
415
  t.plan(2)
413
416
 
414
417
  const fastify = Fastify()
415
- t.teardown(fastify.close.bind(fastify))
418
+ t.after(() => fastify.close())
416
419
 
417
420
  let order = 0
418
421
 
419
422
  fastify.addHook('onListen', function (done) {
420
- t.equal(++order, 1, '1st called in root')
423
+ t.assert.strictEqual(++order, 1, '1st called in root')
421
424
  done()
422
425
  })
423
426
 
424
427
  fastify.addHook('onListen', function (done) {
425
- t.equal(++order, 2, '2nd called in root')
428
+ t.assert.strictEqual(++order, 2, '2nd called in root')
426
429
  done()
427
430
  })
428
431
  fastify.listen({
429
432
  host: '::1',
430
433
  port: 0
431
- })
434
+ }, testDone)
432
435
  })
433
436
 
434
437
  test('non-localhost async onListen should be called in order', { skip: isIPv6Missing }, async t => {
435
438
  t.plan(2)
436
439
  const fastify = Fastify()
437
- t.teardown(fastify.close.bind(fastify))
440
+ t.after(() => fastify.close())
438
441
  let order = 0
439
442
 
440
443
  fastify.addHook('onListen', async function () {
441
- t.equal(++order, 1, '1st async called in root')
444
+ t.assert.strictEqual(++order, 1, '1st async called in root')
442
445
  })
443
446
 
444
447
  fastify.addHook('onListen', async function () {
445
- t.equal(++order, 2, '2nd async called in root')
448
+ t.assert.strictEqual(++order, 2, '2nd async called in root')
446
449
  })
447
450
 
448
451
  await fastify.listen({
@@ -451,7 +454,7 @@ test('non-localhost async onListen should be called in order', { skip: isIPv6Mis
451
454
  })
452
455
  })
453
456
 
454
- test('non-localhost sync onListen should log errors as warnings and continue', { skip: isIPv6Missing }, t => {
457
+ test('non-localhost sync onListen should log errors as warnings and continue', { skip: isIPv6Missing }, (t, testDone) => {
455
458
  t.plan(4)
456
459
  const stream = split(JSON.parse)
457
460
  const fastify = Fastify({
@@ -461,34 +464,34 @@ test('non-localhost sync onListen should log errors as warnings and continue', {
461
464
  level: 'info'
462
465
  }
463
466
  })
464
- t.teardown(fastify.close.bind(fastify))
467
+ t.after(() => fastify.close())
465
468
 
466
469
  stream.on('data', message => {
467
470
  if (message.msg.includes('FAIL ON LISTEN')) {
468
- t.pass('Logged Error Message')
471
+ t.assert.ok('Logged Error Message')
469
472
  }
470
473
  })
471
474
  let order = 0
472
475
 
473
476
  fastify.addHook('onListen', function (done) {
474
- t.equal(++order, 1)
477
+ t.assert.strictEqual(++order, 1)
475
478
  done()
476
479
  })
477
480
 
478
481
  fastify.addHook('onListen', function () {
479
- t.equal(++order, 2)
482
+ t.assert.strictEqual(++order, 2)
480
483
  throw new Error('FAIL ON LISTEN')
481
484
  })
482
485
 
483
486
  fastify.addHook('onListen', function (done) {
484
- t.equal(++order, 3, 'should still run')
487
+ t.assert.strictEqual(++order, 3, 'should still run')
485
488
  done()
486
489
  })
487
490
 
488
491
  fastify.listen({
489
492
  host: '::1',
490
493
  port: 0
491
- })
494
+ }, testDone)
492
495
  })
493
496
 
494
497
  test('non-localhost async onListen should log errors as warnings and continue', { skip: isIPv6Missing }, async t => {
@@ -501,29 +504,29 @@ test('non-localhost async onListen should log errors as warnings and continue',
501
504
  level: 'info'
502
505
  }
503
506
  })
504
- t.teardown(fastify.close.bind(fastify))
507
+ t.after(() => fastify.close())
505
508
 
506
509
  stream.on('data', message => {
507
510
  if (message.msg.includes('FAIL ON LISTEN')) {
508
- t.pass('Logged Error Message')
511
+ t.assert.ok('Logged Error Message')
509
512
  }
510
513
  })
511
514
 
512
515
  let order = 0
513
516
 
514
517
  fastify.addHook('onListen', async function () {
515
- t.equal(++order, 1)
516
- t.pass('called in root')
518
+ t.assert.strictEqual(++order, 1)
519
+ t.assert.ok('called in root')
517
520
  })
518
521
 
519
522
  fastify.addHook('onListen', async function () {
520
- t.equal(++order, 2, '2nd async failed in root')
523
+ t.assert.strictEqual(++order, 2, '2nd async failed in root')
521
524
  throw new Error('FAIL ON LISTEN')
522
525
  })
523
526
 
524
527
  fastify.addHook('onListen', async function () {
525
- t.equal(++order, 3)
526
- t.pass('should still run')
528
+ t.assert.strictEqual(++order, 3)
529
+ t.assert.ok('should still run')
527
530
  })
528
531
 
529
532
  await fastify.listen({
@@ -532,14 +535,14 @@ test('non-localhost async onListen should log errors as warnings and continue',
532
535
  })
533
536
  })
534
537
 
535
- test('non-localhost Register onListen hook after a plugin inside a plugin', { skip: isIPv6Missing }, t => {
538
+ test('non-localhost Register onListen hook after a plugin inside a plugin', { skip: isIPv6Missing }, (t, testDone) => {
536
539
  t.plan(3)
537
540
  const fastify = Fastify()
538
- t.teardown(fastify.close.bind(fastify))
541
+ t.after(() => fastify.close())
539
542
 
540
543
  fastify.register(fp(function (instance, opts, done) {
541
544
  instance.addHook('onListen', function (done) {
542
- t.pass('called')
545
+ t.assert.ok('called')
543
546
  done()
544
547
  })
545
548
  done()
@@ -547,12 +550,12 @@ test('non-localhost Register onListen hook after a plugin inside a plugin', { sk
547
550
 
548
551
  fastify.register(fp(function (instance, opts, done) {
549
552
  instance.addHook('onListen', function (done) {
550
- t.pass('called')
553
+ t.assert.ok('called')
551
554
  done()
552
555
  })
553
556
 
554
557
  instance.addHook('onListen', function (done) {
555
- t.pass('called')
558
+ t.assert.ok('called')
556
559
  done()
557
560
  })
558
561
 
@@ -562,10 +565,10 @@ test('non-localhost Register onListen hook after a plugin inside a plugin', { sk
562
565
  fastify.listen({
563
566
  host: '::1',
564
567
  port: 0
565
- })
568
+ }, testDone)
566
569
  })
567
570
 
568
- test('non-localhost Register onListen hook after a plugin inside a plugin should log errors as warnings and continue', { skip: isIPv6Missing }, t => {
571
+ test('non-localhost Register onListen hook after a plugin inside a plugin should log errors as warnings and continue', { skip: isIPv6Missing }, (t, testDone) => {
569
572
  t.plan(6)
570
573
  const stream = split(JSON.parse)
571
574
  const fastify = Fastify({
@@ -575,17 +578,17 @@ test('non-localhost Register onListen hook after a plugin inside a plugin should
575
578
  level: 'info'
576
579
  }
577
580
  })
578
- t.teardown(fastify.close.bind(fastify))
581
+ t.after(() => fastify.close())
579
582
 
580
583
  stream.on('data', message => {
581
584
  if (message.msg.includes('Plugin Error')) {
582
- t.pass('Logged Error Message')
585
+ t.assert.ok('Logged Error Message')
583
586
  }
584
587
  })
585
588
 
586
589
  fastify.register(fp(function (instance, opts, done) {
587
590
  instance.addHook('onListen', function () {
588
- t.pass('called')
591
+ t.assert.ok('called')
589
592
  throw new Error('Plugin Error')
590
593
  })
591
594
  done()
@@ -593,12 +596,12 @@ test('non-localhost Register onListen hook after a plugin inside a plugin should
593
596
 
594
597
  fastify.register(fp(function (instance, opts, done) {
595
598
  instance.addHook('onListen', function () {
596
- t.pass('called')
599
+ t.assert.ok('called')
597
600
  throw new Error('Plugin Error')
598
601
  })
599
602
 
600
603
  instance.addHook('onListen', function () {
601
- t.pass('called')
604
+ t.assert.ok('called')
602
605
  throw new Error('Plugin Error')
603
606
  })
604
607
 
@@ -608,42 +611,42 @@ test('non-localhost Register onListen hook after a plugin inside a plugin should
608
611
  fastify.listen({
609
612
  host: '::1',
610
613
  port: 0
611
- })
614
+ }, testDone)
612
615
  })
613
616
 
614
- test('non-localhost onListen encapsulation should be called in order', { skip: isIPv6Missing }, t => {
617
+ test('non-localhost onListen encapsulation should be called in order', { skip: isIPv6Missing }, (t, testDone) => {
615
618
  t.plan(6)
616
619
  const fastify = Fastify()
617
- t.teardown(fastify.close.bind(fastify))
620
+ t.after(() => fastify.close())
618
621
 
619
622
  let order = 0
620
623
 
621
624
  fastify.addHook('onListen', function (done) {
622
- t.equal(++order, 1, 'called in root')
623
- t.equal(this.pluginName, fastify.pluginName, 'the this binding is the right instance')
625
+ t.assert.strictEqual(++order, 1, 'called in root')
626
+ t.assert.strictEqual(this.pluginName, fastify.pluginName, 'the this binding is the right instance')
624
627
  done()
625
628
  })
626
629
 
627
630
  fastify.register(async (childOne, o) => {
628
631
  childOne.addHook('onListen', function (done) {
629
- t.equal(++order, 2, 'called in childOne')
630
- t.equal(this.pluginName, childOne.pluginName, 'the this binding is the right instance')
632
+ t.assert.strictEqual(++order, 2, 'called in childOne')
633
+ t.assert.strictEqual(this.pluginName, childOne.pluginName, 'the this binding is the right instance')
631
634
  done()
632
635
  })
633
636
  childOne.register(async (childTwo, o) => {
634
637
  childTwo.addHook('onListen', async function () {
635
- t.equal(++order, 3, 'called in childTwo')
636
- t.equal(this.pluginName, childTwo.pluginName, 'the this binding is the right instance')
638
+ t.assert.strictEqual(++order, 3, 'called in childTwo')
639
+ t.assert.strictEqual(this.pluginName, childTwo.pluginName, 'the this binding is the right instance')
637
640
  })
638
641
  })
639
642
  })
640
643
  fastify.listen({
641
644
  host: '::1',
642
645
  port: 0
643
- })
646
+ }, testDone)
644
647
  })
645
648
 
646
- test('non-localhost onListen encapsulation should be called in order and should log errors as warnings and continue', { skip: isIPv6Missing }, t => {
649
+ test('non-localhost onListen encapsulation should be called in order and should log errors as warnings and continue', { skip: isIPv6Missing }, (t, testDone) => {
647
650
  t.plan(7)
648
651
  const stream = split(JSON.parse)
649
652
  const fastify = Fastify({
@@ -653,33 +656,33 @@ test('non-localhost onListen encapsulation should be called in order and should
653
656
  level: 'info'
654
657
  }
655
658
  })
656
- t.teardown(fastify.close.bind(fastify))
659
+ t.after(() => fastify.close())
657
660
 
658
661
  stream.on('data', message => {
659
662
  if (message.msg.includes('Error in onListen hook of childTwo')) {
660
- t.pass('Logged Error Message')
663
+ t.assert.ok('Logged Error Message')
661
664
  }
662
665
  })
663
666
 
664
667
  let order = 0
665
668
 
666
669
  fastify.addHook('onListen', function (done) {
667
- t.equal(++order, 1, 'called in root')
670
+ t.assert.strictEqual(++order, 1, 'called in root')
668
671
 
669
- t.equal(this.pluginName, fastify.pluginName, 'the this binding is the right instance')
672
+ t.assert.strictEqual(this.pluginName, fastify.pluginName, 'the this binding is the right instance')
670
673
  done()
671
674
  })
672
675
 
673
676
  fastify.register(async (childOne, o) => {
674
677
  childOne.addHook('onListen', function (done) {
675
- t.equal(++order, 2, 'called in childOne')
676
- t.equal(this.pluginName, childOne.pluginName, 'the this binding is the right instance')
678
+ t.assert.strictEqual(++order, 2, 'called in childOne')
679
+ t.assert.strictEqual(this.pluginName, childOne.pluginName, 'the this binding is the right instance')
677
680
  done()
678
681
  })
679
682
  childOne.register(async (childTwo, o) => {
680
683
  childTwo.addHook('onListen', async function () {
681
- t.equal(++order, 3, 'called in childTwo')
682
- t.equal(this.pluginName, childTwo.pluginName, 'the this binding is the right instance')
684
+ t.assert.strictEqual(++order, 3, 'called in childTwo')
685
+ t.assert.strictEqual(this.pluginName, childTwo.pluginName, 'the this binding is the right instance')
683
686
  throw new Error('Error in onListen hook of childTwo')
684
687
  })
685
688
  })
@@ -687,52 +690,54 @@ test('non-localhost onListen encapsulation should be called in order and should
687
690
  fastify.listen({
688
691
  host: '::1',
689
692
  port: 0
690
- })
693
+ }, testDone)
691
694
  })
692
695
 
693
- test('onListen localhost should work in order with callback', t => {
696
+ test('onListen localhost should work in order with callback', (t, testDone) => {
694
697
  t.plan(4)
695
698
  const fastify = Fastify()
696
- t.teardown(fastify.close.bind(fastify))
699
+ t.after(() => fastify.close())
697
700
  let order = 0
698
701
 
699
702
  fastify.addHook('onListen', function (done) {
700
- t.equal(++order, 1, '1st called in root')
703
+ t.assert.strictEqual(++order, 1, '1st called in root')
701
704
  done()
702
705
  })
703
706
 
704
707
  fastify.addHook('onListen', function (done) {
705
- t.equal(++order, 2, '2nd called in root')
708
+ t.assert.strictEqual(++order, 2, '2nd called in root')
706
709
  done()
707
710
  })
708
711
 
709
712
  fastify.listen({ port: 0 }, (err) => {
710
- t.equal(fastify.server.address().address, localhost)
711
- t.error(err)
713
+ t.assert.strictEqual(fastify.server.address().address, localhost)
714
+ t.assert.ifError(err)
715
+ testDone()
712
716
  })
713
717
  })
714
718
 
715
- test('onListen localhost should work in order with callback in async', t => {
719
+ test('onListen localhost should work in order with callback in async', (t, testDone) => {
716
720
  t.plan(4)
717
721
  const fastify = Fastify()
718
- t.teardown(fastify.close.bind(fastify))
722
+ t.after(() => fastify.close())
719
723
  let order = 0
720
724
 
721
725
  fastify.addHook('onListen', async function () {
722
- t.equal(++order, 1, '1st called in root')
726
+ t.assert.strictEqual(++order, 1, '1st called in root')
723
727
  })
724
728
 
725
729
  fastify.addHook('onListen', async function () {
726
- t.equal(++order, 2, '2nd called in root')
730
+ t.assert.strictEqual(++order, 2, '2nd called in root')
727
731
  })
728
732
 
729
733
  fastify.listen({ host: 'localhost', port: 0 }, (err) => {
730
- t.equal(fastify.server.address().address, localhost)
731
- t.error(err)
734
+ t.assert.strictEqual(fastify.server.address().address, localhost)
735
+ t.assert.ifError(err)
736
+ testDone()
732
737
  })
733
738
  })
734
739
 
735
- test('onListen localhost sync with callback should log errors as warnings and continue', t => {
740
+ test('onListen localhost sync with callback should log errors as warnings and continue', (t, testDone) => {
736
741
  t.plan(6)
737
742
  const stream = split(JSON.parse)
738
743
  const fastify = Fastify({
@@ -742,38 +747,39 @@ test('onListen localhost sync with callback should log errors as warnings and co
742
747
  level: 'info'
743
748
  }
744
749
  })
745
- t.teardown(fastify.close.bind(fastify))
750
+ t.after(() => fastify.close())
746
751
 
747
752
  stream.on('data', message => {
748
753
  if (message.msg.includes('FAIL ON LISTEN')) {
749
- t.pass('Logged Error Message')
754
+ t.assert.ok('Logged Error Message')
750
755
  }
751
756
  })
752
757
 
753
758
  let order = 0
754
759
 
755
760
  fastify.addHook('onListen', function (done) {
756
- t.equal(++order, 1, '1st called in root')
761
+ t.assert.strictEqual(++order, 1, '1st called in root')
757
762
  done()
758
763
  })
759
764
 
760
765
  fastify.addHook('onListen', function () {
761
- t.equal(++order, 2, 'error sync called in root')
766
+ t.assert.strictEqual(++order, 2, 'error sync called in root')
762
767
  throw new Error('FAIL ON LISTEN')
763
768
  })
764
769
 
765
770
  fastify.addHook('onListen', function (done) {
766
- t.equal(++order, 3, '1st called in root')
771
+ t.assert.strictEqual(++order, 3, '1st called in root')
767
772
  done()
768
773
  })
769
774
 
770
775
  fastify.listen({ port: 0 }, (err) => {
771
- t.error(err)
772
- t.equal(fastify.server.address().address, localhost)
776
+ t.assert.ifError(err)
777
+ t.assert.strictEqual(fastify.server.address().address, localhost)
778
+ testDone()
773
779
  })
774
780
  })
775
781
 
776
- test('onListen localhost async with callback should log errors as warnings and continue', t => {
782
+ test('onListen localhost async with callback should log errors as warnings and continue', (t, testDone) => {
777
783
  t.plan(6)
778
784
  const stream = split(JSON.parse)
779
785
  const fastify = Fastify({
@@ -783,43 +789,44 @@ test('onListen localhost async with callback should log errors as warnings and c
783
789
  level: 'info'
784
790
  }
785
791
  })
786
- t.teardown(fastify.close.bind(fastify))
792
+ t.after(() => fastify.close())
787
793
 
788
794
  stream.on('data', message => {
789
795
  if (message.msg.includes('FAIL ON LISTEN')) {
790
- t.pass('Logged Error Message')
796
+ t.assert.ok('Logged Error Message')
791
797
  }
792
798
  })
793
799
 
794
800
  let order = 0
795
801
 
796
802
  fastify.addHook('onListen', async function () {
797
- t.pass('1st called in root')
803
+ t.assert.ok('1st called in root')
798
804
  })
799
805
 
800
806
  fastify.addHook('onListen', async function () {
801
- t.equal(++order, 1, 'error sync called in root')
807
+ t.assert.strictEqual(++order, 1, 'error sync called in root')
802
808
  throw new Error('FAIL ON LISTEN')
803
809
  })
804
810
 
805
811
  fastify.addHook('onListen', async function () {
806
- t.pass('3rd called in root')
812
+ t.assert.ok('3rd called in root')
807
813
  })
808
814
 
809
815
  fastify.listen({ port: 0 }, (err) => {
810
- t.error(err)
811
- t.equal(fastify.server.address().address, localhost)
816
+ t.assert.ifError(err)
817
+ t.assert.strictEqual(fastify.server.address().address, localhost)
818
+ testDone()
812
819
  })
813
820
  })
814
821
 
815
- test('Register onListen hook localhost with callback after a plugin inside a plugin', t => {
822
+ test('Register onListen hook localhost with callback after a plugin inside a plugin', (t, testDone) => {
816
823
  t.plan(5)
817
824
  const fastify = Fastify()
818
- t.teardown(fastify.close.bind(fastify))
825
+ t.after(() => fastify.close())
819
826
 
820
827
  fastify.register(fp(function (instance, opts, done) {
821
828
  instance.addHook('onListen', function (done) {
822
- t.pass('called')
829
+ t.assert.ok('called')
823
830
  done()
824
831
  })
825
832
  done()
@@ -827,12 +834,12 @@ test('Register onListen hook localhost with callback after a plugin inside a plu
827
834
 
828
835
  fastify.register(fp(function (instance, opts, done) {
829
836
  instance.addHook('onListen', function (done) {
830
- t.pass('called')
837
+ t.assert.ok('called')
831
838
  done()
832
839
  })
833
840
 
834
841
  instance.addHook('onListen', function (done) {
835
- t.pass('called')
842
+ t.assert.ok('called')
836
843
  done()
837
844
  })
838
845
 
@@ -840,86 +847,90 @@ test('Register onListen hook localhost with callback after a plugin inside a plu
840
847
  }))
841
848
 
842
849
  fastify.listen({ port: 0 }, (err) => {
843
- t.equal(fastify.server.address().address, localhost)
844
- t.error(err)
850
+ t.assert.strictEqual(fastify.server.address().address, localhost)
851
+ t.assert.ifError(err)
852
+ testDone()
845
853
  })
846
854
  })
847
855
 
848
- test('onListen localhost with callback encapsulation should be called in order', t => {
856
+ test('onListen localhost with callback encapsulation should be called in order', (t, testDone) => {
849
857
  t.plan(8)
850
858
  const fastify = Fastify()
851
- t.teardown(fastify.close.bind(fastify))
859
+ t.after(() => fastify.close())
852
860
 
853
861
  let order = 0
854
862
 
855
863
  fastify.addHook('onListen', function (done) {
856
- t.equal(++order, 1, 'called in root')
857
- t.equal(this.pluginName, fastify.pluginName, 'the this binding is the right instance')
864
+ t.assert.strictEqual(++order, 1, 'called in root')
865
+ t.assert.strictEqual(this.pluginName, fastify.pluginName, 'the this binding is the right instance')
858
866
  done()
859
867
  })
860
868
 
861
869
  fastify.register(async (childOne, o) => {
862
870
  childOne.addHook('onListen', function (done) {
863
- t.equal(++order, 2, 'called in childOne')
864
- t.equal(this.pluginName, childOne.pluginName, 'the this binding is the right instance')
871
+ t.assert.strictEqual(++order, 2, 'called in childOne')
872
+ t.assert.strictEqual(this.pluginName, childOne.pluginName, 'the this binding is the right instance')
865
873
  done()
866
874
  })
867
875
  childOne.register(async (childTwo, o) => {
868
876
  childTwo.addHook('onListen', async function () {
869
- t.equal(++order, 3, 'called in childTwo')
870
- t.equal(this.pluginName, childTwo.pluginName, 'the this binding is the right instance')
877
+ t.assert.strictEqual(++order, 3, 'called in childTwo')
878
+ t.assert.strictEqual(this.pluginName, childTwo.pluginName, 'the this binding is the right instance')
871
879
  })
872
880
  })
873
881
  })
874
882
  fastify.listen({ port: 0 }, (err) => {
875
- t.equal(fastify.server.address().address, localhost)
876
- t.error(err)
883
+ t.assert.strictEqual(fastify.server.address().address, localhost)
884
+ t.assert.ifError(err)
885
+ testDone()
877
886
  })
878
887
  })
879
888
 
880
- test('onListen non-localhost should work in order with callback in sync', { skip: isIPv6Missing }, t => {
889
+ test('onListen non-localhost should work in order with callback in sync', { skip: isIPv6Missing }, (t, testDone) => {
881
890
  t.plan(4)
882
891
  const fastify = Fastify()
883
- t.teardown(fastify.close.bind(fastify))
892
+ t.after(() => fastify.close())
884
893
  let order = 0
885
894
 
886
895
  fastify.addHook('onListen', function (done) {
887
- t.equal(++order, 1, '1st called in root')
896
+ t.assert.strictEqual(++order, 1, '1st called in root')
888
897
  done()
889
898
  })
890
899
 
891
900
  fastify.addHook('onListen', function (done) {
892
- t.equal(++order, 2, '2nd called in root')
901
+ t.assert.strictEqual(++order, 2, '2nd called in root')
893
902
  done()
894
903
  })
895
904
 
896
905
  fastify.listen({ host: '::1', port: 0 }, (err) => {
897
- t.equal(fastify.server.address().address, '::1')
898
- t.error(err)
906
+ t.assert.strictEqual(fastify.server.address().address, '::1')
907
+ t.assert.ifError(err)
908
+ testDone()
899
909
  })
900
910
  })
901
911
 
902
- test('onListen non-localhost should work in order with callback in async', { skip: isIPv6Missing }, t => {
912
+ test('onListen non-localhost should work in order with callback in async', { skip: isIPv6Missing }, (t, testDone) => {
903
913
  t.plan(4)
904
914
  const fastify = Fastify()
905
- t.teardown(fastify.close.bind(fastify))
915
+ t.after(() => fastify.close())
906
916
  let order = 0
907
917
 
908
918
  fastify.addHook('onListen', async function () {
909
- t.equal(++order, 1, '1st called in root')
919
+ t.assert.strictEqual(++order, 1, '1st called in root')
910
920
  })
911
921
 
912
922
  fastify.addHook('onListen', async function () {
913
- t.equal(++order, 2, '2nd called in root')
923
+ t.assert.strictEqual(++order, 2, '2nd called in root')
914
924
  })
915
925
 
916
926
  fastify.listen({ host: '::1', port: 0 }, (err) => {
917
- t.equal(fastify.server.address().address, '::1')
918
- t.error(err)
927
+ t.assert.strictEqual(fastify.server.address().address, '::1')
928
+ t.assert.ifError(err)
929
+ testDone()
919
930
  })
920
931
  })
921
932
 
922
- test('onListen non-localhost sync with callback should log errors as warnings and continue', { skip: isIPv6Missing }, t => {
933
+ test('onListen non-localhost sync with callback should log errors as warnings and continue', { skip: isIPv6Missing }, (t, testDone) => {
923
934
  t.plan(8)
924
935
 
925
936
  const stream = split(JSON.parse)
@@ -930,40 +941,41 @@ test('onListen non-localhost sync with callback should log errors as warnings an
930
941
  level: 'info'
931
942
  }
932
943
  })
933
- t.teardown(fastify.close.bind(fastify))
944
+ t.after(() => fastify.close())
934
945
 
935
946
  stream.on('data', message => {
936
947
  if (message.msg.includes('FAIL ON LISTEN')) {
937
- t.pass('Logged Error Message')
948
+ t.assert.ok('Logged Error Message')
938
949
  }
939
950
  })
940
951
 
941
952
  let order = 0
942
953
 
943
954
  fastify.addHook('onListen', function (done) {
944
- t.equal(++order, 1)
945
- t.pass('1st called in root')
955
+ t.assert.strictEqual(++order, 1)
956
+ t.assert.ok('1st called in root')
946
957
  done()
947
958
  })
948
959
 
949
960
  fastify.addHook('onListen', function () {
950
- t.equal(++order, 2)
961
+ t.assert.strictEqual(++order, 2)
951
962
  throw new Error('FAIL ON LISTEN')
952
963
  })
953
964
 
954
965
  fastify.addHook('onListen', function (done) {
955
- t.equal(++order, 3)
956
- t.pass('3rd called in root')
966
+ t.assert.strictEqual(++order, 3)
967
+ t.assert.ok('3rd called in root')
957
968
  done()
958
969
  })
959
970
 
960
971
  fastify.listen({ host: '::1', port: 0 }, (err) => {
961
- t.error(err)
962
- t.equal(fastify.server.address().address, '::1')
972
+ t.assert.ifError(err)
973
+ t.assert.strictEqual(fastify.server.address().address, '::1')
974
+ testDone()
963
975
  })
964
976
  })
965
977
 
966
- test('onListen non-localhost async with callback should log errors as warnings and continue', { skip: isIPv6Missing }, t => {
978
+ test('onListen non-localhost async with callback should log errors as warnings and continue', { skip: isIPv6Missing }, (t, testDone) => {
967
979
  t.plan(8)
968
980
 
969
981
  const stream = split(JSON.parse)
@@ -974,45 +986,46 @@ test('onListen non-localhost async with callback should log errors as warnings a
974
986
  level: 'info'
975
987
  }
976
988
  })
977
- t.teardown(fastify.close.bind(fastify))
989
+ t.after(() => fastify.close())
978
990
 
979
991
  stream.on('data', message => {
980
992
  if (message.msg.includes('FAIL ON LISTEN')) {
981
- t.pass('Logged Error Message')
993
+ t.assert.ok('Logged Error Message')
982
994
  }
983
995
  })
984
996
 
985
997
  let order = 0
986
998
 
987
999
  fastify.addHook('onListen', async function () {
988
- t.equal(++order, 1)
989
- t.pass('1st called in root')
1000
+ t.assert.strictEqual(++order, 1)
1001
+ t.assert.ok('1st called in root')
990
1002
  })
991
1003
 
992
1004
  fastify.addHook('onListen', async function () {
993
- t.equal(++order, 2, 'error sync called in root')
1005
+ t.assert.strictEqual(++order, 2, 'error sync called in root')
994
1006
  throw new Error('FAIL ON LISTEN')
995
1007
  })
996
1008
 
997
1009
  fastify.addHook('onListen', async function () {
998
- t.equal(++order, 3)
999
- t.pass('3rd called in root')
1010
+ t.assert.strictEqual(++order, 3)
1011
+ t.assert.ok('3rd called in root')
1000
1012
  })
1001
1013
 
1002
1014
  fastify.listen({ host: '::1', port: 0 }, (err) => {
1003
- t.error(err)
1004
- t.equal(fastify.server.address().address, '::1')
1015
+ t.assert.ifError(err)
1016
+ t.assert.strictEqual(fastify.server.address().address, '::1')
1017
+ testDone()
1005
1018
  })
1006
1019
  })
1007
1020
 
1008
- test('Register onListen hook non-localhost with callback after a plugin inside a plugin', { skip: isIPv6Missing }, t => {
1021
+ test('Register onListen hook non-localhost with callback after a plugin inside a plugin', { skip: isIPv6Missing }, (t, testDone) => {
1009
1022
  t.plan(5)
1010
1023
  const fastify = Fastify()
1011
- t.teardown(fastify.close.bind(fastify))
1024
+ t.after(() => fastify.close())
1012
1025
 
1013
1026
  fastify.register(fp(function (instance, opts, done) {
1014
1027
  instance.addHook('onListen', function (done) {
1015
- t.pass('called')
1028
+ t.assert.ok('called')
1016
1029
  done()
1017
1030
  })
1018
1031
  done()
@@ -1020,12 +1033,12 @@ test('Register onListen hook non-localhost with callback after a plugin inside a
1020
1033
 
1021
1034
  fastify.register(fp(function (instance, opts, done) {
1022
1035
  instance.addHook('onListen', function (done) {
1023
- t.pass('called')
1036
+ t.assert.ok('called')
1024
1037
  done()
1025
1038
  })
1026
1039
 
1027
1040
  instance.addHook('onListen', function (done) {
1028
- t.pass('called')
1041
+ t.assert.ok('called')
1029
1042
  done()
1030
1043
  })
1031
1044
 
@@ -1033,91 +1046,93 @@ test('Register onListen hook non-localhost with callback after a plugin inside a
1033
1046
  }))
1034
1047
 
1035
1048
  fastify.listen({ host: '::1', port: 0 }, (err) => {
1036
- t.equal(fastify.server.address().address, '::1')
1037
- t.error(err)
1049
+ t.assert.strictEqual(fastify.server.address().address, '::1')
1050
+ t.assert.ifError(err)
1051
+ testDone()
1038
1052
  })
1039
1053
  })
1040
1054
 
1041
- test('onListen non-localhost with callback encapsulation should be called in order', { skip: isIPv6Missing }, t => {
1055
+ test('onListen non-localhost with callback encapsulation should be called in order', { skip: isIPv6Missing }, (t, testDone) => {
1042
1056
  t.plan(8)
1043
1057
  const fastify = Fastify()
1044
- t.teardown(fastify.close.bind(fastify))
1058
+ t.after(() => fastify.close())
1045
1059
 
1046
1060
  let order = 0
1047
1061
 
1048
1062
  fastify.addHook('onListen', function (done) {
1049
- t.equal(++order, 1, 'called in root')
1050
- t.equal(this.pluginName, fastify.pluginName, 'the this binding is the right instance')
1063
+ t.assert.strictEqual(++order, 1, 'called in root')
1064
+ t.assert.strictEqual(this.pluginName, fastify.pluginName, 'the this binding is the right instance')
1051
1065
  done()
1052
1066
  })
1053
1067
 
1054
1068
  fastify.register(async (childOne, o) => {
1055
1069
  childOne.addHook('onListen', function (done) {
1056
- t.equal(++order, 2, 'called in childOne')
1057
- t.equal(this.pluginName, childOne.pluginName, 'the this binding is the right instance')
1070
+ t.assert.strictEqual(++order, 2, 'called in childOne')
1071
+ t.assert.strictEqual(this.pluginName, childOne.pluginName, 'the this binding is the right instance')
1058
1072
  done()
1059
1073
  })
1060
1074
  childOne.register(async (childTwo, o) => {
1061
1075
  childTwo.addHook('onListen', async function () {
1062
- t.equal(++order, 3, 'called in childTwo')
1063
- t.equal(this.pluginName, childTwo.pluginName, 'the this binding is the right instance')
1076
+ t.assert.strictEqual(++order, 3, 'called in childTwo')
1077
+ t.assert.strictEqual(this.pluginName, childTwo.pluginName, 'the this binding is the right instance')
1064
1078
  })
1065
1079
  })
1066
1080
  })
1067
1081
  fastify.listen({ host: '::1', port: 0 }, (err) => {
1068
- t.equal(fastify.server.address().address, '::1')
1069
- t.error(err)
1082
+ t.assert.strictEqual(fastify.server.address().address, '::1')
1083
+ t.assert.ifError(err)
1084
+ testDone()
1070
1085
  })
1071
1086
  })
1072
1087
 
1073
- test('onListen sync should work if user does not pass done', t => {
1088
+ test('onListen sync should work if user does not pass done', (t, testDone) => {
1074
1089
  t.plan(2)
1075
1090
  const fastify = Fastify()
1076
- t.teardown(fastify.close.bind(fastify))
1091
+ t.after(() => fastify.close())
1077
1092
  let order = 0
1078
1093
 
1079
1094
  fastify.addHook('onListen', function () {
1080
- t.equal(++order, 1, '1st called in root')
1095
+ t.assert.strictEqual(++order, 1, '1st called in root')
1081
1096
  })
1082
1097
 
1083
1098
  fastify.addHook('onListen', function () {
1084
- t.equal(++order, 2, '2nd called in root')
1099
+ t.assert.strictEqual(++order, 2, '2nd called in root')
1085
1100
  })
1086
1101
 
1087
1102
  fastify.listen({
1088
1103
  host: 'localhost',
1089
1104
  port: 0
1090
- })
1105
+ }, testDone)
1091
1106
  })
1092
1107
 
1093
- test('async onListen does not need to be awaited', t => {
1108
+ test('async onListen does not need to be awaited', (t, testDone) => {
1094
1109
  const fastify = Fastify()
1095
- t.teardown(fastify.close.bind(fastify))
1110
+ t.after(() => fastify.close())
1096
1111
  let order = 0
1097
1112
 
1098
1113
  fastify.addHook('onListen', async function () {
1099
- t.equal(++order, 1, '1st async called in root')
1114
+ t.assert.strictEqual(++order, 1, '1st async called in root')
1100
1115
  })
1101
1116
 
1102
1117
  fastify.addHook('onListen', async function () {
1103
- t.equal(++order, 2, '2nd async called in root')
1118
+ t.assert.strictEqual(++order, 2, '2nd async called in root')
1104
1119
  t.end()
1105
1120
  })
1106
1121
 
1107
1122
  fastify.listen({
1108
1123
  host: 'localhost',
1109
1124
  port: 0
1110
- })
1125
+ }, testDone)
1111
1126
  })
1112
1127
 
1113
- test('onListen hooks do not block /1', t => {
1128
+ test('onListen hooks do not block /1', (t, testDone) => {
1114
1129
  t.plan(2)
1115
1130
 
1116
1131
  const fastify = Fastify()
1117
- t.teardown(fastify.close.bind(fastify))
1132
+ t.after(() => fastify.close())
1118
1133
 
1119
1134
  fastify.addHook('onListen', function (done) {
1120
- t.equal(fastify[kState].listening, true)
1135
+ t.assert.strictEqual(fastify[kState].listening, true)
1121
1136
  done()
1122
1137
  })
1123
1138
 
@@ -1125,7 +1140,8 @@ test('onListen hooks do not block /1', t => {
1125
1140
  host: 'localhost',
1126
1141
  port: 0
1127
1142
  }, err => {
1128
- t.error(err)
1143
+ t.assert.ifError(err)
1144
+ testDone()
1129
1145
  })
1130
1146
  })
1131
1147
 
@@ -1133,10 +1149,10 @@ test('onListen hooks do not block /2', async t => {
1133
1149
  t.plan(1)
1134
1150
 
1135
1151
  const fastify = Fastify()
1136
- t.teardown(fastify.close.bind(fastify))
1152
+ t.after(() => fastify.close())
1137
1153
 
1138
1154
  fastify.addHook('onListen', async function () {
1139
- t.equal(fastify[kState].listening, true)
1155
+ t.assert.strictEqual(fastify[kState].listening, true)
1140
1156
  })
1141
1157
 
1142
1158
  await fastify.listen({