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,21 +1,20 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
3
+ const { test } = require('node:test')
4
4
  const Fastify = require('../fastify')
5
5
 
6
6
  // asyncDispose doesn't exist in node <= 16
7
- t.test('async dispose should close fastify', { skip: !('asyncDispose' in Symbol) }, async t => {
7
+ test('async dispose should close fastify', { skip: !('asyncDispose' in Symbol) }, async t => {
8
8
  t.plan(2)
9
9
 
10
10
  const fastify = Fastify()
11
11
 
12
12
  await fastify.listen({ port: 0 })
13
13
 
14
- t.equal(fastify.server.listening, true)
14
+ t.assert.strictEqual(fastify.server.listening, true)
15
15
 
16
16
  // the same as syntax sugar for
17
17
  // await using app = fastify()
18
18
  await fastify[Symbol.asyncDispose]()
19
-
20
- t.equal(fastify.server.listening, false)
19
+ t.assert.strictEqual(fastify.server.listening, false)
21
20
  })
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { createHook } = require('node:async_hooks')
4
- const t = require('tap')
4
+ const { test } = require('node:test')
5
5
  const Fastify = require('..')
6
6
  const sget = require('simple-get').concat
7
7
 
@@ -20,27 +20,17 @@ createHook({
20
20
 
21
21
  const app = Fastify({ logger: false })
22
22
 
23
- app.get('/', function (request, reply) {
24
- reply.send({ id: 42 })
25
- })
26
-
27
- app.post('/', function (request, reply) {
28
- reply.send({ id: 42 })
29
- })
23
+ test('test async hooks', (t, done) => {
24
+ app.get('/', function (request, reply) {
25
+ reply.send({ id: 42 })
26
+ })
30
27
 
31
- app.listen({ port: 0 }, function (err, address) {
32
- t.error(err)
28
+ app.post('/', function (request, reply) {
29
+ reply.send({ id: 42 })
30
+ })
33
31
 
34
- sget({
35
- method: 'POST',
36
- url: 'http://localhost:' + app.server.address().port,
37
- body: {
38
- hello: 'world'
39
- },
40
- json: true
41
- }, (err, response, body) => {
42
- t.error(err)
43
- t.equal(response.statusCode, 200)
32
+ app.listen({ port: 0 }, function (err, address) {
33
+ t.assert.ifError(err)
44
34
 
45
35
  sget({
46
36
  method: 'POST',
@@ -50,19 +40,31 @@ app.listen({ port: 0 }, function (err, address) {
50
40
  },
51
41
  json: true
52
42
  }, (err, response, body) => {
53
- t.error(err)
54
- t.equal(response.statusCode, 200)
43
+ t.assert.ifError(err)
44
+ t.assert.strictEqual(response.statusCode, 200)
55
45
 
56
46
  sget({
57
- method: 'GET',
47
+ method: 'POST',
58
48
  url: 'http://localhost:' + app.server.address().port,
49
+ body: {
50
+ hello: 'world'
51
+ },
59
52
  json: true
60
53
  }, (err, response, body) => {
61
- t.error(err)
62
- t.equal(response.statusCode, 200)
63
- app.close()
64
- t.equal(remainingIds.size, 0)
65
- t.end()
54
+ t.assert.ifError(err)
55
+ t.assert.strictEqual(response.statusCode, 200)
56
+
57
+ sget({
58
+ method: 'GET',
59
+ url: 'http://localhost:' + app.server.address().port,
60
+ json: true
61
+ }, (err, response, body) => {
62
+ t.assert.ifError(err)
63
+ t.assert.strictEqual(response.statusCode, 200)
64
+ app.close()
65
+ t.assert.strictEqual(remainingIds.size, 0)
66
+ done()
67
+ })
66
68
  })
67
69
  })
68
70
  })
@@ -1,26 +1,25 @@
1
1
  'use strict'
2
2
 
3
- const Fastify = require('..')
3
+ const Fastify = require('../fastify')
4
4
  const sget = require('simple-get').concat
5
5
  const zlib = require('node:zlib')
6
- const t = require('tap')
7
- const test = t.test
6
+ const { test } = require('node:test')
8
7
 
9
- test('bodyLimit', t => {
8
+ test('bodyLimit', (t, done) => {
10
9
  t.plan(5)
11
10
 
12
11
  try {
13
12
  Fastify({ bodyLimit: 1.3 })
14
- t.fail('option must be an integer')
13
+ t.assert.fail('option must be an integer')
15
14
  } catch (err) {
16
- t.ok(err)
15
+ t.assert.ok(err)
17
16
  }
18
17
 
19
18
  try {
20
19
  Fastify({ bodyLimit: [] })
21
- t.fail('option must be an integer')
20
+ t.assert.fail('option must be an integer')
22
21
  } catch (err) {
23
- t.ok(err)
22
+ t.assert.ok(err)
24
23
  }
25
24
 
26
25
  const fastify = Fastify({ bodyLimit: 1 })
@@ -30,8 +29,8 @@ test('bodyLimit', t => {
30
29
  })
31
30
 
32
31
  fastify.listen({ port: 0 }, function (err) {
33
- t.error(err)
34
- t.teardown(() => { fastify.close() })
32
+ t.assert.ifError(err)
33
+ t.after(() => { fastify.close() })
35
34
 
36
35
  sget({
37
36
  method: 'POST',
@@ -40,14 +39,15 @@ test('bodyLimit', t => {
40
39
  body: [],
41
40
  json: true
42
41
  }, (err, response, body) => {
43
- t.error(err)
44
- t.equal(response.statusCode, 413)
42
+ t.assert.ifError(err)
43
+ t.assert.strictEqual(response.statusCode, 413)
44
+ done()
45
45
  })
46
46
  })
47
47
  })
48
48
 
49
- test('bodyLimit is applied to decoded content', t => {
50
- t.plan(9)
49
+ test('bodyLimit is applied to decoded content', async (t) => {
50
+ t.plan(6)
51
51
 
52
52
  const body = { x: 'x'.repeat(30000) }
53
53
  const json = JSON.stringify(body)
@@ -56,7 +56,7 @@ test('bodyLimit is applied to decoded content', t => {
56
56
  const fastify = Fastify()
57
57
 
58
58
  fastify.addHook('preParsing', async (req, reply, payload) => {
59
- t.equal(req.headers['content-length'], `${encoded.length}`)
59
+ t.assert.strictEqual(req.headers['content-length'], `${encoded.length}`)
60
60
  const unzip = zlib.createGunzip()
61
61
  Object.defineProperty(unzip, 'receivedEncodedLength', {
62
62
  get () {
@@ -79,53 +79,53 @@ test('bodyLimit is applied to decoded content', t => {
79
79
  fastify.post('/body-limit-20k', {
80
80
  bodyLimit: 20000,
81
81
  onError: async (req, res, err) => {
82
- t.equal(err.code, 'FST_ERR_CTP_BODY_TOO_LARGE')
83
- t.equal(err.statusCode, 413)
82
+ t.assert.strictEqual(err.code, 'FST_ERR_CTP_BODY_TOO_LARGE')
83
+ t.assert.strictEqual(err.statusCode, 413)
84
84
  }
85
85
  }, (request, reply) => {
86
86
  reply.send({ x: 'handler should not be called' })
87
87
  })
88
88
 
89
- fastify.inject({
90
- method: 'POST',
91
- url: '/body-limit-40k',
92
- headers: {
93
- 'content-encoding': 'gzip',
94
- 'content-type': 'application/json'
95
- },
96
- payload: encoded
97
- }, (err, res) => {
98
- t.error(err)
99
- t.equal(res.statusCode, 200)
100
- t.same(res.json(), body)
89
+ await t.test('bodyLimit 40k', async (t) => {
90
+ const result = await fastify.inject({
91
+ method: 'POST',
92
+ url: '/body-limit-40k',
93
+ headers: {
94
+ 'content-encoding': 'gzip',
95
+ 'content-type': 'application/json'
96
+ },
97
+ payload: encoded
98
+ })
99
+ t.assert.strictEqual(result.statusCode, 200)
100
+ t.assert.deepStrictEqual(result.json(), body)
101
101
  })
102
102
 
103
- fastify.inject({
104
- method: 'POST',
105
- url: '/body-limit-20k',
106
- headers: {
107
- 'content-encoding': 'gzip',
108
- 'content-type': 'application/json'
109
- },
110
- payload: encoded
111
- }, (err, res) => {
112
- t.error(err)
113
- t.equal(res.statusCode, 413)
103
+ await t.test('bodyLimit 20k', async (t) => {
104
+ const result = await fastify.inject({
105
+ method: 'POST',
106
+ url: '/body-limit-20k',
107
+ headers: {
108
+ 'content-encoding': 'gzip',
109
+ 'content-type': 'application/json'
110
+ },
111
+ payload: encoded
112
+ })
113
+ t.assert.strictEqual(result.statusCode, 413)
114
114
  })
115
115
  })
116
116
 
117
- test('default request.routeOptions.bodyLimit should be 1048576', t => {
117
+ test('default request.routeOptions.bodyLimit should be 1048576', (t, done) => {
118
118
  t.plan(4)
119
119
  const fastify = Fastify()
120
120
  fastify.post('/default-bodylimit', {
121
121
  handler (request, reply) {
122
- t.equal(1048576, request.routeOptions.bodyLimit)
122
+ t.assert.strictEqual(1048576, request.routeOptions.bodyLimit)
123
123
  reply.send({ })
124
124
  }
125
125
  })
126
126
  fastify.listen({ port: 0 }, function (err) {
127
- t.error(err)
128
- t.teardown(() => { fastify.close() })
127
+ t.assert.ifError(err)
128
+ t.after(() => { fastify.close() })
129
129
 
130
130
  sget({
131
131
  method: 'POST',
@@ -134,25 +134,26 @@ test('default request.routeOptions.bodyLimit should be 1048576', t => {
134
134
  body: [],
135
135
  json: true
136
136
  }, (err, response, body) => {
137
- t.error(err)
138
- t.equal(response.statusCode, 200)
137
+ t.assert.ifError(err)
138
+ t.assert.strictEqual(response.statusCode, 200)
139
+ done()
139
140
  })
140
141
  })
141
142
  })
142
143
 
143
- test('request.routeOptions.bodyLimit should be equal to route limit', t => {
144
+ test('request.routeOptions.bodyLimit should be equal to route limit', (t, done) => {
144
145
  t.plan(4)
145
146
  const fastify = Fastify({ bodyLimit: 1 })
146
147
  fastify.post('/route-limit', {
147
148
  bodyLimit: 1000,
148
149
  handler (request, reply) {
149
- t.equal(1000, request.routeOptions.bodyLimit)
150
+ t.assert.strictEqual(1000, request.routeOptions.bodyLimit)
150
151
  reply.send({})
151
152
  }
152
153
  })
153
154
  fastify.listen({ port: 0 }, function (err) {
154
- t.error(err)
155
- t.teardown(() => { fastify.close() })
155
+ t.assert.ifError(err)
156
+ t.after(() => { fastify.close() })
156
157
 
157
158
  sget({
158
159
  method: 'POST',
@@ -161,24 +162,25 @@ test('request.routeOptions.bodyLimit should be equal to route limit', t => {
161
162
  body: [],
162
163
  json: true
163
164
  }, (err, response, body) => {
164
- t.error(err)
165
- t.equal(response.statusCode, 200)
165
+ t.assert.ifError(err)
166
+ t.assert.strictEqual(response.statusCode, 200)
167
+ done()
166
168
  })
167
169
  })
168
170
  })
169
171
 
170
- test('request.routeOptions.bodyLimit should be equal to server limit', t => {
172
+ test('request.routeOptions.bodyLimit should be equal to server limit', (t, done) => {
171
173
  t.plan(4)
172
174
  const fastify = Fastify({ bodyLimit: 100 })
173
175
  fastify.post('/server-limit', {
174
176
  handler (request, reply) {
175
- t.equal(100, request.routeOptions.bodyLimit)
177
+ t.assert.strictEqual(100, request.routeOptions.bodyLimit)
176
178
  reply.send({})
177
179
  }
178
180
  })
179
181
  fastify.listen({ port: 0 }, function (err) {
180
- t.error(err)
181
- t.teardown(() => { fastify.close() })
182
+ t.assert.ifError(err)
183
+ t.after(() => { fastify.close() })
182
184
 
183
185
  sget({
184
186
  method: 'POST',
@@ -187,8 +189,9 @@ test('request.routeOptions.bodyLimit should be equal to server limit', t => {
187
189
  body: [],
188
190
  json: true
189
191
  }, (err, response, body) => {
190
- t.error(err)
191
- t.equal(response.statusCode, 200)
192
+ t.assert.ifError(err)
193
+ t.assert.strictEqual(response.statusCode, 200)
194
+ done()
192
195
  })
193
196
  })
194
197
  })
@@ -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
 
7
6
  test('Buffer test', async t => {
@@ -12,7 +11,7 @@ test('Buffer test', async t => {
12
11
  return request.body
13
12
  })
14
13
 
15
- test('should return 200 if the body is not empty', async t => {
14
+ await test('should return 200 if the body is not empty', async t => {
16
15
  t.plan(3)
17
16
 
18
17
  const response = await fastify.inject({
@@ -24,12 +23,12 @@ test('Buffer test', async t => {
24
23
  }
25
24
  })
26
25
 
27
- t.error(response.error)
28
- t.equal(response.statusCode, 200)
29
- t.same(response.payload.toString(), '{"hello":"world"}')
26
+ t.assert.ifError(response.error)
27
+ t.assert.strictEqual(response.statusCode, 200)
28
+ t.assert.deepStrictEqual(response.payload.toString(), '{"hello":"world"}')
30
29
  })
31
30
 
32
- test('should return 400 if the body is empty', async t => {
31
+ await test('should return 400 if the body is empty', async t => {
33
32
  t.plan(3)
34
33
 
35
34
  const response = await fastify.inject({
@@ -41,9 +40,9 @@ test('Buffer test', async t => {
41
40
  }
42
41
  })
43
42
 
44
- t.error(response.error)
45
- t.equal(response.statusCode, 400)
46
- t.same(JSON.parse(response.payload.toString()), {
43
+ t.assert.ifError(response.error)
44
+ t.assert.strictEqual(response.statusCode, 400)
45
+ t.assert.deepStrictEqual(JSON.parse(response.payload.toString()), {
47
46
  error: 'Bad Request',
48
47
  code: 'FST_ERR_CTP_EMPTY_JSON_BODY',
49
48
  message: 'Body cannot be empty when content-type is set to \'application/json\'',
@@ -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 fs = require('node:fs')
6
5
  const path = require('node:path')
7
6
  const { loadESLint } = require('eslint')
@@ -22,7 +21,7 @@ test('check generated code syntax', async (t) => {
22
21
 
23
22
  // if there are any invalid syntax
24
23
  // fatal count will be greater than 0
25
- t.equal(result[0].fatalErrorCount, 0)
24
+ t.assert.strictEqual(result[0].fatalErrorCount, 0)
26
25
  })
27
26
 
28
27
  const isPrepublish = !!process.env.PREPUBLISH
@@ -33,5 +32,5 @@ test('ensure the current error serializer is latest', { skip: !isPrepublish }, a
33
32
  const current = await fs.promises.readFile(path.resolve('lib/error-serializer.js'))
34
33
 
35
34
  // line break should not be a problem depends on system
36
- t.equal(unifyLineBreak(current), unifyLineBreak(code))
35
+ t.assert.strictEqual(unifyLineBreak(current), unifyLineBreak(code))
37
36
  })
@@ -2,8 +2,7 @@
2
2
 
3
3
  const fs = require('node:fs')
4
4
  const path = require('node:path')
5
- const t = require('tap')
6
- const test = t.test
5
+ const { test } = require('node:test')
7
6
  const fastify = require('../../fastify')()
8
7
 
9
8
  test('should be the same as package.json', t => {
@@ -11,5 +10,5 @@ test('should be the same as package.json', t => {
11
10
 
12
11
  const json = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'package.json')).toString('utf8'))
13
12
 
14
- t.equal(fastify.version, json.version)
13
+ t.assert.strictEqual(fastify.version, json.version)
15
14
  })
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const os = require('os')
3
+ const os = require('node:os')
4
4
  const forge = require('node-forge')
5
5
 
6
6
  // from self-cert module
@@ -1,12 +1,12 @@
1
1
  # Bundlers test stack
2
2
 
3
- In some cases, developers bundle their apps for several targets such as serverless applications.
4
- Even if it's not recommended by Fastify team; we need to ensure we do not break the build process.
3
+ In some cases, developers bundle their apps for several targets such as serverless applications.
4
+ Even if it's not recommended by Fastify team; we need to ensure we do not break the build process.
5
5
  Please note this might result in features behaving differently, like the version handling check for plugins.
6
6
 
7
7
  ## Test bundlers
8
8
 
9
- The bundler test stack has been defined separately from the rest of the Unit testing stack because it's not a
9
+ The bundler test stack has been defined separately from the rest of the Unit testing stack because it's not a
10
10
  part of the fastify lib itself. Note that the tests run in CI only on NodeJs LTS version.
11
11
  Developers do not need to install every bundler to run unit tests.
12
12
 
@@ -23,7 +23,7 @@ stack dependencies. See:
23
23
 
24
24
  ## Bundler test development
25
25
 
26
- To not break the fastify unit testing stack please name test files like this `*-test.js` and not `*.test.js`,
26
+ To not break the fastify unit testing stack please name test files like this `*-test.js` and not `*.test.js`,
27
27
  otherwise it will be targeted by the regular expression used for unit tests for fastify.
28
- Tests need to ensure the build process works and the fastify application can be run,
28
+ Tests need to ensure the build process works and the fastify application can be run,
29
29
  no need to go in deep testing unless an issue is raised.
@@ -1,31 +1,32 @@
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 fastifySuccess = require('./dist/success')
6
5
  const fastifyFailPlugin = require('./dist/failPlugin')
7
6
 
8
- test('Bundled package should work', (t) => {
7
+ test('Bundled package should work', (t, done) => {
9
8
  t.plan(4)
10
9
  fastifySuccess.ready((err) => {
11
- t.error(err)
10
+ t.assert.ifError(err)
12
11
  fastifySuccess.inject(
13
12
  {
14
13
  method: 'GET',
15
14
  url: '/'
16
15
  },
17
16
  (error, res) => {
18
- t.error(error)
19
- t.equal(res.statusCode, 200)
20
- t.same(res.json(), { hello: 'world' })
17
+ t.assert.ifError(error)
18
+ t.assert.strictEqual(res.statusCode, 200)
19
+ t.assert.deepStrictEqual(res.json(), { hello: 'world' })
20
+ done()
21
21
  }
22
22
  )
23
23
  })
24
24
  })
25
25
 
26
- test('Bundled package should not work with bad plugin version', (t) => {
26
+ test('Bundled package should not work with bad plugin version', (t, done) => {
27
27
  t.plan(1)
28
28
  fastifyFailPlugin.ready((err) => {
29
- t.match(err.message, /expected '9.x' fastify version/i)
29
+ t.assert.match(err.message, /expected '9.x' fastify version/i)
30
+ done()
30
31
  })
31
32
  })
@@ -1,31 +1,32 @@
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 fastifySuccess = require('./dist/success')
6
5
  const fastifyFailPlugin = require('./dist/failPlugin')
7
6
 
8
- test('Bundled package should work', (t) => {
7
+ test('Bundled package should work', (t, done) => {
9
8
  t.plan(4)
10
9
  fastifySuccess.ready((err) => {
11
- t.error(err)
10
+ t.assert.ifError(err)
12
11
  fastifySuccess.inject(
13
12
  {
14
13
  method: 'GET',
15
14
  url: '/'
16
15
  },
17
16
  (error, res) => {
18
- t.error(error)
19
- t.equal(res.statusCode, 200)
20
- t.same(res.json(), { hello: 'world' })
17
+ t.assert.ifError(error)
18
+ t.assert.strictEqual(res.statusCode, 200)
19
+ t.assert.deepStrictEqual(res.json(), { hello: 'world' })
20
+ done()
21
21
  }
22
22
  )
23
23
  })
24
24
  })
25
25
 
26
- test('Bundled package should not work with bad plugin version', (t) => {
26
+ test('Bundled package should not work with bad plugin version', (t, done) => {
27
27
  t.plan(1)
28
28
  fastifyFailPlugin.ready((err) => {
29
- t.match(err.message, /expected '9.x' fastify version/i)
29
+ t.assert.match(err.message, /expected '9.x' fastify version/i)
30
+ done()
30
31
  })
31
32
  })