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.
- package/.vscode/settings.json +22 -0
- package/docs/Guides/Ecosystem.md +7 -2
- package/docs/Guides/Serverless.md +28 -69
- package/docs/Reference/Errors.md +0 -2
- package/docs/Reference/Server.md +17 -1
- package/eslint.config.js +17 -9
- package/fastify.js +6 -2
- package/lib/decorate.js +2 -2
- package/lib/errors.js +0 -8
- package/lib/logger-factory.js +1 -1
- package/lib/logger-pino.js +2 -2
- package/lib/reply.js +2 -2
- package/lib/request.js +1 -1
- package/lib/server.js +30 -51
- package/package.json +4 -4
- package/test/close-pipelining.test.js +5 -4
- package/test/decorator.test.js +422 -341
- package/test/helper.js +107 -69
- package/test/hooks.on-listen.test.js +255 -239
- package/test/hooks.on-ready.test.js +110 -92
- package/test/inject.test.js +114 -97
- package/test/input-validation.js +63 -53
- package/test/internals/errors.test.js +1 -11
- package/test/internals/hooks.test.js +17 -0
- package/test/issue-4959.test.js +2 -2
- package/test/logger/response.test.js +19 -20
- package/test/options.error-handler.test.js +1 -1
- package/test/options.test.js +1 -1
- package/test/output-validation.test.js +49 -70
- package/test/patch.error-handler.test.js +1 -1
- package/test/patch.test.js +1 -1
- package/test/plugin.1.test.js +71 -60
- package/test/promises.test.js +36 -30
- package/test/put.error-handler.test.js +1 -1
- package/test/put.test.js +1 -1
- package/test/reply-error.test.js +169 -148
- package/test/reply-trailers.test.js +119 -108
- package/test/schema-feature.test.js +309 -238
- package/test/schema-validation.test.js +44 -2
- package/test/stream.1.test.js +30 -27
- package/test/stream.2.test.js +20 -10
- package/test/stream.3.test.js +37 -31
- package/test/types/errors.test-d.ts +0 -1
- package/test/types/plugin.test-d.ts +1 -1
- package/test/types/register.test-d.ts +1 -1
- package/test/use-semicolon-delimiter.test.js +1 -1
- package/types/errors.d.ts +0 -1
- package/test/http2/missing-http2-module.test.js +0 -17
package/test/plugin.1.test.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const t = require('
|
|
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.
|
|
30
|
-
t.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
89
|
+
t.assert.ok(!fastify.test)
|
|
87
90
|
})
|
|
88
91
|
|
|
89
92
|
fastify.listen({ port: 0 }, err => {
|
|
90
|
-
t.
|
|
91
|
-
t.
|
|
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.
|
|
98
|
-
t.
|
|
99
|
-
t.
|
|
100
|
-
t.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
151
|
-
t.
|
|
152
|
-
t.
|
|
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.
|
|
158
|
-
t.
|
|
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.
|
|
169
|
+
t.assert.ok(!fastify.global)
|
|
166
170
|
})
|
|
167
171
|
|
|
168
172
|
fastify.listen({ port: 0 }, err => {
|
|
169
|
-
t.
|
|
170
|
-
t.
|
|
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.
|
|
177
|
-
t.
|
|
178
|
-
t.
|
|
179
|
-
t.
|
|
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.
|
|
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.
|
|
225
|
-
t.
|
|
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.
|
|
232
|
-
t.
|
|
233
|
-
t.
|
|
234
|
-
t.
|
|
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.
|
|
242
|
-
t.
|
|
243
|
-
t.
|
|
244
|
-
t.
|
|
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
|
})
|
package/test/promises.test.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
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
|
-
|
|
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.
|
|
74
|
-
t.
|
|
75
|
-
t.
|
|
76
|
-
t.
|
|
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.
|
|
87
|
-
t.
|
|
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.
|
|
99
|
-
t.
|
|
100
|
-
t.
|
|
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.
|
|
111
|
-
t.
|
|
112
|
-
t.
|
|
113
|
-
t.
|
|
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.
|
|
124
|
-
t.
|
|
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.
|
|
135
|
-
t.
|
|
136
|
-
t.
|
|
137
|
-
t.
|
|
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
|
})
|
package/test/put.test.js
CHANGED