fastify 4.24.3 → 4.25.1
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 +10 -5
- package/SECURITY.md +27 -0
- package/docs/Guides/Ecosystem.md +18 -6
- package/docs/Guides/Getting-Started.md +3 -3
- package/docs/Guides/Plugins-Guide.md +2 -2
- package/docs/Guides/Style-Guide.md +7 -7
- package/docs/Reference/ContentTypeParser.md +2 -0
- package/docs/Reference/Errors.md +171 -397
- package/docs/Reference/Hooks.md +8 -2
- package/docs/Reference/Index.md +2 -0
- package/docs/Reference/Reply.md +16 -5
- package/docs/Reference/Request.md +1 -1
- package/docs/Reference/Routes.md +5 -5
- package/docs/Reference/TypeScript.md +1 -1
- package/docs/Reference/Warnings.md +77 -0
- package/fastify.js +37 -20
- package/lib/decorate.js +2 -2
- package/lib/errors.js +1 -1
- package/lib/hooks.js +1 -1
- package/lib/pluginUtils.js +10 -1
- package/lib/reply.js +5 -5
- package/lib/request.js +14 -7
- package/lib/route.js +9 -5
- package/lib/server.js +20 -27
- package/lib/validation.js +5 -5
- package/lib/warnings.js +110 -40
- package/package.json +3 -3
- package/test/close-pipelining.test.js +4 -4
- package/test/close.test.js +3 -3
- package/test/constrained-routes.test.js +24 -24
- package/test/decorator.test.js +27 -22
- package/test/default-route.test.js +7 -7
- package/test/fastify-instance.test.js +120 -0
- package/test/hooks.on-ready.test.js +16 -0
- package/test/hooks.test.js +1 -3
- package/test/http2/constraint.test.js +1 -1
- package/test/internals/errors.test.js +28 -3
- package/test/internals/reply.test.js +33 -9
- package/test/logger/instantiation.test.js +2 -1
- package/test/plugin.4.test.js +47 -0
- package/test/register.test.js +5 -5
- package/test/reply-trailers.test.js +1 -1
- package/test/route.7.test.js +7 -6
- package/test/schema-examples.test.js +2 -2
- package/test/schema-feature.test.js +11 -11
- package/test/server.test.js +51 -0
- package/test/types/hooks.test-d.ts +124 -1
- package/test/types/instance.test-d.ts +12 -0
- package/test/types/logger.test-d.ts +14 -0
- package/test/types/reply.test-d.ts +25 -6
- package/test/types/request.test-d.ts +3 -2
- package/test/types/route.test-d.ts +31 -0
- package/test/versioned-routes.test.js +7 -6
- package/types/hooks.d.ts +183 -0
- package/types/instance.d.ts +12 -12
- package/types/reply.d.ts +7 -10
- package/types/request.d.ts +2 -1
- package/types/route.d.ts +37 -26
- package/types/utils.d.ts +10 -0
package/lib/warnings.js
CHANGED
|
@@ -1,42 +1,112 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
3
|
+
const { createDeprecation, createWarning } = require('process-warning')
|
|
4
|
+
|
|
5
|
+
const FSTDEP005 = createDeprecation({
|
|
6
|
+
code: 'FSTDEP005',
|
|
7
|
+
message: 'You are accessing the deprecated "request.connection" property. Use "request.socket" instead.'
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const FSTDEP006 = createDeprecation({
|
|
11
|
+
code: 'FSTDEP006',
|
|
12
|
+
message: 'You are decorating Request/Reply with a reference type. This reference is shared amongst all requests. Use onRequest hook instead. Property: %s'
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const FSTDEP007 = createDeprecation({
|
|
16
|
+
code: 'FSTDEP007',
|
|
17
|
+
message: 'You are trying to set a HEAD route using "exposeHeadRoute" route flag when a sibling route is already set. See documentation for more info.'
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const FSTDEP008 = createDeprecation({
|
|
21
|
+
code: 'FSTDEP008',
|
|
22
|
+
message: 'You are using route constraints via the route { version: "..." } option, use { constraints: { version: "..." } } option instead.'
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const FSTDEP009 = createDeprecation({
|
|
26
|
+
code: 'FSTDEP009',
|
|
27
|
+
message: 'You are using a custom route versioning strategy via the server { versioning: "..." } option, use { constraints: { version: "..." } } option instead.'
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const FSTDEP010 = createDeprecation({
|
|
31
|
+
code: 'FSTDEP010',
|
|
32
|
+
message: 'Modifying the "reply.sent" property is deprecated. Use the "reply.hijack()" method instead.'
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const FSTDEP011 = createDeprecation({
|
|
36
|
+
code: 'FSTDEP011',
|
|
37
|
+
message: 'Variadic listen method is deprecated. Please use ".listen(optionsObject)" instead. The variadic signature will be removed in `fastify@5`.'
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const FSTDEP012 = createDeprecation({
|
|
41
|
+
code: 'FSTDEP012',
|
|
42
|
+
message: 'request.context property access is deprecated. Please use "request.routeOptions.config" or "request.routeOptions.schema" instead for accessing Route settings. The "request.context" will be removed in `fastify@5`.'
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const FSTDEP013 = createDeprecation({
|
|
46
|
+
code: 'FSTDEP013',
|
|
47
|
+
message: 'Direct return of "trailers" function is deprecated. Please use "callback" or "async-await" for return value. The support of direct return will removed in `fastify@5`.'
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const FSTDEP014 = createDeprecation({
|
|
51
|
+
code: 'FSTDEP014',
|
|
52
|
+
message: 'You are trying to set/access the default route. This property is deprecated. Please, use setNotFoundHandler if you want to custom a 404 handler or the wildcard (*) to match all routes.'
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const FSTDEP015 = createDeprecation({
|
|
56
|
+
code: 'FSTDEP015',
|
|
57
|
+
message: 'You are accessing the deprecated "request.routeSchema" property. Use "request.routeOptions.schema" instead. Property "req.routeSchema" will be removed in `fastify@5`.'
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const FSTDEP016 = createDeprecation({
|
|
61
|
+
code: 'FSTDEP016',
|
|
62
|
+
message: 'You are accessing the deprecated "request.routeConfig" property. Use "request.routeOptions.config" instead. Property "req.routeConfig" will be removed in `fastify@5`.'
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const FSTDEP017 = createDeprecation({
|
|
66
|
+
code: 'FSTDEP017',
|
|
67
|
+
message: 'You are accessing the deprecated "request.routerPath" property. Use "request.routeOptions.url" instead. Property "req.routerPath" will be removed in `fastify@5`.'
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const FSTDEP018 = createDeprecation({
|
|
71
|
+
code: 'FSTDEP018',
|
|
72
|
+
message: 'You are accessing the deprecated "request.routerMethod" property. Use "request.routeOptions.method" instead. Property "req.routerMethod" will be removed in `fastify@5`.'
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
const FSTDEP019 = createDeprecation({
|
|
76
|
+
code: 'FSTDEP019',
|
|
77
|
+
message: 'reply.context property access is deprecated. Please use "request.routeOptions.config" or "request.routeOptions.schema" instead for accessing Route settings. The "reply.context" will be removed in `fastify@5`.'
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const FSTWRN001 = createWarning({
|
|
81
|
+
name: 'FastifyWarning',
|
|
82
|
+
code: 'FSTWRN001',
|
|
83
|
+
message: 'The %s schema for %s: %s is missing. This may indicate the schema is not well specified.',
|
|
84
|
+
unlimited: true
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const FSTWRN002 = createWarning({
|
|
88
|
+
name: 'FastifyWarning',
|
|
89
|
+
code: 'FSTWRN002',
|
|
90
|
+
message: 'The %s plugin being registered mixes async and callback styles, which will result in an error in `fastify@5`',
|
|
91
|
+
unlimited: true
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
module.exports = {
|
|
95
|
+
FSTDEP005,
|
|
96
|
+
FSTDEP006,
|
|
97
|
+
FSTDEP007,
|
|
98
|
+
FSTDEP008,
|
|
99
|
+
FSTDEP009,
|
|
100
|
+
FSTDEP010,
|
|
101
|
+
FSTDEP011,
|
|
102
|
+
FSTDEP012,
|
|
103
|
+
FSTDEP013,
|
|
104
|
+
FSTDEP014,
|
|
105
|
+
FSTDEP015,
|
|
106
|
+
FSTDEP016,
|
|
107
|
+
FSTDEP017,
|
|
108
|
+
FSTDEP018,
|
|
109
|
+
FSTDEP019,
|
|
110
|
+
FSTWRN001,
|
|
111
|
+
FSTWRN002
|
|
112
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastify",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.25.1",
|
|
4
4
|
"description": "Fast and low overhead web framework, for Node.js",
|
|
5
5
|
"main": "fastify.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -197,8 +197,8 @@
|
|
|
197
197
|
"fast-json-stringify": "^5.8.0",
|
|
198
198
|
"find-my-way": "^7.7.0",
|
|
199
199
|
"light-my-request": "^5.11.0",
|
|
200
|
-
"pino": "^8.
|
|
201
|
-
"process-warning": "^
|
|
200
|
+
"pino": "^8.17.0",
|
|
201
|
+
"process-warning": "^3.0.0",
|
|
202
202
|
"proxy-addr": "^2.0.7",
|
|
203
203
|
"rfdc": "^1.3.0",
|
|
204
204
|
"secure-json-parse": "^2.7.0",
|
|
@@ -36,8 +36,8 @@ test('Should return 503 while closing - pipelining', async t => {
|
|
|
36
36
|
await instance.close()
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
const
|
|
40
|
-
test('Should not return 503 while closing - pipelining - return503OnClosing: false, skip Node >=
|
|
39
|
+
const isNodeVersionGte1819 = semver.gte(process.version, '18.19.0')
|
|
40
|
+
test('Should not return 503 while closing - pipelining - return503OnClosing: false, skip Node >= v18.19.x', { skip: isNodeVersionGte1819 }, async t => {
|
|
41
41
|
const fastify = Fastify({
|
|
42
42
|
return503OnClosing: false,
|
|
43
43
|
forceCloseConnections: false
|
|
@@ -67,8 +67,8 @@ test('Should not return 503 while closing - pipelining - return503OnClosing: fal
|
|
|
67
67
|
await instance.close()
|
|
68
68
|
})
|
|
69
69
|
|
|
70
|
-
test('Should close the socket abruptly - pipelining - return503OnClosing: false, skip Node <
|
|
71
|
-
// Since Node
|
|
70
|
+
test('Should close the socket abruptly - pipelining - return503OnClosing: false, skip Node < v18.19.x', { skip: !isNodeVersionGte1819 }, async t => {
|
|
71
|
+
// Since Node v18, we will always invoke server.closeIdleConnections()
|
|
72
72
|
// therefore our socket will be closed
|
|
73
73
|
const fastify = Fastify({
|
|
74
74
|
return503OnClosing: false,
|
package/test/close.test.js
CHANGED
|
@@ -204,8 +204,8 @@ test('Should return error while closing (callback) - injection', t => {
|
|
|
204
204
|
})
|
|
205
205
|
})
|
|
206
206
|
|
|
207
|
-
const
|
|
208
|
-
test('Current opened connection should continue to work after closing and return "connection: close" header - return503OnClosing: false, skip Node >=
|
|
207
|
+
const isNodeVersionGte1819 = semver.gte(process.version, '18.19.0')
|
|
208
|
+
test('Current opened connection should continue to work after closing and return "connection: close" header - return503OnClosing: false, skip Node >= v18.19.x', { skip: isNodeVersionGte1819 }, t => {
|
|
209
209
|
const fastify = Fastify({
|
|
210
210
|
return503OnClosing: false,
|
|
211
211
|
forceCloseConnections: false
|
|
@@ -243,7 +243,7 @@ test('Current opened connection should continue to work after closing and return
|
|
|
243
243
|
})
|
|
244
244
|
})
|
|
245
245
|
|
|
246
|
-
test('Current opened connection should NOT continue to work after closing and return "connection: close" header - return503OnClosing: false, skip Node <
|
|
246
|
+
test('Current opened connection should NOT continue to work after closing and return "connection: close" header - return503OnClosing: false, skip Node < v18.19.x', { skip: !isNodeVersionGte1819 }, t => {
|
|
247
247
|
t.plan(4)
|
|
248
248
|
const fastify = Fastify({
|
|
249
249
|
return503OnClosing: false,
|
|
@@ -11,7 +11,7 @@ test('Should register a host constrained route', t => {
|
|
|
11
11
|
fastify.route({
|
|
12
12
|
method: 'GET',
|
|
13
13
|
url: '/',
|
|
14
|
-
constraints: { host: 'fastify.
|
|
14
|
+
constraints: { host: 'fastify.dev' },
|
|
15
15
|
handler: (req, reply) => {
|
|
16
16
|
reply.send({ hello: 'world' })
|
|
17
17
|
}
|
|
@@ -21,7 +21,7 @@ test('Should register a host constrained route', t => {
|
|
|
21
21
|
method: 'GET',
|
|
22
22
|
url: '/',
|
|
23
23
|
headers: {
|
|
24
|
-
host: 'fastify.
|
|
24
|
+
host: 'fastify.dev'
|
|
25
25
|
}
|
|
26
26
|
}, (err, res) => {
|
|
27
27
|
t.error(err)
|
|
@@ -56,9 +56,9 @@ test('Should register the same route with host constraints', t => {
|
|
|
56
56
|
fastify.route({
|
|
57
57
|
method: 'GET',
|
|
58
58
|
url: '/',
|
|
59
|
-
constraints: { host: 'fastify.
|
|
59
|
+
constraints: { host: 'fastify.dev' },
|
|
60
60
|
handler: (req, reply) => {
|
|
61
|
-
reply.send('fastify.
|
|
61
|
+
reply.send('fastify.dev')
|
|
62
62
|
}
|
|
63
63
|
})
|
|
64
64
|
|
|
@@ -75,12 +75,12 @@ test('Should register the same route with host constraints', t => {
|
|
|
75
75
|
method: 'GET',
|
|
76
76
|
url: '/',
|
|
77
77
|
headers: {
|
|
78
|
-
host: 'fastify.
|
|
78
|
+
host: 'fastify.dev'
|
|
79
79
|
}
|
|
80
80
|
}, (err, res) => {
|
|
81
81
|
t.error(err)
|
|
82
82
|
t.equal(res.statusCode, 200)
|
|
83
|
-
t.equal(res.payload, 'fastify.
|
|
83
|
+
t.equal(res.payload, 'fastify.dev')
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
fastify.inject({
|
|
@@ -479,7 +479,7 @@ test('The hasConstraintStrategy should return false for default constraints unti
|
|
|
479
479
|
fastify.route({
|
|
480
480
|
method: 'GET',
|
|
481
481
|
url: '/',
|
|
482
|
-
constraints: { host: 'fastify.
|
|
482
|
+
constraints: { host: 'fastify.dev' },
|
|
483
483
|
handler: (req, reply) => {
|
|
484
484
|
reply.send({ hello: 'from any other domain' })
|
|
485
485
|
}
|
|
@@ -533,9 +533,9 @@ test('Should allow registering an unconstrained route after a constrained route'
|
|
|
533
533
|
fastify.route({
|
|
534
534
|
method: 'GET',
|
|
535
535
|
url: '/',
|
|
536
|
-
constraints: { host: 'fastify.
|
|
536
|
+
constraints: { host: 'fastify.dev' },
|
|
537
537
|
handler: (req, reply) => {
|
|
538
|
-
reply.send({ hello: 'from fastify.
|
|
538
|
+
reply.send({ hello: 'from fastify.dev' })
|
|
539
539
|
}
|
|
540
540
|
})
|
|
541
541
|
|
|
@@ -551,11 +551,11 @@ test('Should allow registering an unconstrained route after a constrained route'
|
|
|
551
551
|
method: 'GET',
|
|
552
552
|
url: '/',
|
|
553
553
|
headers: {
|
|
554
|
-
host: 'fastify.
|
|
554
|
+
host: 'fastify.dev'
|
|
555
555
|
}
|
|
556
556
|
}, (err, res) => {
|
|
557
557
|
t.error(err)
|
|
558
|
-
t.same(JSON.parse(res.payload), { hello: 'from fastify.
|
|
558
|
+
t.same(JSON.parse(res.payload), { hello: 'from fastify.dev' })
|
|
559
559
|
t.equal(res.statusCode, 200)
|
|
560
560
|
})
|
|
561
561
|
|
|
@@ -580,7 +580,7 @@ test('Should allow registering constrained routes in a prefixed plugin', t => {
|
|
|
580
580
|
fastify.register(async (scope, opts) => {
|
|
581
581
|
scope.route({
|
|
582
582
|
method: 'GET',
|
|
583
|
-
constraints: { host: 'fastify.
|
|
583
|
+
constraints: { host: 'fastify.dev' },
|
|
584
584
|
path: '/route',
|
|
585
585
|
handler: (req, reply) => {
|
|
586
586
|
reply.send({ ok: true })
|
|
@@ -592,7 +592,7 @@ test('Should allow registering constrained routes in a prefixed plugin', t => {
|
|
|
592
592
|
method: 'GET',
|
|
593
593
|
url: '/prefix/route',
|
|
594
594
|
headers: {
|
|
595
|
-
host: 'fastify.
|
|
595
|
+
host: 'fastify.dev'
|
|
596
596
|
}
|
|
597
597
|
}, (err, res) => {
|
|
598
598
|
t.error(err)
|
|
@@ -608,7 +608,7 @@ test('Should allow registering a constrained GET route after a constrained HEAD
|
|
|
608
608
|
fastify.route({
|
|
609
609
|
method: 'HEAD',
|
|
610
610
|
url: '/',
|
|
611
|
-
constraints: { host: 'fastify.
|
|
611
|
+
constraints: { host: 'fastify.dev' },
|
|
612
612
|
handler: (req, reply) => {
|
|
613
613
|
reply.header('content-type', 'text/plain')
|
|
614
614
|
reply.send('custom HEAD response')
|
|
@@ -618,7 +618,7 @@ test('Should allow registering a constrained GET route after a constrained HEAD
|
|
|
618
618
|
fastify.route({
|
|
619
619
|
method: 'GET',
|
|
620
620
|
url: '/',
|
|
621
|
-
constraints: { host: 'fastify.
|
|
621
|
+
constraints: { host: 'fastify.dev' },
|
|
622
622
|
handler: (req, reply) => {
|
|
623
623
|
reply.send({ hello: 'from any other domain' })
|
|
624
624
|
}
|
|
@@ -628,7 +628,7 @@ test('Should allow registering a constrained GET route after a constrained HEAD
|
|
|
628
628
|
method: 'HEAD',
|
|
629
629
|
url: '/',
|
|
630
630
|
headers: {
|
|
631
|
-
host: 'fastify.
|
|
631
|
+
host: 'fastify.dev'
|
|
632
632
|
}
|
|
633
633
|
}, (err, res) => {
|
|
634
634
|
t.error(err)
|
|
@@ -653,7 +653,7 @@ test('Should allow registering a constrained GET route after an unconstrained HE
|
|
|
653
653
|
fastify.route({
|
|
654
654
|
method: 'GET',
|
|
655
655
|
url: '/',
|
|
656
|
-
constraints: { host: 'fastify.
|
|
656
|
+
constraints: { host: 'fastify.dev' },
|
|
657
657
|
handler: (req, reply) => {
|
|
658
658
|
reply.header('content-type', 'text/plain')
|
|
659
659
|
reply.send('Hello from constrains: length is about 41')
|
|
@@ -664,7 +664,7 @@ test('Should allow registering a constrained GET route after an unconstrained HE
|
|
|
664
664
|
method: 'HEAD',
|
|
665
665
|
url: '/',
|
|
666
666
|
headers: {
|
|
667
|
-
host: 'fastify.
|
|
667
|
+
host: 'fastify.dev'
|
|
668
668
|
}
|
|
669
669
|
}, (err, res) => {
|
|
670
670
|
t.error(err)
|
|
@@ -682,7 +682,7 @@ test('Will not try to re-createprefixed HEAD route if it already exists and expo
|
|
|
682
682
|
scope.route({
|
|
683
683
|
method: 'HEAD',
|
|
684
684
|
path: '/route',
|
|
685
|
-
constraints: { host: 'fastify.
|
|
685
|
+
constraints: { host: 'fastify.dev' },
|
|
686
686
|
handler: (req, reply) => {
|
|
687
687
|
reply.header('content-type', 'text/plain')
|
|
688
688
|
reply.send('custom HEAD response')
|
|
@@ -691,7 +691,7 @@ test('Will not try to re-createprefixed HEAD route if it already exists and expo
|
|
|
691
691
|
scope.route({
|
|
692
692
|
method: 'GET',
|
|
693
693
|
path: '/route',
|
|
694
|
-
constraints: { host: 'fastify.
|
|
694
|
+
constraints: { host: 'fastify.dev' },
|
|
695
695
|
handler: (req, reply) => {
|
|
696
696
|
reply.send({ ok: true })
|
|
697
697
|
}
|
|
@@ -723,7 +723,7 @@ test('allows separate constrained and unconstrained HEAD routes', async (t) => {
|
|
|
723
723
|
scope.route({
|
|
724
724
|
method: 'HEAD',
|
|
725
725
|
path: '/route',
|
|
726
|
-
constraints: { host: 'fastify.
|
|
726
|
+
constraints: { host: 'fastify.dev' },
|
|
727
727
|
handler: (req, reply) => {
|
|
728
728
|
reply.header('content-type', 'text/plain')
|
|
729
729
|
reply.send('constrained HEAD response')
|
|
@@ -733,7 +733,7 @@ test('allows separate constrained and unconstrained HEAD routes', async (t) => {
|
|
|
733
733
|
scope.route({
|
|
734
734
|
method: 'GET',
|
|
735
735
|
path: '/route',
|
|
736
|
-
constraints: { host: 'fastify.
|
|
736
|
+
constraints: { host: 'fastify.dev' },
|
|
737
737
|
handler: (req, reply) => {
|
|
738
738
|
reply.send({ ok: true })
|
|
739
739
|
}
|
|
@@ -869,7 +869,7 @@ test('Allow regex constraints in routes', t => {
|
|
|
869
869
|
fastify.route({
|
|
870
870
|
method: 'GET',
|
|
871
871
|
url: '/',
|
|
872
|
-
constraints: { host: /.*\.fastify\.
|
|
872
|
+
constraints: { host: /.*\.fastify\.dev$/ },
|
|
873
873
|
handler: (req, reply) => {
|
|
874
874
|
reply.send({ hello: 'from fastify dev domain' })
|
|
875
875
|
}
|
|
@@ -879,7 +879,7 @@ test('Allow regex constraints in routes', t => {
|
|
|
879
879
|
method: 'GET',
|
|
880
880
|
url: '/',
|
|
881
881
|
headers: {
|
|
882
|
-
host: 'dev.fastify.
|
|
882
|
+
host: 'dev.fastify.dev'
|
|
883
883
|
}
|
|
884
884
|
}, (err, res) => {
|
|
885
885
|
t.error(err)
|
package/test/decorator.test.js
CHANGED
|
@@ -790,31 +790,33 @@ test('decorate* should throw if called after ready', async t => {
|
|
|
790
790
|
})
|
|
791
791
|
|
|
792
792
|
test('decorate* should emit warning if an array is passed', t => {
|
|
793
|
-
t.plan(
|
|
794
|
-
|
|
793
|
+
t.plan(1)
|
|
794
|
+
|
|
795
|
+
function onWarning (name) {
|
|
795
796
|
t.equal(name, 'test_array')
|
|
796
|
-
t.equal(code, 'FSTDEP006')
|
|
797
|
-
}
|
|
798
|
-
const warning = {
|
|
799
|
-
emit: onWarning
|
|
800
797
|
}
|
|
801
798
|
|
|
802
|
-
const decorate = proxyquire('../lib/decorate', {
|
|
799
|
+
const decorate = proxyquire('../lib/decorate', {
|
|
800
|
+
'./warnings': {
|
|
801
|
+
FSTDEP006: onWarning
|
|
802
|
+
}
|
|
803
|
+
})
|
|
803
804
|
const fastify = proxyquire('..', { './lib/decorate.js': decorate })()
|
|
804
805
|
fastify.decorateRequest('test_array', [])
|
|
805
806
|
})
|
|
806
807
|
|
|
807
808
|
test('decorate* should emit warning if object type is passed', t => {
|
|
808
|
-
t.plan(
|
|
809
|
-
|
|
809
|
+
t.plan(1)
|
|
810
|
+
|
|
811
|
+
function onWarning (name) {
|
|
810
812
|
t.equal(name, 'test_object')
|
|
811
|
-
t.equal(code, 'FSTDEP006')
|
|
812
|
-
}
|
|
813
|
-
const warning = {
|
|
814
|
-
emit: onWarning
|
|
815
813
|
}
|
|
816
814
|
|
|
817
|
-
const decorate = proxyquire('../lib/decorate', {
|
|
815
|
+
const decorate = proxyquire('../lib/decorate', {
|
|
816
|
+
'./warnings': {
|
|
817
|
+
FSTDEP006: onWarning
|
|
818
|
+
}
|
|
819
|
+
})
|
|
818
820
|
const fastify = proxyquire('..', { './lib/decorate.js': decorate })()
|
|
819
821
|
fastify.decorateRequest('test_object', { foo: 'bar' })
|
|
820
822
|
})
|
|
@@ -823,10 +825,12 @@ test('decorate* should not emit warning if object with getter/setter is passed',
|
|
|
823
825
|
function onWarning (warning) {
|
|
824
826
|
t.fail('Should not call a warn')
|
|
825
827
|
}
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
828
|
+
|
|
829
|
+
const decorate = proxyquire('../lib/decorate', {
|
|
830
|
+
'./warnings': {
|
|
831
|
+
FSTDEP006: onWarning
|
|
832
|
+
}
|
|
833
|
+
})
|
|
830
834
|
const fastify = proxyquire('..', { './lib/decorate.js': decorate })()
|
|
831
835
|
|
|
832
836
|
fastify.decorateRequest('test_getter_setter', {
|
|
@@ -844,11 +848,12 @@ test('decorate* should not emit warning if string,bool,numbers are passed', t =>
|
|
|
844
848
|
function onWarning (warning) {
|
|
845
849
|
t.fail('Should not call a warn')
|
|
846
850
|
}
|
|
847
|
-
const warning = {
|
|
848
|
-
emit: onWarning
|
|
849
|
-
}
|
|
850
851
|
|
|
851
|
-
const decorate = proxyquire('../lib/decorate', {
|
|
852
|
+
const decorate = proxyquire('../lib/decorate', {
|
|
853
|
+
'./warnings': {
|
|
854
|
+
FSTDEP006: onWarning
|
|
855
|
+
}
|
|
856
|
+
})
|
|
852
857
|
const fastify = proxyquire('..', { './lib/decorate.js': decorate })()
|
|
853
858
|
|
|
854
859
|
fastify.decorateRequest('test_str', 'foo')
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const t = require('tap')
|
|
4
4
|
const test = t.test
|
|
5
5
|
const Fastify = require('..')
|
|
6
|
-
const
|
|
6
|
+
const { FSTDEP014 } = require('../lib/warnings')
|
|
7
7
|
|
|
8
8
|
// Silence the standard warning logs. We will test the messages explicitly.
|
|
9
9
|
process.removeAllListeners('warning')
|
|
@@ -18,13 +18,13 @@ test('setDefaultRoute should emit a deprecation warning', t => {
|
|
|
18
18
|
|
|
19
19
|
process.on('warning', onWarning)
|
|
20
20
|
function onWarning (warning) {
|
|
21
|
-
t.equal(warning.name, '
|
|
22
|
-
t.equal(warning.code,
|
|
21
|
+
t.equal(warning.name, 'DeprecationWarning')
|
|
22
|
+
t.equal(warning.code, FSTDEP014.code)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
t.teardown(() => {
|
|
26
26
|
process.removeListener('warning', onWarning)
|
|
27
|
-
|
|
27
|
+
FSTDEP014.emitted = false
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
fastify.setDefaultRoute(defaultRoute)
|
|
@@ -37,13 +37,13 @@ test('getDefaultRoute should emit a deprecation warning', t => {
|
|
|
37
37
|
|
|
38
38
|
process.on('warning', onWarning)
|
|
39
39
|
function onWarning (warning) {
|
|
40
|
-
t.equal(warning.name, '
|
|
41
|
-
t.equal(warning.code,
|
|
40
|
+
t.equal(warning.name, 'DeprecationWarning')
|
|
41
|
+
t.equal(warning.code, FSTDEP014.code)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
t.teardown(() => {
|
|
45
45
|
process.removeListener('warning', onWarning)
|
|
46
|
-
|
|
46
|
+
FSTDEP014.emitted = false
|
|
47
47
|
})
|
|
48
48
|
|
|
49
49
|
fastify.getDefaultRoute()
|
|
@@ -132,6 +132,126 @@ test('childLoggerFactory in plugin should be separate from the external one', as
|
|
|
132
132
|
t.same(fastify.childLoggerFactory, fastify[kChildLoggerFactory])
|
|
133
133
|
})
|
|
134
134
|
|
|
135
|
+
test('ready should resolve in order when called multiply times (promises only)', async (t) => {
|
|
136
|
+
const app = Fastify()
|
|
137
|
+
const expectedOrder = [1, 2, 3, 4, 5]
|
|
138
|
+
const result = []
|
|
139
|
+
|
|
140
|
+
const promises = [1, 2, 3, 4, 5]
|
|
141
|
+
.map((id) => app.ready().then(() => result.push(id)))
|
|
142
|
+
|
|
143
|
+
await Promise.all(promises)
|
|
144
|
+
|
|
145
|
+
t.strictSame(result, expectedOrder, 'Should resolve in order')
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
test('ready should reject in order when called multiply times (promises only)', async (t) => {
|
|
149
|
+
const app = Fastify()
|
|
150
|
+
const expectedOrder = [1, 2, 3, 4, 5]
|
|
151
|
+
const result = []
|
|
152
|
+
|
|
153
|
+
app.register((instance, opts, done) => {
|
|
154
|
+
setTimeout(() => done(new Error('test')), 500)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const promises = [1, 2, 3, 4, 5]
|
|
158
|
+
.map((id) => app.ready().catch(() => result.push(id)))
|
|
159
|
+
|
|
160
|
+
await Promise.all(promises)
|
|
161
|
+
|
|
162
|
+
t.strictSame(result, expectedOrder, 'Should resolve in order')
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
test('ready should reject in order when called multiply times (callbacks only)', async (t) => {
|
|
166
|
+
const app = Fastify()
|
|
167
|
+
const expectedOrder = [1, 2, 3, 4, 5]
|
|
168
|
+
const result = []
|
|
169
|
+
|
|
170
|
+
app.register((instance, opts, done) => {
|
|
171
|
+
setTimeout(() => done(new Error('test')), 500)
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
expectedOrder.map((id) => app.ready(() => result.push(id)))
|
|
175
|
+
|
|
176
|
+
await app.ready().catch(err => {
|
|
177
|
+
t.equal(err.message, 'test')
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
t.strictSame(result, expectedOrder, 'Should resolve in order')
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
test('ready should resolve in order when called multiply times (callbacks only)', async (t) => {
|
|
184
|
+
const app = Fastify()
|
|
185
|
+
const expectedOrder = [1, 2, 3, 4, 5]
|
|
186
|
+
const result = []
|
|
187
|
+
|
|
188
|
+
expectedOrder.map((id) => app.ready(() => result.push(id)))
|
|
189
|
+
|
|
190
|
+
await app.ready()
|
|
191
|
+
|
|
192
|
+
t.strictSame(result, expectedOrder, 'Should resolve in order')
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
test('ready should resolve in order when called multiply times (mixed)', async (t) => {
|
|
196
|
+
const app = Fastify()
|
|
197
|
+
const expectedOrder = [1, 2, 3, 4, 5, 6]
|
|
198
|
+
const result = []
|
|
199
|
+
|
|
200
|
+
for (const order of expectedOrder) {
|
|
201
|
+
if (order % 2) {
|
|
202
|
+
app.ready(() => result.push(order))
|
|
203
|
+
} else {
|
|
204
|
+
app.ready().then(() => result.push(order))
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
await app.ready()
|
|
209
|
+
|
|
210
|
+
t.strictSame(result, expectedOrder, 'Should resolve in order')
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
test('ready should reject in order when called multiply times (mixed)', async (t) => {
|
|
214
|
+
const app = Fastify()
|
|
215
|
+
const expectedOrder = [1, 2, 3, 4, 5, 6]
|
|
216
|
+
const result = []
|
|
217
|
+
|
|
218
|
+
app.register((instance, opts, done) => {
|
|
219
|
+
setTimeout(() => done(new Error('test')), 500)
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
for (const order of expectedOrder) {
|
|
223
|
+
if (order % 2) {
|
|
224
|
+
app.ready(() => result.push(order))
|
|
225
|
+
} else {
|
|
226
|
+
app.ready().then(null, () => result.push(order))
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
await app.ready().catch(err => {
|
|
231
|
+
t.equal(err.message, 'test')
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
t.strictSame(result, expectedOrder, 'Should resolve in order')
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
test('ready should resolve in order when called multiply times (mixed)', async (t) => {
|
|
238
|
+
const app = Fastify()
|
|
239
|
+
const expectedOrder = [1, 2, 3, 4, 5, 6]
|
|
240
|
+
const result = []
|
|
241
|
+
|
|
242
|
+
for (const order of expectedOrder) {
|
|
243
|
+
if (order % 2) {
|
|
244
|
+
app.ready().then(() => result.push(order))
|
|
245
|
+
} else {
|
|
246
|
+
app.ready(() => result.push(order))
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
await app.ready()
|
|
251
|
+
|
|
252
|
+
t.strictSame(result, expectedOrder, 'Should resolve in order')
|
|
253
|
+
})
|
|
254
|
+
|
|
135
255
|
test('fastify instance should contains listeningOrigin property (with port and host)', async t => {
|
|
136
256
|
t.plan(1)
|
|
137
257
|
const port = 3000
|