fastify 5.3.2 → 5.4.0

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 (103) hide show
  1. package/README.md +2 -0
  2. package/build/build-validation.js +2 -1
  3. package/docs/Guides/Delay-Accepting-Requests.md +3 -3
  4. package/docs/Guides/Ecosystem.md +16 -7
  5. package/docs/Guides/Serverless.md +28 -69
  6. package/docs/Reference/ContentTypeParser.md +1 -1
  7. package/docs/Reference/Errors.md +2 -4
  8. package/docs/Reference/Hooks.md +14 -14
  9. package/docs/Reference/Logging.md +3 -3
  10. package/docs/Reference/Middleware.md +1 -1
  11. package/docs/Reference/Reply.md +8 -8
  12. package/docs/Reference/Request.md +1 -1
  13. package/docs/Reference/Routes.md +3 -3
  14. package/docs/Reference/Server.md +40 -10
  15. package/docs/Reference/Validation-and-Serialization.md +1 -1
  16. package/eslint.config.js +17 -9
  17. package/fastify.d.ts +2 -1
  18. package/fastify.js +20 -4
  19. package/lib/configValidator.js +1 -1
  20. package/lib/decorate.js +2 -2
  21. package/lib/errors.js +6 -8
  22. package/lib/logger-factory.js +1 -1
  23. package/lib/logger-pino.js +2 -2
  24. package/lib/pluginOverride.js +3 -1
  25. package/lib/reply.js +9 -13
  26. package/lib/request.js +4 -11
  27. package/lib/server.js +30 -51
  28. package/lib/symbols.js +1 -0
  29. package/lib/warnings.js +8 -0
  30. package/package.json +11 -7
  31. package/test/404s.test.js +226 -325
  32. package/test/allow-unsafe-regex.test.js +19 -48
  33. package/test/als.test.js +28 -40
  34. package/test/async-await.test.js +11 -2
  35. package/test/body-limit.test.js +41 -65
  36. package/test/build-certificate.js +1 -1
  37. package/test/close-pipelining.test.js +5 -4
  38. package/test/custom-parser-async.test.js +17 -22
  39. package/test/decorator-namespace.test._js_ +3 -4
  40. package/test/decorator.test.js +422 -341
  41. package/test/diagnostics-channel/async-delay-request.test.js +7 -16
  42. package/test/diagnostics-channel/sync-delay-request.test.js +7 -16
  43. package/test/helper.js +108 -70
  44. package/test/hooks-async.test.js +248 -218
  45. package/test/hooks.on-listen.test.js +255 -239
  46. package/test/hooks.on-ready.test.js +110 -92
  47. package/test/hooks.test.js +910 -769
  48. package/test/http-methods/lock.test.js +31 -31
  49. package/test/http-methods/mkcol.test.js +5 -9
  50. package/test/http-methods/proppatch.test.js +23 -29
  51. package/test/http-methods/report.test.js +44 -69
  52. package/test/http-methods/search.test.js +67 -82
  53. package/test/http2/closing.test.js +38 -20
  54. package/test/http2/secure-with-fallback.test.js +28 -27
  55. package/test/https/https.test.js +56 -53
  56. package/test/inject.test.js +114 -97
  57. package/test/input-validation.js +63 -53
  58. package/test/internals/errors.test.js +0 -10
  59. package/test/internals/handle-request.test.js +49 -66
  60. package/test/internals/hooks.test.js +17 -0
  61. package/test/issue-4959.test.js +14 -5
  62. package/test/listen.4.test.js +31 -43
  63. package/test/logger/response.test.js +19 -20
  64. package/test/nullable-validation.test.js +33 -46
  65. package/test/options.error-handler.test.js +1 -1
  66. package/test/options.test.js +1 -1
  67. package/test/output-validation.test.js +49 -72
  68. package/test/patch.error-handler.test.js +1 -1
  69. package/test/patch.test.js +1 -1
  70. package/test/plugin.1.test.js +71 -60
  71. package/test/plugin.2.test.js +104 -86
  72. package/test/plugin.3.test.js +56 -35
  73. package/test/plugin.4.test.js +124 -119
  74. package/test/promises.test.js +36 -30
  75. package/test/proto-poisoning.test.js +78 -97
  76. package/test/put.error-handler.test.js +1 -1
  77. package/test/put.test.js +1 -1
  78. package/test/reply-error.test.js +169 -148
  79. package/test/reply-trailers.test.js +119 -108
  80. package/test/request-error.test.js +0 -46
  81. package/test/route-hooks.test.js +112 -92
  82. package/test/route-prefix.test.js +194 -133
  83. package/test/schema-feature.test.js +309 -238
  84. package/test/schema-serialization.test.js +177 -154
  85. package/test/schema-special-usage.test.js +165 -132
  86. package/test/schema-validation.test.js +278 -199
  87. package/test/set-error-handler.test.js +58 -1
  88. package/test/skip-reply-send.test.js +64 -69
  89. package/test/stream.1.test.js +30 -27
  90. package/test/stream.2.test.js +20 -10
  91. package/test/stream.3.test.js +37 -31
  92. package/test/trust-proxy.test.js +32 -58
  93. package/test/types/errors.test-d.ts +0 -1
  94. package/test/types/fastify.test-d.ts +3 -0
  95. package/test/types/plugin.test-d.ts +1 -1
  96. package/test/types/register.test-d.ts +1 -1
  97. package/test/types/request.test-d.ts +1 -0
  98. package/test/url-rewriting.test.js +45 -62
  99. package/test/use-semicolon-delimiter.test.js +1 -1
  100. package/types/errors.d.ts +0 -1
  101. package/types/request.d.ts +1 -0
  102. package/.taprc +0 -7
  103. package/test/http2/missing-http2-module.test.js +0 -17
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { Readable } = require('node:stream')
4
- const test = require('tap').test
4
+ const { test } = require('node:test')
5
5
  const sget = require('simple-get').concat
