fastify 5.1.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.
- package/README.md +12 -7
- package/docs/Guides/Database.md +15 -15
- package/docs/Guides/Detecting-When-Clients-Abort.md +28 -28
- package/docs/Guides/Ecosystem.md +13 -7
- package/docs/Guides/Index.md +1 -1
- package/docs/Guides/Migration-Guide-V4.md +11 -11
- package/docs/Guides/Migration-Guide-V5.md +5 -5
- package/docs/Guides/Plugins-Guide.md +1 -1
- package/docs/Guides/Prototype-Poisoning.md +3 -3
- package/docs/Guides/Recommendations.md +9 -9
- package/docs/Guides/Serverless.md +5 -5
- package/docs/Guides/Testing.md +8 -8
- package/docs/Guides/Write-Plugin.md +1 -1
- package/docs/Guides/Write-Type-Provider.md +3 -3
- package/docs/Reference/Decorators.md +2 -2
- package/docs/Reference/Errors.md +2 -2
- package/docs/Reference/Hooks.md +7 -7
- package/docs/Reference/LTS.md +8 -0
- package/docs/Reference/Logging.md +5 -4
- package/docs/Reference/Reply.md +54 -53
- package/docs/Reference/Request.md +49 -43
- package/docs/Reference/Routes.md +7 -7
- package/docs/Reference/Server.md +31 -27
- package/docs/Reference/TypeScript.md +9 -9
- package/docs/Reference/Validation-and-Serialization.md +5 -5
- package/examples/typescript-server.ts +1 -1
- package/fastify.d.ts +4 -4
- package/fastify.js +1 -1
- package/lib/error-handler.js +9 -9
- package/lib/errors.js +1 -1
- package/lib/hooks.js +4 -1
- package/lib/request.js +11 -10
- package/package.json +3 -4
- package/test/{allowUnsafeRegex.test.js → allow-unsafe-regex.test.js} +4 -4
- package/test/async-dispose.test.js +0 -1
- package/test/async_hooks.test.js +4 -4
- package/test/buffer.test.js +4 -4
- package/test/build-certificate.js +1 -1
- package/test/bundler/README.md +5 -5
- package/test/case-insensitive.test.js +10 -10
- package/test/check.test.js +2 -3
- package/test/{childLoggerFactory.test.js → child-logger-factory.test.js} +1 -1
- package/test/client-timeout.test.js +1 -1
- package/test/close-pipelining.test.js +0 -1
- package/test/conditional-pino.test.js +3 -3
- package/test/content-length.test.js +53 -68
- package/test/content-parser.test.js +178 -167
- package/test/content-type.test.js +8 -9
- package/test/context-config.test.js +44 -54
- package/test/custom-parser.5.test.js +32 -32
- package/test/encapsulated-child-logger-factory.test.js +8 -8
- package/test/encapsulated-error-handler.test.js +20 -20
- package/test/fastify-instance.test.js +33 -34
- package/test/{findRoute.test.js → find-route.test.js} +11 -10
- package/test/fluent-schema.test.js +33 -36
- package/test/handler-context.test.js +11 -11
- package/test/has-route.test.js +12 -15
- package/test/header-overflow.test.js +13 -12
- package/test/hooks.on-ready.test.js +2 -2
- package/test/hooks.test.js +19 -19
- package/test/http-methods/head.test.js +0 -3
- package/test/imports.test.js +2 -2
- package/test/internals/errors.test.js +1 -1
- package/test/listen.5.test.js +9 -9
- package/test/{maxRequestsPerSocket.test.js → max-requests-per-socket.test.js} +30 -30
- package/test/middleware.test.js +4 -5
- package/test/noop-set.test.js +1 -1
- package/test/post-empty-body.test.js +18 -11
- package/test/pretty-print.test.js +59 -49
- package/test/proto-poisoning.test.js +42 -37
- package/test/reply-code.test.js +34 -32
- package/test/{reply-earlyHints.test.js → reply-early-hints.test.js} +21 -19
- package/test/request-header-host.test.js +154 -12
- package/test/request-id.test.js +31 -25
- package/test/{requestTimeout.test.js → request-timeout.test.js} +11 -11
- package/test/route.3.test.js +3 -2
- package/test/route.8.test.js +20 -20
- package/test/router-options.test.js +80 -77
- package/test/schema-examples.test.js +72 -38
- package/test/server.test.js +12 -12
- package/test/set-error-handler.test.js +2 -3
- package/test/stream-serializers.test.js +10 -7
- package/test/sync-routes.test.js +18 -18
- package/test/trust-proxy.test.js +51 -45
- package/test/type-provider.test.js +8 -6
- package/test/types/content-type-parser.test-d.ts +1 -1
- package/test/types/fastify.test-d.ts +4 -4
- package/test/types/instance.test-d.ts +3 -1
- package/test/types/logger.test-d.ts +2 -2
- package/test/types/plugin.test-d.ts +2 -2
- package/test/types/register.test-d.ts +2 -2
- package/test/types/reply.test-d.ts +1 -1
- package/test/types/route.test-d.ts +1 -1
- package/test/types/serverFactory.test-d.ts +1 -1
- package/test/types/type-provider.test-d.ts +1 -1
- package/test/url-rewriting.test.js +35 -38
- package/test/{useSemicolonDelimiter.test.js → use-semicolon-delimiter.test.js} +30 -30
- package/test/validation-error-handling.test.js +259 -285
- package/types/hooks.d.ts +1 -1
- package/types/instance.d.ts +9 -2
- package/types/reply.d.ts +1 -1
- package/types/request.d.ts +0 -4
- package/types/serverFactory.d.ts +3 -3
- package/types/utils.d.ts +3 -3
- /package/test/{connectionTimeout.test.js → connection-timeout.test.js} +0 -0
- /package/test/internals/{contentTypeParser.test.js → content-type-parser.test.js} +0 -0
- /package/test/internals/{handleRequest.test.js → handle-request.test.js} +0 -0
- /package/test/internals/{hookRunner.test.js → hook-runner.test.js} +0 -0
- /package/test/internals/{initialConfig.test.js → initial-config.test.js} +0 -0
- /package/test/internals/{reqIdGenFactory.test.js → req-id-gen-factory.test.js} +0 -0
- /package/test/{wrapThenable.test.js → wrap-thenable.test.js} +0 -0
|
@@ -72,9 +72,9 @@ test('Return 200 when Host header is empty', (t, done) => {
|
|
|
72
72
|
t.after(() => fastify.close())
|
|
73
73
|
|
|
74
74
|
fastify.get('/', async function (request) {
|
|
75
|
-
t.assert.
|
|
76
|
-
t.assert.
|
|
77
|
-
t.assert.
|
|
75
|
+
t.assert.strictEqual(request.host, '')
|
|
76
|
+
t.assert.strictEqual(request.hostname, '')
|
|
77
|
+
t.assert.strictEqual(request.port, null)
|
|
78
78
|
return { ok: true }
|
|
79
79
|
})
|
|
80
80
|
fastify.listen({ port: 0 }, err => {
|
|
@@ -104,9 +104,9 @@ test('Return 200 when Host header is empty with trust proxy', (t, done) => {
|
|
|
104
104
|
t.after(() => fastify.close())
|
|
105
105
|
|
|
106
106
|
fastify.get('/', async function (request) {
|
|
107
|
-
t.assert.
|
|
108
|
-
t.assert.
|
|
109
|
-
t.assert.
|
|
107
|
+
t.assert.strictEqual(request.host, '')
|
|
108
|
+
t.assert.strictEqual(request.hostname, '')
|
|
109
|
+
t.assert.strictEqual(request.port, null)
|
|
110
110
|
return { ok: true }
|
|
111
111
|
})
|
|
112
112
|
fastify.listen({ port: 0 }, err => {
|
|
@@ -140,9 +140,9 @@ test('Return 200 when Host header is missing and http.requireHostHeader = false'
|
|
|
140
140
|
t.after(() => fastify.close())
|
|
141
141
|
|
|
142
142
|
fastify.get('/', async function (request) {
|
|
143
|
-
t.assert.
|
|
144
|
-
t.assert.
|
|
145
|
-
t.assert.
|
|
143
|
+
t.assert.strictEqual(request.host, '')
|
|
144
|
+
t.assert.strictEqual(request.hostname, '')
|
|
145
|
+
t.assert.strictEqual(request.port, null)
|
|
146
146
|
return { ok: true }
|
|
147
147
|
})
|
|
148
148
|
fastify.listen({ port: 0 }, err => {
|
|
@@ -175,9 +175,9 @@ test('Return 200 when Host header is missing and http.requireHostHeader = false
|
|
|
175
175
|
t.after(() => fastify.close())
|
|
176
176
|
|
|
177
177
|
fastify.get('/', async function (request) {
|
|
178
|
-
t.assert.
|
|
179
|
-
t.assert.
|
|
180
|
-
t.assert.
|
|
178
|
+
t.assert.strictEqual(request.host, '')
|
|
179
|
+
t.assert.strictEqual(request.hostname, '')
|
|
180
|
+
t.assert.strictEqual(request.port, null)
|
|
181
181
|
return { ok: true }
|
|
182
182
|
})
|
|
183
183
|
fastify.listen({ port: 0 }, err => {
|
|
@@ -195,3 +195,145 @@ test('Return 200 when Host header is missing and http.requireHostHeader = false
|
|
|
195
195
|
})
|
|
196
196
|
})
|
|
197
197
|
})
|
|
198
|
+
|
|
199
|
+
test('Return 200 when Host header is missing using HTTP/1.0', (t, done) => {
|
|
200
|
+
t.plan(5)
|
|
201
|
+
let data = Buffer.alloc(0)
|
|
202
|
+
const fastify = Fastify({
|
|
203
|
+
keepAliveTimeout: 10
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
t.after(() => fastify.close())
|
|
207
|
+
|
|
208
|
+
fastify.get('/', async function (request) {
|
|
209
|
+
t.assert.strictEqual(request.host, '')
|
|
210
|
+
t.assert.strictEqual(request.hostname, '')
|
|
211
|
+
t.assert.strictEqual(request.port, null)
|
|
212
|
+
return { ok: true }
|
|
213
|
+
})
|
|
214
|
+
fastify.listen({ port: 0 }, err => {
|
|
215
|
+
t.assert.ifError(err)
|
|
216
|
+
|
|
217
|
+
const socket = connect(fastify.server.address().port)
|
|
218
|
+
socket.write('GET / HTTP/1.0\r\n\r\n')
|
|
219
|
+
socket.on('data', c => (data = Buffer.concat([data, c])))
|
|
220
|
+
socket.on('end', () => {
|
|
221
|
+
t.assert.match(
|
|
222
|
+
data.toString('utf-8'),
|
|
223
|
+
/^HTTP\/1.1 200 OK/
|
|
224
|
+
)
|
|
225
|
+
done()
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
test('Return 200 when Host header is missing with trust proxy using HTTP/1.0', (t, done) => {
|
|
231
|
+
t.plan(5)
|
|
232
|
+
let data = Buffer.alloc(0)
|
|
233
|
+
const fastify = Fastify({
|
|
234
|
+
trustProxy: true,
|
|
235
|
+
keepAliveTimeout: 10
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
t.after(() => fastify.close())
|
|
239
|
+
|
|
240
|
+
fastify.get('/', async function (request) {
|
|
241
|
+
t.assert.strictEqual(request.host, '')
|
|
242
|
+
t.assert.strictEqual(request.hostname, '')
|
|
243
|
+
t.assert.strictEqual(request.port, null)
|
|
244
|
+
return { ok: true }
|
|
245
|
+
})
|
|
246
|
+
fastify.listen({ port: 0 }, err => {
|
|
247
|
+
t.assert.ifError(err)
|
|
248
|
+
|
|
249
|
+
const socket = connect(fastify.server.address().port)
|
|
250
|
+
socket.write('GET / HTTP/1.0\r\n\r\n')
|
|
251
|
+
socket.on('data', c => (data = Buffer.concat([data, c])))
|
|
252
|
+
socket.on('end', () => {
|
|
253
|
+
t.assert.match(
|
|
254
|
+
data.toString('utf-8'),
|
|
255
|
+
/^HTTP\/1.1 200 OK/
|
|
256
|
+
)
|
|
257
|
+
done()
|
|
258
|
+
})
|
|
259
|
+
})
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
test('Return 200 when Host header is removed by schema', (t, done) => {
|
|
263
|
+
t.plan(5)
|
|
264
|
+
let data = Buffer.alloc(0)
|
|
265
|
+
const fastify = Fastify({
|
|
266
|
+
keepAliveTimeout: 10
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
t.after(() => fastify.close())
|
|
270
|
+
|
|
271
|
+
fastify.get('/', {
|
|
272
|
+
schema: {
|
|
273
|
+
headers: {
|
|
274
|
+
type: 'object',
|
|
275
|
+
properties: {},
|
|
276
|
+
additionalProperties: false
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}, async function (request) {
|
|
280
|
+
t.assert.strictEqual(request.host, '')
|
|
281
|
+
t.assert.strictEqual(request.hostname, '')
|
|
282
|
+
t.assert.strictEqual(request.port, null)
|
|
283
|
+
return { ok: true }
|
|
284
|
+
})
|
|
285
|
+
fastify.listen({ port: 0 }, err => {
|
|
286
|
+
t.assert.ifError(err)
|
|
287
|
+
|
|
288
|
+
const socket = connect(fastify.server.address().port)
|
|
289
|
+
socket.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
|
290
|
+
socket.on('data', c => (data = Buffer.concat([data, c])))
|
|
291
|
+
socket.on('end', () => {
|
|
292
|
+
t.assert.match(
|
|
293
|
+
data.toString('utf-8'),
|
|
294
|
+
/^HTTP\/1.1 200 OK/
|
|
295
|
+
)
|
|
296
|
+
done()
|
|
297
|
+
})
|
|
298
|
+
})
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
test('Return 200 when Host header is removed by schema with trust proxy', (t, done) => {
|
|
302
|
+
t.plan(5)
|
|
303
|
+
let data = Buffer.alloc(0)
|
|
304
|
+
const fastify = Fastify({
|
|
305
|
+
trustProxy: true,
|
|
306
|
+
keepAliveTimeout: 10
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
t.after(() => fastify.close())
|
|
310
|
+
|
|
311
|
+
fastify.get('/', {
|
|
312
|
+
schema: {
|
|
313
|
+
headers: {
|
|
314
|
+
type: 'object',
|
|
315
|
+
properties: {},
|
|
316
|
+
additionalProperties: false
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}, async function (request) {
|
|
320
|
+
t.assert.strictEqual(request.host, '')
|
|
321
|
+
t.assert.strictEqual(request.hostname, '')
|
|
322
|
+
t.assert.strictEqual(request.port, null)
|
|
323
|
+
return { ok: true }
|
|
324
|
+
})
|
|
325
|
+
fastify.listen({ port: 0 }, err => {
|
|
326
|
+
t.assert.ifError(err)
|
|
327
|
+
|
|
328
|
+
const socket = connect(fastify.server.address().port)
|
|
329
|
+
socket.write('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n')
|
|
330
|
+
socket.on('data', c => (data = Buffer.concat([data, c])))
|
|
331
|
+
socket.on('end', () => {
|
|
332
|
+
t.assert.match(
|
|
333
|
+
data.toString('utf-8'),
|
|
334
|
+
/^HTTP\/1.1 200 OK/
|
|
335
|
+
)
|
|
336
|
+
done()
|
|
337
|
+
})
|
|
338
|
+
})
|
|
339
|
+
})
|
package/test/request-id.test.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const Fastify = require('..')
|
|
5
5
|
const sget = require('simple-get').concat
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
test('The request id header key can be customized', async (t) => {
|
|
8
8
|
t.plan(2)
|
|
9
9
|
const REQUEST_ID = '42'
|
|
10
10
|
|
|
@@ -13,16 +13,16 @@ t.test('The request id header key can be customized', async (t) => {
|
|
|
13
13
|
})
|
|
14
14
|
|
|
15
15
|
fastify.get('/', (req, reply) => {
|
|
16
|
-
t.
|
|
16
|
+
t.assert.strictEqual(req.id, REQUEST_ID)
|
|
17
17
|
reply.send({ id: req.id })
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
const response = await fastify.inject({ method: 'GET', url: '/', headers: { 'my-custom-request-id': REQUEST_ID } })
|
|
21
21
|
const body = await response.json()
|
|
22
|
-
t.
|
|
22
|
+
t.assert.strictEqual(body.id, REQUEST_ID)
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
test('The request id header key can be customized', async (t) => {
|
|
26
26
|
t.plan(2)
|
|
27
27
|
const REQUEST_ID = '42'
|
|
28
28
|
|
|
@@ -31,16 +31,16 @@ t.test('The request id header key can be customized', async (t) => {
|
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
fastify.get('/', (req, reply) => {
|
|
34
|
-
t.
|
|
34
|
+
t.assert.strictEqual(req.id, REQUEST_ID)
|
|
35
35
|
reply.send({ id: req.id })
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
const response = await fastify.inject({ method: 'GET', url: '/', headers: { 'MY-CUSTOM-REQUEST-ID': REQUEST_ID } })
|
|
39
39
|
const body = await response.json()
|
|
40
|
-
t.
|
|
40
|
+
t.assert.strictEqual(body.id, REQUEST_ID)
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
test('The request id header key can be customized', (t, done) => {
|
|
44
44
|
t.plan(4)
|
|
45
45
|
const REQUEST_ID = '42'
|
|
46
46
|
|
|
@@ -49,13 +49,14 @@ t.test('The request id header key can be customized', (t) => {
|
|
|
49
49
|
})
|
|
50
50
|
|
|
51
51
|
fastify.get('/', (req, reply) => {
|
|
52
|
-
t.
|
|
52
|
+
t.assert.strictEqual(req.id, REQUEST_ID)
|
|
53
53
|
reply.send({ id: req.id })
|
|
54
54
|
})
|
|
55
55
|
|
|
56
|
+
t.after(() => fastify.close())
|
|
57
|
+
|
|
56
58
|
fastify.listen({ port: 0 }, (err, address) => {
|
|
57
|
-
t.
|
|
58
|
-
t.teardown(() => fastify.close())
|
|
59
|
+
t.assert.ifError(err)
|
|
59
60
|
|
|
60
61
|
sget({
|
|
61
62
|
method: 'GET',
|
|
@@ -64,13 +65,14 @@ t.test('The request id header key can be customized', (t) => {
|
|
|
64
65
|
'my-custom-request-id': REQUEST_ID
|
|
65
66
|
}
|
|
66
67
|
}, (err, response, body) => {
|
|
67
|
-
t.
|
|
68
|
-
t.
|
|
68
|
+
t.assert.ifError(err)
|
|
69
|
+
t.assert.strictEqual(body.toString(), `{"id":"${REQUEST_ID}"}`)
|
|
70
|
+
done()
|
|
69
71
|
})
|
|
70
72
|
})
|
|
71
73
|
})
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
test('The request id header key can be customized', (t, done) => {
|
|
74
76
|
t.plan(4)
|
|
75
77
|
const REQUEST_ID = '42'
|
|
76
78
|
|
|
@@ -79,13 +81,14 @@ t.test('The request id header key can be customized', (t) => {
|
|
|
79
81
|
})
|
|
80
82
|
|
|
81
83
|
fastify.get('/', (req, reply) => {
|
|
82
|
-
t.
|
|
84
|
+
t.assert.strictEqual(req.id, REQUEST_ID)
|
|
83
85
|
reply.send({ id: req.id })
|
|
84
86
|
})
|
|
85
87
|
|
|
88
|
+
t.after(() => fastify.close())
|
|
89
|
+
|
|
86
90
|
fastify.listen({ port: 0 }, (err, address) => {
|
|
87
|
-
t.
|
|
88
|
-
t.teardown(() => fastify.close())
|
|
91
|
+
t.assert.ifError(err)
|
|
89
92
|
|
|
90
93
|
sget({
|
|
91
94
|
method: 'GET',
|
|
@@ -94,13 +97,14 @@ t.test('The request id header key can be customized', (t) => {
|
|
|
94
97
|
'MY-CUSTOM-REQUEST-ID': REQUEST_ID
|
|
95
98
|
}
|
|
96
99
|
}, (err, response, body) => {
|
|
97
|
-
t.
|
|
98
|
-
t.
|
|
100
|
+
t.assert.ifError(err)
|
|
101
|
+
t.assert.strictEqual(body.toString(), `{"id":"${REQUEST_ID}"}`)
|
|
102
|
+
done()
|
|
99
103
|
})
|
|
100
104
|
})
|
|
101
105
|
})
|
|
102
106
|
|
|
103
|
-
|
|
107
|
+
test('The request id header key can be customized', (t, done) => {
|
|
104
108
|
t.plan(4)
|
|
105
109
|
const REQUEST_ID = '42'
|
|
106
110
|
|
|
@@ -109,13 +113,14 @@ t.test('The request id header key can be customized', (t) => {
|
|
|
109
113
|
})
|
|
110
114
|
|
|
111
115
|
fastify.get('/', (req, reply) => {
|
|
112
|
-
t.
|
|
116
|
+
t.assert.strictEqual(req.id, REQUEST_ID)
|
|
113
117
|
reply.send({ id: req.id })
|
|
114
118
|
})
|
|
115
119
|
|
|
120
|
+
t.after(() => fastify.close())
|
|
121
|
+
|
|
116
122
|
fastify.listen({ port: 0 }, (err, address) => {
|
|
117
|
-
t.
|
|
118
|
-
t.teardown(() => fastify.close())
|
|
123
|
+
t.assert.ifError(err)
|
|
119
124
|
|
|
120
125
|
sget({
|
|
121
126
|
method: 'GET',
|
|
@@ -124,8 +129,9 @@ t.test('The request id header key can be customized', (t) => {
|
|
|
124
129
|
'MY-CUSTOM-REQUEST-ID': REQUEST_ID
|
|
125
130
|
}
|
|
126
131
|
}, (err, response, body) => {
|
|
127
|
-
t.
|
|
128
|
-
t.
|
|
132
|
+
t.assert.ifError(err)
|
|
133
|
+
t.assert.strictEqual(body.toString(), `{"id":"${REQUEST_ID}"}`)
|
|
134
|
+
done()
|
|
129
135
|
})
|
|
130
136
|
})
|
|
131
137
|
})
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const http = require('node:http')
|
|
4
|
-
const { test } = require('
|
|
5
|
-
const Fastify = require('
|
|
4
|
+
const { test } = require('node:test')
|
|
5
|
+
const Fastify = require('..')
|
|
6
6
|
|
|
7
7
|
test('requestTimeout passed to server', t => {
|
|
8
8
|
t.plan(5)
|
|
9
9
|
|
|
10
10
|
try {
|
|
11
11
|
Fastify({ requestTimeout: 500.1 })
|
|
12
|
-
t.fail('option must be an integer')
|
|
12
|
+
t.assert.fail('option must be an integer')
|
|
13
13
|
} catch (err) {
|
|
14
|
-
t.ok(err)
|
|
14
|
+
t.assert.ok(err)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
try {
|
|
18
18
|
Fastify({ requestTimeout: [] })
|
|
19
|
-
t.fail('option must be an integer')
|
|
19
|
+
t.assert.fail('option must be an integer')
|
|
20
20
|
} catch (err) {
|
|
21
|
-
t.ok(err)
|
|
21
|
+
t.assert.ok(err)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const httpServer = Fastify({ requestTimeout: 1000 }).server
|
|
25
|
-
t.
|
|
25
|
+
t.assert.strictEqual(httpServer.requestTimeout, 1000)
|
|
26
26
|
|
|
27
27
|
const httpsServer = Fastify({ requestTimeout: 1000, https: true }).server
|
|
28
|
-
t.
|
|
28
|
+
t.assert.strictEqual(httpsServer.requestTimeout, 1000)
|
|
29
29
|
|
|
30
30
|
const serverFactory = (handler, _) => {
|
|
31
31
|
const server = http.createServer((req, res) => {
|
|
@@ -35,19 +35,19 @@ test('requestTimeout passed to server', t => {
|
|
|
35
35
|
return server
|
|
36
36
|
}
|
|
37
37
|
const customServer = Fastify({ requestTimeout: 4000, serverFactory }).server
|
|
38
|
-
t.
|
|
38
|
+
t.assert.strictEqual(customServer.requestTimeout, 5000)
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
test('requestTimeout should be set', async (t) => {
|
|
42
42
|
t.plan(1)
|
|
43
43
|
|
|
44
44
|
const initialConfig = Fastify({ requestTimeout: 5000 }).initialConfig
|
|
45
|
-
t.
|
|
45
|
+
t.assert.strictEqual(initialConfig.requestTimeout, 5000)
|
|
46
46
|
})
|
|
47
47
|
|
|
48
48
|
test('requestTimeout should 0', async (t) => {
|
|
49
49
|
t.plan(1)
|
|
50
50
|
|
|
51
51
|
const initialConfig = Fastify().initialConfig
|
|
52
|
-
t.
|
|
52
|
+
t.assert.strictEqual(initialConfig.requestTimeout, 0)
|
|
53
53
|
})
|
package/test/route.3.test.js
CHANGED
|
@@ -5,7 +5,7 @@ const joi = require('joi')
|
|
|
5
5
|
const Fastify = require('..')
|
|
6
6
|
|
|
7
7
|
test('does not mutate joi schemas', (t, done) => {
|
|
8
|
-
t.plan(
|
|
8
|
+
t.plan(5)
|
|
9
9
|
|
|
10
10
|
const fastify = Fastify()
|
|
11
11
|
function validatorCompiler ({ schema, method, url, httpPart }) {
|
|
@@ -31,7 +31,8 @@ test('does not mutate joi schemas', (t, done) => {
|
|
|
31
31
|
params: { an_id: joi.number() }
|
|
32
32
|
},
|
|
33
33
|
handler (req, res) {
|
|
34
|
-
t.assert.
|
|
34
|
+
t.assert.strictEqual(Object.keys(req.params).length, 1)
|
|
35
|
+
t.assert.strictEqual(req.params.an_id, '42')
|
|
35
36
|
res.send({ hello: 'world' })
|
|
36
37
|
}
|
|
37
38
|
})
|
package/test/route.8.test.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
const sget = require('simple-get').concat
|
|
6
|
-
const Fastify = require('
|
|
5
|
+
const Fastify = require('..')
|
|
7
6
|
const {
|
|
8
7
|
FST_ERR_INVALID_URL
|
|
9
8
|
} = require('../lib/errors')
|
|
@@ -24,9 +23,9 @@ test('Request and Reply share the route options', async t => {
|
|
|
24
23
|
url: '/',
|
|
25
24
|
config,
|
|
26
25
|
handler: (req, reply) => {
|
|
27
|
-
t.
|
|
28
|
-
t.
|
|
29
|
-
t.match(req.routeOptions.config, config, 'there are url and method additional properties')
|
|
26
|
+
t.assert.deepStrictEqual(req.routeOptions, reply.routeOptions)
|
|
27
|
+
t.assert.deepStrictEqual(req.routeOptions.config, reply.routeOptions.config)
|
|
28
|
+
t.assert.match(req.routeOptions.config, config, 'there are url and method additional properties')
|
|
30
29
|
|
|
31
30
|
reply.send({ hello: 'world' })
|
|
32
31
|
}
|
|
@@ -62,10 +61,10 @@ test('Will not try to re-createprefixed HEAD route if it already exists and expo
|
|
|
62
61
|
|
|
63
62
|
await fastify.ready()
|
|
64
63
|
|
|
65
|
-
t.ok(true)
|
|
64
|
+
t.assert.ok(true)
|
|
66
65
|
})
|
|
67
66
|
|
|
68
|
-
test('route with non-english characters', t => {
|
|
67
|
+
test('route with non-english characters', (t, done) => {
|
|
69
68
|
t.plan(4)
|
|
70
69
|
|
|
71
70
|
const fastify = Fastify()
|
|
@@ -75,16 +74,17 @@ test('route with non-english characters', t => {
|
|
|
75
74
|
})
|
|
76
75
|
|
|
77
76
|
fastify.listen({ port: 0 }, err => {
|
|
78
|
-
t.
|
|
79
|
-
t.
|
|
77
|
+
t.assert.ifError(err)
|
|
78
|
+
t.after(() => fastify.close())
|
|
80
79
|
|
|
81
80
|
sget({
|
|
82
81
|
method: 'GET',
|
|
83
82
|
url: getServerUrl(fastify) + encodeURI('/föö')
|
|
84
83
|
}, (err, response, body) => {
|
|
85
|
-
t.
|
|
86
|
-
t.
|
|
87
|
-
t.
|
|
84
|
+
t.assert.ifError(err)
|
|
85
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
86
|
+
t.assert.strictEqual(body.toString(), 'here /föö')
|
|
87
|
+
done()
|
|
88
88
|
})
|
|
89
89
|
})
|
|
90
90
|
})
|
|
@@ -96,7 +96,7 @@ test('invalid url attribute - non string URL', t => {
|
|
|
96
96
|
try {
|
|
97
97
|
fastify.get(/^\/(donations|skills|blogs)/, () => { })
|
|
98
98
|
} catch (error) {
|
|
99
|
-
t.
|
|
99
|
+
t.assert.strictEqual(error.code, FST_ERR_INVALID_URL().code)
|
|
100
100
|
}
|
|
101
101
|
})
|
|
102
102
|
|
|
@@ -117,7 +117,7 @@ test('exposeHeadRoute should not reuse the same route option', async t => {
|
|
|
117
117
|
})
|
|
118
118
|
|
|
119
119
|
fastify.addHook('onRoute', function (routeOption) {
|
|
120
|
-
t.
|
|
120
|
+
t.assert.strictEqual(routeOption.onRequest.length, 1)
|
|
121
121
|
})
|
|
122
122
|
|
|
123
123
|
fastify.route({
|
|
@@ -140,7 +140,7 @@ test('using fastify.all when a catchall is defined does not degrade performance'
|
|
|
140
140
|
fastify.all(`/${i}`, async (_, reply) => reply.json({ ok: true }))
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
t.
|
|
143
|
+
t.assert.ok("fastify.all doesn't degrade performance")
|
|
144
144
|
})
|
|
145
145
|
|
|
146
146
|
test('Adding manually HEAD route after GET with the same path throws Fastify duplicated route instance error', t => {
|
|
@@ -164,9 +164,9 @@ test('Adding manually HEAD route after GET with the same path throws Fastify dup
|
|
|
164
164
|
reply.send({ hello: 'world' })
|
|
165
165
|
}
|
|
166
166
|
})
|
|
167
|
-
t.fail('Should throw fastify duplicated route declaration')
|
|
167
|
+
t.assert.fail('Should throw fastify duplicated route declaration')
|
|
168
168
|
} catch (error) {
|
|
169
|
-
t.
|
|
169
|
+
t.assert.strictEqual(error.code, 'FST_ERR_DUPLICATED_ROUTE')
|
|
170
170
|
}
|
|
171
171
|
})
|
|
172
172
|
|
|
@@ -198,7 +198,7 @@ test('Will pass onSend hook to HEAD method if exposeHeadRoutes is true /1', asyn
|
|
|
198
198
|
method: 'HEAD'
|
|
199
199
|
})
|
|
200
200
|
|
|
201
|
-
t.
|
|
201
|
+
t.assert.strictEqual(result.headers['x-content-type'], 'application/fastify')
|
|
202
202
|
})
|
|
203
203
|
|
|
204
204
|
test('Will pass onSend hook to HEAD method if exposeHeadRoutes is true /2', async (t) => {
|
|
@@ -229,5 +229,5 @@ test('Will pass onSend hook to HEAD method if exposeHeadRoutes is true /2', asyn
|
|
|
229
229
|
method: 'HEAD'
|
|
230
230
|
})
|
|
231
231
|
|
|
232
|
-
t.
|
|
232
|
+
t.assert.strictEqual(result.headers['x-content-type'], 'application/fastify')
|
|
233
233
|
})
|