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,16 +1,15 @@
|
|
|
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
|
const h2url = require('h2url')
|
|
7
6
|
const msg = { hello: 'world' }
|
|
8
7
|
|
|
9
8
|
const { buildCertificate } = require('../build-certificate')
|
|
10
|
-
|
|
9
|
+
test.before(buildCertificate)
|
|
11
10
|
|
|
12
|
-
test('secure', (t) => {
|
|
13
|
-
t.plan(
|
|
11
|
+
test('secure', async (t) => {
|
|
12
|
+
t.plan(4)
|
|
14
13
|
|
|
15
14
|
let fastify
|
|
16
15
|
try {
|
|
@@ -21,9 +20,9 @@ test('secure', (t) => {
|
|
|
21
20
|
cert: global.context.cert
|
|
22
21
|
}
|
|
23
22
|
})
|
|
24
|
-
t.
|
|
23
|
+
t.assert.ok(true, 'Key/cert successfully loaded')
|
|
25
24
|
} catch (e) {
|
|
26
|
-
t.fail('Key/cert loading failed'
|
|
25
|
+
t.assert.fail('Key/cert loading failed')
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
fastify.get('/', function (req, reply) {
|
|
@@ -36,35 +35,33 @@ test('secure', (t) => {
|
|
|
36
35
|
reply.code(200).send({ hostname: req.hostname, port: req.port })
|
|
37
36
|
})
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
t.teardown(() => { fastify.close() })
|
|
38
|
+
t.after(() => { fastify.close() })
|
|
39
|
+
await fastify.listen({ port: 0 })
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
await t.test('https get request', async (t) => {
|
|
42
|
+
t.plan(3)
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
const url = `https://localhost:${fastify.server.address().port}`
|
|
45
|
+
const res = await h2url.concat({ url })
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
t.assert.strictEqual(res.headers[':status'], 200)
|
|
48
|
+
t.assert.strictEqual(res.headers['content-length'], '' + JSON.stringify(msg).length)
|
|
49
|
+
t.assert.deepStrictEqual(JSON.parse(res.body), msg)
|
|
50
|
+
})
|
|
53
51
|
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
await t.test('https get request without trust proxy - protocol', async (t) => {
|
|
53
|
+
t.plan(2)
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
const url = `https://localhost:${fastify.server.address().port}/proto`
|
|
56
|
+
t.assert.deepStrictEqual(JSON.parse((await h2url.concat({ url })).body), { proto: 'https' })
|
|
57
|
+
t.assert.deepStrictEqual(JSON.parse((await h2url.concat({ url, headers: { 'X-Forwarded-Proto': 'lorem' } })).body), { proto: 'https' })
|
|
58
|
+
})
|
|
59
|
+
await t.test('https get request - test hostname and port', async (t) => {
|
|
60
|
+
t.plan(2)
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})
|
|
62
|
+
const url = `https://localhost:${fastify.server.address().port}/hostname_port`
|
|
63
|
+
const parsedbody = JSON.parse((await h2url.concat({ url })).body)
|
|
64
|
+
t.assert.strictEqual(parsedbody.hostname, 'localhost')
|
|
65
|
+
t.assert.strictEqual(parsedbody.port, fastify.server.address().port)
|
|
69
66
|
})
|
|
70
67
|
})
|
|
@@ -1,31 +1,30 @@
|
|
|
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
|
const h2url = require('h2url')
|
|
7
6
|
const msg = { hello: 'world' }
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
test('http2 unknown http method', async t => {
|
|
9
|
+
const fastify = Fastify({
|
|
10
|
+
http2: true
|
|
11
|
+
})
|
|
12
12
|
|
|
13
|
-
fastify.get('/', function (req, reply) {
|
|
14
|
-
|
|
15
|
-
})
|
|
13
|
+
fastify.get('/', function (req, reply) {
|
|
14
|
+
reply.code(200).send(msg)
|
|
15
|
+
})
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
t.teardown(() => { fastify.close() })
|
|
17
|
+
t.after(() => { fastify.close() })
|
|
18
|
+
await fastify.listen({ port: 0 })
|
|
20
19
|
|
|
21
|
-
test('http UNKNOWN_METHOD request', async (t) => {
|
|
20
|
+
await t.test('http UNKNOWN_METHOD request', async (t) => {
|
|
22
21
|
t.plan(2)
|
|
23
22
|
|
|
24
23
|
const url = `http://localhost:${fastify.server.address().port}`
|
|
25
24
|
const res = await h2url.concat({ url, method: 'UNKNOWN_METHOD' })
|
|
26
25
|
|
|
27
|
-
t.
|
|
28
|
-
t.
|
|
26
|
+
t.assert.strictEqual(res.headers[':status'], 404)
|
|
27
|
+
t.assert.deepStrictEqual(JSON.parse(res.body), {
|
|
29
28
|
statusCode: 404,
|
|
30
29
|
code: 'FST_ERR_NOT_FOUND',
|
|
31
30
|
error: 'Not Found',
|
|
@@ -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 Fastify = require('../..')
|
|
6
5
|
const https = require('node:https')
|
|
7
6
|
const dns = require('node:dns').promises
|
|
@@ -18,7 +17,7 @@ async function setup () {
|
|
|
18
17
|
|
|
19
18
|
const fastify = Fastify({
|
|
20
19
|
serverFactory: (handler, opts) => {
|
|
21
|
-
t.ok(opts.serverFactory, 'it is called once for localhost')
|
|
20
|
+
t.assert.ok(opts.serverFactory, 'it is called once for localhost')
|
|
22
21
|
|
|
23
22
|
const options = {
|
|
24
23
|
key: global.context.key,
|
|
@@ -34,10 +33,10 @@ async function setup () {
|
|
|
34
33
|
}
|
|
35
34
|
})
|
|
36
35
|
|
|
37
|
-
t.
|
|
36
|
+
t.after(() => { fastify.close() })
|
|
38
37
|
|
|
39
38
|
fastify.get('/', (req, reply) => {
|
|
40
|
-
t.ok(req.raw.custom)
|
|
39
|
+
t.assert.ok(req.raw.custom)
|
|
41
40
|
reply.send({ hello: 'world' })
|
|
42
41
|
})
|
|
43
42
|
|
|
@@ -52,8 +51,8 @@ async function setup () {
|
|
|
52
51
|
if (err) {
|
|
53
52
|
return reject(err)
|
|
54
53
|
}
|
|
55
|
-
t.
|
|
56
|
-
t.
|
|
54
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
55
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
57
56
|
resolve()
|
|
58
57
|
})
|
|
59
58
|
})
|
package/test/https/https.test.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
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
5
|
const Fastify = require('../..')
|
|
7
6
|
|
|
8
7
|
const { buildCertificate } = require('../build-certificate')
|
|
9
|
-
|
|
8
|
+
test.before(buildCertificate)
|
|
10
9
|
|
|
11
|
-
test('https', (t) => {
|
|
12
|
-
t.plan(
|
|
10
|
+
test('https', async (t) => {
|
|
11
|
+
t.plan(3)
|
|
13
12
|
|
|
14
13
|
let fastify
|
|
15
14
|
try {
|
|
@@ -19,9 +18,9 @@ test('https', (t) => {
|
|
|
19
18
|
cert: global.context.cert
|
|
20
19
|
}
|
|
21
20
|
})
|
|
22
|
-
t.
|
|
21
|
+
t.assert.ok('Key/cert successfully loaded')
|
|
23
22
|
} catch (e) {
|
|
24
|
-
t.fail('Key/cert loading failed'
|
|
23
|
+
t.assert.fail('Key/cert loading failed')
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
fastify.get('/', function (req, reply) {
|
|
@@ -32,51 +31,52 @@ test('https', (t) => {
|
|
|
32
31
|
reply.code(200).send({ proto: req.protocol })
|
|
33
32
|
})
|
|
34
33
|
|
|
35
|
-
fastify.listen({ port: 0 }
|
|
36
|
-
t.error(err)
|
|
37
|
-
t.teardown(() => { fastify.close() })
|
|
34
|
+
await fastify.listen({ port: 0 })
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
t.after(() => { fastify.close() })
|
|
37
|
+
|
|
38
|
+
await t.test('https get request', (t, done) => {
|
|
39
|
+
t.plan(4)
|
|
40
|
+
sget({
|
|
41
|
+
method: 'GET',
|
|
42
|
+
url: 'https://localhost:' + fastify.server.address().port,
|
|
43
|
+
rejectUnauthorized: false
|
|
44
|
+
}, (err, response, body) => {
|
|
45
|
+
t.assert.ifError(err)
|
|
46
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
47
|
+
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
48
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
49
|
+
done()
|
|
51
50
|
})
|
|
51
|
+
})
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
53
|
+
await t.test('https get request without trust proxy - protocol', (t, done) => {
|
|
54
|
+
t.plan(4)
|
|
55
|
+
sget({
|
|
56
|
+
method: 'GET',
|
|
57
|
+
url: 'https://localhost:' + fastify.server.address().port + '/proto',
|
|
58
|
+
rejectUnauthorized: false
|
|
59
|
+
}, (err, response, body) => {
|
|
60
|
+
t.assert.ifError(err)
|
|
61
|
+
t.assert.deepStrictEqual(JSON.parse(body), { proto: 'https' })
|
|
62
|
+
})
|
|
63
|
+
sget({
|
|
64
|
+
method: 'GET',
|
|
65
|
+
url: 'https://localhost:' + fastify.server.address().port + '/proto',
|
|
66
|
+
rejectUnauthorized: false,
|
|
67
|
+
headers: {
|
|
68
|
+
'x-forwarded-proto': 'lorem'
|
|
69
|
+
}
|
|
70
|
+
}, (err, response, body) => {
|
|
71
|
+
t.assert.ifError(err)
|
|
72
|
+
t.assert.deepStrictEqual(JSON.parse(body), { proto: 'https' })
|
|
73
|
+
done()
|
|
74
74
|
})
|
|
75
75
|
})
|
|
76
76
|
})
|
|
77
77
|
|
|
78
|
-
test('https - headers', (t) => {
|
|
79
|
-
t.plan(
|
|
78
|
+
test('https - headers', async (t) => {
|
|
79
|
+
t.plan(3)
|
|
80
80
|
let fastify
|
|
81
81
|
try {
|
|
82
82
|
fastify = Fastify({
|
|
@@ -85,49 +85,49 @@ test('https - headers', (t) => {
|
|
|
85
85
|
cert: global.context.cert
|
|
86
86
|
}
|
|
87
87
|
})
|
|
88
|
-
t.
|
|
88
|
+
t.assert.ok('Key/cert successfully loaded')
|
|
89
89
|
} catch (e) {
|
|
90
|
-
t.fail('Key/cert loading failed'
|
|
90
|
+
t.assert.fail('Key/cert loading failed')
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
fastify.get('/', function (req, reply) {
|
|
94
94
|
reply.code(200).send({ hello: 'world', hostname: req.hostname, port: req.port })
|
|
95
95
|
})
|
|
96
96
|
|
|
97
|
-
t.
|
|
97
|
+
t.after(async () => { await fastify.close() })
|
|
98
98
|
|
|
99
|
-
fastify.listen({ port: 0 }
|
|
100
|
-
t.error(err)
|
|
99
|
+
await fastify.listen({ port: 0 })
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
await t.test('https get request', (t, done) => {
|
|
102
|
+
t.plan(4)
|
|
103
|
+
sget({
|
|
104
|
+
method: 'GET',
|
|
105
|
+
url: 'https://localhost:' + fastify.server.address().port,
|
|
106
|
+
rejectUnauthorized: false
|
|
107
|
+
}, (err, response, body) => {
|
|
108
|
+
t.assert.ifError(err)
|
|
109
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
110
|
+
const parsedBody = JSON.parse(body)
|
|
111
|
+
t.assert.strictEqual(parsedBody.hostname, 'localhost')
|
|
112
|
+
t.assert.strictEqual(parsedBody.port, fastify.server.address().port)
|
|
113
|
+
done()
|
|
115
114
|
})
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
115
|
+
})
|
|
116
|
+
await t.test('https get request - test port fall back', (t, done) => {
|
|
117
|
+
t.plan(3)
|
|
118
|
+
sget({
|
|
119
|
+
method: 'GET',
|
|
120
|
+
headers: {
|
|
121
|
+
host: 'example.com'
|
|
122
|
+
},
|
|
123
|
+
url: 'https://localhost:' + fastify.server.address().port,
|
|
124
|
+
rejectUnauthorized: false
|
|
125
|
+
}, (err, response, body) => {
|
|
126
|
+
t.assert.ifError(err)
|
|
127
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
128
|
+
const parsedBody = JSON.parse(body)
|
|
129
|
+
t.assert.strictEqual(parsedBody.port, null)
|
|
130
|
+
done()
|
|
131
131
|
})
|
|
132
132
|
})
|
|
133
133
|
})
|
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.
|
|
8
|
+
t.assert.ok(fastify)
|
|
9
|
+
t.assert.strictEqual(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.
|
|
15
|
+
t.assert.ok(fastify)
|
|
16
|
+
t.assert.strictEqual(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
|
})
|