fastify 5.0.0 → 5.1.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/docs/Guides/Ecosystem.md +1 -8
- package/docs/Guides/Migration-Guide-V5.md +128 -4
- package/docs/Guides/Testing.md +51 -50
- package/docs/Guides/Write-Plugin.md +1 -1
- package/docs/Reference/ContentTypeParser.md +4 -4
- package/docs/Reference/Errors.md +1 -1
- package/docs/Reference/Reply.md +1 -5
- package/docs/Reference/Request.md +2 -1
- package/docs/Reference/Routes.md +9 -6
- package/docs/Reference/Server.md +1 -1
- package/fastify.d.ts +10 -1
- package/fastify.js +8 -6
- package/lib/contentTypeParser.js +9 -7
- package/lib/context.js +1 -2
- package/lib/fourOhFour.js +1 -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 +15 -9
- package/lib/route.js +23 -22
- package/lib/validation.js +2 -2
- package/package.json +12 -13
- package/test/404s.test.js +675 -629
- package/test/500s.test.js +72 -63
- package/test/allowUnsafeRegex.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 -4
- 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/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 -9
- package/test/childLoggerFactory.test.js +56 -19
- package/test/client-timeout.test.js +5 -5
- package/test/close-pipelining.test.js +6 -7
- package/test/conditional-pino.test.js +47 -0
- package/test/connectionTimeout.test.js +10 -11
- package/test/constrained-routes.test.js +243 -236
- package/test/content-parser.test.js +17 -0
- package/test/custom-http-server.test.js +16 -20
- 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/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/hooks.test.js +6 -6
- 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 -54
- 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 +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 +53 -42
- package/test/internals/hookRunner.test.js +99 -100
- package/test/internals/hooks.test.js +31 -35
- package/test/internals/initialConfig.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 +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/noop-set.test.js +5 -5
- package/test/request-error.test.js +122 -0
- package/test/request-header-host.test.js +197 -0
- package/test/route.1.test.js +79 -72
- package/test/route.2.test.js +17 -16
- package/test/route.3.test.js +30 -26
- 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 +62 -0
- package/test/same-shape.test.js +5 -5
- package/test/serialize-response.test.js +9 -10
- package/test/server.test.js +67 -70
- package/test/test-reporter.mjs +68 -0
- package/test/types/fastify.test-d.ts +12 -0
- package/test/types/hooks.test-d.ts +2 -1
- package/test/types/instance.test-d.ts +10 -12
- package/test/types/plugin.test-d.ts +15 -7
- package/test/types/register.test-d.ts +20 -4
- package/test/types/route.test-d.ts +33 -3
- package/test/versioned-routes.test.js +126 -113
- package/test/web-api.test.js +48 -37
- package/test/wrapThenable.test.js +10 -9
- package/types/hooks.d.ts +1 -0
- package/types/register.d.ts +12 -3
- package/types/request.d.ts +2 -2
- package/types/utils.d.ts +10 -2
- package/test/types/import.js +0 -2
package/test/imports.test.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
|
|
6
5
|
test('should import as default', t => {
|
|
7
6
|
t.plan(2)
|
|
8
7
|
const fastify = require('..')
|
|
9
|
-
t.ok(fastify)
|
|
10
|
-
t.equal(typeof fastify, 'function')
|
|
8
|
+
t.assert.ok(fastify)
|
|
9
|
+
t.assert.equal(typeof fastify, 'function')
|
|
11
10
|
})
|
|
12
11
|
|
|
13
12
|
test('should import as esm', t => {
|
|
14
13
|
t.plan(2)
|
|
15
14
|
const { fastify } = require('..')
|
|
16
|
-
t.ok(fastify)
|
|
17
|
-
t.equal(typeof fastify, 'function')
|
|
15
|
+
t.assert.ok(fastify)
|
|
16
|
+
t.assert.equal(typeof fastify, 'function')
|
|
18
17
|
})
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
const Fastify = require('../..')
|
|
6
5
|
|
|
7
|
-
test('fastify.all should add all the methods to the same url', t => {
|
|
6
|
+
test('fastify.all should add all the methods to the same url', async t => {
|
|
8
7
|
const fastify = Fastify()
|
|
9
8
|
|
|
10
9
|
const requirePayload = [
|
|
@@ -14,15 +13,15 @@ test('fastify.all should add all the methods to the same url', t => {
|
|
|
14
13
|
]
|
|
15
14
|
|
|
16
15
|
const supportedMethods = fastify.supportedMethods
|
|
17
|
-
t.plan(supportedMethods.length
|
|
16
|
+
t.plan(supportedMethods.length)
|
|
18
17
|
|
|
19
18
|
fastify.all('/', (req, reply) => {
|
|
20
19
|
reply.send({ method: req.raw.method })
|
|
21
20
|
})
|
|
22
21
|
|
|
23
|
-
supportedMethods.
|
|
22
|
+
await Promise.all(supportedMethods.map(async method => injectRequest(method)))
|
|
24
23
|
|
|
25
|
-
function injectRequest (method) {
|
|
24
|
+
async function injectRequest (method) {
|
|
26
25
|
const options = {
|
|
27
26
|
url: '/',
|
|
28
27
|
method
|
|
@@ -32,10 +31,8 @@ test('fastify.all should add all the methods to the same url', t => {
|
|
|
32
31
|
options.payload = { hello: 'world' }
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
fastify.inject(options
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
t.same(payload, { method })
|
|
39
|
-
})
|
|
34
|
+
const res = await fastify.inject(options)
|
|
35
|
+
const payload = JSON.parse(res.payload)
|
|
36
|
+
t.assert.deepStrictEqual(payload, { method })
|
|
40
37
|
}
|
|
41
38
|
})
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const proxyquire = require('proxyquire')
|
|
5
|
-
const test = t.test
|
|
6
5
|
const { Readable } = require('node:stream')
|
|
7
6
|
const { kTestInternals, kRouteContext } = require('../../lib/symbols')
|
|
8
7
|
const Request = require('../../lib/request')
|
|
@@ -17,8 +16,8 @@ test('rawBody function', t => {
|
|
|
17
16
|
asString: true,
|
|
18
17
|
asBuffer: false,
|
|
19
18
|
fn (req, bodyInString, done) {
|
|
20
|
-
t.
|
|
21
|
-
t.
|
|
19
|
+
t.assert.strictEqual(bodyInString, body.toString())
|
|
20
|
+
t.assert.strictEqual(typeof done, 'function')
|
|
22
21
|
return {
|
|
23
22
|
then (cb) {
|
|
24
23
|
cb()
|
|
@@ -70,8 +69,8 @@ test('Should support Webpack and faux modules', t => {
|
|
|
70
69
|
asString: true,
|
|
71
70
|
asBuffer: false,
|
|
72
71
|
fn (req, bodyInString, done) {
|
|
73
|
-
t.
|
|
74
|
-
t.
|
|
72
|
+
t.assert.strictEqual(bodyInString, body.toString())
|
|
73
|
+
t.assert.strictEqual(typeof done, 'function')
|
|
75
74
|
return {
|
|
76
75
|
then (cb) {
|
|
77
76
|
cb()
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { test } = require('
|
|
4
|
-
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
const { kRouteContext } = require('../../lib/symbols')
|
|
6
5
|
const Context = require('../../lib/context')
|
|
7
6
|
|
|
8
7
|
const Fastify = require('../..')
|
|
9
8
|
|
|
10
|
-
test('context', context => {
|
|
9
|
+
test('context', async context => {
|
|
11
10
|
context.plan(1)
|
|
12
11
|
|
|
13
|
-
context.test('Should not contain undefined as key prop', async t => {
|
|
12
|
+
await context.test('Should not contain undefined as key prop', async t => {
|
|
13
|
+
t.plan(4)
|
|
14
14
|
const app = Fastify()
|
|
15
15
|
|
|
16
16
|
app.get('/', (req, reply) => {
|
|
17
|
-
t.
|
|
18
|
-
t.
|
|
19
|
-
t.
|
|
20
|
-
t.
|
|
17
|
+
t.assert.ok(req[kRouteContext] instanceof Context)
|
|
18
|
+
t.assert.ok(reply[kRouteContext] instanceof Context)
|
|
19
|
+
t.assert.ok(!('undefined' in reply[kRouteContext]))
|
|
20
|
+
t.assert.ok(!('undefined' in req[kRouteContext]))
|
|
21
21
|
|
|
22
22
|
reply.send('hello world!')
|
|
23
23
|
})
|
|
@@ -25,9 +25,7 @@ test('context', context => {
|
|
|
25
25
|
try {
|
|
26
26
|
await app.inject('/')
|
|
27
27
|
} catch (e) {
|
|
28
|
-
t.fail(e)
|
|
28
|
+
t.assert.fail(e)
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
t.plan(4)
|
|
32
30
|
})
|
|
33
31
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
const decorator = require('../../lib/decorate')
|
|
6
5
|
const {
|
|
7
6
|
kState
|
|
@@ -22,7 +21,7 @@ test('decorate should add the given method to its instance', t => {
|
|
|
22
21
|
|
|
23
22
|
const server = build()
|
|
24
23
|
server.add('test', () => {})
|
|
25
|
-
t.ok(server.test)
|
|
24
|
+
t.assert.ok(server.test)
|
|
26
25
|
})
|
|
27
26
|
|
|
28
27
|
test('decorate is chainable', t => {
|
|
@@ -44,15 +43,15 @@ test('decorate is chainable', t => {
|
|
|
44
43
|
.add('test2', () => {})
|
|
45
44
|
.add('test3', () => {})
|
|
46
45
|
|
|
47
|
-
t.ok(server.test1)
|
|
48
|
-
t.ok(server.test2)
|
|
49
|
-
t.ok(server.test3)
|
|
46
|
+
t.assert.ok(server.test1)
|
|
47
|
+
t.assert.ok(server.test2)
|
|
48
|
+
t.assert.ok(server.test3)
|
|
50
49
|
})
|
|
51
50
|
|
|
52
51
|
test('checkExistence should check if a property is part of the given instance', t => {
|
|
53
52
|
t.plan(1)
|
|
54
53
|
const instance = { test: () => {} }
|
|
55
|
-
t.ok(decorator.exist(instance, 'test'))
|
|
54
|
+
t.assert.ok(decorator.exist(instance, 'test'))
|
|
56
55
|
})
|
|
57
56
|
|
|
58
57
|
test('checkExistence should find the instance if not given', t => {
|
|
@@ -71,7 +70,7 @@ test('checkExistence should find the instance if not given', t => {
|
|
|
71
70
|
|
|
72
71
|
const server = build()
|
|
73
72
|
server.add('test', () => {})
|
|
74
|
-
t.ok(server.check('test'))
|
|
73
|
+
t.assert.ok(server.check('test'))
|
|
75
74
|
})
|
|
76
75
|
|
|
77
76
|
test('checkExistence should check the prototype as well', t => {
|
|
@@ -80,7 +79,7 @@ test('checkExistence should check the prototype as well', t => {
|
|
|
80
79
|
Instance.prototype.test = () => {}
|
|
81
80
|
|
|
82
81
|
const instance = new Instance()
|
|
83
|
-
t.ok(decorator.exist(instance, 'test'))
|
|
82
|
+
t.assert.ok(decorator.exist(instance, 'test'))
|
|
84
83
|
})
|
|
85
84
|
|
|
86
85
|
test('checkDependencies should throw if a dependency is not present', t => {
|
|
@@ -88,10 +87,10 @@ test('checkDependencies should throw if a dependency is not present', t => {
|
|
|
88
87
|
const instance = {}
|
|
89
88
|
try {
|
|
90
89
|
decorator.dependencies(instance, 'foo', ['test'])
|
|
91
|
-
t.fail()
|
|
90
|
+
t.assert.fail()
|
|
92
91
|
} catch (e) {
|
|
93
|
-
t.
|
|
94
|
-
t.
|
|
92
|
+
t.assert.strictEqual(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY')
|
|
93
|
+
t.assert.strictEqual(e.message, 'The decorator is missing dependency \'test\'.')
|
|
95
94
|
}
|
|
96
95
|
})
|
|
97
96
|
|
|
@@ -112,10 +111,10 @@ test('decorate should internally call checkDependencies', t => {
|
|
|
112
111
|
|
|
113
112
|
try {
|
|
114
113
|
server.add('method', () => {}, ['test'])
|
|
115
|
-
t.fail()
|
|
114
|
+
t.assert.fail()
|
|
116
115
|
} catch (e) {
|
|
117
|
-
t.
|
|
118
|
-
t.
|
|
116
|
+
t.assert.strictEqual(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY')
|
|
117
|
+
t.assert.strictEqual(e.message, 'The decorator is missing dependency \'test\'.')
|
|
119
118
|
}
|
|
120
119
|
})
|
|
121
120
|
|
|
@@ -132,14 +131,14 @@ test('decorate should recognize getter/setter objects', t => {
|
|
|
132
131
|
decorator.add.call(one, 'foo', {
|
|
133
132
|
getter: () => this._a,
|
|
134
133
|
setter: (val) => {
|
|
135
|
-
t.
|
|
134
|
+
t.assert.ok(true)
|
|
136
135
|
this._a = val
|
|
137
136
|
}
|
|
138
137
|
})
|
|
139
|
-
t.
|
|
140
|
-
t.
|
|
138
|
+
t.assert.strictEqual(Object.hasOwn(one, 'foo'), true)
|
|
139
|
+
t.assert.strictEqual(one.foo, undefined)
|
|
141
140
|
one.foo = 'a'
|
|
142
|
-
t.
|
|
141
|
+
t.assert.strictEqual(one.foo, 'a')
|
|
143
142
|
|
|
144
143
|
// getter only
|
|
145
144
|
const two = {
|
|
@@ -152,6 +151,6 @@ test('decorate should recognize getter/setter objects', t => {
|
|
|
152
151
|
decorator.add.call(two, 'foo', {
|
|
153
152
|
getter: () => 'a getter'
|
|
154
153
|
})
|
|
155
|
-
t.
|
|
156
|
-
t.
|
|
154
|
+
t.assert.strictEqual(Object.hasOwn(two, 'foo'), true)
|
|
155
|
+
t.assert.strictEqual(two.foo, 'a getter')
|
|
157
156
|
})
|