fastify 5.0.0 → 5.2.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 (201) hide show
  1. package/.borp.yaml +3 -0
  2. package/.vscode/settings.json +22 -0
  3. package/README.md +12 -7
  4. package/docs/Guides/Database.md +15 -15
  5. package/docs/Guides/Detecting-When-Clients-Abort.md +28 -28
  6. package/docs/Guides/Ecosystem.md +14 -15
  7. package/docs/Guides/Index.md +1 -1
  8. package/docs/Guides/Migration-Guide-V4.md +11 -11
  9. package/docs/Guides/Migration-Guide-V5.md +133 -9
  10. package/docs/Guides/Plugins-Guide.md +1 -1
  11. package/docs/Guides/Prototype-Poisoning.md +3 -3
  12. package/docs/Guides/Recommendations.md +9 -9
  13. package/docs/Guides/Serverless.md +5 -5
  14. package/docs/Guides/Testing.md +58 -57
  15. package/docs/Guides/Write-Plugin.md +2 -2
  16. package/docs/Guides/Write-Type-Provider.md +3 -3
  17. package/docs/Reference/ContentTypeParser.md +4 -4
  18. package/docs/Reference/Decorators.md +2 -2
  19. package/docs/Reference/Errors.md +3 -3
  20. package/docs/Reference/Hooks.md +7 -7
  21. package/docs/Reference/LTS.md +8 -0
  22. package/docs/Reference/Logging.md +5 -4
  23. package/docs/Reference/Reply.md +55 -58
  24. package/docs/Reference/Request.md +49 -42
  25. package/docs/Reference/Routes.md +16 -13
  26. package/docs/Reference/Server.md +32 -28
  27. package/docs/Reference/TypeScript.md +9 -9
  28. package/docs/Reference/Validation-and-Serialization.md +5 -5
  29. package/examples/typescript-server.ts +1 -1
  30. package/fastify.d.ts +14 -5
  31. package/fastify.js +8 -6
  32. package/lib/contentTypeParser.js +9 -7
  33. package/lib/context.js +1 -2
  34. package/lib/error-handler.js +9 -9
  35. package/lib/errors.js +1 -1
  36. package/lib/fourOhFour.js +1 -1
  37. package/lib/hooks.js +4 -1
  38. package/lib/{logger.js → logger-factory.js} +70 -122
  39. package/lib/logger-pino.js +68 -0
  40. package/lib/pluginOverride.js +1 -1
  41. package/lib/pluginUtils.js +2 -2
  42. package/lib/reply.js +4 -5
  43. package/lib/request.js +16 -9
  44. package/lib/route.js +23 -22
  45. package/lib/validation.js +2 -2
  46. package/package.json +13 -15
  47. package/test/404s.test.js +675 -629
  48. package/test/500s.test.js +72 -63
  49. package/test/{allowUnsafeRegex.test.js → allow-unsafe-regex.test.js} +30 -26
  50. package/test/als.test.js +48 -45
  51. package/test/async-await.test.js +148 -134
  52. package/test/async-dispose.test.js +4 -5
  53. package/test/async_hooks.test.js +30 -28
  54. package/test/{bodyLimit.test.js → body-limit.test.js} +61 -58
  55. package/test/buffer.test.js +9 -10
  56. package/test/build/error-serializer.test.js +3 -4
  57. package/test/build/version.test.js +2 -3
  58. package/test/build-certificate.js +1 -1
  59. package/test/bundler/README.md +5 -5
  60. package/test/bundler/esbuild/bundler-test.js +10 -9
  61. package/test/bundler/webpack/bundler-test.js +10 -9
  62. package/test/case-insensitive.test.js +31 -28
  63. package/test/chainable.test.js +4 -5
  64. package/test/check.test.js +8 -10
  65. package/test/{childLoggerFactory.test.js → child-logger-factory.test.js} +56 -19
  66. package/test/client-timeout.test.js +5 -5
  67. package/test/close-pipelining.test.js +6 -8
  68. package/test/conditional-pino.test.js +47 -0
  69. package/test/{connectionTimeout.test.js → connection-timeout.test.js} +10 -11
  70. package/test/constrained-routes.test.js +243 -236
  71. package/test/content-length.test.js +53 -68
  72. package/test/content-parser.test.js +186 -158
  73. package/test/content-type.test.js +8 -9
  74. package/test/context-config.test.js +44 -54
  75. package/test/custom-http-server.test.js +16 -20
  76. package/test/custom-parser.5.test.js +32 -32
  77. package/test/diagnostics-channel/404.test.js +15 -15
  78. package/test/diagnostics-channel/async-delay-request.test.js +25 -25
  79. package/test/diagnostics-channel/async-request.test.js +24 -24
  80. package/test/diagnostics-channel/error-before-handler.test.js +4 -5
  81. package/test/diagnostics-channel/error-request.test.js +19 -19
  82. package/test/diagnostics-channel/error-status.test.js +8 -8
  83. package/test/diagnostics-channel/init.test.js +6 -7
  84. package/test/diagnostics-channel/sync-delay-request.test.js +16 -16
  85. package/test/diagnostics-channel/sync-request-reply.test.js +16 -16
  86. package/test/diagnostics-channel/sync-request.test.js +19 -19
  87. package/test/encapsulated-child-logger-factory.test.js +8 -8
  88. package/test/encapsulated-error-handler.test.js +20 -20
  89. package/test/esm/errorCodes.test.mjs +5 -5
  90. package/test/esm/esm.test.mjs +3 -3
  91. package/test/esm/named-exports.mjs +3 -3
  92. package/test/esm/other.mjs +2 -2
  93. package/test/fastify-instance.test.js +33 -34
  94. package/test/{findRoute.test.js → find-route.test.js} +11 -10
  95. package/test/fluent-schema.test.js +33 -36
  96. package/test/handler-context.test.js +11 -11
  97. package/test/has-route.test.js +12 -15
  98. package/test/header-overflow.test.js +13 -12
  99. package/test/hooks.on-ready.test.js +2 -2
  100. package/test/hooks.test.js +25 -25
  101. package/test/http-methods/copy.test.js +22 -24
  102. package/test/http-methods/custom-http-methods.test.js +24 -21
  103. package/test/http-methods/get.test.js +97 -84
  104. package/test/http-methods/head.test.js +63 -57
  105. package/test/http-methods/lock.test.js +21 -20
  106. package/test/http-methods/mkcalendar.test.js +31 -27
  107. package/test/http-methods/mkcol.test.js +10 -10
  108. package/test/http-methods/move.test.js +11 -11
  109. package/test/http-methods/propfind.test.js +32 -27
  110. package/test/http-methods/proppatch.test.js +21 -19
  111. package/test/http-methods/report.test.js +32 -27
  112. package/test/http-methods/search.test.js +52 -47
  113. package/test/http-methods/trace.test.js +3 -4
  114. package/test/http-methods/unlock.test.js +10 -10
  115. package/test/http2/closing.test.js +50 -58
  116. package/test/http2/constraint.test.js +47 -50
  117. package/test/http2/head.test.js +18 -19
  118. package/test/http2/missing-http2-module.test.js +4 -5
  119. package/test/http2/plain.test.js +31 -31
  120. package/test/http2/secure-with-fallback.test.js +61 -61
  121. package/test/http2/secure.test.js +28 -31
  122. package/test/http2/unknown-http-method.test.js +13 -14
  123. package/test/https/custom-https-server.test.js +6 -7
  124. package/test/https/https.test.js +78 -78
  125. package/test/imports.test.js +5 -6
  126. package/test/internals/all.test.js +8 -11
  127. package/test/internals/{contentTypeParser.test.js → content-type-parser.test.js} +5 -6
  128. package/test/internals/context.test.js +9 -11
  129. package/test/internals/decorator.test.js +20 -21
  130. package/test/internals/errors.test.js +427 -427
  131. package/test/internals/{handleRequest.test.js → handle-request.test.js} +53 -42
  132. package/test/internals/{hookRunner.test.js → hook-runner.test.js} +99 -100
  133. package/test/internals/hooks.test.js +31 -35
  134. package/test/internals/{initialConfig.test.js → initial-config.test.js} +92 -80
  135. package/test/internals/logger.test.js +28 -28
  136. package/test/internals/plugin.test.js +17 -18
  137. package/test/internals/reply-serialize.test.js +106 -106
  138. package/test/internals/reply.test.js +620 -585
  139. package/test/internals/{reqIdGenFactory.test.js → req-id-gen-factory.test.js} +31 -31
  140. package/test/internals/request-validate.test.js +218 -221
  141. package/test/internals/request.test.js +225 -107
  142. package/test/internals/server.test.js +15 -12
  143. package/test/internals/validation.test.js +35 -36
  144. package/test/{keepAliveTimeout.test.js → keep-alive-timeout.test.js} +9 -10
  145. package/test/listen.5.test.js +9 -9
  146. package/test/{maxRequestsPerSocket.test.js → max-requests-per-socket.test.js} +30 -30
  147. package/test/middleware.test.js +4 -5
  148. package/test/noop-set.test.js +5 -5
  149. package/test/post-empty-body.test.js +18 -11
  150. package/test/pretty-print.test.js +59 -49
  151. package/test/proto-poisoning.test.js +42 -37
  152. package/test/reply-code.test.js +34 -32
  153. package/test/{reply-earlyHints.test.js → reply-early-hints.test.js} +21 -19
  154. package/test/request-error.test.js +122 -0
  155. package/test/request-header-host.test.js +339 -0
  156. package/test/request-id.test.js +31 -25
  157. package/test/{requestTimeout.test.js → request-timeout.test.js} +11 -11
  158. package/test/route.1.test.js +79 -72
  159. package/test/route.2.test.js +17 -16
  160. package/test/route.3.test.js +32 -27
  161. package/test/route.4.test.js +21 -25
  162. package/test/route.5.test.js +45 -64
  163. package/test/route.6.test.js +70 -89
  164. package/test/route.7.test.js +61 -65
  165. package/test/route.8.test.js +80 -18
  166. package/test/router-options.test.js +80 -77
  167. package/test/same-shape.test.js +5 -5
  168. package/test/schema-examples.test.js +72 -38
  169. package/test/serialize-response.test.js +9 -10
  170. package/test/server.test.js +75 -78
  171. package/test/set-error-handler.test.js +2 -3
  172. package/test/stream-serializers.test.js +10 -7
  173. package/test/sync-routes.test.js +18 -18
  174. package/test/test-reporter.mjs +68 -0
  175. package/test/trust-proxy.test.js +51 -45
  176. package/test/type-provider.test.js +8 -6
  177. package/test/types/content-type-parser.test-d.ts +1 -1
  178. package/test/types/fastify.test-d.ts +16 -4
  179. package/test/types/hooks.test-d.ts +2 -1
  180. package/test/types/instance.test-d.ts +13 -13
  181. package/test/types/logger.test-d.ts +2 -2
  182. package/test/types/plugin.test-d.ts +17 -9
  183. package/test/types/register.test-d.ts +22 -6
  184. package/test/types/reply.test-d.ts +1 -1
  185. package/test/types/route.test-d.ts +34 -4
  186. package/test/types/serverFactory.test-d.ts +1 -1
  187. package/test/types/type-provider.test-d.ts +1 -1
  188. package/test/url-rewriting.test.js +35 -38
  189. package/test/{useSemicolonDelimiter.test.js → use-semicolon-delimiter.test.js} +30 -30
  190. package/test/validation-error-handling.test.js +259 -285
  191. package/test/versioned-routes.test.js +126 -113
  192. package/test/web-api.test.js +48 -37
  193. package/test/{wrapThenable.test.js → wrap-thenable.test.js} +10 -9
  194. package/types/hooks.d.ts +2 -1
  195. package/types/instance.d.ts +9 -2
  196. package/types/register.d.ts +12 -3
  197. package/types/reply.d.ts +1 -1
  198. package/types/request.d.ts +2 -6
  199. package/types/serverFactory.d.ts +3 -3
  200. package/types/utils.d.ts +13 -5
  201. package/test/types/import.js +0 -2
