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,10 +1,10 @@
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 Fastify = require('..')
5
+ const { waitForCb } = require('./toolkit')
6
6
 
7
- test('Prefix options should add a prefix for all the routes inside a register / 1', t => {
7
+ test('Prefix options should add a prefix for all the routes inside a register / 1', (t, testDone) => {
8
8
  t.plan(6)
9
9
  const fastify = Fastify()
10
10
 
@@ -27,32 +27,37 @@ test('Prefix options should add a prefix for all the routes inside a register /
27
27
  done()
28
28
  }, { prefix: '/v1' })
29
29
 
30
+ const completion = waitForCb({ steps: 3 })
30
31
  fastify.inject({
31
32
  method: 'GET',
32
33
  url: '/first'
33
34
  }, (err, res) => {
34
- t.error(err)
35
- t.same(JSON.parse(res.payload), { route: '/first' })
35
+ t.assert.ifError(err)
36
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/first' })
37
+ completion.stepIn()
36
38
  })
37
39
 
38
40
  fastify.inject({
39
41
  method: 'GET',
40
42
  url: '/v1/first'
41
43
  }, (err, res) => {
42
- t.error(err)
43
- t.same(JSON.parse(res.payload), { route: '/v1/first' })
44
+ t.assert.ifError(err)
45
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/first' })
46
+ completion.stepIn()
44
47
  })
45
48
 
46
49
  fastify.inject({
47
50
  method: 'GET',
48
51
  url: '/v1/v2/first'
49
52
  }, (err, res) => {
50
- t.error(err)
51
- t.same(JSON.parse(res.payload), { route: '/v1/v2/first' })
53
+ t.assert.ifError(err)
54
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/v2/first' })
55
+ completion.stepIn()
52
56
  })
57
+ completion.patience.then(testDone)
53
58
  })
54
59
 
55
- test('Prefix options should add a prefix for all the routes inside a register / 2', t => {
60
+ test('Prefix options should add a prefix for all the routes inside a register / 2', (t, testDone) => {
56
61
  t.plan(4)
57
62
  const fastify = Fastify()
58
63
 
@@ -67,24 +72,27 @@ test('Prefix options should add a prefix for all the routes inside a register /
67
72
  done()
68
73
  }, { prefix: '/v1' })
69
74
 
75
+ const completion = waitForCb({ steps: 2 })
70
76
  fastify.inject({
71
77
  method: 'GET',
72
78
  url: '/v1/first'
73
79
  }, (err, res) => {
74
- t.error(err)
75
- t.same(JSON.parse(res.payload), { route: '/v1/first' })
80
+ t.assert.ifError(err)
81
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/first' })
82
+ completion.stepIn()
76
83
  })
77
-
78
84
  fastify.inject({
79
85
  method: 'GET',
80
86
  url: '/v1/second'
81
87
  }, (err, res) => {
82
- t.error(err)
83
- t.same(JSON.parse(res.payload), { route: '/v1/second' })
88
+ t.assert.ifError(err)
89
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/second' })
90
+ completion.stepIn()
84
91
  })
92
+ completion.patience.then(testDone)
85
93
  })
86
94
 
87
- test('Prefix options should add a prefix for all the chained routes inside a register / 3', t => {
95
+ test('Prefix options should add a prefix for all the chained routes inside a register / 3', (t, testDone) => {
88
96
  t.plan(4)
89
97
 
90
98
  const fastify = Fastify()
@@ -100,24 +108,27 @@ test('Prefix options should add a prefix for all the chained routes inside a reg
100
108
  done()
101
109
  }, { prefix: '/v1' })
102
110
 
111
+ const completion = waitForCb({ steps: 2 })
103
112
  fastify.inject({
104
113
  method: 'GET',
105
114
  url: '/v1/first'
106
115
  }, (err, res) => {
107
- t.error(err)
108
- t.same(JSON.parse(res.payload), { route: '/v1/first' })
116
+ t.assert.ifError(err)
117
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/first' })
118
+ completion.stepIn()
109
119
  })
110
-
111
120
  fastify.inject({
112
121
  method: 'GET',
113
122
  url: '/v1/second'
114
123
  }, (err, res) => {
115
- t.error(err)
116
- t.same(JSON.parse(res.payload), { route: '/v1/second' })
124
+ t.assert.ifError(err)
125
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/second' })
126
+ completion.stepIn()
117
127
  })
128
+ completion.patience.then(testDone)
118
129
  })
119
130
 
120
- test('Prefix should support parameters as well', t => {
131
+ test('Prefix should support parameters as well', (t, testDone) => {
121
132
  t.plan(2)
122
133
  const fastify = Fastify()
123
134
 
@@ -132,12 +143,13 @@ test('Prefix should support parameters as well', t => {
132
143
  method: 'GET',
133
144
  url: '/v1/param/hello'
134
145
  }, (err, res) => {
135
- t.error(err)
136
- t.same(JSON.parse(res.payload), { id: 'param' })
146
+ t.assert.ifError(err)
147
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { id: 'param' })
148
+ testDone()
137
149
  })
138
150
  })
139
151
 
140
- test('Prefix should support /', t => {
152
+ test('Prefix should support /', (t, testDone) => {
141
153
  t.plan(2)
142
154
  const fastify = Fastify()
143
155
 
@@ -152,12 +164,13 @@ test('Prefix should support /', t => {
152
164
  method: 'GET',
153
165
  url: '/v1'
154
166
  }, (err, res) => {
155
- t.error(err)
156
- t.same(JSON.parse(res.payload), { hello: 'world' })
167
+ t.assert.ifError(err)
168
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
169
+ testDone()
157
170
  })
158
171
  })
159
172
 
160
- test('Prefix without /', t => {
173
+ test('Prefix without /', (t, testDone) => {
161
174
  t.plan(2)
162
175
  const fastify = Fastify()
163
176
 
@@ -172,12 +185,13 @@ test('Prefix without /', t => {
172
185
  method: 'GET',
173
186
  url: '/v1'
174
187
  }, (err, res) => {
175
- t.error(err)
176
- t.same(JSON.parse(res.payload), { hello: 'world' })
188
+ t.assert.ifError(err)
189
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
190
+ testDone()
177
191
  })
178
192
  })
179
193
 
180
- test('Prefix with trailing /', t => {
194
+ test('Prefix with trailing /', (t, testDone) => {
181
195
  t.plan(6)
182
196
  const fastify = Fastify()
183
197
 
@@ -199,32 +213,35 @@ test('Prefix with trailing /', t => {
199
213
  done()
200
214
  }, { prefix: '/v1/' })
201
215
 
216
+ const completion = waitForCb({ steps: 3 })
202
217
  fastify.inject({
203
218
  method: 'GET',
204
219
  url: '/v1/route1'
205
220
  }, (err, res) => {
206
- t.error(err)
207
- t.same(JSON.parse(res.payload), { hello: 'world1' })
221
+ t.assert.ifError(err)
222
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world1' })
223
+ completion.stepIn()
208
224
  })
209
-
210
225
  fastify.inject({
211
226
  method: 'GET',
212
227
  url: '/v1/route2'
213
228
  }, (err, res) => {
214
- t.error(err)
215
- t.same(JSON.parse(res.payload), { hello: 'world2' })
229
+ t.assert.ifError(err)
230
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world2' })
231
+ completion.stepIn()
216
232
  })
217
-
218
233
  fastify.inject({
219
234
  method: 'GET',
220
235
  url: '/v1/inner/route3'
221
236
  }, (err, res) => {
222
- t.error(err)
223
- t.same(JSON.parse(res.payload), { hello: 'world3' })
237
+ t.assert.ifError(err)
238
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world3' })
239
+ completion.stepIn()
224
240
  })
241
+ completion.patience.then(testDone)
225
242
  })
226
243
 
227
- test('Prefix works multiple levels deep', t => {
244
+ test('Prefix works multiple levels deep', (t, testDone) => {
228
245
  t.plan(2)
229
246
  const fastify = Fastify()
230
247
 
@@ -248,12 +265,13 @@ test('Prefix works multiple levels deep', t => {
248
265
  method: 'GET',
249
266
  url: '/v1/v2/v3'
250
267
  }, (err, res) => {
251
- t.error(err)
252
- t.same(JSON.parse(res.payload), { hello: 'world' })
268
+ t.assert.ifError(err)
269
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
270
+ testDone()
253
271
  })
254
272
  })
255
273
 
256
- test('Different register - encapsulation check', t => {
274
+ test('Different register - encapsulation check', (t, testDone) => {
257
275
  t.plan(4)
258
276
  const fastify = Fastify()
259
277
 
@@ -281,24 +299,27 @@ test('Different register - encapsulation check', t => {
281
299
  done()
282
300
  }, { prefix: '/v3' })
283
301
 
302
+ const completion = waitForCb({ steps: 2 })
284
303
  fastify.inject({
285
304
  method: 'GET',
286
305
  url: '/v1/v2'
287
306
  }, (err, res) => {
288
- t.error(err)
289
- t.same(JSON.parse(res.payload), { route: '/v1/v2' })
307
+ t.assert.ifError(err)
308
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v1/v2' })
309
+ completion.stepIn()
290
310
  })
291
-
292
311
  fastify.inject({
293
312
  method: 'GET',
294
313
  url: '/v3/v4'
295
314
  }, (err, res) => {
296
- t.error(err)
297
- t.same(JSON.parse(res.payload), { route: '/v3/v4' })
315
+ t.assert.ifError(err)
316
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { route: '/v3/v4' })
317
+ completion.stepIn()
298
318
  })
319
+ completion.patience.then(testDone)
299
320
  })
300
321
 
301
- test('Can retrieve prefix within encapsulated instances', t => {
322
+ test('Can retrieve prefix within encapsulated instances', (t, testDone) => {
302
323
  t.plan(4)
303
324
  const fastify = Fastify()
304
325
 
@@ -317,24 +338,27 @@ test('Can retrieve prefix within encapsulated instances', t => {
317
338
  done()
318
339
  }, { prefix: '/v1' })
319
340
 
341
+ const completion = waitForCb({ steps: 2 })
320
342
  fastify.inject({
321
343
  method: 'GET',
322
344
  url: '/v1/one'
323
345
  }, (err, res) => {
324
- t.error(err)
325
- t.equal(res.payload, '/v1')
346
+ t.assert.ifError(err)
347
+ t.assert.deepStrictEqual(res.payload, '/v1')
348
+ completion.stepIn()
326
349
  })
327
-
328
350
  fastify.inject({
329
351
  method: 'GET',
330
352
  url: '/v1/v2/two'
331
353
  }, (err, res) => {
332
- t.error(err)
333
- t.equal(res.payload, '/v1/v2')
354
+ t.assert.ifError(err)
355
+ t.assert.deepStrictEqual(res.payload, '/v1/v2')
356
+ completion.stepIn()
334
357
  })
358
+ completion.patience.then(testDone)
335
359
  })
336
360
 
337
- test('matches both /prefix and /prefix/ with a / route', t => {
361
+ test('matches both /prefix and /prefix/ with a / route', (t, testDone) => {
338
362
  t.plan(4)
339
363
  const fastify = Fastify()
340
364
 
@@ -346,24 +370,27 @@ test('matches both /prefix and /prefix/ with a / route', t => {
346
370
  done()
347
371
  }, { prefix: '/prefix' })
348
372
 
373
+ const completion = waitForCb({ steps: 2 })
349
374
  fastify.inject({
350
375
  method: 'GET',
351
376
  url: '/prefix'
352
377
  }, (err, res) => {
353
- t.error(err)
354
- t.same(JSON.parse(res.payload), { hello: 'world' })
378
+ t.assert.ifError(err)
379
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
380
+ completion.stepIn()
355
381
  })
356
-
357
382
  fastify.inject({
358
383
  method: 'GET',
359
384
  url: '/prefix/'
360
385
  }, (err, res) => {
361
- t.error(err)
362
- t.same(JSON.parse(res.payload), { hello: 'world' })
386
+ t.assert.ifError(err)
387
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
388
+ completion.stepIn()
363
389
  })
390
+ completion.patience.then(testDone)
364
391
  })
365
392
 
366
- test('prefix "/prefix/" does not match "/prefix" with a / route', t => {
393
+ test('prefix "/prefix/" does not match "/prefix" with a / route', (t, testDone) => {
367
394
  t.plan(4)
368
395
  const fastify = Fastify()
369
396
 
@@ -375,24 +402,27 @@ test('prefix "/prefix/" does not match "/prefix" with a / route', t => {
375
402
  done()
376
403
  }, { prefix: '/prefix/' })
377
404
 
405
+ const completion = waitForCb({ steps: 2 })
378
406
  fastify.inject({
379
407
  method: 'GET',
380
408
  url: '/prefix'
381
409
  }, (err, res) => {
382
- t.error(err)
383
- t.equal(res.statusCode, 404)
410
+ t.assert.ifError(err)
411
+ t.assert.deepStrictEqual(res.statusCode, 404)
412
+ completion.stepIn()
384
413
  })
385
-
386
414
  fastify.inject({
387
415
  method: 'GET',
388
416
  url: '/prefix/'
389
417
  }, (err, res) => {
390
- t.error(err)
391
- t.same(JSON.parse(res.payload), { hello: 'world' })
418
+ t.assert.ifError(err)
419
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
420
+ completion.stepIn()
392
421
  })
422
+ completion.patience.then(testDone)
393
423
  })
394
424
 
395
- test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true', t => {
425
+ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true', (t, testDone) => {
396
426
  t.plan(4)
397
427
  const fastify = Fastify({
398
428
  ignoreTrailingSlash: true
@@ -406,24 +436,27 @@ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: tr
406
436
  done()
407
437
  }, { prefix: '/prefix' })
408
438
 
439
+ const completion = waitForCb({ steps: 2 })
409
440
  fastify.inject({
410
441
  method: 'GET',
411
442
  url: '/prefix'
412
443
  }, (err, res) => {
413
- t.error(err)
414
- t.same(JSON.parse(res.payload), { hello: 'world' })
444
+ t.assert.ifError(err)
445
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
446
+ completion.stepIn()
415
447
  })
416
-
417
448
  fastify.inject({
418
449
  method: 'GET',
419
450
  url: '/prefix/'
420
451
  }, (err, res) => {
421
- t.error(err)
422
- t.same(JSON.parse(res.payload), { hello: 'world' })
452
+ t.assert.ifError(err)
453
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
454
+ completion.stepIn()
423
455
  })
456
+ completion.patience.then(testDone)
424
457
  })
425
458
 
426
- test('matches both /prefix and /prefix/ with a / route - ignoreDuplicateSlashes: true', t => {
459
+ test('matches both /prefix and /prefix/ with a / route - ignoreDuplicateSlashes: true', (t, testDone) => {
427
460
  t.plan(4)
428
461
  const fastify = Fastify({
429
462
  ignoreDuplicateSlashes: true
@@ -437,24 +470,27 @@ test('matches both /prefix and /prefix/ with a / route - ignoreDuplicateSlashes:
437
470
  done()
438
471
  }, { prefix: '/prefix' })
439
472
 
473
+ const completion = waitForCb({ steps: 2 })
440
474
  fastify.inject({
441
475
  method: 'GET',
442
476
  url: '/prefix'
443
477
  }, (err, res) => {
444
- t.error(err)
445
- t.same(JSON.parse(res.payload), { hello: 'world' })
478
+ t.assert.ifError(err)
479
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
480
+ completion.stepIn()
446
481
  })
447
-
448
482
  fastify.inject({
449
483
  method: 'GET',
450
484
  url: '/prefix/'
451
485
  }, (err, res) => {
452
- t.error(err)
453
- t.same(JSON.parse(res.payload), { hello: 'world' })
486
+ t.assert.ifError(err)
487
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
488
+ completion.stepIn()
454
489
  })
490
+ completion.patience.then(testDone)
455
491
  })
456
492
 
457
- test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreTrailingSlash: false', t => {
493
+ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreTrailingSlash: false', (t, testDone) => {
458
494
  t.plan(4)
459
495
  const fastify = Fastify({
460
496
  ignoreTrailingSlash: false
@@ -473,24 +509,27 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
473
509
  done()
474
510
  }, { prefix: '/prefix' })
475
511
 
512
+ const completion = waitForCb({ steps: 2 })
476
513
  fastify.inject({
477
514
  method: 'GET',
478
515
  url: '/prefix'
479
516
  }, (err, res) => {
480
- t.error(err)
481
- t.same(JSON.parse(res.payload), { hello: 'world' })
517
+ t.assert.ifError(err)
518
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
519
+ completion.stepIn()
482
520
  })
483
-
484
521
  fastify.inject({
485
522
  method: 'GET',
486
523
  url: '/prefix/'
487
524
  }, (err, res) => {
488
- t.error(err)
489
- t.same(JSON.parse(res.payload), { hello: 'world' })
525
+ t.assert.ifError(err)
526
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
527
+ completion.stepIn()
490
528
  })
529
+ completion.patience.then(testDone)
491
530
  })
492
531
 
493
- test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: false', t => {
532
+ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: false', (t, testDone) => {
494
533
  t.plan(4)
495
534
  const fastify = Fastify({
496
535
  ignoreDuplicateSlashes: false
@@ -509,24 +548,27 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
509
548
  done()
510
549
  }, { prefix: '/prefix' })
511
550
 
551
+ const completion = waitForCb({ steps: 2 })
512
552
  fastify.inject({
513
553
  method: 'GET',
514
554
  url: '/prefix'
515
555
  }, (err, res) => {
516
- t.error(err)
517
- t.same(JSON.parse(res.payload), { hello: 'world' })
556
+ t.assert.ifError(err)
557
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
558
+ completion.stepIn()
518
559
  })
519
-
520
560
  fastify.inject({
521
561
  method: 'GET',
522
562
  url: '/prefix/'
523
563
  }, (err, res) => {
524
- t.error(err)
525
- t.same(JSON.parse(res.payload), { hello: 'world' })
564
+ t.assert.ifError(err)
565
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
566
+ completion.stepIn()
526
567
  })
568
+ completion.patience.then(testDone)
527
569
  })
528
570
 
529
- test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true, ignoreDuplicateSlashes: true', t => {
571
+ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true, ignoreDuplicateSlashes: true', (t, testDone) => {
530
572
  t.plan(4)
531
573
  const fastify = Fastify({
532
574
  ignoreTrailingSlash: true,
@@ -541,24 +583,27 @@ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: tr
541
583
  done()
542
584
  }, { prefix: '/prefix' })
543
585
 
586
+ const completion = waitForCb({ steps: 2 })
544
587
  fastify.inject({
545
588
  method: 'GET',
546
589
  url: '/prefix'
547
590
  }, (err, res) => {
548
- t.error(err)
549
- t.same(JSON.parse(res.payload), { hello: 'world' })
591
+ t.assert.ifError(err)
592
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
593
+ completion.stepIn()
550
594
  })
551
-
552
595
  fastify.inject({
553
596
  method: 'GET',
554
597
  url: '/prefix/'
555
598
  }, (err, res) => {
556
- t.error(err)
557
- t.same(JSON.parse(res.payload), { hello: 'world' })
599
+ t.assert.ifError(err)
600
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
601
+ completion.stepIn()
558
602
  })
603
+ completion.patience.then(testDone)
559
604
  })
560
605
 
561
- test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true, ignoreDuplicateSlashes: false', t => {
606
+ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: true, ignoreDuplicateSlashes: false', (t, testDone) => {
562
607
  t.plan(4)
563
608
  const fastify = Fastify({
564
609
  ignoreTrailingSlash: true,
@@ -573,24 +618,27 @@ test('matches both /prefix and /prefix/ with a / route - ignoreTrailingSlash: tr
573
618
  done()
574
619
  }, { prefix: '/prefix' })
575
620
 
621
+ const completion = waitForCb({ steps: 2 })
576
622
  fastify.inject({
577
623
  method: 'GET',
578
624
  url: '/prefix'
579
625
  }, (err, res) => {
580
- t.error(err)
581
- t.same(JSON.parse(res.payload), { hello: 'world' })
626
+ t.assert.ifError(err)
627
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
628
+ completion.stepIn()
582
629
  })
583
-
584
630
  fastify.inject({
585
631
  method: 'GET',
586
632
  url: '/prefix/'
587
633
  }, (err, res) => {
588
- t.error(err)
589
- t.same(JSON.parse(res.payload), { hello: 'world' })
634
+ t.assert.ifError(err)
635
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
636
+ completion.stepIn()
590
637
  })
638
+ completion.patience.then(testDone)
591
639
  })
592
640
 
593
- test('returns 404 status code with /prefix/ and / route - prefixTrailingSlash: "both" (default), ignoreTrailingSlash: true', t => {
641
+ test('returns 404 status code with /prefix/ and / route - prefixTrailingSlash: "both" (default), ignoreTrailingSlash: true', (t, testDone) => {
594
642
  t.plan(2)
595
643
  const fastify = Fastify({
596
644
  ignoreTrailingSlash: true
@@ -612,16 +660,17 @@ test('returns 404 status code with /prefix/ and / route - prefixTrailingSlash: "
612
660
  method: 'GET',
613
661
  url: '/prefix//'
614
662
  }, (err, res) => {
615
- t.error(err)
616
- t.same(JSON.parse(res.payload), {
663
+ t.assert.ifError(err)
664
+ t.assert.deepStrictEqual(JSON.parse(res.payload), {
617
665
  error: 'Not Found',
618
666
  message: 'Route GET:/prefix// not found',
619
667
  statusCode: 404
620
668
  })
669
+ testDone()
621
670
  })
622
671
  })
623
672
 
624
- test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: true', t => {
673
+ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: true', (t, testDone) => {
625
674
  t.plan(2)
626
675
  const fastify = Fastify({
627
676
  ignoreDuplicateSlashes: true
@@ -643,12 +692,13 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
643
692
  method: 'GET',
644
693
  url: '/prefix//'
645
694
  }, (err, res) => {
646
- t.error(err)
647
- t.same(JSON.parse(res.payload), { hello: 'world' })
695
+ t.assert.ifError(err)
696
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
697
+ testDone()
648
698
  })
649
699
  })
650
700
 
651
- test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreTrailingSlash: true, ignoreDuplicateSlashes: true', t => {
701
+ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreTrailingSlash: true, ignoreDuplicateSlashes: true', (t, testDone) => {
652
702
  t.plan(2)
653
703
  const fastify = Fastify({
654
704
  ignoreTrailingSlash: true,
@@ -671,12 +721,13 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
671
721
  method: 'GET',
672
722
  url: '/prefix//'
673
723
  }, (err, res) => {
674
- t.error(err)
675
- t.same(JSON.parse(res.payload), { hello: 'world' })
724
+ t.assert.ifError(err)
725
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
726
+ testDone()
676
727
  })
677
728
  })
678
729
 
679
- test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: true', t => {
730
+ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "both", ignoreDuplicateSlashes: true', (t, testDone) => {
680
731
  t.plan(2)
681
732
  const fastify = Fastify({
682
733
  ignoreTrailingSlash: true,
@@ -699,12 +750,13 @@ test('matches both /prefix and /prefix/ with a / route - prefixTrailingSlash: "
699
750
  method: 'GET',
700
751
  url: '/prefix//'
701
752
  }, (err, res) => {
702
- t.error(err)
703
- t.same(JSON.parse(res.payload), { hello: 'world' })
753
+ t.assert.ifError(err)
754
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
755
+ testDone()
704
756
  })
705
757
  })
706
758
 
707
- test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ignoreTrailingSlash: false', t => {
759
+ test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ignoreTrailingSlash: false', (t, testDone) => {
708
760
  t.plan(4)
709
761
  const fastify = Fastify({
710
762
  ignoreTrailingSlash: false
@@ -723,24 +775,27 @@ test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ig
723
775
  done()
724
776
  }, { prefix: '/prefix' })
725
777
 
778
+ const completion = waitForCb({ steps: 2 })
726
779
  fastify.inject({
727
780
  method: 'GET',
728
781
  url: '/prefix'
729
782
  }, (err, res) => {
730
- t.error(err)
731
- t.same(JSON.parse(res.payload), { hello: 'world' })
783
+ t.assert.ifError(err)
784
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
785
+ completion.stepIn()
732
786
  })
733
-
734
787
  fastify.inject({
735
788
  method: 'GET',
736
789
  url: '/prefix/'
737
790
  }, (err, res) => {
738
- t.error(err)
739
- t.equal(JSON.parse(res.payload).statusCode, 404)
791
+ t.assert.ifError(err)
792
+ t.assert.deepStrictEqual(JSON.parse(res.payload).statusCode, 404)
793
+ completion.stepIn()
740
794
  })
795
+ completion.patience.then(testDone)
741
796
  })
742
797
 
743
- test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ignoreDuplicateSlashes: false', t => {
798
+ test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ignoreDuplicateSlashes: false', (t, testDone) => {
744
799
  t.plan(4)
745
800
  const fastify = Fastify({
746
801
  ignoreDuplicateSlashes: false
@@ -759,24 +814,27 @@ test('matches only /prefix with a / route - prefixTrailingSlash: "no-slash", ig
759
814
  done()
760
815
  }, { prefix: '/prefix' })
761
816
 
817
+ const completion = waitForCb({ steps: 2 })
762
818
  fastify.inject({
763
819
  method: 'GET',
764
820
  url: '/prefix'
765
821
  }, (err, res) => {
766
- t.error(err)
767
- t.same(JSON.parse(res.payload), { hello: 'world' })
822
+ t.assert.ifError(err)
823
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
824
+ completion.stepIn()
768
825
  })
769
-
770
826
  fastify.inject({
771
827
  method: 'GET',
772
828
  url: '/prefix/'
773
829
  }, (err, res) => {
774
- t.error(err)
775
- t.equal(JSON.parse(res.payload).statusCode, 404)
830
+ t.assert.ifError(err)
831
+ t.assert.deepStrictEqual(JSON.parse(res.payload).statusCode, 404)
832
+ completion.stepIn()
776
833
  })
834
+ completion.patience.then(testDone)
777
835
  })
778
836
 
779
- test('matches only /prefix/ with a / route - prefixTrailingSlash: "slash", ignoreTrailingSlash: false', t => {
837
+ test('matches only /prefix/ with a / route - prefixTrailingSlash: "slash", ignoreTrailingSlash: false', (t, testDone) => {
780
838
  t.plan(4)
781
839
  const fastify = Fastify({
782
840
  ignoreTrailingSlash: false
@@ -795,21 +853,24 @@ test('matches only /prefix/ with a / route - prefixTrailingSlash: "slash", igno
795
853
  done()
796
854
  }, { prefix: '/prefix' })
797
855
 
856
+ const completion = waitForCb({ steps: 2 })
798
857
  fastify.inject({
799
858
  method: 'GET',
800
859
  url: '/prefix/'
801
860
  }, (err, res) => {
802
- t.error(err)
803
- t.same(JSON.parse(res.payload), { hello: 'world' })
861
+ t.assert.ifError(err)
862
+ t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'world' })
863
+ completion.stepIn()
804
864
  })
805
-
806
865
  fastify.inject({
807
866
  method: 'GET',
808
867
  url: '/prefix'
809
868
  }, (err, res) => {
810
- t.error(err)
811
- t.equal(JSON.parse(res.payload).statusCode, 404)
869
+ t.assert.ifError(err)
870
+ t.assert.deepStrictEqual(JSON.parse(res.payload).statusCode, 404)
871
+ completion.stepIn()
812
872
  })
873
+ completion.patience.then(testDone)
813
874
  })
814
875
 
815
876
  test('calls onRoute only once when prefixing', async t => {
@@ -839,5 +900,5 @@ test('calls onRoute only once when prefixing', async t => {
839
900
 
840
901
  await fastify.ready()
841
902
 
842
- t.same(onRouteCalled, 1)
903
+ t.assert.deepStrictEqual(onRouteCalled, 1)
843
904
  })