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,7 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
4
- const test = t.test
3
+ const { test } = require('node:test')
5
4
 
6
5
  const Ajv = require('ajv')
7
6
  const ajv = new Ajv({ coerceTypes: true })
@@ -13,11 +12,11 @@ const { kSchemaVisited } = require('../../lib/symbols')
13
12
 
14
13
  test('Symbols', t => {
15
14
  t.plan(5)
16
- t.equal(typeof symbols.responseSchema, 'symbol')
17
- t.equal(typeof symbols.bodySchema, 'symbol')
18
- t.equal(typeof symbols.querystringSchema, 'symbol')
19
- t.equal(typeof symbols.paramsSchema, 'symbol')
20
- t.equal(typeof symbols.headersSchema, 'symbol')
15
+ t.assert.strictEqual(typeof symbols.responseSchema, 'symbol')
16
+ t.assert.strictEqual(typeof symbols.bodySchema, 'symbol')
17
+ t.assert.strictEqual(typeof symbols.querystringSchema, 'symbol')
18
+ t.assert.strictEqual(typeof symbols.paramsSchema, 'symbol')
19
+ t.assert.strictEqual(typeof symbols.headersSchema, 'symbol')
21
20
  })
22
21
 
23
22
  ;['compileSchemasForValidation',
@@ -26,15 +25,15 @@ test('Symbols', t => {
26
25
  t.plan(2)
27
26
  const context = {}
28
27
  validation[func](context)
29
- t.equal(typeof context[symbols.bodySchema], 'undefined')
30
- t.equal(typeof context[symbols.responseSchema], 'undefined')
28
+ t.assert.strictEqual(typeof context[symbols.bodySchema], 'undefined')
29
+ t.assert.strictEqual(typeof context[symbols.responseSchema], 'undefined')
31
30
  })
32
31
 
33
32
  test(`${func} schema - missing output schema`, t => {
34
33
  t.plan(1)
35
34
  const context = { schema: {} }
36
35
  validation[func](context, null)
37
- t.equal(typeof context[symbols.responseSchema], 'undefined')
36
+ t.assert.strictEqual(typeof context[symbols.responseSchema], 'undefined')
38
37
  })
39
38
  })
40
39
 
@@ -59,8 +58,8 @@ test('build schema - output schema', t => {
59
58
  }
60
59
  }
61
60
  validation.compileSchemasForSerialization(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
62
- t.equal(typeof opts[symbols.responseSchema]['2xx'], 'function')
63
- t.equal(typeof opts[symbols.responseSchema]['201'], 'function')
61
+ t.assert.strictEqual(typeof opts[symbols.responseSchema]['2xx'], 'function')
62
+ t.assert.strictEqual(typeof opts[symbols.responseSchema]['201'], 'function')
64
63
  })
65
64
 
66
65
  test('build schema - body schema', t => {
@@ -76,7 +75,7 @@ test('build schema - body schema', t => {
76
75
  }
77
76
  }
78
77
  validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
79
- t.equal(typeof opts[symbols.bodySchema], 'function')
78
+ t.assert.strictEqual(typeof opts[symbols.bodySchema], 'function')
80
79
  })
81
80
 
82
81
  test('build schema - body with multiple content type schemas', t => {
@@ -101,8 +100,8 @@ test('build schema - body with multiple content type schemas', t => {
101
100
  }
102
101
  }
103
102
  validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
104
- t.type(opts[symbols.bodySchema]['application/json'], 'function')
105
- t.type(opts[symbols.bodySchema]['text/plain'], 'function')
103
+ t.assert.ok(opts[symbols.bodySchema]['application/json'], 'function')
104
+ t.assert.ok(opts[symbols.bodySchema]['text/plain'], 'function')
106
105
  })
107
106
 
108
107
  test('build schema - avoid repeated normalize schema', t => {
@@ -119,9 +118,9 @@ test('build schema - avoid repeated normalize schema', t => {
119
118
  }
120
119
  }
121
120
  opts.schema = normalizeSchema(opts.schema, serverConfig)
122
- t.not(kSchemaVisited, undefined)
123
- t.equal(opts.schema[kSchemaVisited], true)
124
- t.equal(opts.schema, normalizeSchema(opts.schema, serverConfig))
121
+ t.assert.notStrictEqual(kSchemaVisited, undefined)
122
+ t.assert.strictEqual(opts.schema[kSchemaVisited], true)
123
+ t.assert.strictEqual(opts.schema, normalizeSchema(opts.schema, serverConfig))
125
124
  })
