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
@@ -27,7 +27,7 @@ test('close callback', t => {
27
27
  test('inside register', t => {
28
28
  t.plan(5)
29
29
  const fastify = Fastify()
30
- fastify.register(function (f, opts, next) {
30
+ fastify.register(function (f, opts, done) {
31
31
  f.addHook('onClose', onClose)
32
32
  function onClose (instance, done) {
33
33
  t.ok(instance.prototype === fastify.prototype)
@@ -35,7 +35,7 @@ test('inside register', t => {
35
35
  done()
36
36
  }
37
37
 
38
- next()
38
+ done()
39
39
  })
40
40
 
41
41
  fastify.listen(0, err => {
@@ -53,13 +53,13 @@ test('close order', t => {
53
53
  const fastify = Fastify()
54
54
  const order = [1, 2, 3]
55
55
 
56
- fastify.register(function (f, opts, next) {
56
+ fastify.register(function (f, opts, done) {
57
57
  f.addHook('onClose', (instance, done) => {
58
58
  t.is(order.shift(), 1)
59
59
  done()
60
60
  })
61
61
 
62
- next()
62
+ done()
63
63
  })
64
64
 
65
65
  fastify.addHook('onClose', (instance, done) => {
@@ -82,12 +82,12 @@ test('close order - async', async t => {
82
82
  const fastify = Fastify()
83
83
  const order = [1, 2, 3]
84
84
 
85
- fastify.register(function (f, opts, next) {
85
+ fastify.register(function (f, opts, done) {
86
86
  f.addHook('onClose', async instance => {
87
87
  t.is(order.shift(), 1)
88
88
  })
89
89
 
90
- next()
90
+ done()
91
91
  })
92
92
 
93
93
  fastify.addHook('onClose', () => {
@@ -119,7 +119,7 @@ test('onClose should keep the context', t => {
119
119
  const fastify = Fastify()
120
120
  fastify.register(plugin)
121
121
 
122
- function plugin (instance, opts, next) {
122
+ function plugin (instance, opts, done) {
123
123
  instance.decorate('test', true)
124
124
  instance.addHook('onClose', onClose)
125
125
  t.ok(instance.prototype === fastify.prototype)
@@ -130,7 +130,7 @@ test('onClose should keep the context', t => {
130
130
  done()
131
131
  }
132
132
 
133
- next()
133
+ done()
134
134
  }
135
135
 
136
136
  fastify.close((err) => {
@@ -67,3 +67,55 @@ test('config', t => {
67
67
  t.deepEquals(JSON.parse(response.payload), { url: '/no-config', method: 'GET' })
68
68
  })
69
69
  })
70
+
71
+ test('config with exposeHeadRoutes', t => {
72
+ t.plan(9)
73
+ const fastify = Fastify({ exposeHeadRoutes: true })
74
+
75
+ fastify.get('/get', {
76
+ schema: schema.schema,
77
+ config: Object.assign({}, schema.config)
78
+ }, handler)
79
+
80
+ fastify.route({
81
+ method: 'GET',
82
+ url: '/route',
83
+ schema: schema.schema,
84
+ handler: handler,
85
+ config: Object.assign({}, schema.config)
86
+ })
87
+
88
+ fastify.route({
89
+ method: 'GET',
90
+ url: '/no-config',
91
+ schema: schema.schema,
92
+ handler: handler
93
+ })
94
+
95
+ fastify.inject({
96
+ method: 'GET',
97
+ url: '/get'
98
+ }, (err, response) => {
99
+ t.error(err)
100
+ t.strictEqual(response.statusCode, 200)
101
+ t.deepEquals(JSON.parse(response.payload), Object.assign({ url: '/get', method: 'GET' }, schema.config))
102
+ })
103
+
104
+ fastify.inject({
105
+ method: 'GET',
106
+ url: '/route'
107
+ }, (err, response) => {
108
+ t.error(err)
109
+ t.strictEqual(response.statusCode, 200)
110
+ t.deepEquals(JSON.parse(response.payload), Object.assign({ url: '/route', method: 'GET' }, schema.config))
111
+ })
112
+
113
+ fastify.inject({
114
+ method: 'GET',
115
+ url: '/no-config'
116
+ }, (err, response) => {
117
+ t.error(err)
118
+ t.strictEqual(response.statusCode, 200)
119
+ t.deepEquals(JSON.parse(response.payload), { url: '/no-config', method: 'GET' })
120
+ })
121
+ })
@@ -298,18 +298,18 @@ test('contentTypeParser should support encapsulation', t => {
298
298
  t.plan(6)
299
299
  const fastify = Fastify()
300
300
 
301
- fastify.register((instance, opts, next) => {
301
+ fastify.register((instance, opts, done) => {
302
302
  instance.addContentTypeParser('application/jsoff', () => {})
303
303
  t.ok(instance.hasContentTypeParser('application/jsoff'))
304
304
 
305
- instance.register((instance, opts, next) => {
305
+ instance.register((instance, opts, done) => {
306
306
  instance.addContentTypeParser('application/ffosj', () => {})
307
307
  t.ok(instance.hasContentTypeParser('application/jsoff'))
308
308
  t.ok(instance.hasContentTypeParser('application/ffosj'))
309
- next()
309
+ done()
310
310
  })
311
311
 
312
- next()
312
+ done()
313
313
  })
314
314
 
315
315
  fastify.ready(err => {
@@ -323,7 +323,7 @@ test('contentTypeParser should support encapsulation, second try', t => {
323
323
  t.plan(4)
324
324
  const fastify = Fastify()
325
325
 
326
- fastify.register((instance, opts, next) => {
326
+ fastify.register((instance, opts, done) => {
327
327
  instance.post('/', (req, reply) => {
328
328
  reply.send(req.body)
329
329
  })
@@ -334,7 +334,7 @@ test('contentTypeParser should support encapsulation, second try', t => {
334
334
  })
335
335
  })
336
336
 
337
- next()
337
+ done()
338
338
  })
339
339
 
340
340
  fastify.listen(0, err => {
@@ -662,7 +662,7 @@ test('Can override the default json parser in a plugin', t => {
662
662
  t.plan(5)
663
663
  const fastify = Fastify()
664
664
 
665
- fastify.register((instance, opts, next) => {
665
+ fastify.register((instance, opts, done) => {
666
666
  instance.addContentTypeParser('application/json', function (req, payload, done) {
667
667
  t.ok('called')
668
668
  jsonParser(payload, function (err, body) {
@@ -674,7 +674,7 @@ test('Can override the default json parser in a plugin', t => {
674
674
  reply.send(req.body)
675
675
  })
676
676
 
677
- next()
677
+ done()
678
678
  })
679
679
 
680
680
  fastify.listen(0, err => {
@@ -17,14 +17,14 @@ test('server methods should exist', t => {
17
17
  t.ok(fastify.hasDecorator)
18
18
  })
19
19
 
20
- test('server methods should be incapsulated via .register', t => {
20
+ test('server methods should be encapsulated via .register', t => {
21
21
  t.plan(2)
22
22
  const fastify = Fastify()
23
23
 
24
- fastify.register((instance, opts, next) => {
24
+ fastify.register((instance, opts, done) => {
25
25
  instance.decorate('test', () => {})
26
26
  t.ok(instance.test)
27
- next()
27
+ done()
28
28
  })
29
29
 
30
30
  fastify.ready(() => {
@@ -36,10 +36,10 @@ test('hasServerMethod should check if the given method already exist', t => {
36
36
  t.plan(2)
37
37
  const fastify = Fastify()
38
38
 
39
- fastify.register((instance, opts, next) => {
39
+ fastify.register((instance, opts, done) => {
40
40
  instance.decorate('test', () => {})
41
41
  t.ok(instance.hasDecorator('test'))
42
- next()
42
+ done()
43
43
  })
44
44
 
45
45
  fastify.ready(() => {
@@ -51,7 +51,7 @@ test('decorate should throw if a declared dependency is not present', t => {
51
51
  t.plan(3)
52
52
  const fastify = Fastify()
53
53
 
54
- fastify.register((instance, opts, next) => {
54
+ fastify.register((instance, opts, done) => {
55
55
  try {
56
56
  instance.decorate('test', () => {}, ['dependency'])
57
57
  t.fail()
@@ -59,7 +59,7 @@ test('decorate should throw if a declared dependency is not present', t => {
59
59
  t.is(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY')
60
60
  t.is(e.message, 'The decorator is missing dependency \'dependency\'.')
61
61
  }
62
- next()
62
+ done()
63
63
  })
64
64
 
65
65
  fastify.ready(() => t.pass())
@@ -70,8 +70,8 @@ test('should pass error for missing request decorator', t => {
70
70
  t.plan(2)
71
71
  const fastify = Fastify()
72
72
 
73
- const plugin = fp(function (instance, opts, next) {
74
- next()
73
+ const plugin = fp(function (instance, opts, done) {
74
+ done()
75
75
  }, {
76
76
  decorators: {
77
77
  request: ['foo']
@@ -89,7 +89,7 @@ test('decorateReply inside register', t => {
89
89
  t.plan(12)
90
90
  const fastify = Fastify()
91
91
 
92
- fastify.register((instance, opts, next) => {
92
+ fastify.register((instance, opts, done) => {
93
93
  instance.decorateReply('test', 'test')
94
94
  t.ok(instance[symbols.kReply].prototype.test)
95
95
 
@@ -98,7 +98,7 @@ test('decorateReply inside register', t => {
98
98
  reply.send({ hello: 'world' })
99
99
  })
100
100
 
101
- next()
101
+ done()
102
102
  })
103
103
 
104
104
  fastify.get('/no', (req, reply) => {
@@ -136,7 +136,7 @@ test('decorateReply as plugin (inside .after)', t => {
136
136
  t.plan(11)
137
137
  const fastify = Fastify()
138
138
 
139
- fastify.register((instance, opts, next) => {
139
+ fastify.register((instance, opts, done) => {
140
140
  instance.register(fp((i, o, n) => {
141
141
  instance.decorateReply('test', 'test')
142
142
  n()
@@ -146,7 +146,7 @@ test('decorateReply as plugin (inside .after)', t => {
146
146
  reply.send({ hello: 'world' })
147
147
  })
148
148
  })
149
- next()
149
+ done()
150
150
  })
151
151
 
152
152
  fastify.get('/no', (req, reply) => {
@@ -184,7 +184,7 @@ test('decorateReply as plugin (outside .after)', t => {
184
184
  t.plan(11)
185
185
  const fastify = Fastify()
186
186
 
187
- fastify.register((instance, opts, next) => {
187
+ fastify.register((instance, opts, done) => {
188
188
  instance.register(fp((i, o, n) => {
189
189
  instance.decorateReply('test', 'test')
190
190
  n()
@@ -194,7 +194,7 @@ test('decorateReply as plugin (outside .after)', t => {
194
194
  t.ok(reply.test)
195
195
  reply.send({ hello: 'world' })
196
196
  })
197
- next()
197
+ done()
198
198
  })
199
199
 
200
200
  fastify.get('/no', (req, reply) => {
@@ -232,7 +232,7 @@ test('decorateRequest inside register', t => {
232
232
  t.plan(12)
233
233
  const fastify = Fastify()
234
234
 
235
- fastify.register((instance, opts, next) => {
235
+ fastify.register((instance, opts, done) => {
236
236
  instance.decorateRequest('test', 'test')
237
237
  t.ok(instance[symbols.kRequest].prototype.test)
238
238
 
@@ -241,7 +241,7 @@ test('decorateRequest inside register', t => {
241
241
  reply.send({ hello: 'world' })
242
242
  })
243
243
 
244
- next()
244
+ done()
245
245
  })
246
246
 
247
247
  fastify.get('/no', (req, reply) => {
@@ -279,7 +279,7 @@ test('decorateRequest as plugin (inside .after)', t => {
279
279
  t.plan(11)
280
280
  const fastify = Fastify()
281
281
 
282
- fastify.register((instance, opts, next) => {
282
+ fastify.register((instance, opts, done) => {
283
283
  instance.register(fp((i, o, n) => {
284
284
  instance.decorateRequest('test', 'test')
285
285
  n()
@@ -289,7 +289,7 @@ test('decorateRequest as plugin (inside .after)', t => {
289
289
  reply.send({ hello: 'world' })
290
290
  })
291
291
  })
292
- next()
292
+ done()
293
293
  })
294
294
 
295
295
  fastify.get('/no', (req, reply) => {
@@ -327,7 +327,7 @@ test('decorateRequest as plugin (outside .after)', t => {
327
327
  t.plan(11)
328
328
  const fastify = Fastify()
329
329
 
330
- fastify.register((instance, opts, next) => {
330
+ fastify.register((instance, opts, done) => {
331
331
  instance.register(fp((i, o, n) => {
332
332
  instance.decorateRequest('test', 'test')
333
333
  n()
@@ -337,7 +337,7 @@ test('decorateRequest as plugin (outside .after)', t => {
337
337
  t.ok(req.test)
338
338
  reply.send({ hello: 'world' })
339
339
  })
340
- next()
340
+ done()
341
341
  })
342
342
 
343
343
  fastify.get('/no', (req, reply) => {
@@ -413,10 +413,10 @@ test('hasRequestDecorator', t => {
413
413
 
414
414
  t.notOk(fastify.hasRequestDecorator(requestDecoratorName))
415
415
 
416
- fastify.register(function (fastify2, opts, next) {
416
+ fastify.register(function (fastify2, opts, done) {
417
417
  fastify2.decorateRequest(requestDecoratorName, 42)
418
418
  t.ok(fastify2.hasRequestDecorator(requestDecoratorName))
419
- next()
419
+ done()
420
420
  })
421
421
 
422
422
  t.notOk(fastify.hasRequestDecorator(requestDecoratorName))
@@ -432,9 +432,9 @@ test('hasRequestDecorator', t => {
432
432
 
433
433
  fastify.decorateRequest(requestDecoratorName, 42)
434
434
 
435
- fastify.register(function (fastify2, opts, next) {
435
+ fastify.register(function (fastify2, opts, done) {
436
436
  t.ok(fastify2.hasRequestDecorator(requestDecoratorName))
437
- next()
437
+ done()
438
438
  })
439
439
 
440
440
  fastify.ready(function () {
@@ -469,10 +469,10 @@ test('hasReplyDecorator', t => {
469
469
 
470
470
  t.notOk(fastify.hasReplyDecorator(replyDecoratorName))
471
471
 
472
- fastify.register(function (fastify2, opts, next) {
472
+ fastify.register(function (fastify2, opts, done) {
473
473
  fastify2.decorateReply(replyDecoratorName, 42)
474
474
  t.ok(fastify2.hasReplyDecorator(replyDecoratorName))
475
- next()
475
+ done()
476
476
  })
477
477
 
478
478
  t.notOk(fastify.hasReplyDecorator(replyDecoratorName))
@@ -488,9 +488,9 @@ test('hasReplyDecorator', t => {
488
488
 
489
489
  fastify.decorateReply(replyDecoratorName, 42)
490
490
 
491
- fastify.register(function (fastify2, opts, next) {
491
+ fastify.register(function (fastify2, opts, done) {
492
492
  t.ok(fastify2.hasReplyDecorator(replyDecoratorName))
493
- next()
493
+ done()
494
494
  })
495
495
 
496
496
  fastify.ready(function () {
@@ -505,7 +505,7 @@ test('should register properties via getter/setter objects', t => {
505
505
  t.plan(3)
506
506
  const fastify = Fastify()
507
507
 
508
- fastify.register((instance, opts, next) => {
508
+ fastify.register((instance, opts, done) => {
509
509
  instance.decorate('test', {
510
510
  getter () {
511
511
  return 'a getter'
@@ -513,7 +513,7 @@ test('should register properties via getter/setter objects', t => {
513
513
  })
514
514
  t.ok(instance.test)
515
515
  t.is(instance.test, 'a getter')
516
- next()
516
+ done()
517
517
  })
518
518
 
519
519
  fastify.ready(() => {
@@ -525,7 +525,7 @@ test('decorateRequest should work with getter/setter', t => {
525
525
  t.plan(5)
526
526
  const fastify = Fastify()
527
527
 
528
- fastify.register((instance, opts, next) => {
528
+ fastify.register((instance, opts, done) => {
529
529
  instance.decorateRequest('test', {
530
530
  getter () {
531
531
  return 'a getter'
@@ -536,7 +536,7 @@ test('decorateRequest should work with getter/setter', t => {
536
536
  res.send({ test: req.test })
537
537
  })
538
538
 
539
- next()
539
+ done()
540
540
  })
541
541
 
542
542
  fastify.get('/not-decorated', (req, res) => {
@@ -561,7 +561,7 @@ test('decorateReply should work with getter/setter', t => {
561
561
  t.plan(5)
562
562
  const fastify = Fastify()
563
563
 
564
- fastify.register((instance, opts, next) => {
564
+ fastify.register((instance, opts, done) => {
565
565
  instance.decorateReply('test', {
566
566
  getter () {
567
567
  return 'a getter'
@@ -572,7 +572,7 @@ test('decorateReply should work with getter/setter', t => {
572
572
  res.send({ test: res.test })
573
573
  })
574
574
 
575
- next()
575
+ done()
576
576
  })
577
577
 
578
578
  fastify.get('/not-decorated', (req, res) => {
@@ -597,10 +597,10 @@ test('should register empty values', t => {
597
597
  t.plan(2)
598
598
  const fastify = Fastify()
599
599
 
600
- fastify.register((instance, opts, next) => {
600
+ fastify.register((instance, opts, done) => {
601
601
  instance.decorate('test', null)
602
602
  t.true(instance.hasOwnProperty('test'))
603
- next()
603
+ done()
604
604
  })
605
605
 
606
606
  fastify.ready(() => {
@@ -617,7 +617,7 @@ test('nested plugins can override things', t => {
617
617
  fastify.decorateRequest('test', rootFunc)
618
618
  fastify.decorateReply('test', rootFunc)
619
619
 
620
- fastify.register((instance, opts, next) => {
620
+ fastify.register((instance, opts, done) => {
621
621
  const func = () => {}
622
622
  instance.decorate('test', func)
623
623
  instance.decorateRequest('test', func)
@@ -626,7 +626,7 @@ test('nested plugins can override things', t => {
626
626
  t.equal(instance.test, func)
627
627
  t.equal(instance[symbols.kRequest].prototype.test, func)
628
628
  t.equal(instance[symbols.kReply].prototype.test, func)
629
- next()
629
+ done()
630
630
  })
631
631
 
632
632
  fastify.ready(() => {
@@ -640,24 +640,24 @@ test('a decorator should addSchema to all the encapsulated tree', t => {
640
640
  t.plan(1)
641
641
  const fastify = Fastify()
642
642
 
643
- const decorator = function (instance, opts, next) {
643
+ const decorator = function (instance, opts, done) {
644
644
  instance.decorate('decoratorAddSchema', function (whereAddTheSchema) {
645
645
  instance.addSchema({
646
646
  $id: 'schema',
647
647
  type: 'string'
648
648
  })
649
649
  })
650
- next()
650
+ done()
651
651
  }
652
652
 
653
653
  fastify.register(fp(decorator))
654
654
 
655
- fastify.register(function (instance, opts, next) {
656
- instance.register((subInstance, opts, next) => {
655
+ fastify.register(function (instance, opts, done) {
656
+ instance.register((subInstance, opts, done) => {
657
657
  subInstance.decoratorAddSchema()
658
- next()
658
+ done()
659
659
  })
660
- next()
660
+ done()
661
661
  })
662
662
 
663
663
  fastify.ready(t.error)
@@ -671,10 +671,10 @@ test('after can access to a decorated instance and previous plugin decoration',
671
671
 
672
672
  const fastify = Fastify()
673
673
 
674
- fastify.register(fp(function (instance, options, next) {
674
+ fastify.register(fp(function (instance, options, done) {
675
675
  instance.decorate('test', TEST_VALUE)
676
676
 
677
- next()
677
+ done()
678
678
  })).after(function (err, instance, done) {
679
679
  t.error(err)
680
680
  t.equal(instance.test, TEST_VALUE)
@@ -683,13 +683,13 @@ test('after can access to a decorated instance and previous plugin decoration',
683
683
  done()
684
684
  })
685
685
 
686
- fastify.register(fp(function (instance, options, next) {
686
+ fastify.register(fp(function (instance, options, done) {
687
687
  t.equal(instance.test, TEST_VALUE)
688
688
  t.equal(instance.test2, OTHER_TEST_VALUE)
689
689
 
690
690
  instance.decorate('test3', NEW_TEST_VALUE)
691
691
 
692
- next()
692
+ done()
693
693
  })).after(function (err, instance, done) {
694
694
  t.error(err)
695
695
  t.equal(instance.test, TEST_VALUE)
@@ -0,0 +1,43 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const test = t.test
5
+ const Fastify = require('..')
6
+
7
+ test('should fail if defaultRoute is not a function', t => {
8
+ t.plan(1)
9
+
10
+ const fastify = Fastify()
11
+ const defaultRoute = {}
12
+
13
+ fastify.get('/', () => {})
14
+
15
+ try {
16
+ fastify.setDefaultRoute(defaultRoute)
17
+ } catch (error) {
18
+ t.equal(error.code, 'FST_ERR_DEFAULT_ROUTE_INVALID_TYPE')
19
+ }
20
+ })
21
+
22
+ test('correctly sets, returns, and calls defaultRoute', t => {
23
+ t.plan(3)
24
+
25
+ const fastify = Fastify()
26
+ const defaultRoute = (req, res) => {
27
+ res.end('hello from defaultRoute')
28
+ }
29
+
30
+ fastify.setDefaultRoute(defaultRoute)
31
+ const returnedDefaultRoute = fastify.getDefaultRoute()
32
+ t.equal(returnedDefaultRoute, defaultRoute)
33
+
34
+ fastify.get('/', () => {})
35
+
36
+ fastify.inject({
37
+ method: 'GET',
38
+ url: '/random'
39
+ }, (err, res) => {
40
+ t.error(err)
41
+ t.equal(res.body, 'hello from defaultRoute')
42
+ })
43
+ })
@@ -79,7 +79,7 @@ test('errorHandler in plugin should be separate from the external one', async t
79
79
  t.plan(4)
80
80
  const fastify = Fastify()
81
81
 
82
- fastify.register((instance, opts, next) => {
82
+ fastify.register((instance, opts, done) => {
83
83
  const inPluginErrHandler = (_, __, reply) => {
84
84
  reply.send({ plugin: 'error-object' })
85
85
  }
@@ -89,7 +89,7 @@ test('errorHandler in plugin should be separate from the external one', async t
89
89
  t.notSame(instance.errorHandler, fastify.errorHandler)
90
90
  t.equal(instance.errorHandler.name, 'bound inPluginErrHandler')
91
91
 
92
- next()
92
+ done()
93
93
  })
94
94
 
95
95
  await fastify.ready()
@@ -3,9 +3,9 @@
3
3
  const t = require('tap')
4
4
  const test = t.test
5
5
  const Fastify = require('..')
6
- const S = require('fluent-schema')
6
+ const S = require('fluent-json-schema')
7
7
 
8
- test('use fluent-schema object', t => {
8
+ test('use fluent-json-schema object', t => {
9
9
  t.plan(15)
10
10
  const fastify = Fastify()
11
11
 
@@ -90,7 +90,7 @@ test('use fluent-schema object', t => {
90
90
  })
91
91
  })
92
92
 
93
- test('use complex fluent-schema object', t => {
93
+ test('use complex fluent-json-schema object', t => {
94
94
  t.plan(1)
95
95
  const fastify = Fastify()
96
96
 
@@ -8,9 +8,9 @@ test('handlers receive correct `this` context', (t) => {
8
8
  t.plan(4)
9
9
 
10
10
  // simulate plugin that uses fastify-plugin
11
- const plugin = function (instance, opts, next) {
11
+ const plugin = function (instance, opts, done) {
12
12
  instance.decorate('foo', 'foo')
13
- next()
13
+ done()
14
14
  }
15
15
  plugin[Symbol.for('skip-override')] = true
16
16
 
@@ -530,7 +530,7 @@ test('preHandler respond with a stream', t => {
530
530
  })
531
531
 
532
532
  // we are calling `reply.send` inside the `preHandler` hook with a stream,
533
- // this triggers the `onSend` hook event if `preHanlder` has not yet finished
533
+ // this triggers the `onSend` hook event if `preHandler` has not yet finished
534
534
  const order = [1, 2]
535
535
 
536
536
  fastify.addHook('preHandler', async (req, reply) => {
@@ -655,8 +655,8 @@ test('preSerializationEnd should handle errors if the serialize method throws',
655
655
  t.plan(2)
656
656
  const fastify = Fastify()
657
657
 
658
- fastify.addHook('preSerialization', (request, reply, payload, next) => {
659
- next(null, payload)
658
+ fastify.addHook('preSerialization', (request, reply, payload, done) => {
659
+ done(null, payload)
660
660
  })
661
661
 
662
662
  fastify.post('/', {