fastify 5.0.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/.borp.yaml +3 -0
- package/.vscode/settings.json +22 -0
- 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 +14 -15
- package/docs/Guides/Index.md +1 -1
- package/docs/Guides/Migration-Guide-V4.md +11 -11
- package/docs/Guides/Migration-Guide-V5.md +133 -9
- 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 +58 -57
- package/docs/Guides/Write-Plugin.md +2 -2
- package/docs/Guides/Write-Type-Provider.md +3 -3
- package/docs/Reference/ContentTypeParser.md +4 -4
- package/docs/Reference/Decorators.md +2 -2
- package/docs/Reference/Errors.md +3 -3
- 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 +55 -58
- package/docs/Reference/Request.md +49 -42
- package/docs/Reference/Routes.md +16 -13
- package/docs/Reference/Server.md +32 -28
- 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 +14 -5
- package/fastify.js +8 -6
- package/lib/contentTypeParser.js +9 -7
- package/lib/context.js +1 -2
- package/lib/error-handler.js +9 -9
- package/lib/errors.js +1 -1
- package/lib/fourOhFour.js +1 -1
- package/lib/hooks.js +4 -1
- package/lib/{logger.js → logger-factory.js} +70 -122
- package/lib/logger-pino.js +68 -0
- package/lib/pluginOverride.js +1 -1
- package/lib/pluginUtils.js +2 -2
- package/lib/reply.js +4 -5
- package/lib/request.js +16 -9
- package/lib/route.js +23 -22
- package/lib/validation.js +2 -2
- package/package.json +13 -15
- package/test/404s.test.js +675 -629
- package/test/500s.test.js +72 -63
- package/test/{allowUnsafeRegex.test.js → allow-unsafe-regex.test.js} +30 -26
- package/test/als.test.js +48 -45
- package/test/async-await.test.js +148 -134
- package/test/async-dispose.test.js +4 -5
- package/test/async_hooks.test.js +30 -28
- package/test/{bodyLimit.test.js → body-limit.test.js} +61 -58
- package/test/buffer.test.js +9 -10
- package/test/build/error-serializer.test.js +3 -4
- package/test/build/version.test.js +2 -3
- package/test/build-certificate.js +1 -1
- package/test/bundler/README.md +5 -5
- package/test/bundler/esbuild/bundler-test.js +10 -9
- package/test/bundler/webpack/bundler-test.js +10 -9
- package/test/case-insensitive.test.js +31 -28
- package/test/chainable.test.js +4 -5
- package/test/check.test.js +8 -10
- package/test/{childLoggerFactory.test.js → child-logger-factory.test.js} +56 -19
- package/test/client-timeout.test.js +5 -5
- package/test/close-pipelining.test.js +6 -8
- package/test/conditional-pino.test.js +47 -0
- package/test/{connectionTimeout.test.js → connection-timeout.test.js} +10 -11
- package/test/constrained-routes.test.js +243 -236
- package/test/content-length.test.js +53 -68
- package/test/content-parser.test.js +186 -158
- package/test/content-type.test.js +8 -9
- package/test/context-config.test.js +44 -54
- package/test/custom-http-server.test.js +16 -20
- package/test/custom-parser.5.test.js +32 -32
- package/test/diagnostics-channel/404.test.js +15 -15
- package/test/diagnostics-channel/async-delay-request.test.js +25 -25
- package/test/diagnostics-channel/async-request.test.js +24 -24
- package/test/diagnostics-channel/error-before-handler.test.js +4 -5
- package/test/diagnostics-channel/error-request.test.js +19 -19
- package/test/diagnostics-channel/error-status.test.js +8 -8
- package/test/diagnostics-channel/init.test.js +6 -7
- package/test/diagnostics-channel/sync-delay-request.test.js +16 -16
- package/test/diagnostics-channel/sync-request-reply.test.js +16 -16
- package/test/diagnostics-channel/sync-request.test.js +19 -19
- package/test/encapsulated-child-logger-factory.test.js +8 -8
- package/test/encapsulated-error-handler.test.js +20 -20
- package/test/esm/errorCodes.test.mjs +5 -5
- package/test/esm/esm.test.mjs +3 -3
- package/test/esm/named-exports.mjs +3 -3
- package/test/esm/other.mjs +2 -2
- 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 +25 -25
- package/test/http-methods/copy.test.js +22 -24
- package/test/http-methods/custom-http-methods.test.js +24 -21
- package/test/http-methods/get.test.js +97 -84
- package/test/http-methods/head.test.js +63 -57
- package/test/http-methods/lock.test.js +21 -20
- package/test/http-methods/mkcalendar.test.js +31 -27
- package/test/http-methods/mkcol.test.js +10 -10
- package/test/http-methods/move.test.js +11 -11
- package/test/http-methods/propfind.test.js +32 -27
- package/test/http-methods/proppatch.test.js +21 -19
- package/test/http-methods/report.test.js +32 -27
- package/test/http-methods/search.test.js +52 -47
- package/test/http-methods/trace.test.js +3 -4
- package/test/http-methods/unlock.test.js +10 -10
- package/test/http2/closing.test.js +50 -58
- package/test/http2/constraint.test.js +47 -50
- package/test/http2/head.test.js +18 -19
- package/test/http2/missing-http2-module.test.js +4 -5
- package/test/http2/plain.test.js +31 -31
- package/test/http2/secure-with-fallback.test.js +61 -61
- package/test/http2/secure.test.js +28 -31
- package/test/http2/unknown-http-method.test.js +13 -14
- package/test/https/custom-https-server.test.js +6 -7
- package/test/https/https.test.js +78 -78
- package/test/imports.test.js +5 -6
- package/test/internals/all.test.js +8 -11
- package/test/internals/{contentTypeParser.test.js → content-type-parser.test.js} +5 -6
- package/test/internals/context.test.js +9 -11
- package/test/internals/decorator.test.js +20 -21
- package/test/internals/errors.test.js +427 -427
- package/test/internals/{handleRequest.test.js → handle-request.test.js} +53 -42
- package/test/internals/{hookRunner.test.js → hook-runner.test.js} +99 -100
- package/test/internals/hooks.test.js +31 -35
- package/test/internals/{initialConfig.test.js → initial-config.test.js} +92 -80
- package/test/internals/logger.test.js +28 -28
- package/test/internals/plugin.test.js +17 -18
- package/test/internals/reply-serialize.test.js +106 -106
- package/test/internals/reply.test.js +620 -585
- package/test/internals/{reqIdGenFactory.test.js → req-id-gen-factory.test.js} +31 -31
- package/test/internals/request-validate.test.js +218 -221
- package/test/internals/request.test.js +225 -107
- package/test/internals/server.test.js +15 -12
- package/test/internals/validation.test.js +35 -36
- package/test/{keepAliveTimeout.test.js → keep-alive-timeout.test.js} +9 -10
- 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 +5 -5
- 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-error.test.js +122 -0
- package/test/request-header-host.test.js +339 -0
- package/test/request-id.test.js +31 -25
- package/test/{requestTimeout.test.js → request-timeout.test.js} +11 -11
- package/test/route.1.test.js +79 -72
- package/test/route.2.test.js +17 -16
- package/test/route.3.test.js +32 -27
- package/test/route.4.test.js +21 -25
- package/test/route.5.test.js +45 -64
- package/test/route.6.test.js +70 -89
- package/test/route.7.test.js +61 -65
- package/test/route.8.test.js +80 -18
- package/test/router-options.test.js +80 -77
- package/test/same-shape.test.js +5 -5
- package/test/schema-examples.test.js +72 -38
- package/test/serialize-response.test.js +9 -10
- package/test/server.test.js +75 -78
- 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/test-reporter.mjs +68 -0
- 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 +16 -4
- package/test/types/hooks.test-d.ts +2 -1
- package/test/types/instance.test-d.ts +13 -13
- package/test/types/logger.test-d.ts +2 -2
- package/test/types/plugin.test-d.ts +17 -9
- package/test/types/register.test-d.ts +22 -6
- package/test/types/reply.test-d.ts +1 -1
- package/test/types/route.test-d.ts +34 -4
- 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/test/versioned-routes.test.js +126 -113
- package/test/web-api.test.js +48 -37
- package/test/{wrapThenable.test.js → wrap-thenable.test.js} +10 -9
- package/types/hooks.d.ts +2 -1
- package/types/instance.d.ts +9 -2
- package/types/register.d.ts +12 -3
- package/types/reply.d.ts +1 -1
- package/types/request.d.ts +2 -6
- package/types/serverFactory.d.ts +3 -3
- package/types/utils.d.ts +13 -5
- package/test/types/import.js +0 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const split = require('split2')
|
|
4
|
-
const test = require('
|
|
4
|
+
const { test } = require('node:test')
|
|
5
5
|
const Fastify = require('../')
|
|
6
6
|
const {
|
|
7
7
|
FST_ERR_BAD_URL,
|
|
@@ -19,12 +19,12 @@ test('Should honor ignoreTrailingSlash option', async t => {
|
|
|
19
19
|
})
|
|
20
20
|
|
|
21
21
|
let res = await fastify.inject('/test')
|
|
22
|
-
t.
|
|
23
|
-
t.
|
|
22
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
23
|
+
t.assert.strictEqual(res.payload.toString(), 'test')
|
|
24
24
|
|
|
25
25
|
res = await fastify.inject('/test/')
|
|
26
|
-
t.
|
|
27
|
-
t.
|
|
26
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
27
|
+
t.assert.strictEqual(res.payload.toString(), 'test')
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
test('Should honor ignoreDuplicateSlashes option', async t => {
|
|
@@ -38,12 +38,12 @@ test('Should honor ignoreDuplicateSlashes option', async t => {
|
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
let res = await fastify.inject('/test/test/test')
|
|
41
|
-
t.
|
|
42
|
-
t.
|
|
41
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
42
|
+
t.assert.strictEqual(res.payload.toString(), 'test')
|
|
43
43
|
|
|
44
44
|
res = await fastify.inject('/test//test///test')
|
|
45
|
-
t.
|
|
46
|
-
t.
|
|
45
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
46
|
+
t.assert.strictEqual(res.payload.toString(), 'test')
|
|
47
47
|
})
|
|
48
48
|
|
|
49
49
|
test('Should honor ignoreTrailingSlash and ignoreDuplicateSlashes options', async t => {
|
|
@@ -58,40 +58,35 @@ test('Should honor ignoreTrailingSlash and ignoreDuplicateSlashes options', asyn
|
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
let res = await fastify.inject('/test/test/test/')
|
|
61
|
-
t.
|
|
62
|
-
t.
|
|
61
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
62
|
+
t.assert.strictEqual(res.payload.toString(), 'test')
|
|
63
63
|
|
|
64
64
|
res = await fastify.inject('/test//test///test//')
|
|
65
|
-
t.
|
|
66
|
-
t.
|
|
65
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
66
|
+
t.assert.strictEqual(res.payload.toString(), 'test')
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
-
test('Should honor maxParamLength option', t => {
|
|
70
|
-
t.plan(4)
|
|
69
|
+
test('Should honor maxParamLength option', async (t) => {
|
|
71
70
|
const fastify = Fastify({ maxParamLength: 10 })
|
|
72
71
|
|
|
73
72
|
fastify.get('/test/:id', (req, reply) => {
|
|
74
73
|
reply.send({ hello: 'world' })
|
|
75
74
|
})
|
|
76
75
|
|
|
77
|
-
fastify.inject({
|
|
76
|
+
const res = await fastify.inject({
|
|
78
77
|
method: 'GET',
|
|
79
78
|
url: '/test/123456789'
|
|
80
|
-
}, (error, res) => {
|
|
81
|
-
t.error(error)
|
|
82
|
-
t.equal(res.statusCode, 200)
|
|
83
79
|
})
|
|
80
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
84
81
|
|
|
85
|
-
fastify.inject({
|
|
82
|
+
const resError = await fastify.inject({
|
|
86
83
|
method: 'GET',
|
|
87
84
|
url: '/test/123456789abcd'
|
|
88
|
-
}, (error, res) => {
|
|
89
|
-
t.error(error)
|
|
90
|
-
t.equal(res.statusCode, 404)
|
|
91
85
|
})
|
|
86
|
+
t.assert.strictEqual(resError.statusCode, 404)
|
|
92
87
|
})
|
|
93
88
|
|
|
94
|
-
test('Should expose router options via getters on request and reply', t => {
|
|
89
|
+
test('Should expose router options via getters on request and reply', (t, done) => {
|
|
95
90
|
t.plan(9)
|
|
96
91
|
const fastify = Fastify()
|
|
97
92
|
const expectedSchema = {
|
|
@@ -106,13 +101,13 @@ test('Should expose router options via getters on request and reply', t => {
|
|
|
106
101
|
fastify.get('/test/:id', {
|
|
107
102
|
schema: expectedSchema
|
|
108
103
|
}, (req, reply) => {
|
|
109
|
-
t.
|
|
110
|
-
t.
|
|
111
|
-
t.
|
|
112
|
-
t.
|
|
113
|
-
t.
|
|
114
|
-
t.
|
|
115
|
-
t.
|
|
104
|
+
t.assert.strictEqual(reply.routeOptions.config.url, '/test/:id')
|
|
105
|
+
t.assert.strictEqual(reply.routeOptions.config.method, 'GET')
|
|
106
|
+
t.assert.deepStrictEqual(req.routeOptions.schema, expectedSchema)
|
|
107
|
+
t.assert.strictEqual(typeof req.routeOptions.handler, 'function')
|
|
108
|
+
t.assert.strictEqual(req.routeOptions.config.url, '/test/:id')
|
|
109
|
+
t.assert.strictEqual(req.routeOptions.config.method, 'GET')
|
|
110
|
+
t.assert.strictEqual(req.is404, false)
|
|
116
111
|
reply.send({ hello: 'world' })
|
|
117
112
|
})
|
|
118
113
|
|
|
@@ -120,17 +115,18 @@ test('Should expose router options via getters on request and reply', t => {
|
|
|
120
115
|
method: 'GET',
|
|
121
116
|
url: '/test/123456789'
|
|
122
117
|
}, (error, res) => {
|
|
123
|
-
t.
|
|
124
|
-
t.
|
|
118
|
+
t.assert.ifError(error)
|
|
119
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
120
|
+
done()
|
|
125
121
|
})
|
|
126
122
|
})
|
|
127
123
|
|
|
128
|
-
test('Should set is404 flag for unmatched paths', t => {
|
|
124
|
+
test('Should set is404 flag for unmatched paths', (t, done) => {
|
|
129
125
|
t.plan(3)
|
|
130
126
|
const fastify = Fastify()
|
|
131
127
|
|
|
132
128
|
fastify.setNotFoundHandler((req, reply) => {
|
|
133
|
-
t.
|
|
129
|
+
t.assert.strictEqual(req.is404, true)
|
|
134
130
|
reply.code(404).send({ error: 'Not Found', message: 'Four oh for', statusCode: 404 })
|
|
135
131
|
})
|
|
136
132
|
|
|
@@ -138,19 +134,20 @@ test('Should set is404 flag for unmatched paths', t => {
|
|
|
138
134
|
method: 'GET',
|
|
139
135
|
url: '/nonexist/123456789'
|
|
140
136
|
}, (error, res) => {
|
|
141
|
-
t.
|
|
142
|
-
t.
|
|
137
|
+
t.assert.ifError(error)
|
|
138
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
139
|
+
done()
|
|
143
140
|
})
|
|
144
141
|
})
|
|
145
142
|
|
|
146
|
-
test('Should honor frameworkErrors option - FST_ERR_BAD_URL', t => {
|
|
143
|
+
test('Should honor frameworkErrors option - FST_ERR_BAD_URL', (t, done) => {
|
|
147
144
|
t.plan(3)
|
|
148
145
|
const fastify = Fastify({
|
|
149
146
|
frameworkErrors: function (err, req, res) {
|
|
150
147
|
if (err instanceof FST_ERR_BAD_URL) {
|
|
151
|
-
t.ok(true)
|
|
148
|
+
t.assert.ok(true)
|
|
152
149
|
} else {
|
|
153
|
-
t.fail()
|
|
150
|
+
t.assert.fail()
|
|
154
151
|
}
|
|
155
152
|
res.send(`${err.message} - ${err.code}`)
|
|
156
153
|
}
|
|
@@ -166,13 +163,14 @@ test('Should honor frameworkErrors option - FST_ERR_BAD_URL', t => {
|
|
|
166
163
|
url: '/test/%world'
|
|
167
164
|
},
|
|
168
165
|
(err, res) => {
|
|
169
|
-
t.
|
|
170
|
-
t.
|
|
166
|
+
t.assert.ifError(err)
|
|
167
|
+
t.assert.strictEqual(res.body, '\'/test/%world\' is not a valid url component - FST_ERR_BAD_URL')
|
|
168
|
+
done()
|
|
171
169
|
}
|
|
172
170
|
)
|
|
173
171
|
})
|
|
174
172
|
|
|
175
|
-
test('Should supply Fastify request to the logger in frameworkErrors wrapper - FST_ERR_BAD_URL', t => {
|
|
173
|
+
test('Should supply Fastify request to the logger in frameworkErrors wrapper - FST_ERR_BAD_URL', (t, done) => {
|
|
176
174
|
t.plan(8)
|
|
177
175
|
|
|
178
176
|
const REQ_ID = 'REQ-1234'
|
|
@@ -180,15 +178,15 @@ test('Should supply Fastify request to the logger in frameworkErrors wrapper - F
|
|
|
180
178
|
|
|
181
179
|
const fastify = Fastify({
|
|
182
180
|
frameworkErrors: function (err, req, res) {
|
|
183
|
-
t.
|
|
184
|
-
t.
|
|
181
|
+
t.assert.deepStrictEqual(req.id, REQ_ID)
|
|
182
|
+
t.assert.deepStrictEqual(req.raw.httpVersion, '1.1')
|
|
185
183
|
res.send(`${err.message} - ${err.code}`)
|
|
186
184
|
},
|
|
187
185
|
logger: {
|
|
188
186
|
stream: logStream,
|
|
189
187
|
serializers: {
|
|
190
188
|
req (request) {
|
|
191
|
-
t.
|
|
189
|
+
t.assert.deepStrictEqual(request.id, REQ_ID)
|
|
192
190
|
return { httpVersion: request.raw.httpVersion }
|
|
193
191
|
}
|
|
194
192
|
}
|
|
@@ -201,9 +199,9 @@ test('Should supply Fastify request to the logger in frameworkErrors wrapper - F
|
|
|
201
199
|
})
|
|
202
200
|
|
|
203
201
|
logStream.on('data', (json) => {
|
|
204
|
-
t.
|
|
205
|
-
t.
|
|
206
|
-
t.
|
|
202
|
+
t.assert.deepStrictEqual(json.msg, 'incoming request')
|
|
203
|
+
t.assert.deepStrictEqual(json.reqId, REQ_ID)
|
|
204
|
+
t.assert.deepStrictEqual(json.req.httpVersion, '1.1')
|
|
207
205
|
})
|
|
208
206
|
|
|
209
207
|
fastify.inject(
|
|
@@ -212,13 +210,14 @@ test('Should supply Fastify request to the logger in frameworkErrors wrapper - F
|
|
|
212
210
|
url: '/test/%world'
|
|
213
211
|
},
|
|
214
212
|
(err, res) => {
|
|
215
|
-
t.
|
|
216
|
-
t.
|
|
213
|
+
t.assert.ifError(err)
|
|
214
|
+
t.assert.strictEqual(res.body, '\'/test/%world\' is not a valid url component - FST_ERR_BAD_URL')
|
|
215
|
+
done()
|
|
217
216
|
}
|
|
218
217
|
)
|
|
219
218
|
})
|
|
220
219
|
|
|
221
|
-
test('Should honor disableRequestLogging option in frameworkErrors wrapper - FST_ERR_BAD_URL', t => {
|
|
220
|
+
test('Should honor disableRequestLogging option in frameworkErrors wrapper - FST_ERR_BAD_URL', (t, done) => {
|
|
222
221
|
t.plan(2)
|
|
223
222
|
|
|
224
223
|
const logStream = split(JSON.parse)
|
|
@@ -232,10 +231,10 @@ test('Should honor disableRequestLogging option in frameworkErrors wrapper - FST
|
|
|
232
231
|
stream: logStream,
|
|
233
232
|
serializers: {
|
|
234
233
|
req () {
|
|
235
|
-
t.fail('should not be called')
|
|
234
|
+
t.assert.fail('should not be called')
|
|
236
235
|
},
|
|
237
236
|
res () {
|
|
238
|
-
t.fail('should not be called')
|
|
237
|
+
t.assert.fail('should not be called')
|
|
239
238
|
}
|
|
240
239
|
}
|
|
241
240
|
}
|
|
@@ -246,7 +245,7 @@ test('Should honor disableRequestLogging option in frameworkErrors wrapper - FST
|
|
|
246
245
|
})
|
|
247
246
|
|
|
248
247
|
logStream.on('data', (json) => {
|
|
249
|
-
t.fail('should not be called')
|
|
248
|
+
t.assert.fail('should not be called')
|
|
250
249
|
})
|
|
251
250
|
|
|
252
251
|
fastify.inject(
|
|
@@ -255,13 +254,14 @@ test('Should honor disableRequestLogging option in frameworkErrors wrapper - FST
|
|
|
255
254
|
url: '/test/%world'
|
|
256
255
|
},
|
|
257
256
|
(err, res) => {
|
|
258
|
-
t.
|
|
259
|
-
t.
|
|
257
|
+
t.assert.ifError(err)
|
|
258
|
+
t.assert.strictEqual(res.body, '\'/test/%world\' is not a valid url component - FST_ERR_BAD_URL')
|
|
259
|
+
done()
|
|
260
260
|
}
|
|
261
261
|
)
|
|
262
262
|
})
|
|
263
263
|
|
|
264
|
-
test('Should honor frameworkErrors option - FST_ERR_ASYNC_CONSTRAINT', t => {
|
|
264
|
+
test('Should honor frameworkErrors option - FST_ERR_ASYNC_CONSTRAINT', (t, done) => {
|
|
265
265
|
t.plan(3)
|
|
266
266
|
|
|
267
267
|
const constraint = {
|
|
@@ -282,9 +282,9 @@ test('Should honor frameworkErrors option - FST_ERR_ASYNC_CONSTRAINT', t => {
|
|
|
282
282
|
const fastify = Fastify({
|
|
283
283
|
frameworkErrors: function (err, req, res) {
|
|
284
284
|
if (err instanceof FST_ERR_ASYNC_CONSTRAINT) {
|
|
285
|
-
t.ok(true)
|
|
285
|
+
t.assert.ok(true)
|
|
286
286
|
} else {
|
|
287
|
-
t.fail()
|
|
287
|
+
t.assert.fail()
|
|
288
288
|
}
|
|
289
289
|
res.send(`${err.message} - ${err.code}`)
|
|
290
290
|
},
|
|
@@ -306,13 +306,14 @@ test('Should honor frameworkErrors option - FST_ERR_ASYNC_CONSTRAINT', t => {
|
|
|
306
306
|
url: '/'
|
|
307
307
|
},
|
|
308
308
|
(err, res) => {
|
|
309
|
-
t.
|
|
310
|
-
t.
|
|
309
|
+
t.assert.ifError(err)
|
|
310
|
+
t.assert.strictEqual(res.body, 'Unexpected error from async constraint - FST_ERR_ASYNC_CONSTRAINT')
|
|
311
|
+
done()
|
|
311
312
|
}
|
|
312
313
|
)
|
|
313
314
|
})
|
|
314
315
|
|
|
315
|
-
test('Should supply Fastify request to the logger in frameworkErrors wrapper - FST_ERR_ASYNC_CONSTRAINT', t => {
|
|
316
|
+
test('Should supply Fastify request to the logger in frameworkErrors wrapper - FST_ERR_ASYNC_CONSTRAINT', (t, done) => {
|
|
316
317
|
t.plan(8)
|
|
317
318
|
|
|
318
319
|
const constraint = {
|
|
@@ -336,15 +337,15 @@ test('Should supply Fastify request to the logger in frameworkErrors wrapper - F
|
|
|
336
337
|
const fastify = Fastify({
|
|
337
338
|
constraints: { secret: constraint },
|
|
338
339
|
frameworkErrors: function (err, req, res) {
|
|
339
|
-
t.
|
|
340
|
-
t.
|
|
340
|
+
t.assert.deepStrictEqual(req.id, REQ_ID)
|
|
341
|
+
t.assert.deepStrictEqual(req.raw.httpVersion, '1.1')
|
|
341
342
|
res.send(`${err.message} - ${err.code}`)
|
|
342
343
|
},
|
|
343
344
|
logger: {
|
|
344
345
|
stream: logStream,
|
|
345
346
|
serializers: {
|
|
346
347
|
req (request) {
|
|
347
|
-
t.
|
|
348
|
+
t.assert.deepStrictEqual(request.id, REQ_ID)
|
|
348
349
|
return { httpVersion: request.raw.httpVersion }
|
|
349
350
|
}
|
|
350
351
|
}
|
|
@@ -362,9 +363,9 @@ test('Should supply Fastify request to the logger in frameworkErrors wrapper - F
|
|
|
362
363
|
})
|
|
363
364
|
|
|
364
365
|
logStream.on('data', (json) => {
|
|
365
|
-
t.
|
|
366
|
-
t.
|
|
367
|
-
t.
|
|
366
|
+
t.assert.deepStrictEqual(json.msg, 'incoming request')
|
|
367
|
+
t.assert.deepStrictEqual(json.reqId, REQ_ID)
|
|
368
|
+
t.assert.deepStrictEqual(json.req.httpVersion, '1.1')
|
|
368
369
|
})
|
|
369
370
|
|
|
370
371
|
fastify.inject(
|
|
@@ -373,13 +374,14 @@ test('Should supply Fastify request to the logger in frameworkErrors wrapper - F
|
|
|
373
374
|
url: '/'
|
|
374
375
|
},
|
|
375
376
|
(err, res) => {
|
|
376
|
-
t.
|
|
377
|
-
t.
|
|
377
|
+
t.assert.ifError(err)
|
|
378
|
+
t.assert.strictEqual(res.body, 'Unexpected error from async constraint - FST_ERR_ASYNC_CONSTRAINT')
|
|
379
|
+
done()
|
|
378
380
|
}
|
|
379
381
|
)
|
|
380
382
|
})
|
|
381
383
|
|
|
382
|
-
test('Should honor disableRequestLogging option in frameworkErrors wrapper - FST_ERR_ASYNC_CONSTRAINT', t => {
|
|
384
|
+
test('Should honor disableRequestLogging option in frameworkErrors wrapper - FST_ERR_ASYNC_CONSTRAINT', (t, done) => {
|
|
383
385
|
t.plan(2)
|
|
384
386
|
|
|
385
387
|
const constraint = {
|
|
@@ -409,10 +411,10 @@ test('Should honor disableRequestLogging option in frameworkErrors wrapper - FST
|
|
|
409
411
|
stream: logStream,
|
|
410
412
|
serializers: {
|
|
411
413
|
req () {
|
|
412
|
-
t.fail('should not be called')
|
|
414
|
+
t.assert.fail('should not be called')
|
|
413
415
|
},
|
|
414
416
|
res () {
|
|
415
|
-
t.fail('should not be called')
|
|
417
|
+
t.assert.fail('should not be called')
|
|
416
418
|
}
|
|
417
419
|
}
|
|
418
420
|
}
|
|
@@ -428,7 +430,7 @@ test('Should honor disableRequestLogging option in frameworkErrors wrapper - FST
|
|
|
428
430
|
})
|
|
429
431
|
|
|
430
432
|
logStream.on('data', (json) => {
|
|
431
|
-
t.fail('should not be called')
|
|
433
|
+
t.assert.fail('should not be called')
|
|
432
434
|
})
|
|
433
435
|
|
|
434
436
|
fastify.inject(
|
|
@@ -437,8 +439,9 @@ test('Should honor disableRequestLogging option in frameworkErrors wrapper - FST
|
|
|
437
439
|
url: '/'
|
|
438
440
|
},
|
|
439
441
|
(err, res) => {
|
|
440
|
-
t.
|
|
441
|
-
t.
|
|
442
|
+
t.assert.ifError(err)
|
|
443
|
+
t.assert.strictEqual(res.body, 'Unexpected error from async constraint - FST_ERR_ASYNC_CONSTRAINT')
|
|
444
|
+
done()
|
|
442
445
|
}
|
|
443
446
|
)
|
|
444
447
|
})
|
package/test/same-shape.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { test } = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const fastify = require('..')
|
|
5
5
|
|
|
6
6
|
test('same shape on Request', async (t) => {
|
|
@@ -21,7 +21,7 @@ test('same shape on Request', async (t) => {
|
|
|
21
21
|
|
|
22
22
|
app.get('/', (req, reply) => {
|
|
23
23
|
if (request) {
|
|
24
|
-
t.
|
|
24
|
+
t.assert.deepStrictEqual(request, req)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
request = req
|
|
@@ -51,7 +51,7 @@ test('same shape on Request when object', async (t) => {
|
|
|
51
51
|
|
|
52
52
|
app.get('/', (req, reply) => {
|
|
53
53
|
if (request) {
|
|
54
|
-
t.
|
|
54
|
+
t.assert.deepStrictEqual(request, req)
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
request = req
|
|
@@ -81,7 +81,7 @@ test('same shape on Reply', async (t) => {
|
|
|
81
81
|
|
|
82
82
|
app.get('/', (req, reply) => {
|
|
83
83
|
if (_reply) {
|
|
84
|
-
t.
|
|
84
|
+
t.assert.deepStrictEqual(_reply, reply)
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
_reply = reply
|
|
@@ -111,7 +111,7 @@ test('same shape on Reply when object', async (t) => {
|
|
|
111
111
|
|
|
112
112
|
app.get('/', (req, reply) => {
|
|
113
113
|
if (_reply) {
|
|
114
|
-
t.
|
|
114
|
+
t.assert.deepStrictEqual(_reply, reply)
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
_reply = reply
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { test } = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const localize = require('ajv-i18n')
|
|
5
5
|
const Fastify = require('..')
|
|
6
6
|
|
|
7
|
-
test('Example - URI $id', t => {
|
|
7
|
+
test('Example - URI $id', (t, done) => {
|
|
8
8
|
t.plan(1)
|
|
9
9
|
const fastify = Fastify()
|
|
10
10
|
fastify.addSchema({
|
|
@@ -25,10 +25,13 @@ test('Example - URI $id', t => {
|
|
|
25
25
|
}
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
fastify.ready(err =>
|
|
28
|
+
fastify.ready(err => {
|
|
29
|
+
t.assert.ifError(err)
|
|
30
|
+
done()
|
|
31
|
+
})
|
|
29
32
|
})
|
|
30
33
|
|
|
31
|
-
test('Example - string $id', t => {
|
|
34
|
+
test('Example - string $id', (t, done) => {
|
|
32
35
|
t.plan(1)
|
|
33
36
|
const fastify = Fastify()
|
|
34
37
|
fastify.addSchema({
|
|
@@ -47,10 +50,13 @@ test('Example - string $id', t => {
|
|
|
47
50
|
}
|
|
48
51
|
})
|
|
49
52
|
|
|
50
|
-
fastify.ready(err =>
|
|
53
|
+
fastify.ready(err => {
|
|
54
|
+
t.assert.ifError(err)
|
|
55
|
+
done()
|
|
56
|
+
})
|
|
51
57
|
})
|
|
52
58
|
|
|
53
|
-
test('Example - get schema', t => {
|
|
59
|
+
test('Example - get schema', (t, done) => {
|
|
54
60
|
t.plan(1)
|
|
55
61
|
const fastify = Fastify()
|
|
56
62
|
fastify.addSchema({
|
|
@@ -63,7 +69,8 @@ test('Example - get schema', t => {
|
|
|
63
69
|
|
|
64
70
|
const mySchemas = fastify.getSchemas()
|
|
65
71
|
const mySchema = fastify.getSchema('schemaId')
|
|
66
|
-
t.
|
|
72
|
+
t.assert.deepStrictEqual(mySchemas.schemaId, mySchema)
|
|
73
|
+
done()
|
|
67
74
|
})
|
|
68
75
|
|
|
69
76
|
test('Example - get schema encapsulated', async t => {
|
|
@@ -91,12 +98,12 @@ test('Example - get schema encapsulated', async t => {
|
|
|
91
98
|
const r2 = await fastify.inject('/sub')
|
|
92
99
|
const r3 = await fastify.inject('/deep')
|
|
93
100
|
|
|
94
|
-
t.
|
|
95
|
-
t.
|
|
96
|
-
t.
|
|
101
|
+
t.assert.deepStrictEqual(Object.keys(r1.json()), ['one'])
|
|
102
|
+
t.assert.deepStrictEqual(Object.keys(r2.json()), ['one', 'two'])
|
|
103
|
+
t.assert.deepStrictEqual(Object.keys(r3.json()), ['one', 'two', 'three'])
|
|
97
104
|
})
|
|
98
105
|
|
|
99
|
-
test('Example - validation', t => {
|
|
106
|
+
test('Example - validation', (t, done) => {
|
|
100
107
|
t.plan(1)
|
|
101
108
|
const fastify = Fastify({
|
|
102
109
|
ajv: {
|
|
@@ -168,10 +175,13 @@ test('Example - validation', t => {
|
|
|
168
175
|
}
|
|
169
176
|
|
|
170
177
|
fastify.post('/the/url', { schema }, handler)
|
|
171
|
-
fastify.ready(err =>
|
|
178
|
+
fastify.ready(err => {
|
|
179
|
+
t.assert.ifError(err)
|
|
180
|
+
done()
|
|
181
|
+
})
|
|
172
182
|
})
|
|
173
183
|
|
|
174
|
-
test('Example - ajv config', t => {
|
|
184
|
+
test('Example - ajv config', (t, done) => {
|
|
175
185
|
t.plan(1)
|
|
176
186
|
|
|
177
187
|
const fastify = Fastify({
|
|
@@ -228,10 +238,13 @@ test('Example - ajv config', t => {
|
|
|
228
238
|
}
|
|
229
239
|
})
|
|
230
240
|
|
|
231
|
-
fastify.ready(err =>
|
|
241
|
+
fastify.ready(err => {
|
|
242
|
+
t.assert.ifError(err)
|
|
243
|
+
done()
|
|
244
|
+
})
|
|
232
245
|
})
|
|
233
246
|
|
|
234
|
-
test('Example Joi', t => {
|
|
247
|
+
test('Example Joi', (t, done) => {
|
|
235
248
|
t.plan(1)
|
|
236
249
|
const fastify = Fastify()
|
|
237
250
|
const handler = () => { }
|
|
@@ -248,10 +261,13 @@ test('Example Joi', t => {
|
|
|
248
261
|
}
|
|
249
262
|
}, handler)
|
|
250
263
|
|
|
251
|
-
fastify.ready(err =>
|
|
264
|
+
fastify.ready(err => {
|
|
265
|
+
t.assert.ifError(err)
|
|
266
|
+
done()
|
|
267
|
+
})
|
|
252
268
|
})
|
|
253
269
|
|
|
254
|
-
test('Example yup', t => {
|
|
270
|
+
test('Example yup', (t, done) => {
|
|
255
271
|
t.plan(1)
|
|
256
272
|
const fastify = Fastify()
|
|
257
273
|
const handler = () => { }
|
|
@@ -287,10 +303,13 @@ test('Example yup', t => {
|
|
|
287
303
|
}
|
|
288
304
|
}, handler)
|
|
289
305
|
|
|
290
|
-
fastify.ready(err =>
|
|
306
|
+
fastify.ready(err => {
|
|
307
|
+
t.assert.ifError(err)
|
|
308
|
+
done()
|
|
309
|
+
})
|
|
291
310
|
})
|
|
292
311
|
|
|
293
|
-
test('Example - serialization', t => {
|
|
312
|
+
test('Example - serialization', (t, done) => {
|
|
294
313
|
t.plan(1)
|
|
295
314
|
const fastify = Fastify()
|
|
296
315
|
const handler = () => { }
|
|
@@ -308,10 +327,13 @@ test('Example - serialization', t => {
|
|
|
308
327
|
}
|
|
309
328
|
|
|
310
329
|
fastify.post('/the/url', { schema }, handler)
|
|
311
|
-
fastify.ready(err =>
|
|
330
|
+
fastify.ready(err => {
|
|
331
|
+
t.assert.ifError(err)
|
|
332
|
+
done()
|
|
333
|
+
})
|
|
312
334
|
})
|
|
313
335
|
|
|
314
|
-
test('Example - serialization 2', t => {
|
|
336
|
+
test('Example - serialization 2', (t, done) => {
|
|
315
337
|
t.plan(1)
|
|
316
338
|
const fastify = Fastify()
|
|
317
339
|
const handler = () => { }
|
|
@@ -333,10 +355,13 @@ test('Example - serialization 2', t => {
|
|
|
333
355
|
}
|
|
334
356
|
|
|
335
357
|
fastify.post('/the/url', { schema }, handler)
|
|
336
|
-
fastify.ready(err =>
|
|
358
|
+
fastify.ready(err => {
|
|
359
|
+
t.assert.ifError(err)
|
|
360
|
+
done()
|
|
361
|
+
})
|
|
337
362
|
})
|
|
338
363
|
|
|
339
|
-
test('Example - serializator', t => {
|
|
364
|
+
test('Example - serializator', (t, done) => {
|
|
340
365
|
t.plan(1)
|
|
341
366
|
const fastify = Fastify()
|
|
342
367
|
|
|
@@ -361,10 +386,13 @@ test('Example - serializator', t => {
|
|
|
361
386
|
}
|
|
362
387
|
})
|
|
363
388
|
|
|
364
|
-
fastify.ready(err =>
|
|
389
|
+
fastify.ready(err => {
|
|
390
|
+
t.assert.ifError(err)
|
|
391
|
+
done()
|
|
392
|
+
})
|
|
365
393
|
})
|
|
366
394
|
|
|
367
|
-
test('Example - schemas examples', t => {
|
|
395
|
+
test('Example - schemas examples', (t, done) => {
|
|
368
396
|
t.plan(1)
|
|
369
397
|
const fastify = Fastify()
|
|
370
398
|
const handler = () => { }
|
|
@@ -457,10 +485,13 @@ test('Example - schemas examples', t => {
|
|
|
457
485
|
|
|
458
486
|
})
|
|
459
487
|
|
|
460
|
-
fastify.ready(err =>
|
|
488
|
+
fastify.ready(err => {
|
|
489
|
+
t.assert.ifError(err)
|
|
490
|
+
done()
|
|
491
|
+
})
|
|
461
492
|
})
|
|
462
493
|
|
|
463
|
-
test('should return custom error messages with ajv-errors', t => {
|
|
494
|
+
test('should return custom error messages with ajv-errors', (t, done) => {
|
|
464
495
|
t.plan(3)
|
|
465
496
|
|
|
466
497
|
const fastify = Fastify({
|
|
@@ -508,18 +539,19 @@ test('should return custom error messages with ajv-errors', t => {
|
|
|
508
539
|
},
|
|
509
540
|
url: '/'
|
|
510
541
|
}, (err, res) => {
|
|
511
|
-
t.
|
|
512
|
-
t.
|
|
542
|
+
t.assert.ifError(err)
|
|
543
|
+
t.assert.deepStrictEqual(JSON.parse(res.payload), {
|
|
513
544
|
statusCode: 400,
|
|
514
545
|
code: 'FST_ERR_VALIDATION',
|
|
515
546
|
error: 'Bad Request',
|
|
516
547
|
message: 'body/age bad age - should be num, body name please, body work please'
|
|
517
548
|
})
|
|
518
|
-
t.
|
|
549
|
+
t.assert.strictEqual(res.statusCode, 400)
|
|
550
|
+
done()
|
|
519
551
|
})
|
|
520
552
|
})
|
|
521
553
|
|
|
522
|
-
test('should be able to handle formats of ajv-formats when added by plugins option', t => {
|
|
554
|
+
test('should be able to handle formats of ajv-formats when added by plugins option', (t, done) => {
|
|
523
555
|
t.plan(3)
|
|
524
556
|
|
|
525
557
|
const fastify = Fastify({
|
|
@@ -553,8 +585,8 @@ test('should be able to handle formats of ajv-formats when added by plugins opti
|
|
|
553
585
|
},
|
|
554
586
|
url: '/'
|
|
555
587
|
}, (_err, res) => {
|
|
556
|
-
t.
|
|
557
|
-
t.
|
|
588
|
+
t.assert.strictEqual(res.body, '254381a5-888c-4b41-8116-e3b1a54980bd')
|
|
589
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
558
590
|
})
|
|
559
591
|
|
|
560
592
|
fastify.inject({
|
|
@@ -565,16 +597,17 @@ test('should be able to handle formats of ajv-formats when added by plugins opti
|
|
|
565
597
|
},
|
|
566
598
|
url: '/'
|
|
567
599
|
}, (_err, res) => {
|
|
568
|
-
t.
|
|
600
|
+
t.assert.deepStrictEqual(JSON.parse(res.payload), {
|
|
569
601
|
statusCode: 400,
|
|
570
602
|
code: 'FST_ERR_VALIDATION',
|
|
571
603
|
error: 'Bad Request',
|
|
572
604
|
message: 'body/id must match format "uuid"'
|
|
573
605
|
})
|
|
606
|
+
done()
|
|
574
607
|
})
|
|
575
608
|
})
|
|
576
609
|
|
|
577
|
-
test('should return localized error messages with ajv-i18n', t => {
|
|
610
|
+
test('should return localized error messages with ajv-i18n', (t, done) => {
|
|
578
611
|
t.plan(3)
|
|
579
612
|
|
|
580
613
|
const schema = {
|
|
@@ -614,14 +647,15 @@ test('should return localized error messages with ajv-i18n', t => {
|
|
|
614
647
|
},
|
|
615
648
|
url: '/'
|
|
616
649
|
}, (err, res) => {
|
|
617
|
-
t.
|
|
618
|
-
t.
|
|
650
|
+
t.assert.ifError(err)
|
|
651
|
+
t.assert.deepStrictEqual(JSON.parse(res.payload), [{
|
|
619
652
|
instancePath: '',
|
|
620
653
|
keyword: 'required',
|
|
621
654
|
message: 'должно иметь обязательное поле work',
|
|
622
655
|
params: { missingProperty: 'work' },
|
|
623
656
|
schemaPath: '#/required'
|
|
624
657
|
}])
|
|
625
|
-
t.
|
|
658
|
+
t.assert.strictEqual(res.statusCode, 400)
|
|
659
|
+
done()
|
|
626
660
|
})
|
|
627
661
|
})
|