126
125
 
127
126
  test('build schema - query schema', t => {
@@ -139,8 +138,8 @@ test('build schema - query schema', t => {
139
138
  }
140
139
  opts.schema = normalizeSchema(opts.schema, serverConfig)
141
140
  validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
142
- t.type(opts[symbols.querystringSchema].schema.type, 'string')
143
- t.equal(typeof opts[symbols.querystringSchema], 'function')
141
+ t.assert.ok(typeof opts[symbols.querystringSchema].schema.type === 'string')
142
+ t.assert.strictEqual(typeof opts[symbols.querystringSchema], 'function')
144
143
  })
145
144
 
146
145
  test('build schema - query schema abbreviated', t => {
@@ -158,8 +157,8 @@ test('build schema - query schema abbreviated', t => {
158
157
  }
159
158
  opts.schema = normalizeSchema(opts.schema, serverConfig)
160
159
  validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
161
- t.type(opts[symbols.querystringSchema].schema.type, 'string')
162
- t.equal(typeof opts[symbols.querystringSchema], 'function')
160
+ t.assert.ok(typeof opts[symbols.querystringSchema].schema.type === 'string')
161
+ t.assert.strictEqual(typeof opts[symbols.querystringSchema], 'function')
163
162
  })
164
163
 
165
164
  test('build schema - querystring schema', t => {
@@ -175,8 +174,8 @@ test('build schema - querystring schema', t => {
175
174
  }
176
175
  }
177
176
  validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
178
- t.type(opts[symbols.querystringSchema].schema.type, 'string')
179
- t.equal(typeof opts[symbols.querystringSchema], 'function')
177
+ t.assert.ok(typeof opts[symbols.querystringSchema].schema.type === 'string')
178
+ t.assert.strictEqual(typeof opts[symbols.querystringSchema], 'function')
180
179
  })
181
180
 
182
181
  test('build schema - querystring schema abbreviated', t => {
@@ -194,8 +193,8 @@ test('build schema - querystring schema abbreviated', t => {
194
193
  }
195
194
  opts.schema = normalizeSchema(opts.schema, serverConfig)
196
195
  validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
197
- t.type(opts[symbols.querystringSchema].schema.type, 'string')
198
- t.equal(typeof opts[symbols.querystringSchema], 'function')
196
+ t.assert.ok(typeof opts[symbols.querystringSchema].schema.type === 'string')
197
+ t.assert.strictEqual(typeof opts[symbols.querystringSchema], 'function')
199
198
  })
200
199
 
201
200
  test('build schema - must throw if querystring and query schema exist', t => {
@@ -220,8 +219,8 @@ test('build schema - must throw if querystring and query schema exist', t => {
220
219
  }
221
220
  opts.schema = normalizeSchema(opts.schema, serverConfig)
222
221
  } catch (err) {
223
- t.equal(err.code, 'FST_ERR_SCH_DUPLICATE')
224
- t.equal(err.message, 'Schema with \'querystring\' already present!')
222
+ t.assert.strictEqual(err.code, 'FST_ERR_SCH_DUPLICATE')
223
+ t.assert.strictEqual(err.message, 'Schema with \'querystring\' already present!')
225
224
  }
226
225
  })
227
226
 
@@ -238,7 +237,7 @@ test('build schema - params schema', t => {
238
237
  }
239
238
  }
240
239
  validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
241
- t.equal(typeof opts[symbols.paramsSchema], 'function')
240
+ t.assert.strictEqual(typeof opts[symbols.paramsSchema], 'function')
242
241
  })
243
242
 
244
243
  test('build schema - headers schema', t => {
@@ -254,7 +253,7 @@ test('build schema - headers schema', t => {
254
253
  }
255
254
  }
256
255
  validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
257
- t.equal(typeof opts[symbols.headersSchema], 'function')
256
+ t.assert.strictEqual(typeof opts[symbols.headersSchema], 'function')
258
257
  })
259
258
 
260
259
  test('build schema - headers are lowercase', t => {
@@ -270,7 +269,7 @@ test('build schema - headers are lowercase', t => {
270
269
  }
271
270
  }
272
271
  validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => {
273
- t.ok(schema.properties['content-type'], 'lowercase content-type exists')
272
+ t.assert.ok(schema.properties['content-type'], 'lowercase content-type exists')
274
273
  return () => { }
275
274
  })
276
275
  })
