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,16 +1,15 @@
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
  const h2url = require('h2url')
7
6
  const msg = { hello: 'world' }
8
7
 
9
8
  const { buildCertificate } = require('../build-certificate')
10
- t.before(buildCertificate)
9
+ test.before(buildCertificate)
11
10
 
12
- test('secure', (t) => {
13
- t.plan(5)
11
+ test('secure', async (t) => {
12
+ t.plan(4)
14
13
 
15
14
  let fastify
16
15
  try {
@@ -21,9 +20,9 @@ test('secure', (t) => {
21
20
  cert: global.context.cert
22
21
  }
23
22
  })
24
- t.pass('Key/cert successfully loaded')
23
+ t.assert.ok(true, 'Key/cert successfully loaded')
25
24
  } catch (e) {
26
- t.fail('Key/cert loading failed', e)
25
+ t.assert.fail('Key/cert loading failed')
27
26
  }
28
27
 
29
28
  fastify.get('/', function (req, reply) {
@@ -36,35 +35,33 @@ test('secure', (t) => {
36
35
  reply.code(200).send({ hostname: req.hostname, port: req.port })
37
36
  })
38
37
 
39
- fastify.listen({ port: 0 }, err => {
40
- t.error(err)
41
- t.teardown(() => { fastify.close() })
38
+ t.after(() => { fastify.close() })
39
+ await fastify.listen({ port: 0 })
42
40
 
43
- t.test('https get request', async (t) => {
44
- t.plan(3)
41
+ await t.test('https get request', async (t) => {
42
+ t.plan(3)
45
43
 
46
- const url = `https://localhost:${fastify.server.address().port}`
47
- const res = await h2url.concat({ url })
44
+ const url = `https://localhost:${fastify.server.address().port}`
45
+ const res = await h2url.concat({ url })
48
46
 
49
- t.equal(res.headers[':status'], 200)
50
- t.equal(res.headers['content-length'], '' + JSON.stringify(msg).length)
51
- t.same(JSON.parse(res.body), msg)
52
- })
47
+ t.assert.strictEqual(res.headers[':status'], 200)
48
+ t.assert.strictEqual(res.headers['content-length'], '' + JSON.stringify(msg).length)
49
+ t.assert.deepStrictEqual(JSON.parse(res.body), msg)
50
+ })
53
51
 
54
- t.test('https get request without trust proxy - protocol', async (t) => {
55
- t.plan(2)
52
+ await t.test('https get request without trust proxy - protocol', async (t) => {
53
+ t.plan(2)
56
54
 
57
- const url = `https://localhost:${fastify.server.address().port}/proto`
58
- t.same(JSON.parse((await h2url.concat({ url })).body), { proto: 'https' })
59
- t.same(JSON.parse((await h2url.concat({ url, headers: { 'X-Forwarded-Proto': 'lorem' } })).body), { proto: 'https' })
60
- })
61
- t.test('https get request - test hostname and port', async (t) => {
62
- t.plan(2)
55
+ const url = `https://localhost:${fastify.server.address().port}/proto`
56
+ t.assert.deepStrictEqual(JSON.parse((await h2url.concat({ url })).body), { proto: 'https' })
57
+ t.assert.deepStrictEqual(JSON.parse((await h2url.concat({ url, headers: { 'X-Forwarded-Proto': 'lorem' } })).body), { proto: 'https' })
58
+ })
59
+ await t.test('https get request - test hostname and port', async (t) => {
60
+ t.plan(2)
63
61
 
64
- const url = `https://localhost:${fastify.server.address().port}/hostname_port`
65
- const parsedbody = JSON.parse((await h2url.concat({ url })).body)
66
- t.equal(parsedbody.hostname, 'localhost')
67
- t.equal(parsedbody.port, fastify.server.address().port)
68
- })
62
+ const url = `https://localhost:${fastify.server.address().port}/hostname_port`
63
+ const parsedbody = JSON.parse((await h2url.concat({ url })).body)
64
+ t.assert.strictEqual(parsedbody.hostname, 'localhost')
65
+ t.assert.strictEqual(parsedbody.port, fastify.server.address().port)
69
66
  })
70
67
  })
@@ -1,31 +1,30 @@
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
  const h2url = require('h2url')
7
6
  const msg = { hello: 'world' }
8
7
 
9
- const fastify = Fastify({
10
- http2: true
11
- })
8
+ test('http2 unknown http method', async t => {
9
+ const fastify = Fastify({
10
+ http2: true
11
+ })
12
12
 
13
- fastify.get('/', function (req, reply) {
14
- reply.code(200).send(msg)
15
- })
13
+ fastify.get('/', function (req, reply) {
14
+ reply.code(200).send(msg)
15
+ })
16
16
 
17
- fastify.listen({ port: 0 }, err => {
18
- t.error(err)
19
- t.teardown(() => { fastify.close() })
17
+ t.after(() => { fastify.close() })
18
+ await fastify.listen({ port: 0 })
20
19
 
21
- test('http UNKNOWN_METHOD request', async (t) => {
20
+ await t.test('http UNKNOWN_METHOD request', async (t) => {
22
21
  t.plan(2)
23
22
 
24
23
  const url = `http://localhost:${fastify.server.address().port}`
25
24
  const res = await h2url.concat({ url, method: 'UNKNOWN_METHOD' })
26
25
 
27
- t.equal(res.headers[':status'], 404)
28
- t.same(JSON.parse(res.body), {
26
+ t.assert.strictEqual(res.headers[':status'], 404)
27
+ t.assert.deepStrictEqual(JSON.parse(res.body), {
29
28
  statusCode: 404,
30
29
  code: 'FST_ERR_NOT_FOUND',
31
30
  error: 'Not Found',
@@ -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
  const Fastify = require('../..')
6
5
  const https = require('node:https')
7
6
  const dns = require('node:dns').promises
@@ -18,7 +17,7 @@ async function setup () {
18
17
 
19
18
  const fastify = Fastify({
20
19
  serverFactory: (handler, opts) => {
21
- t.ok(opts.serverFactory, 'it is called once for localhost')
20
+ t.assert.ok(opts.serverFactory, 'it is called once for localhost')
22
21
 
23
22
  const options = {
24
23
  key: global.context.key,
@@ -34,10 +33,10 @@ async function setup () {
34
33
  }
35
34
  })
36
35
 
37
- t.teardown(fastify.close.bind(fastify))
36
+ t.after(() => { fastify.close() })
38
37
 
39
38
  fastify.get('/', (req, reply) => {
40
- t.ok(req.raw.custom)
39
+ t.assert.ok(req.raw.custom)
41
40
  reply.send({ hello: 'world' })
42
41
  })
43
42
 
@@ -52,8 +51,8 @@ async function setup () {
52
51
  if (err) {
53
52
  return reject(err)
54
53
  }
55
- t.equal(response.statusCode, 200)
56
- t.same(JSON.parse(body), { hello: 'world' })
54
+ t.assert.strictEqual(response.statusCode, 200)
55
+ t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
57
56
  resolve()
58
57
  })
59
58
  })
@@ -1,15 +1,14 @@
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 sget = require('simple-get').concat
6
5
  const Fastify = require('../..')
7
6
 
8
7
  const { buildCertificate } = require('../build-certificate')
9
- t.before(buildCertificate)
8
+ test.before(buildCertificate)
10
9
 
11
- test('https', (t) => {
12
- t.plan(4)
10
+ test('https', async (t) => {
11
+ t.plan(3)
13
12
 
14
13
  let fastify
15
14
  try {
@@ -19,9 +18,9 @@ test('https', (t) => {
19
18
  cert: global.context.cert
20
19
  }
21
20
  })
22
- t.pass('Key/cert successfully loaded')
21
+ t.assert.ok('Key/cert successfully loaded')
23
22
  } catch (e) {
24
- t.fail('Key/cert loading failed', e)
23
+ t.assert.fail('Key/cert loading failed')
25
24
  }
26
25
 
27
26
  fastify.get('/', function (req, reply) {
@@ -32,51 +31,52 @@ test('https', (t) => {
32
31
  reply.code(200).send({ proto: req.protocol })
33
32
  })
34
33
 
35
- fastify.listen({ port: 0 }, err => {
36
- t.error(err)
37
- t.teardown(() => { fastify.close() })
34
+ await fastify.listen({ port: 0 })
38
35
 
39
- t.test('https get request', t => {
40
- t.plan(4)
41
- sget({
42
- method: 'GET',
43
- url: 'https://localhost:' + fastify.server.address().port,
44
- rejectUnauthorized: false
45
- }, (err, response, body) => {
46
- t.error(err)
47
- t.equal(response.statusCode, 200)
48
- t.equal(response.headers['content-length'], '' + body.length)
49
- t.same(JSON.parse(body), { hello: 'world' })
50
- })
36
+ t.after(() => { fastify.close() })
37
+
38
+ await t.test('https get request', (t, done) => {
39
+ t.plan(4)
40
+ sget({
41
+ method: 'GET',
42
+ url: 'https://localhost:' + fastify.server.address().port,
43
+ rejectUnauthorized: false
44
+ }, (err, response, body) => {
45
+ t.assert.ifError(err)
46
+ t.assert.strictEqual(response.statusCode, 200)
47
+ t.assert.strictEqual(response.headers['content-length'], '' + body.length)
48
+ t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
49
+ done()
51
50
  })
51
+ })
52
52
 
53
- t.test('https get request without trust proxy - protocol', t => {
54
- t.plan(4)
55
- sget({
56
- method: 'GET',
57
- url: 'https://localhost:' + fastify.server.address().port + '/proto',
58
- rejectUnauthorized: false
59
- }, (err, response, body) => {
60
- t.error(err)
61
- t.same(JSON.parse(body), { proto: 'https' })
62
- })
63
- sget({
64
- method: 'GET',
65
- url: 'https://localhost:' + fastify.server.address().port + '/proto',
66
- rejectUnauthorized: false,
67
- headers: {
68
- 'x-forwarded-proto': 'lorem'
69
- }
70
- }, (err, response, body) => {
71
- t.error(err)
72
- t.same(JSON.parse(body), { proto: 'https' })
73
- })
53
+ await t.test('https get request without trust proxy - protocol', (t, done) => {
54
+ t.plan(4)
55
+ sget({
56
+ method: 'GET',
57
+ url: 'https://localhost:' + fastify.server.address().port + '/proto',
58
+ rejectUnauthorized: false
59
+ }, (err, response, body) => {
60
+ t.assert.ifError(err)
61
+ t.assert.deepStrictEqual(JSON.parse(body), { proto: 'https' })
62
+ })
63
+ sget({
64
+ method: 'GET',
65
+ url: 'https://localhost:' + fastify.server.address().port + '/proto',
66
+ rejectUnauthorized: false,
67
+ headers: {
68
+ 'x-forwarded-proto': 'lorem'
69
+ }
70
+ }, (err, response, body) => {
71
+ t.assert.ifError(err)
72
+ t.assert.deepStrictEqual(JSON.parse(body), { proto: 'https' })
73
+ done()
74
74
  })
75
75
  })
76
76
  })
77
77
 
78
- test('https - headers', (t) => {
79
- t.plan(4)
78
+ test('https - headers', async (t) => {
79
+ t.plan(3)
80
80
  let fastify
81
81
  try {
82
82
  fastify = Fastify({
@@ -85,49 +85,49 @@ test('https - headers', (t) => {
85
85
  cert: global.context.cert
86
86
  }
87
87
  })
88
- t.pass('Key/cert successfully loaded')
88
+ t.assert.ok('Key/cert successfully loaded')
89
89
  } catch (e) {
90
- t.fail('Key/cert loading failed', e)
90
+ t.assert.fail('Key/cert loading failed')
91
91
  }
92
92
 
93
93
  fastify.get('/', function (req, reply) {
94
94
  reply.code(200).send({ hello: 'world', hostname: req.hostname, port: req.port })
95
95
  })
96
96
 
97
- t.teardown(async () => { await fastify.close() })
97
+ t.after(async () => { await fastify.close() })
98
98
 
99
- fastify.listen({ port: 0 }, err => {
100
- t.error(err)
99
+ await fastify.listen({ port: 0 })
101
100
 
102
- t.test('https get request', t => {
103
- t.plan(4)
104
- sget({
105
- method: 'GET',
106
- url: 'https://localhost:' + fastify.server.address().port,
107
- rejectUnauthorized: false
108
- }, (err, response, body) => {
109
- t.error(err)
110
- t.equal(response.statusCode, 200)
111
- const parsedBody = JSON.parse(body)
112
- t.equal(parsedBody.hostname, 'localhost')
113
- t.equal(parsedBody.port, fastify.server.address().port)
114
- })
101
+ await t.test('https get request', (t, done) => {
102
+ t.plan(4)
103
+ sget({
104
+ method: 'GET',
105
+ url: 'https://localhost:' + fastify.server.address().port,
106
+ rejectUnauthorized: false
107
+ }, (err, response, body) => {
108
+ t.assert.ifError(err)
109
+ t.assert.strictEqual(response.statusCode, 200)
110
+ const parsedBody = JSON.parse(body)
111
+ t.assert.strictEqual(parsedBody.hostname, 'localhost')
112
+ t.assert.strictEqual(parsedBody.port, fastify.server.address().port)
113
+ done()
115
114
  })
116
- t.test('https get request - test port fall back', t => {
117
- t.plan(3)
118
- sget({
119
- method: 'GET',
120
- headers: {
121
- host: 'example.com'
122
- },
123
- url: 'https://localhost:' + fastify.server.address().port,
124
- rejectUnauthorized: false
125
- }, (err, response, body) => {
126
- t.error(err)
127
- t.equal(response.statusCode, 200)
128
- const parsedBody = JSON.parse(body)
129
- t.equal(parsedBody.port, null)
130
- })
115
+ })
116
+ await t.test('https get request - test port fall back', (t, done) => {
117
+ t.plan(3)
118
+ sget({
119
+ method: 'GET',
120
+ headers: {
121
+ host: 'example.com'
122
+ },
123
+ url: 'https://localhost:' + fastify.server.address().port,
124
+ rejectUnauthorized: false
125
+ }, (err, response, body) => {
126
+ t.assert.ifError(err)
127
+ t.assert.strictEqual(response.statusCode, 200)
128
+ const parsedBody = JSON.parse(body)
129
+ t.assert.strictEqual(parsedBody.port, null)
130
+ done()
131
131
  })
132
132
  })
133
133
  })
@@ -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
 
6
5
  test('should import as default', t => {
7
6
  t.plan(2)
8
7
  const fastify = require('..')
9
- t.ok(fastify)
10
- t.equal(typeof fastify, 'function')
8
+ t.assert.ok(fastify)
9
+ t.assert.strictEqual(typeof fastify, 'function')
11
10
  })
12
11
 
13
12
  test('should import as esm', t => {
14
13
  t.plan(2)
15
14
  const { fastify } = require('..')
16
- t.ok(fastify)
17
- t.equal(typeof fastify, 'function')
15
+ t.assert.ok(fastify)
16
+ t.assert.strictEqual(typeof fastify, 'function')
18
17
  })
@@ -1,10 +1,9 @@
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('fastify.all should add all the methods to the same url', t => {
6
+ test('fastify.all should add all the methods to the same url', async t => {
8
7
  const fastify = Fastify()
9
8
 
10
9
  const requirePayload = [
@@ -14,15 +13,15 @@ test('fastify.all should add all the methods to the same url', t => {
14
13
  ]
15
14
 
16
15
  const supportedMethods = fastify.supportedMethods
17
- t.plan(supportedMethods.length * 2)
16
+ t.plan(supportedMethods.length)
18
17
 
19
18
  fastify.all('/', (req, reply) => {
20
19
  reply.send({ method: req.raw.method })
21
20
  })
22
21
 
23
- supportedMethods.forEach(injectRequest)
22
+ await Promise.all(supportedMethods.map(async method => injectRequest(method)))
24
23
 
25
- function injectRequest (method) {
24
+ async function injectRequest (method) {
26
25
  const options = {
27
26
  url: '/',
28
27
  method
@@ -32,10 +31,8 @@ test('fastify.all should add all the methods to the same url', t => {
32
31
  options.payload = { hello: 'world' }
33
32
  }
34
33
 
35
- fastify.inject(options, (err, res) => {
36
- t.error(err)
37
- const payload = JSON.parse(res.payload)
38
- t.same(payload, { method })
39
- })
34
+ const res = await fastify.inject(options)
35
+ const payload = JSON.parse(res.payload)
36
+ t.assert.deepStrictEqual(payload, { method })
40
37
  }
41
38
  })
@@ -1,8 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
3
+ const { test } = require('node:test')
4
4
  const proxyquire = require('proxyquire')
5
- const test = t.test
6
5
  const { Readable } = require('node:stream')
7
6
  const { kTestInternals, kRouteContext } = require('../../lib/symbols')
8
7
  const Request = require('../../lib/request')
@@ -17,8 +16,8 @@ test('rawBody function', t => {
17
16
  asString: true,
18
17
  asBuffer: false,
19
18
  fn (req, bodyInString, done) {
20
- t.equal(bodyInString, body.toString())
21
- t.equal(typeof done, 'function')
19
+ t.assert.strictEqual(bodyInString, body.toString())
20
+ t.assert.strictEqual(typeof done, 'function')
22
21
  return {
23
22
  then (cb) {
24
23
  cb()
@@ -70,8 +69,8 @@ test('Should support Webpack and faux modules', t => {
70
69
  asString: true,
71
70
  asBuffer: false,
72
71
  fn (req, bodyInString, done) {
73
- t.equal(bodyInString, body.toString())
74
- t.equal(typeof done, 'function')
72
+ t.assert.strictEqual(bodyInString, body.toString())
73
+ t.assert.strictEqual(typeof done, 'function')
75
74
  return {
76
75
  then (cb) {
77
76
  cb()
@@ -1,23 +1,23 @@
1
1
  'use strict'
2
2
 
3
- const { test } = require('tap')
4
-
3
+ const { test } = require('node:test')
5
4
  const { kRouteContext } = require('../../lib/symbols')
6
5
  const Context = require('../../lib/context')
7
6
 
8
7
  const Fastify = require('../..')
9
8
 
10
- test('context', context => {
9
+ test('context', async context => {
11
10
  context.plan(1)
12
11
 
13
- context.test('Should not contain undefined as key prop', async t => {
12
+ await context.test('Should not contain undefined as key prop', async t => {
13
+ t.plan(4)
14
14
  const app = Fastify()
15
15
 
16
16
  app.get('/', (req, reply) => {
17
- t.type(req[kRouteContext], Context)
18
- t.type(reply[kRouteContext], Context)
19
- t.notOk('undefined' in reply[kRouteContext])
20
- t.notOk('undefined' in req[kRouteContext])
17
+ t.assert.ok(req[kRouteContext] instanceof Context)
18
+ t.assert.ok(reply[kRouteContext] instanceof Context)
19
+ t.assert.ok(!('undefined' in reply[kRouteContext]))
20
+ t.assert.ok(!('undefined' in req[kRouteContext]))
21
21
 
22
22
  reply.send('hello world!')
23
23
  })
@@ -25,9 +25,7 @@ test('context', context => {
25
25
  try {
26
26
  await app.inject('/')
27
27
  } catch (e) {
28
- t.fail(e)
28
+ t.assert.fail(e)
29
29
  }
30
-
31
- t.plan(4)
32
30
  })
33
31
  })
@@ -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
  const decorator = require('../../lib/decorate')
6
5
  const {
7
6
  kState
@@ -22,7 +21,7 @@ test('decorate should add the given method to its instance', t => {
22
21
 
23
22
  const server = build()
24
23
  server.add('test', () => {})
25
- t.ok(server.test)
24
+ t.assert.ok(server.test)
26
25
  })
27
26
 
28
27
  test('decorate is chainable', t => {
@@ -44,15 +43,15 @@ test('decorate is chainable', t => {
44
43
  .add('test2', () => {})
45
44
  .add('test3', () => {})
46
45
 
47
- t.ok(server.test1)
48
- t.ok(server.test2)
49
- t.ok(server.test3)
46
+ t.assert.ok(server.test1)
47
+ t.assert.ok(server.test2)
48
+ t.assert.ok(server.test3)
50
49
  })
51
50
 
52
51
  test('checkExistence should check if a property is part of the given instance', t => {
53
52
  t.plan(1)
54
53
  const instance = { test: () => {} }
55
- t.ok(decorator.exist(instance, 'test'))
54
+ t.assert.ok(decorator.exist(instance, 'test'))
56
55
  })
57
56
 
58
57
  test('checkExistence should find the instance if not given', t => {
@@ -71,7 +70,7 @@ test('checkExistence should find the instance if not given', t => {
71
70
 
72
71
  const server = build()
73
72
  server.add('test', () => {})
74
- t.ok(server.check('test'))
73
+ t.assert.ok(server.check('test'))
75
74
  })
76
75
 
77
76
  test('checkExistence should check the prototype as well', t => {
@@ -80,7 +79,7 @@ test('checkExistence should check the prototype as well', t => {
80
79
  Instance.prototype.test = () => {}
81
80
 
82
81
  const instance = new Instance()
83
- t.ok(decorator.exist(instance, 'test'))
82
+ t.assert.ok(decorator.exist(instance, 'test'))
84
83
  })
85
84
 
86
85
  test('checkDependencies should throw if a dependency is not present', t => {
@@ -88,10 +87,10 @@ test('checkDependencies should throw if a dependency is not present', t => {
88
87
  const instance = {}
89
88
  try {
90
89
  decorator.dependencies(instance, 'foo', ['test'])
91
- t.fail()
90
+ t.assert.fail()
92
91
  } catch (e) {
93
- t.equal(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY')
94
- t.equal(e.message, 'The decorator is missing dependency \'test\'.')
92
+ t.assert.strictEqual(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY')
93
+ t.assert.strictEqual(e.message, 'The decorator is missing dependency \'test\'.')
95
94
  }
96
95
  })
97
96
 
@@ -112,10 +111,10 @@ test('decorate should internally call checkDependencies', t => {
112
111
 
113
112
  try {
114
113
  server.add('method', () => {}, ['test'])
115
- t.fail()
114
+ t.assert.fail()
116
115
  } catch (e) {
117
- t.equal(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY')
118
- t.equal(e.message, 'The decorator is missing dependency \'test\'.')
116
+ t.assert.strictEqual(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY')
117
+ t.assert.strictEqual(e.message, 'The decorator is missing dependency \'test\'.')
119
118
  }
120
119
  })
121
120
 
@@ -132,14 +131,14 @@ test('decorate should recognize getter/setter objects', t => {
132
131
  decorator.add.call(one, 'foo', {
133
132
  getter: () => this._a,
134
133
  setter: (val) => {
135
- t.pass()
134
+ t.assert.ok(true)
136
135
  this._a = val
137
136
  }
138
137
  })
139
- t.equal(Object.hasOwn(one, 'foo'), true)
140
- t.equal(one.foo, undefined)
138
+ t.assert.strictEqual(Object.hasOwn(one, 'foo'), true)
139
+ t.assert.strictEqual(one.foo, undefined)
141
140
  one.foo = 'a'
142
- t.equal(one.foo, 'a')
141
+ t.assert.strictEqual(one.foo, 'a')
143
142
 
144
143
  // getter only
145
144
  const two = {
@@ -152,6 +151,6 @@ test('decorate should recognize getter/setter objects', t => {
152
151
  decorator.add.call(two, 'foo', {
153
152
  getter: () => 'a getter'
154
153
  })
155
- t.equal(Object.hasOwn(two, 'foo'), true)
156
- t.equal(two.foo, 'a getter')
154
+ t.assert.strictEqual(Object.hasOwn(two, 'foo'), true)
155
+ t.assert.strictEqual(two.foo, 'a getter')
157
156
  })