fastify 3.9.2 → 3.12.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 (92) hide show
  1. package/GOVERNANCE.md +1 -1
  2. package/README.md +12 -8
  3. package/SECURITY.md +3 -3
  4. package/docs/ContentTypeParser.md +1 -1
  5. package/docs/Ecosystem.md +16 -6
  6. package/docs/Encapsulation.md +5 -2
  7. package/docs/Fluent-Schema.md +4 -4
  8. package/docs/Getting-Started.md +1 -1
  9. package/docs/Hooks.md +28 -1
  10. package/docs/Lifecycle.md +8 -1
  11. package/docs/Middleware.md +5 -4
  12. package/docs/Reply.md +13 -4
  13. package/docs/Routes.md +4 -3
  14. package/docs/Server.md +78 -4
  15. package/docs/Serverless.md +23 -51
  16. package/docs/TypeScript.md +35 -18
  17. package/docs/Validation-and-Serialization.md +4 -4
  18. package/docs/Write-Plugin.md +4 -4
  19. package/examples/hooks-benchmark.js +12 -12
  20. package/examples/hooks.js +16 -16
  21. package/examples/plugin.js +2 -2
  22. package/examples/route-prefix.js +4 -4
  23. package/fastify.d.ts +16 -1
  24. package/fastify.js +33 -16
  25. package/isolate-0x426d1e0-1227-v8.log +4019 -0
  26. package/isolate-0x4d4c7e0-1988-v8.log +4081 -0
  27. package/lib/errors.js +6 -0
  28. package/lib/headRoute.js +31 -0
  29. package/lib/pluginOverride.js +5 -5
  30. package/lib/pluginUtils.js +7 -6
  31. package/lib/reply.js +14 -2
  32. package/lib/reqIdGenFactory.js +5 -0
  33. package/lib/request.js +1 -1
  34. package/lib/route.js +66 -41
  35. package/lib/schema-compilers.js +5 -3
  36. package/lib/schema-controller.js +106 -0
  37. package/lib/schemas.js +14 -24
  38. package/lib/server.js +1 -0
  39. package/lib/symbols.js +1 -3
  40. package/lib/warnings.js +2 -0
  41. package/lib/wrapThenable.js +2 -1
  42. package/package.json +25 -21
  43. package/test/404s.test.js +120 -120
  44. package/test/500s.test.js +8 -8
  45. package/test/async-await.test.js +29 -1
  46. package/test/close.test.js +8 -8
  47. package/test/context-config.test.js +52 -0
  48. package/test/custom-parser.test.js +8 -8
  49. package/test/decorator.test.js +49 -49
  50. package/test/default-route.test.js +43 -0
  51. package/test/fastify-instance.test.js +2 -2
  52. package/test/fluent-schema.test.js +3 -3
  53. package/test/handler-context.test.js +2 -2
  54. package/test/hooks-async.test.js +3 -3
  55. package/test/hooks.on-ready.test.js +12 -12
  56. package/test/hooks.test.js +75 -32
  57. package/test/http2/closing.test.js +23 -1
  58. package/test/inject.test.js +6 -6
  59. package/test/input-validation.js +2 -2
  60. package/test/internals/hookRunner.test.js +50 -50
  61. package/test/internals/reply.test.js +47 -22
  62. package/test/internals/request.test.js +3 -9
  63. package/test/internals/version.test.js +2 -2
  64. package/test/logger.test.js +30 -30
  65. package/test/middleware.test.js +4 -4
  66. package/test/plugin.helper.js +2 -2
  67. package/test/plugin.test.js +154 -99
  68. package/test/register.test.js +11 -11
  69. package/test/request-error.test.js +2 -2
  70. package/test/route-hooks.test.js +24 -24
  71. package/test/route-prefix.test.js +81 -52
  72. package/test/route.test.js +568 -0
  73. package/test/schema-feature.test.js +168 -38
  74. package/test/schema-serialization.test.js +4 -4
  75. package/test/schema-special-usage.test.js +136 -0
  76. package/test/schema-validation.test.js +7 -7
  77. package/test/skip-reply-send.test.js +315 -0
  78. package/test/stream.test.js +6 -6
  79. package/test/throw.test.js +4 -4
  80. package/test/types/instance.test-d.ts +5 -3
  81. package/test/types/plugin.test-d.ts +7 -7
  82. package/test/types/reply.test-d.ts +1 -0
  83. package/test/types/schema.test-d.ts +15 -0
  84. package/test/validation-error-handling.test.js +5 -5
  85. package/test/versioned-routes.test.js +1 -1
  86. package/types/content-type-parser.d.ts +1 -1
  87. package/types/instance.d.ts +6 -3
  88. package/types/plugin.d.ts +1 -1
  89. package/types/reply.d.ts +1 -0
  90. package/types/route.d.ts +8 -2
  91. package/types/schema.d.ts +3 -0
  92. package/test/skip-reply-send.js +0 -98
