fastify 5.3.2 → 5.4.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 (103) hide show
  1. package/README.md +2 -0
  2. package/build/build-validation.js +2 -1
  3. package/docs/Guides/Delay-Accepting-Requests.md +3 -3
  4. package/docs/Guides/Ecosystem.md +16 -7
  5. package/docs/Guides/Serverless.md +28 -69
  6. package/docs/Reference/ContentTypeParser.md +1 -1
  7. package/docs/Reference/Errors.md +2 -4
  8. package/docs/Reference/Hooks.md +14 -14
  9. package/docs/Reference/Logging.md +3 -3
  10. package/docs/Reference/Middleware.md +1 -1
  11. package/docs/Reference/Reply.md +8 -8
  12. package/docs/Reference/Request.md +1 -1
  13. package/docs/Reference/Routes.md +3 -3
  14. package/docs/Reference/Server.md +40 -10
  15. package/docs/Reference/Validation-and-Serialization.md +1 -1
  16. package/eslint.config.js +17 -9
  17. package/fastify.d.ts +2 -1
  18. package/fastify.js +20 -4
  19. package/lib/configValidator.js +1 -1
  20. package/lib/decorate.js +2 -2
  21. package/lib/errors.js +6 -8
  22. package/lib/logger-factory.js +1 -1
  23. package/lib/logger-pino.js +2 -2
  24. package/lib/pluginOverride.js +3 -1
  25. package/lib/reply.js +9 -13
  26. package/lib/request.js +4 -11
  27. package/lib/server.js +30 -51
  28. package/lib/symbols.js +1 -0
  29. package/lib/warnings.js +8 -0
  30. package/package.json +11 -7
  31. package/test/404s.test.js +226 -325
  32. package/test/allow-unsafe-regex.test.js +19 -48
  33. package/test/als.test.js +28 -40
  34. package/test/async-await.test.js +11 -2
  35. package/test/body-limit.test.js +41 -65
  36. package/test/build-certificate.js +1 -1
  37. package/test/close-pipelining.test.js +5 -4
  38. package/test/custom-parser-async.test.js +17 -22
  39. package/test/decorator-namespace.test._js_ +3 -4
  40. package/test/decorator.test.js +422 -341
  41. package/test/diagnostics-channel/async-delay-request.test.js +7 -16
  42. package/test/diagnostics-channel/sync-delay-request.test.js +7 -16
  43. package/test/helper.js +108 -70
  44. package/test/hooks-async.test.js +248 -218
  45. package/test/hooks.on-listen.test.js +255 -239
  46. package/test/hooks.on-ready.test.js +110 -92
  47. package/test/hooks.test.js +910 -769
  48. package/test/http-methods/lock.test.js +31 -31
  49. package/test/http-methods/mkcol.test.js +5 -9
  50. package/test/http-methods/proppatch.test.js +23 -29
  51. package/test/http-methods/report.test.js +44 -69
  52. package/test/http-methods/search.test.js +67 -82
  53. package/test/http2/closing.test.js +38 -20
  54. package/test/http2/secure-with-fallback.test.js +28 -27
  55. package/test/https/https.test.js +56 -53
  56. package/test/inject.test.js +114 -97
  57. package/test/input-validation.js +63 -53
  58. package/test/internals/errors.test.js +0 -10
  59. package/test/internals/handle-request.test.js +49 -66
  60. package/test/internals/hooks.test.js +17 -0
  61. package/test/issue-4959.test.js +14 -5
  62. package/test/listen.4.test.js +31 -43
  63. package/test/logger/response.test.js +19 -20
  64. package/test/nullable-validation.test.js +33 -46
  65. package/test/options.error-handler.test.js +1 -1
  66. package/test/options.test.js +1 -1
  67. package/test/output-validation.test.js +49 -72
  68. package/test/patch.error-handler.test.js +1 -1
  69. package/test/patch.test.js +1 -1
  70. package/test/plugin.1.test.js +71 -60
  71. package/test/plugin.2.test.js +104 -86
  72. package/test/plugin.3.test.js +56 -35
  73. package/test/plugin.4.test.js +124 -119
  74. package/test/promises.test.js +36 -30
  75. package/test/proto-poisoning.test.js +78 -97
  76. package/test/put.error-handler.test.js +1 -1
  77. package/test/put.test.js +1 -1
  78. package/test/reply-error.test.js +169 -148
  79. package/test/reply-trailers.test.js +119 -108
  80. package/test/request-error.test.js +0 -46
  81. package/test/route-hooks.test.js +112 -92
  82. package/test/route-prefix.test.js +194 -133
  83. package/test/schema-feature.test.js +309 -238
  84. package/test/schema-serialization.test.js +177 -154
  85. package/test/schema-special-usage.test.js +165 -132
  86. package/test/schema-validation.test.js +278 -199
  87. package/test/set-error-handler.test.js +58 -1
  88. package/test/skip-reply-send.test.js +64 -69
  89. package/test/stream.1.test.js +30 -27
  90. package/test/stream.2.test.js +20 -10
  91. package/test/stream.3.test.js +37 -31
  92. package/test/trust-proxy.test.js +32 -58
  93. package/test/types/errors.test-d.ts +0 -1
  94. package/test/types/fastify.test-d.ts +3 -0
  95. package/test/types/plugin.test-d.ts +1 -1
  96. package/test/types/register.test-d.ts +1 -1
  97. package/test/types/request.test-d.ts +1 -0
  98. package/test/url-rewriting.test.js +45 -62
  99. package/test/use-semicolon-delimiter.test.js +1 -1
  100. package/types/errors.d.ts +0 -1
  101. package/types/request.d.ts +1 -0
  102. package/.taprc +0 -7
  103. package/test/http2/missing-http2-module.test.js +0 -17
