fastify 5.3.2 → 5.3.3

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 (48) hide show
  1. package/.vscode/settings.json +22 -0
  2. package/docs/Guides/Ecosystem.md +7 -2
  3. package/docs/Guides/Serverless.md +28 -69
  4. package/docs/Reference/Errors.md +0 -2
  5. package/docs/Reference/Server.md +17 -1
  6. package/eslint.config.js +17 -9
  7. package/fastify.js +6 -2
  8. package/lib/decorate.js +2 -2
  9. package/lib/errors.js +0 -8
  10. package/lib/logger-factory.js +1 -1
  11. package/lib/logger-pino.js +2 -2
  12. package/lib/reply.js +2 -2
  13. package/lib/request.js +1 -1
  14. package/lib/server.js +30 -51
  15. package/package.json +4 -4
  16. package/test/close-pipelining.test.js +5 -4
  17. package/test/decorator.test.js +422 -341
  18. package/test/helper.js +107 -69
  19. package/test/hooks.on-listen.test.js +255 -239
  20. package/test/hooks.on-ready.test.js +110 -92
  21. package/test/inject.test.js +114 -97
  22. package/test/input-validation.js +63 -53
  23. package/test/internals/errors.test.js +1 -11
  24. package/test/internals/hooks.test.js +17 -0
  25. package/test/issue-4959.test.js +2 -2
  26. package/test/logger/response.test.js +19 -20
  27. package/test/options.error-handler.test.js +1 -1
  28. package/test/options.test.js +1 -1
  29. package/test/output-validation.test.js +49 -70
  30. package/test/patch.error-handler.test.js +1 -1
  31. package/test/patch.test.js +1 -1
  32. package/test/plugin.1.test.js +71 -60
  33. package/test/promises.test.js +36 -30
  34. package/test/put.error-handler.test.js +1 -1
  35. package/test/put.test.js +1 -1
  36. package/test/reply-error.test.js +169 -148
  37. package/test/reply-trailers.test.js +119 -108
  38. package/test/schema-feature.test.js +309 -238
  39. package/test/schema-validation.test.js +44 -2
  40. package/test/stream.1.test.js +30 -27
  41. package/test/stream.2.test.js +20 -10
  42. package/test/stream.3.test.js +37 -31
  43. package/test/types/errors.test-d.ts +0 -1
  44. package/test/types/plugin.test-d.ts +1 -1
  45. package/test/types/register.test-d.ts +1 -1
  46. package/test/use-semicolon-delimiter.test.js +1 -1
  47. package/types/errors.d.ts +0 -1
  48. package/test/http2/missing-http2-module.test.js +0 -17
@@ -1,21 +1,23 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
3
+ const t = require('node:test')
4
4
  const test = t.test
5
5
  const Fastify = require('../fastify')
6
6
  const sget = require('simple-get').concat
7
7
  const fp = require('fastify-plugin')
8
+ const { waitForCb } = require('./toolkit')
8
9
 