@@ -285,7 +284,7 @@ test('build schema - headers are not lowercased in case of custom object', t =>
285
284
  }
286
285
  }
287
286
  validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => {
288
- t.type(schema, Headers)
287
+ t.assert.ok(schema, Headers)
289
288
  return () => { }
290
289
  })
291
290
  })
@@ -300,7 +299,7 @@ test('build schema - headers are not lowercased in case of custom validator prov
300
299
  }
301
300
  }
302
301
  validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => {
303
- t.type(schema, Headers)
302
+ t.assert.ok(schema, Headers)
304
303
  return () => { }
305
304
  }, true)
306
305
  })
@@ -318,7 +317,7 @@ test('build schema - uppercased headers are not included', t => {
318
317
  }
319
318
  }
320
319
  validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => {
321
- t.notOk('Content-Type' in schema.properties, 'uppercase does not exist')
320
+ t.assert.ok(!('Content-Type' in schema.properties), 'uppercase does not exist')
322
321
  return () => { }
323
322
  })
324
323
  })
@@ -333,7 +332,7 @@ test('build schema - mixed schema types are individually skipped or normalized',
333
332
  body: new CustomSchemaClass()
334
333
  },
335
334
  assertions: (schema) => {
336
- t.type(schema.body, CustomSchemaClass)
335
+ t.assert.ok(schema.body, CustomSchemaClass)
337
336
  }
338
337
  }, {
339
338
  schema: {
@@ -342,7 +341,7 @@ test('build schema - mixed schema types are individually skipped or normalized',
342
341
  }
343
342
  },
344
343
  assertions: (schema) => {
345
- t.type(schema.response[200], CustomSchemaClass)
344
+ t.assert.ok(schema.response[200], CustomSchemaClass)
346
345
  }
347
346
  }]
348
347
 
@@ -2,34 +2,33 @@
2
2
 
3
3
  const Fastify = require('..')
4
4
  const http = require('node:http')
5
- const t = require('tap')
6
- const test = t.test
5
+ const { test } = require('node:test')
7
6
 