@@ -1,13 +1,12 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
4
- const test = t.test
3
+ const { test, describe } = require('node:test')
5
4
  const Fastify = require('../fastify')
6
5
  const fp = require('fastify-plugin')
7
6
  const fakeTimer = require('@sinonjs/fake-timers')
8
7
  const { FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER } = require('../lib/errors')
9
8
 
10
- test('pluginTimeout', t => {
9
+ test('pluginTimeout', (t, testDone) => {
11
10
  t.plan(5)
12
11
  const fastify = Fastify({
13
12
  pluginTimeout: 10
@@ -16,16 +15,17 @@ test('pluginTimeout', t => {
16
15
  // to no call done on purpose
17
16
  })
18
17
  fastify.ready((err) => {
19
- t.ok(err)
20
- t.equal(err.message,
18
+ t.assert.ok(err)
19
+ t.assert.strictEqual(err.message,
21
20
  "fastify-plugin: Plugin did not start in time: 'function (app, opts, done) { -- // to no call done on purpose'. You may have forgotten to call 'done' function or to resolve a Promise")
22
- t.equal(err.code, 'FST_ERR_PLUGIN_TIMEOUT')
23
- t.ok(err.cause)
24
- t.equal(err.cause.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
21
+ t.assert.strictEqual(err.code, 'FST_ERR_PLUGIN_TIMEOUT')
22
+ t.assert.ok(err.cause)
23
+ t.assert.strictEqual(err.cause.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
24
+ testDone()
25
25
  })
26
26
  })
27
27
 
28
- test('pluginTimeout - named function', t => {
28
+ test('pluginTimeout - named function', (t, testDone) => {
29
29
  t.plan(5)
30
30
  const fastify = Fastify({
31
31
  pluginTimeout: 10
@@ -34,16 +34,17 @@ test('pluginTimeout - named function', t => {
34
34
  // to no call done on purpose
35
35
  })
36
36
  fastify.ready((err) => {
37
- t.ok(err)
38
- t.equal(err.message,
37
+ t.assert.ok(err)
38
+ t.assert.strictEqual(err.message,
39
39
  "fastify-plugin: Plugin did not start in time: 'nameFunction'. You may have forgotten to call 'done' function or to resolve a Promise")
40
- t.equal(err.code, 'FST_ERR_PLUGIN_TIMEOUT')
41
- t.ok(err.cause)
42
- t.equal(err.cause.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
40
+ t.assert.strictEqual(err.code, 'FST_ERR_PLUGIN_TIMEOUT')
41
+ t.assert.ok(err.cause)
42
+ t.assert.strictEqual(err.cause.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
43
+ testDone()
43
44
  })
44
45
  })
45
46
 
46
- test('pluginTimeout default', t => {
47
+ test('pluginTimeout default', (t, testDone) => {
47
48
  t.plan(5)
48
49
  const clock = fakeTimer.install({ shouldClearNativeTimers: true })
49
50
 
@@ -54,18 +55,19 @@ test('pluginTimeout default', t => {
54
55
  })
55
56
 
56
57
  fastify.ready((err) => {
57
- t.ok(err)
58
- t.equal(err.message,
58
+ t.assert.ok(err)
59
+ t.assert.strictEqual(err.message,
59
60
  "fastify-plugin: Plugin did not start in time: 'function (app, opts, done) { -- // default time elapsed without calling done'. You may have forgotten to call 'done' function or to resolve a Promise")
60
- t.equal(err.code, 'FST_ERR_PLUGIN_TIMEOUT')
61
- t.ok(err.cause)
62
- t.equal(err.cause.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
61
+ t.assert.strictEqual(err.code, 'FST_ERR_PLUGIN_TIMEOUT')
62
+ t.assert.ok(err.cause)
63
+ t.assert.strictEqual(err.cause.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
64
+ testDone()
63
65
  })
64
66
 
65
- t.teardown(clock.uninstall)
67
+ t.after(clock.uninstall)
66
68
  })
67
69
 
68
- test('plugin metadata - version', t => {
70
+ test('plugin metadata - version', (t, testDone) => {
69
71
  t.plan(1)
70
72
  const fastify = Fastify()
71
73
 
@@ -78,7 +80,8 @@ test('plugin metadata - version', t => {
78
80
  fastify.register(plugin)
79
81
 
80
82
  fastify.ready(() => {
81
- t.pass('everything right')
83
+ t.assert.ok('everything right')
84
+ testDone()
82
85
  })
83
86
 
84
87
  function plugin (instance, opts, done) {
@@ -86,7 +89,7 @@ test('plugin metadata - version', t => {
86
89
  }
87
90
  })
88
91
 
89
- test('plugin metadata - version range', t => {
92
+ test('plugin metadata - version range', (t, testDone) => {
90
93
  t.plan(1)
91
94
  const fastify = Fastify()
92
95
 
@@ -99,7 +102,8 @@ test('plugin metadata - version range', t => {
99
102
  fastify.register(plugin)
100
103
 
101
104
  fastify.ready(() => {
102
- t.pass('everything right')
105
+ t.assert.ok('everything right')
106
+ testDone()
103
107
  })
104
108
 
105
109
  function plugin (instance, opts, done) {
@@ -107,7 +111,7 @@ test('plugin metadata - version range', t => {
107
111
  }
108
112
  })
109
113
 
110
- test('plugin metadata - version not matching requirement', t => {
114
+ test('plugin metadata - version not matching requirement', (t, testDone) => {
111
115
  t.plan(2)
112
116
  const fastify = Fastify()
113
117
 
@@ -120,8 +124,9 @@ test('plugin metadata - version not matching requirement', t => {
120
124
  fastify.register(plugin)
121
125
 
122
126
  fastify.ready((err) => {
123
- t.ok(err)
124
- t.equal(err.code, 'FST_ERR_PLUGIN_VERSION_MISMATCH')
127
+ t.assert.ok(err)
128
+ t.assert.strictEqual(err.code, 'FST_ERR_PLUGIN_VERSION_MISMATCH')
129
+ testDone()
125
130
  })
126
131
 
127
132
  function plugin (instance, opts, done) {
@@ -129,7 +134,7 @@ test('plugin metadata - version not matching requirement', t => {
129
134
  }
130
135
  })
131
136
 
132
- test('plugin metadata - version not matching requirement 2', t => {
137
+ test('plugin metadata - version not matching requirement 2', (t, testDone) => {
133
138
  t.plan(2)
134
139
  const fastify = Fastify()
135
140
  Object.defineProperty(fastify, 'version', {
@@ -145,8 +150,9 @@ test('plugin metadata - version not matching requirement 2', t => {
145
150
  fastify.register(plugin)
146
151
 
147
152
  fastify.ready((err) => {
148
- t.ok(err)
149
- t.equal(err.code, 'FST_ERR_PLUGIN_VERSION_MISMATCH')
153
+ t.assert.ok(err)
154
+ t.assert.strictEqual(err.code, 'FST_ERR_PLUGIN_VERSION_MISMATCH')
155
+ testDone()
150
156
  })
151
157
 
152
158
  function plugin (instance, opts, done) {
@@ -154,7 +160,7 @@ test('plugin metadata - version not matching requirement 2', t => {
154
160
  }
155
161
  })
156
162
 
157
- test('plugin metadata - version not matching requirement 3', t => {
163
+ test('plugin metadata - version not matching requirement 3', (t, testDone) => {
158
164
  t.plan(2)
159
165
  const fastify = Fastify()
160
166
 
@@ -167,8 +173,9 @@ test('plugin metadata - version not matching requirement 3', t => {
167
173
  fastify.register(plugin)
168
174
 
169
175
  fastify.ready((err) => {
170
- t.ok(err)
171
- t.equal(err.code, 'FST_ERR_PLUGIN_VERSION_MISMATCH')
176
+ t.assert.ok(err)
177
+ t.assert.strictEqual(err.code, 'FST_ERR_PLUGIN_VERSION_MISMATCH')
178
+ testDone()
172
179
  })
173
180
 
174
181
  function plugin (instance, opts, done) {
@@ -176,7 +183,7 @@ test('plugin metadata - version not matching requirement 3', t => {
176
183
  }
177
184
  })
178
185
 
179
- test('plugin metadata - release candidate', t => {
186
+ test('plugin metadata - release candidate', (t, testDone) => {
180
187
  t.plan(2)
181
188
  const fastify = Fastify()
182
189
  Object.defineProperty(fastify, 'version', {
@@ -191,8 +198,9 @@ test('plugin metadata - release candidate', t => {
191
198
  fastify.register(plugin)
192
199
 
193
200
  fastify.ready((err) => {
194
- t.error(err)
195
- t.pass('everything right')
201
+ t.assert.ifError(err)
202
+ t.assert.ok('everything right')
203
+ testDone()
196
204
  })
197
205
 
198
206
  function plugin (instance, opts, done) {
@@ -200,9 +208,9 @@ test('plugin metadata - release candidate', t => {
200
208
  }
201
209
  })
202
210
 
203
- test('fastify-rc loads prior version plugins', async t => {
204
- t.test('baseline (rc)', t => {
205
- t.plan(2)
211
+ describe('fastify-rc loads prior version plugins', async () => {
212
+ test('baseline (rc)', (t, testDone) => {
213
+ t.plan(1)
206
214
 
207
215
  const fastify = Fastify()
208
216
  Object.defineProperty(fastify, 'version', {
@@ -221,8 +229,8 @@ test('fastify-rc loads prior version plugins', async t => {
221
229
  fastify.register(plugin)
222
230
 
223
231
  fastify.ready((err) => {
224
- t.error(err)
225
- t.pass('everything right')
232
+ t.assert.ifError(err)
233
+ testDone()
226
234
  })
227
235
 
228
236
  function plugin (instance, opts, done) {
@@ -234,8 +242,8 @@ test('fastify-rc loads prior version plugins', async t => {
234
242
  }
235
243
  })
236
244
 
237
- t.test('pre', t => {
238
- t.plan(2)
245
+ test('pre', (t, testDone) => {
246
+ t.plan(1)
239
247
 
240
248
  const fastify = Fastify()
241
249
  Object.defineProperty(fastify, 'version', { value: '99.0.0-pre.1' })
@@ -245,15 +253,15 @@ test('fastify-rc loads prior version plugins', async t => {
245
253
  fastify.register(plugin)
246
254
 
247
255
  fastify.ready((err) => {
248
- t.error(err)
249
- t.pass()
256
+ t.assert.ifError(err)
257
+ testDone()
250
258
  })
251
259
 
252
260
  function plugin (instance, opts, done) { done() }
253
261
  })
254
262
 
255
- t.test('alpha', t => {
256
- t.plan(2)
263
+ test('alpha', (t, testDone) => {
264
+ t.plan(1)
257
265
 
258
266
  const fastify = Fastify()
259
267
  Object.defineProperty(fastify, 'version', { value: '99.0.0-pre.1' })
@@ -263,19 +271,17 @@ test('fastify-rc loads prior version plugins', async t => {
263
271
  fastify.register(plugin)
264
272
 
265
273
  fastify.ready((err) => {
266
- t.error(err)
267
- t.pass()
274
+ t.assert.ifError(err)
275
+ testDone()
268
276
  })
269
277
 
270
278
  function plugin (instance, opts, done) { done() }
271
279
  })
272
280
  })
273
281
 
274
- test('hasPlugin method exists as a function', t => {
275
- t.plan(1)
276
-
282
+ test('hasPlugin method exists as a function', (t) => {
277
283
  const fastify = Fastify()
278
- t.equal(typeof fastify.hasPlugin, 'function')
284
+ t.assert.strictEqual(typeof fastify.hasPlugin, 'function')
279
285
  })
280
286
 
281
287
  test('hasPlugin returns true if the specified plugin has been registered', async t => {
@@ -284,60 +290,59 @@ test('hasPlugin returns true if the specified plugin has been registered', async
284
290
  const fastify = Fastify()
285
291
 
286
292
  function pluginA (fastify, opts, done) {
287
- t.ok(fastify.hasPlugin('plugin-A'))
293
+ t.assert.ok(fastify.hasPlugin('plugin-A'))
288
294
  done()
289
295
  }
290
296
  pluginA[Symbol.for('fastify.display-name')] = 'plugin-A'
291
297
  fastify.register(pluginA)
292
298
 
293
299
  fastify.register(function pluginB (fastify, opts, done) {
294
- t.ok(fastify.hasPlugin('pluginB'))
300
+ t.assert.ok(fastify.hasPlugin('pluginB'))
295
301
  done()
296
302
  })
297
303
 
298
304
  fastify.register(function (fastify, opts, done) {
299
305
  // one line
300
- t.ok(fastify.hasPlugin('function (fastify, opts, done) { -- // one line'))
306
+ t.assert.ok(fastify.hasPlugin('function (fastify, opts, done) { -- // one line'))
301
307
  done()
302
308
  })
303
309
 
304
310
  await fastify.ready()
305
311
 
306
- t.ok(fastify.hasPlugin('fastify'))
312
+ t.assert.ok(fastify.hasPlugin('fastify'))
307
313
  })
308
314
 
309
- test('hasPlugin returns false if the specified plugin has not been registered', t => {
310
- t.plan(1)
311
-
315
+ test('hasPlugin returns false if the specified plugin has not been registered', (t) => {
312
316
  const fastify = Fastify()
313
- t.notOk(fastify.hasPlugin('pluginFoo'))
317
+ t.assert.ok(!fastify.hasPlugin('pluginFoo'))
314
318
  })
315
319
 
316
320
  test('hasPlugin returns false when using encapsulation', async t => {
317
321
  t.plan(25)
318
322
 
319
323
  const fastify = Fastify()
324
+ t.after(() => fastify.close())
320
325
 
321
326
  fastify.register(function pluginA (fastify, opts, done) {
322
- t.ok(fastify.hasPlugin('pluginA'))
323
- t.notOk(fastify.hasPlugin('pluginAA'))
324
- t.notOk(fastify.hasPlugin('pluginAAA'))
325
- t.notOk(fastify.hasPlugin('pluginAB'))
326
- t.notOk(fastify.hasPlugin('pluginB'))
327
+ t.assert.ok(fastify.hasPlugin('pluginA'))
328
+ t.assert.ok(!fastify.hasPlugin('pluginAA'))
329
+ t.assert.ok(!fastify.hasPlugin('pluginAAA'))
330
+ t.assert.ok(!fastify.hasPlugin('pluginAB'))
331
+ t.assert.ok(!fastify.hasPlugin('pluginB'))
327
332
 
328
333
  fastify.register(function pluginAA (fastify, opts, done) {
329
- t.notOk(fastify.hasPlugin('pluginA'))
330
- t.ok(fastify.hasPlugin('pluginAA'))
331
- t.notOk(fastify.hasPlugin('pluginAAA'))
332
- t.notOk(fastify.hasPlugin('pluginAB'))
333
- t.notOk(fastify.hasPlugin('pluginB'))
334
+ t.assert.ok(!fastify.hasPlugin('pluginA'))
335
+ t.assert.ok(fastify.hasPlugin('pluginAA'))
336
+ t.assert.ok(!fastify.hasPlugin('pluginAAA'))
337
+ t.assert.ok(!fastify.hasPlugin('pluginAB'))
338
+ t.assert.ok(!fastify.hasPlugin('pluginB'))
334
339
 
335
340
  fastify.register(function pluginAAA (fastify, opts, done) {
336
- t.notOk(fastify.hasPlugin('pluginA'))
337
- t.notOk(fastify.hasPlugin('pluginAA'))
338
- t.ok(fastify.hasPlugin('pluginAAA'))
339
- t.notOk(fastify.hasPlugin('pluginAB'))
340
- t.notOk(fastify.hasPlugin('pluginB'))
341
+ t.assert.ok(!fastify.hasPlugin('pluginA'))
342
+ t.assert.ok(!fastify.hasPlugin('pluginAA'))
343
+ t.assert.ok(fastify.hasPlugin('pluginAAA'))
344
+ t.assert.ok(!fastify.hasPlugin('pluginAB'))
345
+ t.assert.ok(!fastify.hasPlugin('pluginB'))
341
346
 
342
347
  done()
343
348
  })
@@ -346,11 +351,11 @@ test('hasPlugin returns false when using encapsulation', async t => {
346
351
  })
347
352
 
348
353
  fastify.register(function pluginAB (fastify, opts, done) {
349
- t.notOk(fastify.hasPlugin('pluginA'))
350
- t.notOk(fastify.hasPlugin('pluginAA'))
351
- t.notOk(fastify.hasPlugin('pluginAAA'))
352
- t.ok(fastify.hasPlugin('pluginAB'))
353
- t.notOk(fastify.hasPlugin('pluginB'))
354
+ t.assert.ok(!fastify.hasPlugin('pluginA'))
355
+ t.assert.ok(!fastify.hasPlugin('pluginAA'))
356
+ t.assert.ok(!fastify.hasPlugin('pluginAAA'))
357
+ t.assert.ok(fastify.hasPlugin('pluginAB'))
358
+ t.assert.ok(!fastify.hasPlugin('pluginB'))
354
359
 
355
360
  done()
356
361
  })
@@ -359,11 +364,11 @@ test('hasPlugin returns false when using encapsulation', async t => {
359
364
  })
360
365
 
361
366
  fastify.register(function pluginB (fastify, opts, done) {
362
- t.notOk(fastify.hasPlugin('pluginA'))
363
- t.notOk(fastify.hasPlugin('pluginAA'))
364
- t.notOk(fastify.hasPlugin('pluginAAA'))
365
- t.notOk(fastify.hasPlugin('pluginAB'))
366
- t.ok(fastify.hasPlugin('pluginB'))
367
+ t.assert.ok(!fastify.hasPlugin('pluginA'))
368
+ t.assert.ok(!fastify.hasPlugin('pluginAA'))
369
+ t.assert.ok(!fastify.hasPlugin('pluginAAA'))
370
+ t.assert.ok(!fastify.hasPlugin('pluginAB'))
371
+ t.assert.ok(fastify.hasPlugin('pluginB'))
367
372
 
368
373
  done()
369
374
  })
@@ -377,26 +382,26 @@ test('hasPlugin returns true when using no encapsulation', async t => {
377
382
  const fastify = Fastify()
378
383
 
379
384
  fastify.register(fp((fastify, opts, done) => {
380
- t.equal(fastify.pluginName, 'fastify -> plugin-AA')
381
- t.ok(fastify.hasPlugin('plugin-AA'))
382
- t.notOk(fastify.hasPlugin('plugin-A'))
383
- t.notOk(fastify.hasPlugin('plugin-AAA'))
384
- t.notOk(fastify.hasPlugin('plugin-AB'))
385
- t.notOk(fastify.hasPlugin('plugin-B'))
385
+ t.assert.strictEqual(fastify.pluginName, 'fastify -> plugin-AA')
386
+ t.assert.ok(fastify.hasPlugin('plugin-AA'))
387
+ t.assert.ok(!fastify.hasPlugin('plugin-A'))
388
+ t.assert.ok(!fastify.hasPlugin('plugin-AAA'))
389
+ t.assert.ok(!fastify.hasPlugin('plugin-AB'))
390
+ t.assert.ok(!fastify.hasPlugin('plugin-B'))
386
391
 
387
392
  fastify.register(fp((fastify, opts, done) => {
388
- t.ok(fastify.hasPlugin('plugin-AA'))
389
- t.ok(fastify.hasPlugin('plugin-A'))
390
- t.notOk(fastify.hasPlugin('plugin-AAA'))
391
- t.notOk(fastify.hasPlugin('plugin-AB'))
392
- t.notOk(fastify.hasPlugin('plugin-B'))
393
+ t.assert.ok(fastify.hasPlugin('plugin-AA'))
394
+ t.assert.ok(fastify.hasPlugin('plugin-A'))
395
+ t.assert.ok(!fastify.hasPlugin('plugin-AAA'))
396
+ t.assert.ok(!fastify.hasPlugin('plugin-AB'))
397
+ t.assert.ok(!fastify.hasPlugin('plugin-B'))
393
398
 
394
399
  fastify.register(fp((fastify, opts, done) => {
395
- t.ok(fastify.hasPlugin('plugin-AA'))
396
- t.ok(fastify.hasPlugin('plugin-A'))
397
- t.ok(fastify.hasPlugin('plugin-AAA'))
398
- t.notOk(fastify.hasPlugin('plugin-AB'))
399
- t.notOk(fastify.hasPlugin('plugin-B'))
400
+ t.assert.ok(fastify.hasPlugin('plugin-AA'))
401
+ t.assert.ok(fastify.hasPlugin('plugin-A'))
402
+ t.assert.ok(fastify.hasPlugin('plugin-AAA'))
403
+ t.assert.ok(!fastify.hasPlugin('plugin-AB'))
404
+ t.assert.ok(!fastify.hasPlugin('plugin-B'))
400
405
 
401
406
  done()
402
407
  }, { name: 'plugin-AAA' }))
@@ -405,11 +410,11 @@ test('hasPlugin returns true when using no encapsulation', async t => {
405
410
  }, { name: 'plugin-A' }))
406
411
 
407
412
  fastify.register(fp((fastify, opts, done) => {
408
- t.ok(fastify.hasPlugin('plugin-AA'))
409
- t.ok(fastify.hasPlugin('plugin-A'))
410
- t.ok(fastify.hasPlugin('plugin-AAA'))
411
- t.ok(fastify.hasPlugin('plugin-AB'))
412
- t.notOk(fastify.hasPlugin('plugin-B'))
413
+ t.assert.ok(fastify.hasPlugin('plugin-AA'))
414
+ t.assert.ok(fastify.hasPlugin('plugin-A'))
415
+ t.assert.ok(fastify.hasPlugin('plugin-AAA'))
416
+ t.assert.ok(fastify.hasPlugin('plugin-AB'))
417
+ t.assert.ok(!fastify.hasPlugin('plugin-B'))
413
418
 
414
419
  done()
415
420
  }, { name: 'plugin-AB' }))
@@ -418,11 +423,11 @@ test('hasPlugin returns true when using no encapsulation', async t => {
418
423
  }, { name: 'plugin-AA' }))
419
424
 
420
425
  fastify.register(fp((fastify, opts, done) => {
421
- t.ok(fastify.hasPlugin('plugin-AA'))
422
- t.ok(fastify.hasPlugin('plugin-A'))
423
- t.ok(fastify.hasPlugin('plugin-AAA'))
424
- t.ok(fastify.hasPlugin('plugin-AB'))
425
- t.ok(fastify.hasPlugin('plugin-B'))
426
+ t.assert.ok(fastify.hasPlugin('plugin-AA'))
427
+ t.assert.ok(fastify.hasPlugin('plugin-A'))
428
+ t.assert.ok(fastify.hasPlugin('plugin-AAA'))
429
+ t.assert.ok(fastify.hasPlugin('plugin-AB'))
430
+ t.assert.ok(fastify.hasPlugin('plugin-B'))
426
431
 
427
432
  done()
428
433
  }, { name: 'plugin-B' }))
@@ -444,12 +449,12 @@ test('hasPlugin returns true when using encapsulation', async t => {
444
449
  fastify.register(plugin)
445
450
 
446
451
  fastify.register(async (server) => {
447
- t.ok(server.hasPlugin(pluginName))
452
+ t.assert.ok(server.hasPlugin(pluginName))
448
453
  })
449
454
 
450
455
  fastify.register(async function foo (server) {
451
456
  server.register(async function bar (server) {
452
- t.ok(server.hasPlugin(pluginName))
457
+ t.assert.ok(server.hasPlugin(pluginName))
453
458
  })
454
459
  })
455
460
 
@@ -471,8 +476,8 @@ test('registering anonymous plugin with mixed style should throw', async t => {
471
476
  await fastify.ready()
472
477
  t.fail('should throw')
473
478
  } catch (error) {
474
- t.type(error, FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER)
475
- t.equal(error.message, 'The anonymousPlugin plugin being registered mixes async and callback styles. Async plugin should not mix async and callback style.')
479
+ t.assert.ok(error instanceof FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER)
480
+ t.assert.strictEqual(error.message, 'The anonymousPlugin plugin being registered mixes async and callback styles. Async plugin should not mix async and callback style.')
476
481
  }
477
482
  })
478
483
 
@@ -493,7 +498,7 @@ test('registering named plugin with mixed style should throw', async t => {
493
498
  await fastify.ready()
494
499
  t.fail('should throw')
495
500
  } catch (error) {
496
- t.type(error, FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER)
497
- t.equal(error.message, 'The error-plugin plugin being registered mixes async and callback styles. Async plugin should not mix async and callback style.')
501
+ t.assert.ok(error instanceof FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER)
502
+ t.assert.strictEqual(error.message, 'The error-plugin plugin being registered mixes async and callback styles. Async plugin should not mix async and callback style.')
498
503
  }
499
504
  })
@@ -1,10 +1,12 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
4
- const test = t.test
3
+ const { test } = require('node:test')
4
+ const assert = require('node:assert')
5
5
  const sget = require('simple-get').concat
6
6
  const fastify = require('..')()
7
7
 
8
+ test.after(() => fastify.close())
9
+
8
10
  const opts = {
9
11
  schema: {
10
12
  response: {
@@ -61,80 +63,84 @@ fastify.get('/return-reply', opts, function (req, reply) {
61
63
  })
62
64
 
63
65
  fastify.listen({ port: 0 }, err => {
64
- t.error(err)
65
- t.teardown(() => { fastify.close() })
66
+ assert.ifError(err)
66
67
 
67
- test('shorthand - sget return promise es6 get', t => {
68
+ test('shorthand - sget return promise es6 get', (t, done) => {
68
69
  t.plan(4)
69
70
  sget({
70
71
  method: 'GET',
71
72
  url: 'http://localhost:' + fastify.server.address().port + '/return'
72
73
  }, (err, response, body) => {
73
- t.error(err)
74
- t.equal(response.statusCode, 200)
75
- t.equal(response.headers['content-length'], '' + body.length)
76
- t.same(JSON.parse(body), { hello: 'world' })
74
+ t.assert.ifError(err)
75
+ t.assert.strictEqual(response.statusCode, 200)
76
+ t.assert.strictEqual(response.headers['content-length'], '' + body.length)
77
+ t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
78
+ done()
77
79
  })
78
80
  })
79
81
 
80
- test('shorthand - sget promise es6 get return error', t => {
82
+ test('shorthand - sget promise es6 get return error', (t, done) => {
81
83
  t.plan(2)
82
84
  sget({
83
85
  method: 'GET',
84
86
  url: 'http://localhost:' + fastify.server.address().port + '/return-error'
85
87
  }, (err, response, body) => {
86
- t.error(err)
87
- t.equal(response.statusCode, 500)
88
+ t.assert.ifError(err)
89
+ t.assert.strictEqual(response.statusCode, 500)
90
+ done()
88
91
  })
89
92
  })
90
93
 
91
- test('sget promise double send', t => {
94
+ test('sget promise double send', (t, done) => {
92
95
  t.plan(3)
93
-
94
96
  sget({
95
97
  method: 'GET',
96
98
  url: 'http://localhost:' + fastify.server.address().port + '/double'
97
99
  }, (err, response, body) => {
98
- t.error(err)
99
- t.equal(response.statusCode, 200)
100
- t.same(JSON.parse(body), { hello: '42' })
100
+ t.assert.ifError(err)
101
+ t.assert.strictEqual(response.statusCode, 200)
102
+ t.assert.deepStrictEqual(JSON.parse(body), { hello: '42' })
103
+ done()
101
104
  })
102
105
  })
103
106
 
104
- test('thenable', t => {
107
+ test('thenable', (t, done) => {
105
108
  t.plan(4)
106
109
  sget({
107
110
  method: 'GET',
108
111
  url: 'http://localhost:' + fastify.server.address().port + '/thenable'
109
112
  }, (err, response, body) => {
110
- t.error(err)
111
- t.equal(response.statusCode, 200)
112
- t.equal(response.headers['content-length'], '' + body.length)
113
- t.same(JSON.parse(body), { hello: 'world' })
113
+ t.assert.ifError(err)
114
+ t.assert.strictEqual(response.statusCode, 200)
115
+ t.assert.strictEqual(response.headers['content-length'], '' + body.length)
116
+ t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
117
+ done()
114
118
  })
115
119
  })
116
120
 
117
- test('thenable (error)', t => {
121
+ test('thenable (error)', (t, done) => {
118
122
  t.plan(2)
119
123
  sget({
120
124
  method: 'GET',
121
125
  url: 'http://localhost:' + fastify.server.address().port + '/thenable-error'
122
126
  }, (err, response, body) => {
123
- t.error(err)
124
- t.equal(response.statusCode, 500)
127
+ t.assert.ifError(err)
128
+ t.assert.strictEqual(response.statusCode, 500)
129
+ done()
125
130
  })
126
131
  })
127
132
 
128
- test('return-reply', t => {
133
+ test('return-reply', (t, done) => {
129
134
  t.plan(4)
130
135
  sget({
131
136
  method: 'GET',
132
137
  url: 'http://localhost:' + fastify.server.address().port + '/return-reply'
133
138
  }, (err, response, body) => {
134
- t.error(err)
135
- t.equal(response.statusCode, 200)
136
- t.equal(response.headers['content-length'], '' + body.length)
137
- t.same(JSON.parse(body), { hello: 'world' })
139
+ t.assert.ifError(err)
140
+ t.assert.strictEqual(response.statusCode, 200)
141
+ t.assert.strictEqual(response.headers['content-length'], '' + body.length)
142
+ t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
143
+ done()
138
144
  })
139
145
  })
140
146
  })