9
- test('require a plugin', t => {
10
+ test('require a plugin', (t, testDone) => {
10
11
  t.plan(1)
11
12
  const fastify = Fastify()
12
13
  fastify.register(require('./plugin.helper'))
13
14
  fastify.ready(() => {
14
- t.ok(fastify.test)
15
+ t.assert.ok(fastify.test)
16
+ testDone()
15
17
  })
16
18
  })
17
19
 
18
- test('plugin metadata - ignore prefix', t => {
20
+ test('plugin metadata - ignore prefix', (t, testDone) => {
19
21
  t.plan(2)
20
22
  const fastify = Fastify()
21
23
 
@@ -26,8 +28,9 @@ test('plugin metadata - ignore prefix', t => {
26
28
  method: 'GET',
27
29
  url: '/'
28
30
  }, function (err, res) {
29
- t.error(err)
30
- t.equal(res.payload, 'hello')
31
+ t.assert.ifError(err)
32
+ t.assert.strictEqual(res.payload, 'hello')
33
+ testDone()
31
34
  })
32
35
 
33
36
  function plugin (instance, opts, done) {
@@ -45,37 +48,37 @@ test('plugin metadata - naming plugins', async t => {
45
48
  fastify.register(require('./plugin.name.display'))
46
49
  fastify.register(function (fastify, opts, done) {
47
50
  // one line
48
- t.equal(fastify.pluginName, 'function (fastify, opts, done) { -- // one line')
51
+ t.assert.strictEqual(fastify.pluginName, 'function (fastify, opts, done) { -- // one line')
49
52
  done()
50
53
  })
51
54
  fastify.register(function fooBar (fastify, opts, done) {
52
- t.equal(fastify.pluginName, 'fooBar')
55
+ t.assert.strictEqual(fastify.pluginName, 'fooBar')
53
56
  done()
54
57
  })
55
58
 
56
59
  await fastify.ready()
57
60
  })
58
61
 
59
- test('fastify.register with fastify-plugin should not encapsulate his code', t => {
62
+ test('fastify.register with fastify-plugin should not encapsulate his code', (t, testDone) => {
60
63
  t.plan(10)
61
64
  const fastify = Fastify()
62
65
 
63
66
  fastify.register((instance, opts, done) => {
64
67
  instance.register(fp((i, o, n) => {
65
68
  i.decorate('test', () => {})
66
- t.ok(i.test)
69
+ t.assert.ok(i.test)
67
70
  n()
68
71
  }))
69
72
 
70
- t.notOk(instance.test)
73
+ t.assert.ok(!instance.test)
71
74
 
72
75
  // the decoration is added at the end
73
76
  instance.after(() => {
74
- t.ok(instance.test)
77
+ t.assert.ok(instance.test)
75
78
  })
76
79
 
77
80
  instance.get('/', (req, reply) => {
78
- t.ok(instance.test)
81
+ t.assert.ok(instance.test)
79
82
  reply.send({ hello: 'world' })
80
83
  })
81
84
 
@@ -83,41 +86,42 @@ test('fastify.register with fastify-plugin should not encapsulate his code', t =
83
86
  })
84
87
 
85
88
  fastify.ready(() => {
86
- t.notOk(fastify.test)
89
+ t.assert.ok(!fastify.test)
87
90
  })
88
91
 
89
92
  fastify.listen({ port: 0 }, err => {
90
- t.error(err)
91
- t.teardown(() => { fastify.close() })
93
+ t.assert.ifError(err)
94
+ t.after(() => { fastify.close() })
92
95
 
93
96
  sget({
94
97
  method: 'GET',
95
98
  url: 'http://localhost:' + fastify.server.address().port
96
99
  }, (err, response, body) => {
97
- t.error(err)
98
- t.equal(response.statusCode, 200)
99
- t.equal(response.headers['content-length'], '' + body.length)
100
- t.same(JSON.parse(body), { hello: 'world' })
100
+ t.assert.ifError(err)
101
+ t.assert.strictEqual(response.statusCode, 200)
102
+ t.assert.strictEqual(response.headers['content-length'], '' + body.length)
103
+ t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
104
+ testDone()
101
105
  })
102
106
  })
103
107
  })
104
108
 
105
- test('fastify.register with fastify-plugin should provide access to external fastify instance if opts argument is a function', t => {
109
+ test('fastify.register with fastify-plugin should provide access to external fastify instance if opts argument is a function', (t, testDone) => {
106
110
  t.plan(22)
107
111
  const fastify = Fastify()
108
112
 
109
113
  fastify.register((instance, opts, done) => {
110
114
  instance.register(fp((i, o, n) => {
111
115
  i.decorate('global', () => {})
112
- t.ok(i.global)
116
+ t.assert.ok(i.global)
113
117
  n()
114
118
  }))
115
119
 
116
120
  instance.register((i, o, n) => n(), p => {
117
- t.notOk(p === instance || p === fastify)
118
- t.ok(Object.prototype.isPrototypeOf.call(instance, p))
119
- t.ok(Object.prototype.isPrototypeOf.call(fastify, p))
120
- t.ok(p.global)
121
+ t.assert.ok(!(p === instance || p === fastify))
122
+ t.assert.ok(Object.prototype.isPrototypeOf.call(instance, p))
123
+ t.assert.ok(Object.prototype.isPrototypeOf.call(fastify, p))
124
+ t.assert.ok(p.global)
121
125
  })
122
126
 
123
127
  instance.register((i, o, n) => {
@@ -125,17 +129,17 @@ test('fastify.register with fastify-plugin should provide access to external fas
125
129
  n()
126
130
  })
127
131
 
128
- instance.register((i, o, n) => n(), p => t.notOk(p.local))
132
+ instance.register((i, o, n) => n(), p => t.assert.ok(!p.local))
129
133
 
130
134
  instance.register((i, o, n) => {
131
- t.ok(i.local)
135
+ t.assert.ok(i.local)
132
136
  n()
133
137
  }, p => p.decorate('local', () => {}))
134
138
 
135
- instance.register((i, o, n) => n(), p => t.notOk(p.local))
139
+ instance.register((i, o, n) => n(), p => t.assert.ok(!p.local))
136
140
 
137
141
  instance.register(fp((i, o, n) => {
138
- t.ok(i.global_2)
142
+ t.assert.ok(i.global_2)
139
143
  n()
140
144
  }), p => p.decorate('global_2', () => 'hello'))
141
145
 
@@ -143,40 +147,41 @@ test('fastify.register with fastify-plugin should provide access to external fas
143
147
  i.decorate('global_2', () => 'world')
144
148
  n()
145
149
  }, p => p.get('/', (req, reply) => {
146
- t.ok(p.global_2)
150
+ t.assert.ok(p.global_2)
147
151
  reply.send({ hello: p.global_2() })
148
152
  }))
149
153
 
150
- t.notOk(instance.global)
151
- t.notOk(instance.global_2)
152
- t.notOk(instance.local)
154
+ t.assert.ok(!instance.global)
155
+ t.assert.ok(!instance.global_2)
156
+ t.assert.ok(!instance.local)
153
157
 
154
158
  // the decoration is added at the end
155
159
  instance.after(() => {
156
- t.ok(instance.global)
157
- t.equal(instance.global_2(), 'hello')
158
- t.notOk(instance.local)
160
+ t.assert.ok(instance.global)
161
+ t.assert.strictEqual(instance.global_2(), 'hello')
162
+ t.assert.ok(!instance.local)
159
163
  })
160
164
 
161
165
  done()
162
166
  })
163
167
 
164
168
  fastify.ready(() => {
165
- t.notOk(fastify.global)
169
+ t.assert.ok(!fastify.global)
166
170
  })
167
171
 
168
172
  fastify.listen({ port: 0 }, err => {
169
- t.error(err)
170
- t.teardown(() => { fastify.close() })
173
+ t.assert.ifError(err)
174
+ t.after(() => { fastify.close() })
171
175
 
172
176
  sget({
173
177
  method: 'GET',
174
178
  url: 'http://localhost:' + fastify.server.address().port
175
179
  }, (err, response, body) => {
176
- t.error(err)
177
- t.equal(response.statusCode, 200)
178
- t.equal(response.headers['content-length'], '' + body.length)
179
- t.same(JSON.parse(body), { hello: 'world' })
180
+ t.assert.ifError(err)
181
+ t.assert.strictEqual(response.statusCode, 200)
182
+ t.assert.strictEqual(response.headers['content-length'], '' + body.length)
183
+ t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
184
+ testDone()
180
185
  })
181
186
  })
182
187
  })
@@ -187,7 +192,7 @@ test('fastify.register with fastify-plugin registers fastify level plugins', t =
187
192
 
188
193
  function fastifyPlugin (instance, opts, done) {
189
194
  instance.decorate('test', 'first')
190
- t.ok(instance.test)
195
+ t.assert.ok(instance.test)
191
196
  done()
192
197
  }
193
198
 
@@ -199,11 +204,11 @@ test('fastify.register with fastify-plugin registers fastify level plugins', t =
199
204
  fastify.register(fp(fastifyPlugin))
200
205
 
201
206
  fastify.register((instance, opts, done) => {
202
- t.ok(instance.test)
207
+ t.assert.ok(instance.test)
203
208
  instance.register(fp(innerPlugin))
204
209
 
205
210
  instance.get('/test2', (req, reply) => {
206
- t.ok(instance.test2)
211
+ t.assert.ok(instance.test2)
207
212
  reply.send({ test2: instance.test2 })
208
213
  })
209
214
 
@@ -211,37 +216,43 @@ test('fastify.register with fastify-plugin registers fastify level plugins', t =
211
216
  })
212
217
 
213
218
  fastify.ready(() => {
214
- t.ok(fastify.test)
215
- t.notOk(fastify.test2)
219
+ t.assert.ok(fastify.test)
220
+ t.assert.ok(!fastify.test2)
216
221
  })
217
222
 
218
223
  fastify.get('/', (req, reply) => {
219
- t.ok(fastify.test)
224
+ t.assert.ok(fastify.test)
220
225
  reply.send({ test: fastify.test })
221
226
  })
222
227
 
228
+ const { stepIn, patience } = waitForCb({ steps: 2 })
229
+
223
230
  fastify.listen({ port: 0 }, err => {
224
- t.error(err)
225
- t.teardown(() => { fastify.close() })
231
+ t.assert.ifError(err)
232
+ t.after(() => { fastify.close() })
226
233
 
227
234
  sget({
228
235
  method: 'GET',
229
236
  url: 'http://localhost:' + fastify.server.address().port
230
237
  }, (err, response, body) => {
231
- t.error(err)
232
- t.equal(response.statusCode, 200)
233
- t.equal(response.headers['content-length'], '' + body.length)
234
- t.same(JSON.parse(body), { test: 'first' })
238
+ t.assert.ifError(err)
239
+ t.assert.strictEqual(response.statusCode, 200)
240
+ t.assert.strictEqual(response.headers['content-length'], '' + body.length)
241
+ t.assert.deepStrictEqual(JSON.parse(body), { test: 'first' })
242
+ stepIn()
235
243
  })
236
244
 
237
245
  sget({
238
246
  method: 'GET',
239
247
  url: 'http://localhost:' + fastify.server.address().port + '/test2'
240
248
  }, (err, response, body) => {
241
- t.error(err)
242
- t.equal(response.statusCode, 200)
243
- t.equal(response.headers['content-length'], '' + body.length)
244
- t.same(JSON.parse(body), { test2: 'second' })
249
+ t.assert.ifError(err)
250
+ t.assert.strictEqual(response.statusCode, 200)
251
+ t.assert.strictEqual(response.headers['content-length'], '' + body.length)
252
+ t.assert.deepStrictEqual(JSON.parse(body), { test2: 'second' })
253
+ stepIn()
245
254
  })
246
255
  })
256
+
257
+ return patience
247
258
  })
@@ -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
  })
@@ -1,5 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
3
+ const t = require('node:test')
4
4
  require('./helper').payloadMethod('put', t, true)
5
5
  require('./input-validation').payloadMethod('put', t)
package/test/put.test.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
3
+ const t = require('node:test')
4
4
  require('./helper').payloadMethod('put', t)
5
5
  require('./input-validation').payloadMethod('put', t)