@@ -33,19 +33,19 @@ test('plugin metadata - ignore prefix', t => {
33
33
  t.equals(res.payload, 'hello')
34
34
  })
35
35
 
36
- function plugin (instance, opts, next) {
36
+ function plugin (instance, opts, done) {
37
37
  instance.get('/', function (request, reply) {
38
38
  reply.send('hello')
39
39
  })
40
- next()
40
+ done()
41
41
  }
42
42
  })
43
43
 
44
- test('fastify.register with fastify-plugin should not incapsulate his code', t => {
44
+ test('fastify.register with fastify-plugin should not encapsulate his code', t => {
45
45
  t.plan(10)
46
46
  const fastify = Fastify()
47
47
 
48
- fastify.register((instance, opts, next) => {
48
+ fastify.register((instance, opts, done) => {
49
49
  instance.register(fp((i, o, n) => {
50
50
  i.decorate('test', () => {})
51
51
  t.ok(i.test)
@@ -64,7 +64,7 @@ test('fastify.register with fastify-plugin should not incapsulate his code', t =
64
64
  reply.send({ hello: 'world' })
65
65
  })
66
66
 
67
- next()
67
+ done()
68
68
  })
69
69
 
70
70
  fastify.ready(() => {
@@ -91,7 +91,7 @@ test('fastify.register with fastify-plugin should provide access to external fas
91
91
  t.plan(22)
92
92
  const fastify = Fastify()
93
93
 
94
- fastify.register((instance, opts, next) => {
94
+ fastify.register((instance, opts, done) => {
95
95
  instance.register(fp((i, o, n) => {
96
96
  i.decorate('global', () => {})
97
97
  t.ok(i.global)
@@ -143,7 +143,7 @@ test('fastify.register with fastify-plugin should provide access to external fas
143
143
  t.notOk(instance.local)
144
144
  })
145
145
 
146
- next()
146
+ done()
147
147
  })
148
148
 
149
149
  fastify.ready(() => {
@@ -170,20 +170,20 @@ test('fastify.register with fastify-plugin registers root level plugins', t => {
170
170
  t.plan(15)
171
171
  const fastify = Fastify()
172
172
 
173
- function rootPlugin (instance, opts, next) {
173
+ function rootPlugin (instance, opts, done) {
174
174
  instance.decorate('test', 'first')
175
175
  t.ok(instance.test)
176
- next()
176
+ done()
177
177
  }
178
178
 
179
- function innerPlugin (instance, opts, next) {
179
+ function innerPlugin (instance, opts, done) {
180
180
  instance.decorate('test2', 'second')
181
- next()
181
+ done()
182
182
  }
183
183
 
184
184
  fastify.register(fp(rootPlugin))
185
185
 
186
- fastify.register((instance, opts, next) => {
186
+ fastify.register((instance, opts, done) => {
187
187
  t.ok(instance.test)
188
188
  instance.register(fp(innerPlugin))
189
189
 
@@ -192,7 +192,7 @@ test('fastify.register with fastify-plugin registers root level plugins', t => {
192
192
  reply.send({ test2: instance.test2 })
193
193
  })
194
194
 
195
- next()
195
+ done()
196
196
  })
197
197
 
198
198
  fastify.ready(() => {
@@ -235,7 +235,7 @@ test('check dependencies - should not throw', t => {
235
235
  t.plan(12)
236
236
  const fastify = Fastify()
237
237
 
238
- fastify.register((instance, opts, next) => {
238
+ fastify.register((instance, opts, done) => {
239
239
  instance.register(fp((i, o, n) => {
240
240
  i.decorate('test', () => {})
241
241
  t.ok(i.test)
@@ -259,7 +259,7 @@ test('check dependencies - should not throw', t => {
259
259
  reply.send({ hello: 'world' })
260
260
  })
261
261
 
262
- next()
262
+ done()
263
263
  })
264
264
 
265
265
  fastify.ready(() => {
@@ -287,7 +287,7 @@ test('check dependencies - should throw', t => {
287
287
  t.plan(12)
288
288
  const fastify = Fastify()
289
289
 
290
- fastify.register((instance, opts, next) => {
290
+ fastify.register((instance, opts, done) => {
291
291
  instance.register(fp((i, o, n) => {
292
292
  try {
293
293
  i.decorate('otherTest', () => {}, ['test'])
@@ -312,7 +312,7 @@ test('check dependencies - should throw', t => {
312
312
  reply.send({ hello: 'world' })
313
313
  })
314
314
 
315
- next()
315
+ done()
316
316
  })
317
317
 
318
318
  fastify.ready(() => {
@@ -339,22 +339,22 @@ test('set the plugin name based on the plugin displayName symbol', t => {
339
339
  t.plan(5)
340
340
  const fastify = Fastify()
341
341
 
342
- fastify.register(fp((fastify, opts, next) => {
342
+ fastify.register(fp((fastify, opts, done) => {
343
343
  t.strictEqual(fastify.pluginName, 'plugin-A')
344
- fastify.register(fp((fastify, opts, next) => {
344
+ fastify.register(fp((fastify, opts, done) => {
345
345
  t.strictEqual(fastify.pluginName, 'plugin-A -> plugin-AB')
346
- next()
346
+ done()
347
347
  }, { name: 'plugin-AB' }))
348
- fastify.register(fp((fastify, opts, next) => {
348
+ fastify.register(fp((fastify, opts, done) => {
349
349
  t.strictEqual(fastify.pluginName, 'plugin-A -> plugin-AB -> plugin-AC')
350
- next()
350
+ done()
351
351
  }, { name: 'plugin-AC' }))
352
- next()
352
+ done()
353
353
  }, { name: 'plugin-A' }))
354
354
 
355
- fastify.register(fp((fastify, opts, next) => {
355
+ fastify.register(fp((fastify, opts, done) => {
356
356
  t.strictEqual(fastify.pluginName, 'plugin-A -> plugin-AB -> plugin-AC -> plugin-B')
357
- next()
357
+ done()
358
358
  }, { name: 'plugin-B' }))
359
359
 
360
360
  fastify.listen(0, err => {
@@ -367,16 +367,16 @@ test('plugin name will change when using no encapsulation', t => {
367
367
  t.plan(5)
368
368
  const fastify = Fastify()
369
369
 
370
- fastify.register(fp((fastify, opts, next) => {
370
+ fastify.register(fp((fastify, opts, done) => {
371
371
  // store it in a different variable will hold the correct name
372
372
  const pluginName = fastify.pluginName
373
- fastify.register(fp((fastify, opts, next) => {
373
+ fastify.register(fp((fastify, opts, done) => {
374
374
  t.strictEqual(fastify.pluginName, 'plugin-A -> plugin-AB')
375
- next()
375
+ done()
376
376
  }, { name: 'plugin-AB' }))
377
- fastify.register(fp((fastify, opts, next) => {
377
+ fastify.register(fp((fastify, opts, done) => {
378
378
  t.strictEqual(fastify.pluginName, 'plugin-A -> plugin-AB -> plugin-AC')
379
- next()
379
+ done()
380
380
  }, { name: 'plugin-AC' }))
381
381
  setImmediate(() => {
382
382
  // normally we would expect the name plugin-A
@@ -384,7 +384,7 @@ test('plugin name will change when using no encapsulation', t => {
384
384
  t.strictEqual(fastify.pluginName, 'plugin-A -> plugin-AB -> plugin-AC')
385
385
  t.strictEqual(pluginName, 'plugin-A')
386
386
  })
387
- next()
387
+ done()
388
388
  }, { name: 'plugin-A' }))
389
389
 
390
390
  fastify.listen(0, err => {
@@ -409,22 +409,22 @@ test('set the plugin name based on the plugin function name', t => {
409
409
  t.plan(5)
410
410
  const fastify = Fastify()
411
411
 
412
- fastify.register(function myPluginA (fastify, opts, next) {
412
+ fastify.register(function myPluginA (fastify, opts, done) {
413
413
  t.strictEqual(fastify.pluginName, 'myPluginA')
414
- fastify.register(function myPluginAB (fastify, opts, next) {
414
+ fastify.register(function myPluginAB (fastify, opts, done) {
415
415
  t.strictEqual(fastify.pluginName, 'myPluginAB')
416
- next()
416
+ done()
417
417
  })
418
418
  setImmediate(() => {
419
419
  // exact name due to encapsulation
420
420
  t.strictEqual(fastify.pluginName, 'myPluginA')
421
421
  })
422
- next()
422
+ done()
423
423
  })
424
424
 
425
- fastify.register(function myPluginB (fastify, opts, next) {
425
+ fastify.register(function myPluginB (fastify, opts, done) {
426
426
  t.strictEqual(fastify.pluginName, 'myPluginB')
427
- next()
427
+ done()
428
428
  })
429
429
 
430
430
  fastify.listen(0, err => {
@@ -437,21 +437,21 @@ test('approximate a plugin name when no meta data is available', t => {
437
437
  t.plan(7)
438
438
  const fastify = Fastify()
439
439
 
440
- fastify.register((fastify, opts, next) => {
440
+ fastify.register((fastify, opts, done) => {
441
441
  // A
442
- t.is(fastify.pluginName.startsWith('(fastify, opts, next)'), true)
442
+ t.is(fastify.pluginName.startsWith('(fastify, opts, done)'), true)
443
443
  t.is(fastify.pluginName.includes('// A'), true)
444
- fastify.register((fastify, opts, next) => {
444
+ fastify.register((fastify, opts, done) => {
445
445
  // B
446
- t.is(fastify.pluginName.startsWith('(fastify, opts, next)'), true)
446
+ t.is(fastify.pluginName.startsWith('(fastify, opts, done)'), true)
447
447
  t.is(fastify.pluginName.includes('// B'), true)
448
- next()
448
+ done()
449
449
  })
450
450
  setImmediate(() => {
451
- t.is(fastify.pluginName.startsWith('(fastify, opts, next)'), true)
451
+ t.is(fastify.pluginName.startsWith('(fastify, opts, done)'), true)
452
452
  t.is(fastify.pluginName.includes('// A'), true)
453
453
  })
454
- next()
454
+ done()
455
455
  })
456
456
 
457
457
  fastify.listen(0, err => {
@@ -464,17 +464,17 @@ test('approximate a plugin name also when fastify-plugin has no meta data', t =>
464
464
  t.plan(4)
465
465
  const fastify = Fastify()
466
466
 
467
- fastify.register(fp((fastify, opts, next) => {
467
+ fastify.register(fp((fastify, opts, done) => {
468
468
  t.match(fastify.pluginName, /plugin\.test/)
469
- fastify.register(fp(function B (fastify, opts, next) {
469
+ fastify.register(fp(function B (fastify, opts, done) {
470
470
  // function has name
471
471
  t.match(fastify.pluginName, /plugin\.test-auto-\d+ -> B/)
472
- next()
472
+ done()
473
473
  }))
474
474
  setImmediate(() => {
475
475
  t.match(fastify.pluginName, /plugin\.test-auto-\d+ -> B/)
476
476
  })
477
- next()
477
+ done()
478
478
  }))
479
479
 
480
480
  fastify.listen(0, err => {
@@ -483,11 +483,11 @@ test('approximate a plugin name also when fastify-plugin has no meta data', t =>
483
483
  })
484
484
  })
485
485
 
486
- test('plugin incapsulation', t => {
486
+ test('plugin encapsulation', t => {
487
487
  t.plan(10)
488
488
  const fastify = Fastify()
489
489
 
490
- fastify.register((instance, opts, next) => {
490
+ fastify.register((instance, opts, done) => {
491
491
  instance.register(fp((i, o, n) => {
492
492
  i.decorate('test', 'first')
493
493
  n()
@@ -497,10 +497,10 @@ test('plugin incapsulation', t => {
497
497
  reply.send({ plugin: instance.test })
498
498
  })
499
499
 
500
- next()
500
+ done()
501
501
  })
502
502
 
503
- fastify.register((instance, opts, next) => {
503
+ fastify.register((instance, opts, done) => {
504
504
  instance.register(fp((i, o, n) => {
505
505
  i.decorate('test', 'second')
506
506
  n()
@@ -510,7 +510,7 @@ test('plugin incapsulation', t => {
510
510
  reply.send({ plugin: instance.test })
511
511
  })
512
512
 
513
- next()
513
+ done()
514
514
  })
515
515
 
516
516
  fastify.ready(() => {
@@ -547,8 +547,8 @@ test('if a plugin raises an error and there is not a callback to handle it, the
547
547
  t.plan(2)
548
548
  const fastify = Fastify()
549
549
 
550
- fastify.register((instance, opts, next) => {
551
- next(new Error('err'))
550
+ fastify.register((instance, opts, done) => {
551
+ done(new Error('err'))
552
552
  })
553
553
 
554
554
  fastify.listen(0, err => {
@@ -561,37 +561,37 @@ test('add hooks after route declaration', t => {
561
561
  t.plan(3)
562
562
  const fastify = Fastify()
563
563
 
564
- function plugin (instance, opts, next) {
564
+ function plugin (instance, opts, done) {
565
565
  instance.decorateRequest('check', null)
566
- instance.addHook('onRequest', (req, reply, next) => {
566
+ instance.addHook('onRequest', (req, reply, done) => {
567
567
  req.check = {}
568
- next()
568
+ done()
569
569
  })
570
- setImmediate(next)
570
+ setImmediate(done)
571
571
  }
572
572
  fastify.register(fp(plugin))
573
573
 
574
- fastify.register((instance, options, next) => {
575
- instance.addHook('preHandler', function b (req, res, next) {
574
+ fastify.register((instance, options, done) => {
575
+ instance.addHook('preHandler', function b (req, res, done) {
576
576
  req.check.hook2 = true
577
- next()
577
+ done()
578
578
  })
579
579
 
580
580
  instance.get('/', (req, reply) => {
581
581
  reply.send(req.check)
582
582
  })
583
583
 
584
- instance.addHook('preHandler', function c (req, res, next) {
584
+ instance.addHook('preHandler', function c (req, res, done) {
585
585
  req.check.hook3 = true
586
- next()
586
+ done()
587
587
  })
588
588
 
589
- next()
589
+ done()
590
590
  })
591
591
 
592
- fastify.addHook('preHandler', function a (req, res, next) {
592
+ fastify.addHook('preHandler', function a (req, res, done) {
593
593
  req.check.hook1 = true
594
- next()
594
+ done()
595
595
  })
596
596
 
597
597
  fastify.listen(0, err => {
@@ -615,22 +615,22 @@ test('nested plugins', t => {
615
615
 
616
616
  t.tearDown(fastify.close.bind(fastify))
617
617
 
618
- fastify.register(function (fastify, opts, next) {
619
- fastify.register((fastify, opts, next) => {
618
+ fastify.register(function (fastify, opts, done) {
619
+ fastify.register((fastify, opts, done) => {
620
620
  fastify.get('/', function (req, reply) {
621
621
  reply.send('I am child 1')
622
622
  })
623
- next()
623
+ done()
624
624
  }, { prefix: '/child1' })
625
625
 
626
- fastify.register((fastify, opts, next) => {
626
+ fastify.register((fastify, opts, done) => {
627
627
  fastify.get('/', function (req, reply) {
628
628
  reply.send('I am child 2')
629
629
  })
630
- next()
630
+ done()
631
631
  }, { prefix: '/child2' })
632
632
 
633
- next()
633
+ done()
634
634
  }, { prefix: '/parent' })
635
635
 
636
636
  fastify.listen(0, err => {
@@ -719,9 +719,64 @@ test('plugin metadata - decorators', t => {
719
719
  t.ok(fastify.plugin)
720
720
  })
721
721
 
722
- function plugin (instance, opts, next) {
722
+ function plugin (instance, opts, done) {
723
723
  instance.decorate('plugin', true)
724
- next()
724
+ done()
725
+ }
726
+ })
727
+
728
+ test('plugin metadata - decorators - should throw', t => {
729
+ t.plan(1)
730
+ const fastify = Fastify()
731
+
732
+ fastify.decorate('plugin1', true)
733
+ fastify.decorateReply('plugin1', true)
734
+
735
+ plugin[Symbol.for('skip-override')] = true
736
+ plugin[Symbol.for('plugin-meta')] = {
737
+ decorators: {
738
+ fastify: ['plugin1'],
739
+ reply: ['plugin1'],
740
+ request: ['plugin1']
741
+ }
742
+ }
743
+
744
+ fastify.register(plugin)
745
+ fastify.ready((err) => {
746
+ t.equals(err.message, "The decorator 'plugin1' is not present in Request")
747
+ })
748
+
749
+ function plugin (instance, opts, done) {
750
+ instance.decorate('plugin', true)
751
+ done()
752
+ }
753
+ })
754
+
755
+ test('plugin metadata - decorators - should throw with plugin name', t => {
756
+ t.plan(1)
757
+ const fastify = Fastify()
758
+
759
+ fastify.decorate('plugin1', true)
760
+ fastify.decorateReply('plugin1', true)
761
+
762
+ plugin[Symbol.for('skip-override')] = true
763
+ plugin[Symbol.for('plugin-meta')] = {
764
+ name: 'the-plugin',
765
+ decorators: {
766
+ fastify: ['plugin1'],
767
+ reply: ['plugin1'],
768
+ request: ['plugin1']
769
+ }
770
+ }
771
+
772
+ fastify.register(plugin)
773
+ fastify.ready((err) => {
774
+ t.equals(err.message, "The decorator 'plugin1' required by 'the-plugin' is not present in Request")
775
+ })
776
+
777
+ function plugin (instance, opts, done) {
778
+ instance.decorate('plugin', true)
779
+ done()
725
780
  }
726
781
  })
727
782
 
@@ -746,12 +801,12 @@ test('plugin metadata - dependencies', t => {
746
801
  t.pass('everything right')
747
802
  })
748
803
 
749
- function dependency (instance, opts, next) {
750
- next()
804
+ function dependency (instance, opts, done) {
805
+ done()
751
806
  }
752
807
 
753
- function plugin (instance, opts, next) {
754
- next()
808
+ function plugin (instance, opts, done) {
809
+ done()
755
810
  }
756
811
  })
757
812
 
@@ -776,17 +831,17 @@ test('plugin metadata - dependencies (nested)', t => {
776
831
  t.pass('everything right')
777
832
  })
778
833
 
779
- function dependency (instance, opts, next) {
780
- next()
834
+ function dependency (instance, opts, done) {
835
+ done()
781
836
  }
782
837
 
783
- function plugin (instance, opts, next) {
838
+ function plugin (instance, opts, done) {
784
839
  instance.register(nested)
785
- next()
840
+ done()
786
841
  }
787
842
 
788
- function nested (instance, opts, next) {
789
- next()
843
+ function nested (instance, opts, done) {
844
+ done()
790
845
  }
791
846
  })
792
847
 
@@ -795,8 +850,8 @@ test('pluginTimeout', t => {
795
850
  const fastify = Fastify({
796
851
  pluginTimeout: 10
797
852
  })
798
- fastify.register(function (app, opts, next) {
799
- // to no call next on purpose
853
+ fastify.register(function (app, opts, done) {
854
+ // to no call done on purpose
800
855
  })
801
856
  fastify.ready((err) => {
802
857
  t.ok(err)
@@ -809,8 +864,8 @@ test('pluginTimeout default', t => {
809
864
  const clock = fakeTimer.install()
810
865
 
811
866
  const fastify = Fastify()
812
- fastify.register(function (app, opts, next) {
813
- // default time elapsed without calling next
867
+ fastify.register(function (app, opts, done) {
868
+ // default time elapsed without calling done
814
869
  clock.tick(10000)
815
870
  })
816
871
 
@@ -838,8 +893,8 @@ test('plugin metadata - version', t => {
838
893
  t.pass('everything right')
839
894
  })
840
895
 
841
- function plugin (instance, opts, next) {
842
- next()
896
+ function plugin (instance, opts, done) {
897
+ done()
843
898
  }
844
899
  })
845
900
 
@@ -859,8 +914,8 @@ test('plugin metadata - version range', t => {
859
914
  t.pass('everything right')
860
915
  })
861
916
 
862
- function plugin (instance, opts, next) {
863
- next()
917
+ function plugin (instance, opts, done) {
918
+ done()
864
919
  }
865
920
  })
866
921
 
@@ -881,8 +936,8 @@ test('plugin metadata - version not matching requirement', t => {
881
936
  t.equal(err.code, 'FST_ERR_PLUGIN_VERSION_MISMATCH')
882
937
  })
883
938
 
884
- function plugin (instance, opts, next) {
885
- next()
939
+ function plugin (instance, opts, done) {
940
+ done()
886
941
  }
887
942
  })
888
943
 
@@ -903,8 +958,8 @@ test('plugin metadata - version not matching requirement 2', t => {
903
958
  t.equal(err.code, 'FST_ERR_PLUGIN_VERSION_MISMATCH')
904
959
  })
905
960
 
906
- function plugin (instance, opts, next) {
907
- next()
961
+ function plugin (instance, opts, done) {
962
+ done()
908
963
  }
909
964
  })
910
965
 
@@ -925,7 +980,7 @@ test('plugin metadata - version not matching requirement 3', t => {
925
980
  t.equal(err.code, 'FST_ERR_PLUGIN_VERSION_MISMATCH')
926
981
  })
927
982
 
928
- function plugin (instance, opts, next) {
929
- next()
983
+ function plugin (instance, opts, done) {
984
+ done()
930
985
  }
931
986
  })
@@ -59,12 +59,12 @@ test('register', t => {
59
59
  }
60
60
  })
61
61
 
62
- test('internal route declaration should pass the error generated by the register to the next handler / 1', t => {
62
+ test('internal route declaration should pass the error generated by the register to the done handler / 1', t => {
63
63
  t.plan(1)
64
64
  const fastify = Fastify()
65
65
 
66
- fastify.register((instance, opts, next) => {
67
- next(new Error('kaboom'))
66
+ fastify.register((instance, opts, done) => {
67
+ done(new Error('kaboom'))
68
68
  })
69
69
 
70
70
  fastify.get('/', (req, reply) => {
@@ -77,12 +77,12 @@ test('internal route declaration should pass the error generated by the register
77
77
  })
78
78
  })
79
79
 
80
- test('internal route declaration should pass the error generated by the register to the next handler / 2', t => {
80
+ test('internal route declaration should pass the error generated by the register to the done handler / 2', t => {
81
81
  t.plan(2)
82
82
  const fastify = Fastify()
83
83
 
84
- fastify.register((instance, opts, next) => {
85
- next(new Error('kaboom'))
84
+ fastify.register((instance, opts, done) => {
85
+ done(new Error('kaboom'))
86
86
  })
87
87
 
88
88
  fastify.get('/', (req, reply) => {
@@ -105,20 +105,20 @@ test('awaitable register and after', async t => {
105
105
  let second = false
106
106
  let third = false
107
107
 
108
- await fastify.register(async (instance, opts, next) => {
108
+ await fastify.register(async (instance, opts, done) => {
109
109
  first = true
110
110
  })
111
111
 
112
112
  t.is(first, true)
113
113
 
114
- fastify.register(async (instance, opts, next) => {
114
+ fastify.register(async (instance, opts, done) => {
115
115
  second = true
116
116
  })
117
117
 
118
118
  await fastify.after()
119
119
  t.is(second, true)
120
120
 
121
- fastify.register(async (instance, opts, next) => {
121
+ fastify.register(async (instance, opts, done) => {
122
122
  third = true
123
123
  })
124
124
 
@@ -145,7 +145,7 @@ test('awaitable register error handling', async t => {
145
145
 
146
146
  await t.rejects(fastify.after(), e)
147
147
 
148
- fastify.register(async (instance, opts, next) => {
148
+ fastify.register(async (instance, opts, done) => {
149
149
  t.fail('should not be executed')
150
150
  })
151
151
 
@@ -167,7 +167,7 @@ test('awaitable after error handling', async t => {
167
167
 
168
168
  await t.rejects(fastify.after(), e)
169
169
 
170
- fastify.register(async (instance, opts, next) => {
170
+ fastify.register(async (instance, opts, done) => {
171
171
  t.fail('should not be executed')
172
172
  })
173
173
 
@@ -170,7 +170,7 @@ test('encapsulated error handler binding', t => {
170
170
 
171
171
  const fastify = Fastify()
172
172
 
173
- fastify.register(function (app, opts, next) {
173
+ fastify.register(function (app, opts, done) {
174
174
  app.decorate('hello', 'world')
175
175
  t.strictEqual(app.hello, 'world')
176
176
  app.post('/', function (req, reply) {
@@ -183,7 +183,7 @@ test('encapsulated error handler binding', t => {
183
183
  .type('application/json; charset=utf-8')
184
184
  .send(err)
185
185
  })
186
- next()
186
+ done()
187
187
  })
188
188
 
189
189
  fastify.inject({