@@ -1,18 +1,17 @@
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('..')
6
5
 
7
- test('route child logger factory does not affect other routes', t => {
8
- t.plan(6)
6
+ test('route child logger factory does not affect other routes', async t => {
7
+ t.plan(4)
9
8
 
10
9
  const fastify = Fastify()
11
10
 
12
11
  const customRouteChildLogger = (logger, bindings, opts, req) => {
13
12
  const child = logger.child(bindings, opts)
14
13
  child.customLog = function (message) {
15
- t.equal(message, 'custom')
14
+ t.assert.strictEqual(message, 'custom')
16
15
  }
17
16
  return child
18
17
  }
@@ -31,42 +30,39 @@ test('route child logger factory does not affect other routes', t => {
31
30
  method: 'GET',
32
31
  path: '/tea',
33
32
  handler: (req, res) => {
34
- t.notMatch(req.log.customLog instanceof Function)
33
+ t.assert.ok(req.log.customLog instanceof Function)
35
34
  res.send()
36
35
  }
37
36
  })
38
37
 
39
- fastify.inject({
38
+ let res = await fastify.inject({
40
39
  method: 'GET',
41
40
  url: '/coffee'
42
- }, (error, res) => {
43
- t.error(error)
44
- t.equal(res.statusCode, 200)
45
41
  })
46
- fastify.inject({
42
+ t.assert.strictEqual(res.statusCode, 200)
43
+
44
+ res = await fastify.inject({
47
45
  method: 'GET',
48
46
  url: '/tea'
49
- }, (error, res) => {
50
- t.error(error)
51
- t.equal(res.statusCode, 200)
52
47
  })
48
+ t.assert.strictEqual(res.statusCode, 200)
53
49
  })
54
- test('route child logger factory overrides global custom error handler', t => {
55
- t.plan(6)
50
+ test('route child logger factory overrides global custom error handler', async t => {
51
+ t.plan(4)
56
52
 
57
53
  const fastify = Fastify()
58
54
 
59
55
  const customGlobalChildLogger = (logger, bindings, opts, req) => {
60
56
  const child = logger.child(bindings, opts)
61
57
  child.globalLog = function (message) {
62
- t.equal(message, 'global')
58
+ t.assert.strictEqual(message, 'global')
63
59
  }
64
60
  return child
65
61
  }
66
62
  const customRouteChildLogger = (logger, bindings, opts, req) => {
67
63
  const child = logger.child(bindings, opts)
68
64
  child.customLog = function (message) {
69
- t.equal(message, 'custom')
65
+ t.assert.strictEqual(message, 'custom')
70
66
  }
71
67
  return child
72
68
  }
@@ -91,24 +87,21 @@ test('route child logger factory overrides global custom error handler', t => {
91
87
  }
92
88
  })
93
89
 
94
- fastify.inject({
90
+ let res = await fastify.inject({
95
91
  method: 'GET',
96
92
  url: '/coffee'
97
- }, (error, res) => {
98
- t.error(error)
99
- t.equal(res.statusCode, 200)
100
93
  })
101
- fastify.inject({
94
+ t.assert.strictEqual(res.statusCode, 200)
95
+
96
+ res = await fastify.inject({
102
97
  method: 'GET',
103
98
  url: '/more-coffee'
104
- }, (error, res) => {
105
- t.error(error)
106
- t.equal(res.statusCode, 200)
107
99
  })
100
+ t.assert.strictEqual(res.statusCode, 200)
108
101
  })
109
102
 
110
- test('Creates a HEAD route for each GET one (default)', t => {
111
- t.plan(8)
103
+ test('Creates a HEAD route for each GET one (default)', async t => {
104
+ t.plan(6)
112
105
 
113
106
  const fastify = Fastify()
114
107
 
@@ -128,29 +121,25 @@ test('Creates a HEAD route for each GET one (default)', t => {
128
121
  }
129
122
  })
130
123
 
131
- fastify.inject({
124
+ let res = await fastify.inject({
132
125
  method: 'HEAD',
133
126
  url: '/more-coffee'
134
- }, (error, res) => {
135
- t.error(error)
136
- t.equal(res.statusCode, 200)
137
- t.equal(res.headers['content-type'], 'application/json; charset=utf-8')
138
- t.same(res.body, '')
139
127
  })
128
+ t.assert.strictEqual(res.statusCode, 200)
129
+ t.assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8')
130
+ t.assert.deepStrictEqual(res.body, '')
140
131
 
141
- fastify.inject({
132
+ res = await fastify.inject({
142
133
  method: 'HEAD',
143
134
  url: '/some-light'
144
- }, (error, res) => {
145
- t.error(error)
146
- t.equal(res.statusCode, 200)
147
- t.equal(res.headers['content-type'], 'text/plain; charset=utf-8')
148
- t.equal(res.body, '')
149
135
  })
136
+ t.assert.strictEqual(res.statusCode, 200)
137
+ t.assert.strictEqual(res.headers['content-type'], 'text/plain; charset=utf-8')
138
+ t.assert.strictEqual(res.body, '')
150
139
  })
151
140
 
152
- test('Do not create a HEAD route for each GET one (exposeHeadRoutes: false)', t => {
153
- t.plan(4)
141
+ test('Do not create a HEAD route for each GET one (exposeHeadRoutes: false)', async t => {
142
+ t.plan(2)
154
143
 
155
144
  const fastify = Fastify({ exposeHeadRoutes: false })
156
145
 
@@ -170,25 +159,21 @@ test('Do not create a HEAD route for each GET one (exposeHeadRoutes: false)', t
170
159
  }
171
160
  })
172
161
 
173
- fastify.inject({
162
+ let res = await fastify.inject({
174
163
  method: 'HEAD',
175
164
  url: '/more-coffee'
176
- }, (error, res) => {
177
- t.error(error)
178
- t.equal(res.statusCode, 404)
179
165
  })
166
+ t.assert.strictEqual(res.statusCode, 404)
180
167
 
181
- fastify.inject({
168
+ res = await fastify.inject({
182
169
  method: 'HEAD',
183
170
  url: '/some-light'
184
- }, (error, res) => {
185
- t.error(error)
186
- t.equal(res.statusCode, 404)
187
171
  })
172
+ t.assert.strictEqual(res.statusCode, 404)
188
173
  })
189
174
 
190
- test('Creates a HEAD route for each GET one', t => {
191
- t.plan(8)
175
+ test('Creates a HEAD route for each GET one', async t => {
176
+ t.plan(6)
192
177
 
193
178
  const fastify = Fastify({ exposeHeadRoutes: true })
194
179
 
@@ -208,23 +193,19 @@ test('Creates a HEAD route for each GET one', t => {
208
193
  }
209
194
  })
210
195
 
211
- fastify.inject({
196
+ let res = await fastify.inject({
212
197
  method: 'HEAD',
213
198
  url: '/more-coffee'
214
- }, (error, res) => {
215
- t.error(error)
216
- t.equal(res.statusCode, 200)
217
- t.equal(res.headers['content-type'], 'application/json; charset=utf-8')
218
- t.same(res.body, '')
219
199
  })
200
+ t.assert.strictEqual(res.statusCode, 200)
201
+ t.assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8')
202
+ t.assert.deepStrictEqual(res.body, '')
220
203
 
221
- fastify.inject({
204
+ res = await fastify.inject({
222
205
  method: 'HEAD',
223
206
  url: '/some-light'
224
- }, (error, res) => {
225
- t.error(error)
226
- t.equal(res.statusCode, 200)
227
- t.equal(res.headers['content-type'], 'text/plain; charset=utf-8')
228
- t.equal(res.body, '')
229
207
  })
208
+ t.assert.strictEqual(res.statusCode, 200)
209
+ t.assert.strictEqual(res.headers['content-type'], 'text/plain; charset=utf-8')
210
+ t.assert.strictEqual(res.body, '')
230
211
  })
@@ -1,8 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const stream = require('node:stream')
4
- const t = require('tap')
5
- const test = t.test
4
+ const { test } = require('node:test')
6
5
  const Fastify = require('..')
7
6
 
8
7
  test('Creates a HEAD route for a GET one with prefixTrailingSlash', async (t) => {
@@ -31,11 +30,11 @@ test('Creates a HEAD route for a GET one with prefixTrailingSlash', async (t) =>
31
30
 
32
31
  await fastify.ready()
33
32
 
34
- t.ok(true)
33
+ t.assert.ok(true)
35
34
  })
36
35
 
37
- test('Will not create a HEAD route that is not GET', t => {
38
- t.plan(11)
36
+ test('Will not create a HEAD route that is not GET', async t => {
37
+ t.plan(8)
39
38
 
40
39
  const fastify = Fastify({ exposeHeadRoutes: true })
41
40
 
@@ -63,38 +62,35 @@ test('Will not create a HEAD route that is not GET', t => {
63
62
  }
64
63
  })
65
64
 
66
- fastify.inject({
65
+ let res = await fastify.inject({
67
66
  method: 'HEAD',
68
67
  url: '/more-coffee'
69
- }, (error, res) => {
70
- t.error(error)
71
- t.equal(res.statusCode, 200)
72
- t.equal(res.headers['content-type'], 'application/json; charset=utf-8')
73
- t.same(res.body, '')
74
68
  })
75
69
 
76
- fastify.inject({
70
+ t.assert.strictEqual(res.statusCode, 200)
71
+ t.assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8')
72
+ t.assert.deepStrictEqual(res.body, '')
73
+
74
+ res = await fastify.inject({
77
75
  method: 'HEAD',
78
76
  url: '/some-light'
79
- }, (error, res) => {
80
- t.error(error)
81
- t.equal(res.statusCode, 200)
82
- t.equal(res.headers['content-type'], undefined)
83
- t.equal(res.headers['content-length'], '0')
84
- t.equal(res.body, '')
85
77
  })
86
78
 
87
- fastify.inject({
79
+ t.assert.strictEqual(res.statusCode, 200)
80
+ t.assert.strictEqual(res.headers['content-type'], undefined)
81
+ t.assert.strictEqual(res.headers['content-length'], '0')
82
+ t.assert.strictEqual(res.body, '')
83
+
84
+ res = await fastify.inject({
88
85
  method: 'HEAD',
89
86
  url: '/something'
90
- }, (error, res) => {
91
- t.error(error)
92
- t.equal(res.statusCode, 404)
93
87
  })
88
+
89
+ t.assert.strictEqual(res.statusCode, 404)
94
90
  })
95
91
 
96
- test('HEAD route should handle properly each response type', t => {
97
- t.plan(25)
92
+ test('HEAD route should handle properly each response type', async t => {
93
+ t.plan(20)
98
94
 
99
95
  const fastify = Fastify({ exposeHeadRoutes: true })
100
96
  const resString = 'Found me!'
@@ -143,64 +139,54 @@ test('HEAD route should handle properly each response type', t => {
143
139
  }
144
140
  })
145
141
 
146
- fastify.inject({
142
+ let res = await fastify.inject({
147
143
  method: 'HEAD',
148
144
  url: '/json'
149
- }, (error, res) => {
150
- t.error(error)
151
- t.equal(res.statusCode, 200)
152
- t.equal(res.headers['content-type'], 'application/json; charset=utf-8')
153
- t.equal(res.headers['content-length'], `${Buffer.byteLength(JSON.stringify(resJSON))}`)
154
- t.same(res.body, '')
155
145
  })
146
+ t.assert.strictEqual(res.statusCode, 200)
147
+ t.assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8')
148
+ t.assert.strictEqual(res.headers['content-length'], `${Buffer.byteLength(JSON.stringify(resJSON))}`)
149
+ t.assert.deepStrictEqual(res.body, '')
156
150
 
157
- fastify.inject({
151
+ res = await fastify.inject({
158
152
  method: 'HEAD',
159
153
  url: '/string'
160
- }, (error, res) => {
161
- t.error(error)
162
- t.equal(res.statusCode, 200)
163
- t.equal(res.headers['content-type'], 'text/plain; charset=utf-8')
164
- t.equal(res.headers['content-length'], `${Buffer.byteLength(resString)}`)
165
- t.equal(res.body, '')
166
154
  })
155
+ t.assert.strictEqual(res.statusCode, 200)
156
+ t.assert.strictEqual(res.headers['content-type'], 'text/plain; charset=utf-8')
157
+ t.assert.strictEqual(res.headers['content-length'], `${Buffer.byteLength(resString)}`)
158
+ t.assert.strictEqual(res.body, '')
167
159
 
168
- fastify.inject({
160
+ res = await fastify.inject({
169
161
  method: 'HEAD',
170
162
  url: '/buffer'
171
- }, (error, res) => {
172
- t.error(error)
173
- t.equal(res.statusCode, 200)
174
- t.equal(res.headers['content-type'], 'application/octet-stream')
175
- t.equal(res.headers['content-length'], `${resBuffer.byteLength}`)
176
- t.equal(res.body, '')
177
163
  })
164
+ t.assert.strictEqual(res.statusCode, 200)
165
+ t.assert.strictEqual(res.headers['content-type'], 'application/octet-stream')
166
+ t.assert.strictEqual(res.headers['content-length'], `${resBuffer.byteLength}`)
167
+ t.assert.strictEqual(res.body, '')
178
168
 
179
- fastify.inject({
169
+ res = await fastify.inject({
180
170
  method: 'HEAD',
181
171
  url: '/buffer-with-content-type'
182
- }, (error, res) => {
183
- t.error(error)
184
- t.equal(res.statusCode, 200)
185
- t.equal(res.headers['content-type'], 'image/jpeg')
186
- t.equal(res.headers['content-length'], `${resBuffer.byteLength}`)
187
- t.equal(res.body, '')
188
172
  })
173
+ t.assert.strictEqual(res.statusCode, 200)
174
+ t.assert.strictEqual(res.headers['content-type'], 'image/jpeg')
175
+ t.assert.strictEqual(res.headers['content-length'], `${resBuffer.byteLength}`)
176
+ t.assert.strictEqual(res.body, '')
189
177
 
190
- fastify.inject({
178
+ res = await fastify.inject({
191
179
  method: 'HEAD',
192
180
  url: '/stream'
193
- }, (error, res) => {
194
- t.error(error)
195
- t.equal(res.statusCode, 200)
196
- t.equal(res.headers['content-type'], undefined)
197
- t.equal(res.headers['content-length'], undefined)
198
- t.equal(res.body, '')
199
181
  })
182
+ t.assert.strictEqual(res.statusCode, 200)
183
+ t.assert.strictEqual(res.headers['content-type'], undefined)
184
+ t.assert.strictEqual(res.headers['content-length'], undefined)
185
+ t.assert.strictEqual(res.body, '')
200
186
  })
201
187
 
202
- test('HEAD route should respect custom onSend handlers', t => {
203
- t.plan(6)
188
+ test('HEAD route should respect custom onSend handlers', async t => {
189
+ t.plan(5)
204
190
 
205
191
  let counter = 0
206
192
  const resBuffer = Buffer.from('I am a coffee!')
@@ -219,21 +205,20 @@ test('HEAD route should respect custom onSend handlers', t => {
219
205
  onSend: [customOnSend, customOnSend]
220
206
  })
221
207
 
222
- fastify.inject({
208
+ const res = await fastify.inject({
223
209
  method: 'HEAD',
224
210
  url: '/more-coffee'
225
- }, (error, res) => {
226
- t.error(error)
227
- t.equal(res.statusCode, 200)
228
- t.equal(res.headers['content-type'], 'application/octet-stream')
229
- t.equal(res.headers['content-length'], `${resBuffer.byteLength}`)
230
- t.equal(res.body, '')
231
- t.equal(counter, 2)
232
211
  })
212
+
213
+ t.assert.strictEqual(res.statusCode, 200)
214
+ t.assert.strictEqual(res.headers['content-type'], 'application/octet-stream')
215
+ t.assert.strictEqual(res.headers['content-length'], `${resBuffer.byteLength}`)
216
+ t.assert.strictEqual(res.body, '')
217
+ t.assert.strictEqual(counter, 2)
233
218
  })
234
219
 
235
- test('route onSend can be function or array of functions', t => {
236
- t.plan(12)
220
+ test('route onSend can be function or array of functions', async t => {
221
+ t.plan(10)
237
222
  const counters = { single: 0, multiple: 0 }
238
223
 
239
224
  const resBuffer = Buffer.from('I am a coffee!')
@@ -261,23 +246,19 @@ test('route onSend can be function or array of functions', t => {
261
246
  onSend: [customOnSend, customOnSend]
262
247
  })
263
248
 
264
- fastify.inject({ method: 'HEAD', url: '/coffee' }, (error, res) => {
265
- t.error(error)
266
- t.equal(res.statusCode, 200)
267
- t.equal(res.headers['content-type'], 'application/octet-stream')
268
- t.equal(res.headers['content-length'], `${resBuffer.byteLength}`)
269
- t.equal(res.body, '')
270
- t.equal(counters.single, 1)
271
- })
272
-
273
- fastify.inject({ method: 'HEAD', url: '/more-coffee' }, (error, res) => {
274
- t.error(error)
275
- t.equal(res.statusCode, 200)
276
- t.equal(res.headers['content-type'], 'application/octet-stream')
277
- t.equal(res.headers['content-length'], `${resBuffer.byteLength}`)
278
- t.equal(res.body, '')
279
- t.equal(counters.multiple, 2)
280
- })
249
+ let res = await fastify.inject({ method: 'HEAD', url: '/coffee' })
250
+ t.assert.strictEqual(res.statusCode, 200)
251
+ t.assert.strictEqual(res.headers['content-type'], 'application/octet-stream')
252
+ t.assert.strictEqual(res.headers['content-length'], `${resBuffer.byteLength}`)
253
+ t.assert.strictEqual(res.body, '')
254
+ t.assert.strictEqual(counters.single, 1)
255
+
256
+ res = await fastify.inject({ method: 'HEAD', url: '/more-coffee' })
257
+ t.assert.strictEqual(res.statusCode, 200)
258
+ t.assert.strictEqual(res.headers['content-type'], 'application/octet-stream')
259
+ t.assert.strictEqual(res.headers['content-length'], `${resBuffer.byteLength}`)
260
+ t.assert.strictEqual(res.body, '')
261
+ t.assert.strictEqual(counters.multiple, 2)
281
262
  })
282
263
 
283
264
  test('no warning for exposeHeadRoute', async t => {
@@ -293,7 +274,7 @@ test('no warning for exposeHeadRoute', async t => {
293
274
  })
294
275
 
295
276
  const listener = (w) => {
296
- t.fail('no warning')
277
+ t.assert.fail('no warning')
297
278
  }
298
279
 
299
280
  process.on('warning', listener)