8
7
  test('keepAliveTimeout', t => {
9
8
  t.plan(6)
10
9
 
11
10
  try {
12
11
  Fastify({ keepAliveTimeout: 1.3 })
13
- t.fail('option must be an integer')
12
+ t.assert.fail('option must be an integer')
14
13
  } catch (err) {
15
- t.ok(err)
14
+ t.assert.ok(err)
16
15
  }
17
16
 
18
17
  try {
19
18
  Fastify({ keepAliveTimeout: [] })
20
- t.fail('option must be an integer')
19
+ t.assert.fail('option must be an integer')
21
20
  } catch (err) {
22
- t.ok(err)
21
+ t.assert.ok(err)
23
22
  }
24
23
 
25
24
  const httpServer = Fastify({ keepAliveTimeout: 1 }).server
26
- t.equal(httpServer.keepAliveTimeout, 1)
25
+ t.assert.strictEqual(httpServer.keepAliveTimeout, 1)
27
26
 
28
27
  const httpsServer = Fastify({ keepAliveTimeout: 2, https: {} }).server
29
- t.equal(httpsServer.keepAliveTimeout, 2)
28
+ t.assert.strictEqual(httpsServer.keepAliveTimeout, 2)
30
29
 
31
30
  const http2Server = Fastify({ keepAliveTimeout: 3, http2: true }).server
32
- t.not(http2Server.keepAliveTimeout, 3)
31
+ t.assert.notStrictEqual(http2Server.keepAliveTimeout, 3)
33
32
 
34
33
  const serverFactory = (handler, _) => {
35
34
  const server = http.createServer((req, res) => {
@@ -39,5 +38,5 @@ test('keepAliveTimeout', t => {
39
38
  return server
40
39
  }
41
40
  const customServer = Fastify({ keepAliveTimeout: 4, serverFactory }).server
42
- t.equal(customServer.keepAliveTimeout, 5)
41
+ t.assert.strictEqual(customServer.keepAliveTimeout, 5)
43
42
  })
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { test } = require('tap')
3
+ const { test } = require('node:test')
4
4
  const net = require('node:net')
5
5
  const Fastify = require('../fastify')
6
6
  const { once } = require('node:events')
@@ -26,9 +26,9 @@ test('same port conflict and success should not fire callback multiple times - c
26
26
  switch (count) {
27
27
  case 6: {
28
28
  // success in here
29
- t.error(err)
29
+ t.assert.ifError(err)
30
30
  fastify.close((err) => {
31
- t.error(err)
31
+ t.assert.ifError(err)
32
32
  promise.resolve()
33
33
  })
34
34
  break
@@ -42,7 +42,7 @@ test('same port conflict and success should not fire callback multiple times - c
42
42
  }
43
43
  default: {
44
44
  // expect error
45
- t.equal(err.code, 'EADDRINUSE')
45
+ t.assert.strictEqual(err.code, 'EADDRINUSE')
46
46
  setTimeout(() => {
47
47
  fastify.listen(option, callback)
48
48
  }, 100)
@@ -65,27 +65,27 @@ test('same port conflict and success should not fire callback multiple times - p
65
65
  try {
66
66
  await fastify.listen(option)
67
67
  } catch (err) {
68
- t.equal(err.code, 'EADDRINUSE')
68
+ t.assert.strictEqual(err.code, 'EADDRINUSE')
69
69
  }
70
70
  try {
71
71
  await fastify.listen(option)
72
72
  } catch (err) {
73
- t.equal(err.code, 'EADDRINUSE')
73
+ t.assert.strictEqual(err.code, 'EADDRINUSE')
74
74
  }
75
75
  try {
76
76
  await fastify.listen(option)
77
77
  } catch (err) {
78
- t.equal(err.code, 'EADDRINUSE')
78
+ t.assert.strictEqual(err.code, 'EADDRINUSE')
79
79
  }
80
80
  try {
81
81
  await fastify.listen(option)
82
82
  } catch (err) {
83
- t.equal(err.code, 'EADDRINUSE')
83
+ t.assert.strictEqual(err.code, 'EADDRINUSE')
84
84
  }
85
85
  try {
86
86
  await fastify.listen(option)
87
87
  } catch (err) {
88
- t.equal(err.code, 'EADDRINUSE')
88
+ t.assert.strictEqual(err.code, 'EADDRINUSE')
89
89
  }
90
90
 
91
91
  server.close()
@@ -1,10 +1,10 @@
1
1
  'use strict'
2
2
 
3
3
  const net = require('node:net')
4
- const { test } = require('tap')
5
- const Fastify = require('../fastify')
4
+ const { test } = require('node:test')
5
+ const Fastify = require('..')
6
6
 
7
- test('maxRequestsPerSocket', t => {
7
+ test('maxRequestsPerSocket', (t, done) => {
8
8
  t.plan(8)
9
9
 
10
10
  const fastify = Fastify({ maxRequestsPerSocket: 2 })
@@ -12,32 +12,32 @@ test('maxRequestsPerSocket', t => {
12
12
  reply.send({ hello: 'world' })
13
13
  })
14
14
 
15
- t.teardown(fastify.close.bind(fastify))
16
-
17
15
  fastify.listen({ port: 0 }, function (err) {
18
- t.error(err)
16
+ t.assert.ifError(err)
19
17
 
20
18
  const port = fastify.server.address().port
21
19
  const client = net.createConnection({ port }, () => {
22
20
  client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
23
21
 
24
22
  client.once('data', data => {
25
- t.match(data.toString(), /Connection:\s*keep-alive/i)
26
- t.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
27
- t.match(data.toString(), /200 OK/i)
23
+ t.assert.match(data.toString(), /Connection:\s*keep-alive/i)
24
+ t.assert.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
25
+ t.assert.match(data.toString(), /200 OK/i)
28
26
 
29
27
  client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
30
28
 
31
29
  client.once('data', data => {
32
- t.match(data.toString(), /Connection:\s*close/i)
33
- t.match(data.toString(), /200 OK/i)
30
+ t.assert.match(data.toString(), /Connection:\s*close/i)
31
+ t.assert.match(data.toString(), /200 OK/i)
34
32
 
35
33
  client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
36
34
 
37
35
  client.once('data', data => {
38
- t.match(data.toString(), /Connection:\s*close/i)
39
- t.match(data.toString(), /503 Service Unavailable/i)
36
+ t.assert.match(data.toString(), /Connection:\s*close/i)
37
+ t.assert.match(data.toString(), /503 Service Unavailable/i)
40
38
  client.end()
39
+ fastify.close()
40
+ done()
41
41
  })
42
42
  })
43
43
  })
@@ -45,7 +45,7 @@ test('maxRequestsPerSocket', t => {
45
45
  })
46
46
  })
47
47
 
48
- test('maxRequestsPerSocket zero should behave same as null', t => {
48
+ test('maxRequestsPerSocket zero should behave same as null', (t, done) => {
49
49
  t.plan(10)
50
50
 
51
51
  const fastify = Fastify({ maxRequestsPerSocket: 0 })
@@ -53,34 +53,34 @@ test('maxRequestsPerSocket zero should behave same as null', t => {
53
53
  reply.send({ hello: 'world' })
54
54
  })
55
55
 
56
- t.teardown(fastify.close.bind(fastify))
57
-
58
56
  fastify.listen({ port: 0 }, function (err) {
59
- t.error(err)
57
+ t.assert.ifError(err)
60
58
 
61
59
  const port = fastify.server.address().port
62
60
  const client = net.createConnection({ port }, () => {
63
61
  client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
64
62
 
65
63
  client.once('data', data => {
66
- t.match(data.toString(), /Connection:\s*keep-alive/i)
67
- t.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
68
- t.match(data.toString(), /200 OK/i)
64
+ t.assert.match(data.toString(), /Connection:\s*keep-alive/i)
65
+ t.assert.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
66
+ t.assert.match(data.toString(), /200 OK/i)
69
67
 
70
68
  client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
71
69
 
72
70
  client.once('data', data => {
73
- t.match(data.toString(), /Connection:\s*keep-alive/i)
74
- t.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
75
- t.match(data.toString(), /200 OK/i)
71
+ t.assert.match(data.toString(), /Connection:\s*keep-alive/i)
72
+ t.assert.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
73
+ t.assert.match(data.toString(), /200 OK/i)
76
74
 
77
75
  client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
78
76
 
79
77
  client.once('data', data => {
80
- t.match(data.toString(), /Connection:\s*keep-alive/i)
81
- t.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
82
- t.match(data.toString(), /200 OK/i)
78
+ t.assert.match(data.toString(), /Connection:\s*keep-alive/i)
79
+ t.assert.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
80
+ t.assert.match(data.toString(), /200 OK/i)
83
81
  client.end()
82
+ fastify.close()
83
+ done()
84
84
  })
85
85
  })
86
86
  })
@@ -92,22 +92,22 @@ test('maxRequestsPerSocket should be set', async (t) => {
92
92
  t.plan(1)
93
93
 
94
94
  const initialConfig = Fastify({ maxRequestsPerSocket: 5 }).initialConfig
95
- t.same(initialConfig.maxRequestsPerSocket, 5)
95
+ t.assert.deepStrictEqual(initialConfig.maxRequestsPerSocket, 5)
96
96
  })
97
97
 
98
98
  test('maxRequestsPerSocket should 0', async (t) => {
99
99
  t.plan(1)
100
100
 
101
101
  const initialConfig = Fastify().initialConfig
102
- t.same(initialConfig.maxRequestsPerSocket, 0)
102
+ t.assert.deepStrictEqual(initialConfig.maxRequestsPerSocket, 0)
103
103
  })
104
104
 
105
105
  test('requestTimeout passed to server', t => {
106
106
  t.plan(2)
107
107
 
108
108
  const httpServer = Fastify({ maxRequestsPerSocket: 5 }).server
109
- t.equal(httpServer.maxRequestsPerSocket, 5)
109
+ t.assert.strictEqual(httpServer.maxRequestsPerSocket, 5)
110
110
 
111
111
  const httpsServer = Fastify({ maxRequestsPerSocket: 5, https: true }).server
112
- t.equal(httpsServer.maxRequestsPerSocket, 5)
112
+ t.assert.strictEqual(httpsServer.maxRequestsPerSocket, 5)
113
113
  })
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { test } = require('tap')
3
+ const { test } = require('node:test')
4
4
  const Fastify = require('..')
5
5
  const {
6
6
  FST_ERR_DEC_ALREADY_PRESENT
@@ -10,7 +10,7 @@ test('Should be able to override the default use API', t => {
10
10
  t.plan(1)
11
11
  const fastify = Fastify()
12
12
  fastify.decorate('use', () => true)
13
- t.equal(fastify.use(), true)
13
+ t.assert.strictEqual(fastify.use(), true)
14
14
  })
15
15
 
16
16
  test('Cannot decorate use twice', t => {
@@ -20,17 +20,16 @@ test('Cannot decorate use twice', t => {
20
20
  try {
21
21
  fastify.decorate('use', () => true)
22
22
  } catch (err) {
23
- t.ok(err instanceof FST_ERR_DEC_ALREADY_PRESENT)
23
+ t.assert.ok(err instanceof FST_ERR_DEC_ALREADY_PRESENT)
24
24
  }
25
25
  })
26
26
 
27
27
  test('Encapsulation works', t => {
28
- t.plan(1)
29
28
  const fastify = Fastify()
30
29
 
31
30
  fastify.register((instance, opts, done) => {
32
31
  instance.decorate('use', () => true)
33
- t.equal(instance.use(), true)
32
+ t.assert.strictEqual(instance.use(), true)
34
33
  done()
35
34
  })
36
35
 
@@ -1,19 +1,19 @@
1
1
  'use strict'
2
2
 
3
- const tap = require('tap')
3
+ const { test } = require('node:test')
4
4
  const noopSet = require('../lib/noop-set')
5
5
 
6
- tap.test('does a lot of nothing', async t => {
6
+ test('does a lot of nothing', async t => {
7
7
  const aSet = noopSet()
8
- t.type(aSet, 'object')
8
+ t.assert.ok(aSet, 'object')
9
9
 
10
10
  const item = {}
11
11
  aSet.add(item)
12
12
  aSet.add({ another: 'item' })
13
13
  aSet.delete(item)
14
- t.equal(aSet.has(item), true)
14
+ t.assert.strictEqual(aSet.has(item), true)
15
15
 
16
16
  for (const i of aSet) {
17
- t.fail('should not have any items', i)
17
+ t.assert.fail('should not have any items: ' + i)
18
18
  }
19
19
  })
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const { test } = require('tap')
4
- const fastify = require('../')
3
+ const { test } = require('node:test')
4
+ const Fastify = require('..')
5
5
  const { request, setGlobalDispatcher, Agent } = require('undici')
6
6
 
7
7
  setGlobalDispatcher(new Agent({
@@ -9,23 +9,30 @@ setGlobalDispatcher(new Agent({
9
9
  keepAliveMaxTimeout: 10
10
10
  }))
11
11
 
12
- test('post empty body', async t => {
13
- const app = fastify()
14
- t.teardown(app.close.bind(app))
12
+ test('post empty body', { timeout: 3_000 }, async t => {
13
+ const fastify = Fastify({ forceCloseConnections: true })
14
+ const abortController = new AbortController()
15
+ const { signal } = abortController
16
+ t.after(() => {
17
+ fastify.close()
18
+ abortController.abort()
19
+ })
15
20
 
16
- app.post('/bug', async (request, reply) => {
21
+ fastify.post('/bug', async () => {
22
+ // This function must be async and return nothing
17
23
  })
18
24
 
19
- await app.listen({ port: 0 })
25
+ await fastify.listen({ port: 0 })
20
26
 
21
- const res = await request(`http://127.0.0.1:${app.server.address().port}/bug`, {
27
+ const res = await request(`http://localhost:${fastify.server.address().port}/bug`, {
22
28
  method: 'POST',
23
29
  headers: {
24
30
  'Content-Type': 'application/json'
25
31
  },
26
- body: JSON.stringify({ foo: 'bar' })
32
+ body: JSON.stringify({ foo: 'bar' }),
33
+ signal
27
34
  })
28
35
 
29
- t.equal(res.statusCode, 200)
30
- t.equal(await res.body.text(), '')
36
+ t.assert.strictEqual(res.statusCode, 200)
37
+ t.assert.strictEqual(await res.body.text(), '')
31
38
  })