6
6
  const Fastify = require('../')
7
7
 
@@ -16,13 +16,13 @@ function endRouteHook (doneOrPayload, done, doneValue) {
16
16
  }
17
17
 
18
18
  function testExecutionHook (hook) {
19
- test(`${hook}`, t => {
19
+ test(`${hook}`, (t, testDone) => {
20
20
  t.plan(3)
21
21
  const fastify = Fastify()
22
22
 
23
23
  fastify.post('/', {
24
24
  [hook]: (req, reply, doneOrPayload, done) => {
25
- t.pass('hook called')
25
+ t.assert.ok('hook called')
26
26
  endRouteHook(doneOrPayload, done)
27
27
  }
28
28
  }, (req, reply) => {
@@ -34,13 +34,14 @@ function testExecutionHook (hook) {
34
34
  url: '/',
35
35
  payload: { hello: 'world' }
36
36
  }, (err, res) => {
37
- t.error(err)
37
+ t.assert.ifError(err)
38
38
  const payload = JSON.parse(res.payload)
39
- t.same(payload, { hello: 'world' })
39
+ t.assert.deepStrictEqual(payload, { hello: 'world' })
40
+ testDone()
40
41
  })
41
42
  })
42
43
 
43
- test(`${hook} option should be called after ${hook} hook`, t => {
44
+ test(`${hook} option should be called after ${hook} hook`, (t, testDone) => {
44
45
  t.plan(3)
45
46
  const fastify = Fastify()
46
47
  const checker = Object.defineProperty({ calledTimes: 0 }, 'check', {
@@ -48,13 +49,13 @@ function testExecutionHook (hook) {
48
49
  })
49
50
 
50
51
  fastify.addHook(hook, (req, reply, doneOrPayload, done) => {
51
- t.equal(checker.check, 1)
52
+ t.assert.strictEqual(checker.check, 1)
52
53
  endRouteHook(doneOrPayload, done)
53
54
  })
54
55
 
55
56
  fastify.post('/', {
56
57
  [hook]: (req, reply, doneOrPayload, done) => {
57
- t.equal(checker.check, 2)
58
+ t.assert.strictEqual(checker.check, 2)
58
59
  endRouteHook(doneOrPayload, done)
59
60
  }
60
61
  }, (req, reply) => {
@@ -66,11 +67,12 @@ function testExecutionHook (hook) {
66
67
  url: '/',
67
68
  payload: { hello: 'world' }
68
69
  }, (err, res) => {
69
- t.error(err)
70
+ t.assert.ifError(err)
71
+ testDone()
70
72
  })
71
73
  })
72
74
 
73
- test(`${hook} option could accept an array of functions`, t => {
75
+ test(`${hook} option could accept an array of functions`, (t, testDone) => {
74
76
  t.plan(3)
75
77
  const fastify = Fastify()
76
78
  const checker = Object.defineProperty({ calledTimes: 0 }, 'check', {
@@ -80,11 +82,11 @@ function testExecutionHook (hook) {
80
82
  fastify.post('/', {
81
83
  [hook]: [
82
84
  (req, reply, doneOrPayload, done) => {
83
- t.equal(checker.check, 1)
85
+ t.assert.strictEqual(checker.check, 1)
84
86
  endRouteHook(doneOrPayload, done)
85
87
  },
86
88
  (req, reply, doneOrPayload, done) => {
87
- t.equal(checker.check, 2)
89
+ t.assert.strictEqual(checker.check, 2)
88
90
  endRouteHook(doneOrPayload, done)
89
91
  }
90
92
  ]
@@ -97,11 +99,12 @@ function testExecutionHook (hook) {
97
99
  url: '/',
98
100
  payload: { hello: 'world' }
99
101
  }, (err, res) => {
100
- t.error(err)
102
+ t.assert.ifError(err)
103
+ testDone()
101
104
  })
102
105
  })
103
106
 
104
- test(`${hook} option could accept an array of async functions`, t => {
107
+ test(`${hook} option could accept an array of async functions`, (t, testDone) => {
105
108
  t.plan(3)
106
109
  const fastify = Fastify()
107
110
  const checker = Object.defineProperty({ calledTimes: 0 }, 'check', {
@@ -111,10 +114,10 @@ function testExecutionHook (hook) {
111
114
  fastify.post('/', {
112
115
  [hook]: [
113
116
  async (req, reply) => {
114
- t.equal(checker.check, 1)
117
+ t.assert.strictEqual(checker.check, 1)
115
118
  },
116
119
  async (req, reply) => {
117
- t.equal(checker.check, 2)
120
+ t.assert.strictEqual(checker.check, 2)
118
121
  }
119
122
  ]
120
123
  }, (req, reply) => {
@@ -126,11 +129,12 @@ function testExecutionHook (hook) {
126
129
  url: '/',
127
130
  payload: { hello: 'world' }
128
131
  }, (err, res) => {
129
- t.error(err)
132
+ t.assert.ifError(err)
133
+ testDone()
130
134
  })
131
135
  })
132
136
 
133
- test(`${hook} option does not interfere with ${hook} hook`, t => {
137
+ test(`${hook} option does not interfere with ${hook} hook`, (t, testDone) => {
134
138
  t.plan(7)
135
139
  const fastify = Fastify()
136
140
  const checker = Object.defineProperty({ calledTimes: 0 }, 'check', {
@@ -138,13 +142,13 @@ function testExecutionHook (hook) {
138
142
  })
139
143
 
140
144
  fastify.addHook(hook, (req, reply, doneOrPayload, done) => {
141
- t.equal(checker.check, 1)
145
+ t.assert.strictEqual(checker.check, 1)
142
146
  endRouteHook(doneOrPayload, done)
143
147
  })
144
148
 
145
149
  fastify.post('/', {
146
150
  [hook]: (req, reply, doneOrPayload, done) => {
147
- t.equal(checker.check, 2)
151
+ t.assert.strictEqual(checker.check, 2)
148
152
  endRouteHook(doneOrPayload, done)
149
153
  }
150
154
  }, handler)
@@ -159,8 +163,8 @@ function testExecutionHook (hook) {
159
163
  method: 'post',
160
164
  url: '/'
161
165
  }, (err, res) => {
162
- t.error(err)
163
- t.equal(checker.calledTimes, 2)
166
+ t.assert.ifError(err)
167
+ t.assert.strictEqual(checker.calledTimes, 2)
164
168
 
165
169
  checker.calledTimes = 0
166
170
 
@@ -168,15 +172,16 @@ function testExecutionHook (hook) {
168
172
  method: 'post',
169
173
  url: '/no'
170
174
  }, (err, res) => {
171
- t.error(err)
172
- t.equal(checker.calledTimes, 1)
175
+ t.assert.ifError(err)
176
+ t.assert.strictEqual(checker.calledTimes, 1)
177
+ testDone()
173
178
  })
174
179
  })
175
180
  })
176
181
  }
177
182
 
178
183
  function testBeforeHandlerHook (hook) {
179
- test(`${hook} option should be unique per route`, t => {
184
+ test(`${hook} option should be unique per route`, (t, testDone) => {
180
185
  t.plan(4)
181
186
  const fastify = Fastify()
182
187
 
@@ -198,9 +203,9 @@ function testBeforeHandlerHook (hook) {
198
203
  url: '/',
199
204
  payload: { hello: 'world' }
200
205
  }, (err, res) => {
201
- t.error(err)
206
+ t.assert.ifError(err)
202
207
  const payload = JSON.parse(res.payload)
203
- t.same(payload, { hello: 'earth' })
208
+ t.assert.deepStrictEqual(payload, { hello: 'earth' })
204
209
  })
205
210
 
206
211
  fastify.inject({
@@ -208,13 +213,14 @@ function testBeforeHandlerHook (hook) {
208
213
  url: '/no',
209
214
  payload: { hello: 'world' }
210
215
  }, (err, res) => {
211
- t.error(err)
216
+ t.assert.ifError(err)
212
217
  const payload = JSON.parse(res.payload)
213
- t.same(payload, { hello: 'world' })
218
+ t.assert.deepStrictEqual(payload, { hello: 'world' })
219
+ testDone()
214
220
  })
215
221
  })
216
222
 
217
- test(`${hook} option should handle errors`, t => {
223
+ test(`${hook} option should handle errors`, (t, testDone) => {
218
224
  t.plan(3)
219
225
  const fastify = Fastify()
220
226
 
@@ -231,25 +237,26 @@ function testBeforeHandlerHook (hook) {
231
237
  url: '/',
232
238
  payload: { hello: 'world' }
233
239
  }, (err, res) => {
234
- t.error(err)
240
+ t.assert.ifError(err)
235
241
  const payload = JSON.parse(res.payload)
236
- t.equal(res.statusCode, 500)
237
- t.same(payload, {
242
+ t.assert.strictEqual(res.statusCode, 500)
243
+ t.assert.deepStrictEqual(payload, {
238
244
  message: 'kaboom',
239
245
  error: 'Internal Server Error',
240
246
  statusCode: 500
241
247
  })
248
+ testDone()
242
249
  })
243
250
  })
244
251
 
245
- test(`${hook} option should handle throwing objects`, t => {
252
+ test(`${hook} option should handle throwing objects`, (t, testDone) => {
246
253
  t.plan(4)
247
254
  const fastify = Fastify()
248
255
 
249
256
  const myError = { myError: 'kaboom' }
250
257
 
251
258
  fastify.setErrorHandler(async (error, request, reply) => {
252
- t.same(error, myError, 'the error object throws by the user')
259
+ t.assert.deepStrictEqual(error, myError, 'the error object throws by the user')
253
260
  return reply.code(500).send({ this: 'is', my: 'error' })
254
261
  })
255
262
 
@@ -258,20 +265,21 @@ function testBeforeHandlerHook (hook) {
258
265
  throw myError
259
266
  }
260
267
  }, (req, reply) => {
261
- t.fail('the handler must not be called')
268
+ t.assert.fail('the handler must not be called')
262
269
  })
263
270
 
264
271
  fastify.inject({
265
272
  url: '/',
266
273
  method: 'GET'
267
274
  }, (err, res) => {
268
- t.error(err)
269
- t.equal(res.statusCode, 500)
270
- t.same(res.json(), { this: 'is', my: 'error' })
275
+ t.assert.ifError(err)
276
+ t.assert.strictEqual(res.statusCode, 500)
277
+ t.assert.deepStrictEqual(res.json(), { this: 'is', my: 'error' })
278
+ testDone()
271
279
  })
272
280
  })
273
281
 
274
- test(`${hook} option should handle throwing objects by default`, t => {
282
+ test(`${hook} option should handle throwing objects by default`, (t, testDone) => {
275
283
  t.plan(3)
276
284
  const fastify = Fastify()
277
285
 
@@ -281,20 +289,21 @@ function testBeforeHandlerHook (hook) {
281
289
  throw { myError: 'kaboom', message: 'i am an error' }
282
290
  }
283
291
  }, (req, reply) => {
284
- t.fail('the handler must not be called')
292
+ t.assert.fail('the handler must not be called')
285
293
  })
286
294
 
287
295
  fastify.inject({
288
296
  url: '/',
289
297
  method: 'GET'
290
298
  }, (err, res) => {
291
- t.error(err)
292
- t.equal(res.statusCode, 500)
293
- t.same(res.json(), { myError: 'kaboom', message: 'i am an error' })
299
+ t.assert.ifError(err)
300
+ t.assert.strictEqual(res.statusCode, 500)
301
+ t.assert.deepStrictEqual(res.json(), { myError: 'kaboom', message: 'i am an error' })
302
+ testDone()
294
303
  })
295
304
  })
296
305
 
297
- test(`${hook} option should handle errors with custom status code`, t => {
306
+ test(`${hook} option should handle errors with custom status code`, (t, testDone) => {
298
307
  t.plan(3)
299
308
  const fastify = Fastify()
300
309
 
@@ -312,18 +321,19 @@ function testBeforeHandlerHook (hook) {
312
321
  url: '/',
313
322
  payload: { hello: 'world' }
314
323
  }, (err, res) => {
315
- t.error(err)
324
+ t.assert.ifError(err)
316
325
  const payload = JSON.parse(res.payload)
317
- t.equal(res.statusCode, 401)
318
- t.same(payload, {
326
+ t.assert.strictEqual(res.statusCode, 401)
327
+ t.assert.deepStrictEqual(payload, {
319
328
  message: 'go away',
320
329
  error: 'Unauthorized',
321
330
  statusCode: 401
322
331
  })
332
+ testDone()
323
333
  })
324
334
  })
325
335
 
326
- test(`${hook} option should keep the context`, t => {
336
+ test(`${hook} option should keep the context`, (t, testDone) => {
327
337
  t.plan(3)
328
338
  const fastify = Fastify()
329
339
 
@@ -331,7 +341,7 @@ function testBeforeHandlerHook (hook) {
331
341
 
332
342
  fastify.post('/', {
333
343
  [hook]: function (req, reply, doneOrPayload, done) {
334
- t.equal(this.foo, 42)
344
+ t.assert.strictEqual(this.foo, 42)
335
345
  this.foo += 1
336
346
  endRouteHook(doneOrPayload, done)
337
347
  }
@@ -344,13 +354,14 @@ function testBeforeHandlerHook (hook) {
344
354
  url: '/',
345
355
  payload: { hello: 'world' }
346
356
  }, (err, res) => {
347
- t.error(err)
357
+ t.assert.ifError(err)
348
358
  const payload = JSON.parse(res.payload)
349
- t.same(payload, { foo: 43 })
359
+ t.assert.deepStrictEqual(payload, { foo: 43 })
360
+ testDone()
350
361
  })
351
362
  })
352
363
 
353
- test(`${hook} option should keep the context (array)`, t => {
364
+ test(`${hook} option should keep the context (array)`, (t, testDone) => {
354
365
  t.plan(3)
355
366
  const fastify = Fastify()
356
367
 
@@ -358,7 +369,7 @@ function testBeforeHandlerHook (hook) {
358
369
 
359
370
  fastify.post('/', {
360
371
  [hook]: [function (req, reply, doneOrPayload, done) {
361
- t.equal(this.foo, 42)
372
+ t.assert.strictEqual(this.foo, 42)
362
373
  this.foo += 1
363
374
  endRouteHook(doneOrPayload, done)
364
375
  }]
@@ -371,9 +382,10 @@ function testBeforeHandlerHook (hook) {
371
382
  url: '/',
372
383
  payload: { hello: 'world' }
373
384
  }, (err, res) => {
374
- t.error(err)
385
+ t.assert.ifError(err)
375
386
  const payload = JSON.parse(res.payload)
376
- t.same(payload, { foo: 43 })
387
+ t.assert.deepStrictEqual(payload, { foo: 43 })
388
+ testDone()
377
389
  })
378
390
  })
379
391
  }
@@ -390,12 +402,12 @@ testBeforeHandlerHook('onRequest')
390
402
  testBeforeHandlerHook('preValidation')
391
403
  testBeforeHandlerHook('preParsing')
392
404
 
393
- test('preValidation option should be called before preHandler hook', t => {
405
+ test('preValidation option should be called before preHandler hook', (t, testDone) => {
394
406
  t.plan(3)
395
407
  const fastify = Fastify()
396
408
 
397
409
  fastify.addHook('preHandler', (req, reply, done) => {
398
- t.ok(req.called)
410
+ t.assert.ok(req.called)
399
411
  done()
400
412
  })
401
413
 
@@ -413,13 +425,14 @@ test('preValidation option should be called before preHandler hook', t => {
413
425
  url: '/',
414
426
  payload: { hello: 'world' }
415
427
  }, (err, res) => {
416
- t.error(err)
428
+ t.assert.ifError(err)
417
429
  const payload = JSON.parse(res.payload)
418
- t.same(payload, { hello: 'world' })
430
+ t.assert.deepStrictEqual(payload, { hello: 'world' })
431
+ testDone()
419
432
  })
420
433
  })
421
434
 
422
- test('preSerialization option should be able to modify the payload', t => {
435
+ test('preSerialization option should be able to modify the payload', (t, testDone) => {
423
436
  t.plan(3)
424
437
  const fastify = Fastify()
425
438
 
@@ -435,18 +448,19 @@ test('preSerialization option should be able to modify the payload', t => {
435
448
  method: 'GET',
436
449
  url: '/only'
437
450
  }, (err, res) => {
438
- t.error(err)
439
- t.equal(res.statusCode, 200)
440
- t.same(JSON.parse(res.payload), { hello: 'another world' })
451
+ t.assert.ifError(err)
452
+ t.assert.strictEqual(res.statusCode, 200)
453
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'another world' })
454
+ testDone()
441
455
  })
442
456
  })
443
457
 
444
- test('preParsing option should be called before preValidation hook', t => {
458
+ test('preParsing option should be called before preValidation hook', (t, testDone) => {
445
459
  t.plan(3)
446
460
  const fastify = Fastify()
447
461
 
448
462
  fastify.addHook('preValidation', (req, reply, done) => {
449
- t.ok(req.called)
463
+ t.assert.ok(req.called)
450
464
  done()
451
465
  })
452
466
 
@@ -464,13 +478,14 @@ test('preParsing option should be called before preValidation hook', t => {
464
478
  url: '/',
465
479
  payload: { hello: 'world' }
466
480
  }, (err, res) => {
467
- t.error(err)
481
+ t.assert.ifError(err)
468
482
  const payload = JSON.parse(res.payload)
469
- t.same(payload, { hello: 'world' })
483
+ t.assert.deepStrictEqual(payload, { hello: 'world' })
484
+ testDone()
470
485
  })
471
486
  })
472
487
 
473
- test('preParsing option should be able to modify the payload', t => {
488
+ test('preParsing option should be able to modify the payload', (t, testDone) => {
474
489
  t.plan(3)
475
490
  const fastify = Fastify()
476
491
 
@@ -491,13 +506,14 @@ test('preParsing option should be able to modify the payload', t => {
491
506
  url: '/only',
492
507
  payload: { hello: 'world' }
493
508
  }, (err, res) => {
494
- t.error(err)
495
- t.equal(res.statusCode, 200)
496
- t.same(JSON.parse(res.payload), { hello: 'another world' })
509
+ t.assert.ifError(err)
510
+ t.assert.strictEqual(res.statusCode, 200)
511
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'another world' })
512
+ testDone()
497
513
  })
498
514
  })
499
515
 
500
- test('preParsing option should be able to supply statusCode', t => {
516
+ test('preParsing option should be able to supply statusCode', (t, testDone) => {
501
517
  t.plan(4)
502
518
  const fastify = Fastify()
503
519
 
@@ -514,10 +530,10 @@ test('preParsing option should be able to supply statusCode', t => {
514
530
  return stream
515
531
  },
516
532
  onError: async (req, res, err) => {
517
- t.equal(err.statusCode, 408)
533
+ t.assert.strictEqual(err.statusCode, 408)
518
534
  }
519
535
  }, (req, reply) => {
520
- t.fail('should not be called')
536
+ t.assert.fail('should not be called')
521
537
  })
522
538
 
523
539
  fastify.inject({
@@ -525,22 +541,23 @@ test('preParsing option should be able to supply statusCode', t => {
525
541
  url: '/only',
526
542
  payload: { hello: 'world' }
527
543
  }, (err, res) => {
528
- t.error(err)
529
- t.equal(res.statusCode, 408)
530
- t.same(JSON.parse(res.payload), {
544
+ t.assert.ifError(err)
545
+ t.assert.strictEqual(res.statusCode, 408)
546
+ t.assert.deepStrictEqual(JSON.parse(res.payload), {
531
547
  statusCode: 408,
532
548
  error: 'Request Timeout',
533
549
  message: 'kaboom'
534
550
  })
551
+ testDone()
535
552
  })
536
553
  })
537
554
 
538
- test('onRequest option should be called before preParsing', t => {
555
+ test('onRequest option should be called before preParsing', (t, testDone) => {
539
556
  t.plan(3)
540
557
  const fastify = Fastify()
541
558
 
542
559
  fastify.addHook('preParsing', (req, reply, payload, done) => {
543
- t.ok(req.called)
560
+ t.assert.ok(req.called)
544
561
  done()
545
562
  })
546
563
 
@@ -558,39 +575,41 @@ test('onRequest option should be called before preParsing', t => {
558
575
  url: '/',
559
576
  payload: { hello: 'world' }
560
577
  }, (err, res) => {
561
- t.error(err)
578
+ t.assert.ifError(err)
562
579
  const payload = JSON.parse(res.payload)
563
- t.same(payload, { hello: 'world' })
580
+ t.assert.deepStrictEqual(payload, { hello: 'world' })
581
+ testDone()
564
582
  })
565
583
  })
566
584
 
567
- test('onTimeout on route', t => {
585
+ test('onTimeout on route', (t, testDone) => {
568
586
  t.plan(4)
569
587
  const fastify = Fastify({ connectionTimeout: 500 })
570
588
 
571
589
  fastify.get('/timeout', {
572
590
  handler (request, reply) { },
573
591
  onTimeout (request, reply, done) {
574
- t.pass('onTimeout called')
592
+ t.assert.ok('onTimeout called')
575
593
  done()
576
594
  }
577
595
  })
578
596
 
579
597
  fastify.listen({ port: 0 }, (err, address) => {
580
- t.error(err)
581
- t.teardown(() => fastify.close())
598
+ t.assert.ifError(err)
599
+ t.after(() => fastify.close())
582
600
 
583
601
  sget({
584
602
  method: 'GET',
585
603
  url: `${address}/timeout`
586
604
  }, (err, response, body) => {
587
- t.type(err, Error)
588
- t.equal(err.message, 'socket hang up')
605
+ t.assert.ok(err instanceof Error)
606
+ t.assert.strictEqual(err.message, 'socket hang up')
607
+ testDone()
589
608
  })
590
609
  })
591
610
  })
592
611
 
593
- test('onError on route', t => {
612
+ test('onError on route', (t, testDone) => {
594
613
  t.plan(3)
595
614
 
596
615
  const fastify = Fastify()
@@ -600,7 +619,7 @@ test('onError on route', t => {
600
619
  fastify.get('/',
601
620
  {
602
621
  onError (request, reply, error, done) {
603
- t.match(error, err)
622
+ t.assert.deepStrictEqual(error, err)
604
623
  done()
605
624
  }
606
625
  },
@@ -609,11 +628,12 @@ test('onError on route', t => {
609
628
  })
610
629
 
611
630
  fastify.inject('/', (err, res) => {
612
- t.error(err)
613
- t.same(JSON.parse(res.payload), {
631
+ t.assert.ifError(err)
632
+ t.assert.deepStrictEqual(JSON.parse(res.payload), {
614
633
  error: 'Internal Server Error',
615
634
  message: 'kaboom',
616
635
  statusCode: 500
617
636
  })
637
+ testDone()
618
638
  })
619
639
  })