fastify 5.3.2 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/build/build-validation.js +2 -1
- package/docs/Guides/Delay-Accepting-Requests.md +3 -3
- package/docs/Guides/Ecosystem.md +16 -7
- package/docs/Guides/Serverless.md +28 -69
- package/docs/Reference/ContentTypeParser.md +1 -1
- package/docs/Reference/Errors.md +2 -4
- package/docs/Reference/Hooks.md +14 -14
- package/docs/Reference/Logging.md +3 -3
- package/docs/Reference/Middleware.md +1 -1
- package/docs/Reference/Reply.md +8 -8
- package/docs/Reference/Request.md +1 -1
- package/docs/Reference/Routes.md +3 -3
- package/docs/Reference/Server.md +40 -10
- package/docs/Reference/Validation-and-Serialization.md +1 -1
- package/eslint.config.js +17 -9
- package/fastify.d.ts +2 -1
- package/fastify.js +20 -4
- package/lib/configValidator.js +1 -1
- package/lib/decorate.js +2 -2
- package/lib/errors.js +6 -8
- package/lib/logger-factory.js +1 -1
- package/lib/logger-pino.js +2 -2
- package/lib/pluginOverride.js +3 -1
- package/lib/reply.js +9 -13
- package/lib/request.js +4 -11
- package/lib/server.js +30 -51
- package/lib/symbols.js +1 -0
- package/lib/warnings.js +8 -0
- package/package.json +11 -7
- package/test/404s.test.js +226 -325
- package/test/allow-unsafe-regex.test.js +19 -48
- package/test/als.test.js +28 -40
- package/test/async-await.test.js +11 -2
- package/test/body-limit.test.js +41 -65
- package/test/build-certificate.js +1 -1
- package/test/close-pipelining.test.js +5 -4
- package/test/custom-parser-async.test.js +17 -22
- package/test/decorator-namespace.test._js_ +3 -4
- package/test/decorator.test.js +422 -341
- package/test/diagnostics-channel/async-delay-request.test.js +7 -16
- package/test/diagnostics-channel/sync-delay-request.test.js +7 -16
- package/test/helper.js +108 -70
- package/test/hooks-async.test.js +248 -218
- package/test/hooks.on-listen.test.js +255 -239
- package/test/hooks.on-ready.test.js +110 -92
- package/test/hooks.test.js +910 -769
- package/test/http-methods/lock.test.js +31 -31
- package/test/http-methods/mkcol.test.js +5 -9
- package/test/http-methods/proppatch.test.js +23 -29
- package/test/http-methods/report.test.js +44 -69
- package/test/http-methods/search.test.js +67 -82
- package/test/http2/closing.test.js +38 -20
- package/test/http2/secure-with-fallback.test.js +28 -27
- package/test/https/https.test.js +56 -53
- package/test/inject.test.js +114 -97
- package/test/input-validation.js +63 -53
- package/test/internals/errors.test.js +0 -10
- package/test/internals/handle-request.test.js +49 -66
- package/test/internals/hooks.test.js +17 -0
- package/test/issue-4959.test.js +14 -5
- package/test/listen.4.test.js +31 -43
- package/test/logger/response.test.js +19 -20
- package/test/nullable-validation.test.js +33 -46
- package/test/options.error-handler.test.js +1 -1
- package/test/options.test.js +1 -1
- package/test/output-validation.test.js +49 -72
- package/test/patch.error-handler.test.js +1 -1
- package/test/patch.test.js +1 -1
- package/test/plugin.1.test.js +71 -60
- package/test/plugin.2.test.js +104 -86
- package/test/plugin.3.test.js +56 -35
- package/test/plugin.4.test.js +124 -119
- package/test/promises.test.js +36 -30
- package/test/proto-poisoning.test.js +78 -97
- package/test/put.error-handler.test.js +1 -1
- package/test/put.test.js +1 -1
- package/test/reply-error.test.js +169 -148
- package/test/reply-trailers.test.js +119 -108
- package/test/request-error.test.js +0 -46
- package/test/route-hooks.test.js +112 -92
- package/test/route-prefix.test.js +194 -133
- package/test/schema-feature.test.js +309 -238
- package/test/schema-serialization.test.js +177 -154
- package/test/schema-special-usage.test.js +165 -132
- package/test/schema-validation.test.js +278 -199
- package/test/set-error-handler.test.js +58 -1
- package/test/skip-reply-send.test.js +64 -69
- package/test/stream.1.test.js +30 -27
- package/test/stream.2.test.js +20 -10
- package/test/stream.3.test.js +37 -31
- package/test/trust-proxy.test.js +32 -58
- package/test/types/errors.test-d.ts +0 -1
- package/test/types/fastify.test-d.ts +3 -0
- package/test/types/plugin.test-d.ts +1 -1
- package/test/types/register.test-d.ts +1 -1
- package/test/types/request.test-d.ts +1 -0
- package/test/url-rewriting.test.js +45 -62
- package/test/use-semicolon-delimiter.test.js +1 -1
- package/types/errors.d.ts +0 -1
- package/types/request.d.ts +1 -0
- package/.taprc +0 -7
- package/test/http2/missing-http2-module.test.js +0 -17
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
4
|
const Fastify = require('..')
|
|
5
|
-
const sget = require('simple-get').concat
|
|
6
5
|
|
|
7
|
-
test('allow unsafe regex',
|
|
8
|
-
t.plan(
|
|
6
|
+
test('allow unsafe regex', async t => {
|
|
7
|
+
t.plan(2)
|
|
9
8
|
|
|
10
9
|
const fastify = Fastify({
|
|
11
10
|
allowUnsafeRegex: false
|
|
@@ -16,25 +15,15 @@ test('allow unsafe regex', (t, done) => {
|
|
|
16
15
|
reply.send({ foo: req.params.foo })
|
|
17
16
|
})
|
|
18
17
|
|
|
19
|
-
fastify.listen({ port: 0 }
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
url: 'http://localhost:' + fastify.server.address().port + '/1234'
|
|
25
|
-
}, (err, response, body) => {
|
|
26
|
-
t.assert.ifError(err)
|
|
27
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
28
|
-
t.assert.deepStrictEqual(JSON.parse(body), {
|
|
29
|
-
foo: '1234'
|
|
30
|
-
})
|
|
31
|
-
done()
|
|
32
|
-
})
|
|
33
|
-
})
|
|
18
|
+
await fastify.listen({ port: 0 })
|
|
19
|
+
|
|
20
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/1234`)
|
|
21
|
+
t.assert.strictEqual(result.status, 200)
|
|
22
|
+
t.assert.deepStrictEqual(await result.json(), { foo: '1234' })
|
|
34
23
|
})
|
|
35
24
|
|
|
36
|
-
test('allow unsafe regex not match',
|
|
37
|
-
t.plan(
|
|
25
|
+
test('allow unsafe regex not match', async t => {
|
|
26
|
+
t.plan(1)
|
|
38
27
|
|
|
39
28
|
const fastify = Fastify({
|
|
40
29
|
allowUnsafeRegex: false
|
|
@@ -45,18 +34,10 @@ test('allow unsafe regex not match', (t, done) => {
|
|
|
45
34
|
reply.send({ foo: req.params.foo })
|
|
46
35
|
})
|
|
47
36
|
|
|
48
|
-
fastify.listen({ port: 0 }
|
|
49
|
-
t.assert.ifError(err)
|
|
37
|
+
await fastify.listen({ port: 0 })
|
|
50
38
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
url: 'http://localhost:' + fastify.server.address().port + '/a1234'
|
|
54
|
-
}, (err, response, body) => {
|
|
55
|
-
t.assert.ifError(err)
|
|
56
|
-
t.assert.strictEqual(response.statusCode, 404)
|
|
57
|
-
done()
|
|
58
|
-
})
|
|
59
|
-
})
|
|
39
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/a1234`)
|
|
40
|
+
t.assert.strictEqual(result.status, 404)
|
|
60
41
|
})
|
|
61
42
|
|
|
62
43
|
test('allow unsafe regex not safe', (t, done) => {
|
|
@@ -89,8 +70,8 @@ test('allow unsafe regex not safe by default', (t, done) => {
|
|
|
89
70
|
done()
|
|
90
71
|
})
|
|
91
72
|
|
|
92
|
-
test('allow unsafe regex allow unsafe',
|
|
93
|
-
t.plan(
|
|
73
|
+
test('allow unsafe regex allow unsafe', async t => {
|
|
74
|
+
t.plan(3)
|
|
94
75
|
|
|
95
76
|
const fastify = Fastify({
|
|
96
77
|
allowUnsafeRegex: true
|
|
@@ -103,19 +84,9 @@ test('allow unsafe regex allow unsafe', (t, done) => {
|
|
|
103
84
|
})
|
|
104
85
|
})
|
|
105
86
|
|
|
106
|
-
fastify.listen({ port: 0 }
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
url: 'http://localhost:' + fastify.server.address().port + '/1234'
|
|
112
|
-
}, (err, response, body) => {
|
|
113
|
-
t.assert.ifError(err)
|
|
114
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
115
|
-
t.assert.deepStrictEqual(JSON.parse(body), {
|
|
116
|
-
foo: '1234'
|
|
117
|
-
})
|
|
118
|
-
done()
|
|
119
|
-
})
|
|
120
|
-
})
|
|
87
|
+
await fastify.listen({ port: 0 })
|
|
88
|
+
|
|
89
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/1234`)
|
|
90
|
+
t.assert.strictEqual(result.status, 200)
|
|
91
|
+
t.assert.deepStrictEqual(await result.json(), { foo: '1234' })
|
|
121
92
|
})
|
package/test/als.test.js
CHANGED
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
const { AsyncLocalStorage } = require('node:async_hooks')
|
|
4
4
|
const { test } = require('node:test')
|
|
5
5
|
const Fastify = require('..')
|
|
6
|
-
const sget = require('simple-get').concat
|
|
7
6
|
|
|
8
|
-
test('Async Local Storage test', (t
|
|
9
|
-
t.plan(
|
|
7
|
+
test('Async Local Storage test', async (t) => {
|
|
8
|
+
t.plan(12)
|
|
10
9
|
if (!AsyncLocalStorage) {
|
|
11
10
|
t.skip('AsyncLocalStorage not available, skipping test')
|
|
12
11
|
process.exit(0)
|
|
@@ -15,6 +14,8 @@ test('Async Local Storage test', (t, done) => {
|
|
|
15
14
|
const storage = new AsyncLocalStorage()
|
|
16
15
|
const app = Fastify({ logger: false })
|
|
17
16
|
|
|
17
|
+
t.after(() => app.close())
|
|
18
|
+
|
|
18
19
|
let counter = 0
|
|
19
20
|
app.addHook('onRequest', (req, reply, next) => {
|
|
20
21
|
const id = counter++
|
|
@@ -33,45 +34,32 @@ test('Async Local Storage test', (t, done) => {
|
|
|
33
34
|
reply.send({ id })
|
|
34
35
|
})
|
|
35
36
|
|
|
36
|
-
app.listen({ port: 0 }
|
|
37
|
-
t.assert.ifError(err)
|
|
37
|
+
const fastifyServer = await app.listen({ port: 0 })
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
49
|
-
t.assert.deepStrictEqual(body, { id: 0 })
|
|
39
|
+
// First POST request
|
|
40
|
+
const result1 = await fetch(fastifyServer, {
|
|
41
|
+
method: 'POST',
|
|
42
|
+
headers: { 'Content-Type': 'application/json' },
|
|
43
|
+
body: JSON.stringify({ hello: 'world' })
|
|
44
|
+
})
|
|
45
|
+
t.assert.ok(result1.ok)
|
|
46
|
+
t.assert.strictEqual(result1.status, 200)
|
|
47
|
+
t.assert.deepStrictEqual(await result1.json(), { id: 0 })
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
t.assert.ifError(err)
|
|
60
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
61
|
-
t.assert.deepStrictEqual(body, { id: 1 })
|
|
49
|
+
const result2 = await fetch(fastifyServer, {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: { 'Content-Type': 'application/json' },
|
|
52
|
+
body: JSON.stringify({ hello: 'world' })
|
|
53
|
+
})
|
|
54
|
+
t.assert.ok(result2.ok)
|
|
55
|
+
t.assert.strictEqual(result2.status, 200)
|
|
56
|
+
t.assert.deepStrictEqual(await result2.json(), { id: 1 })
|
|
62
57
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
json: true
|
|
67
|
-
}, (err, response, body) => {
|
|
68
|
-
t.assert.ifError(err)
|
|
69
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
70
|
-
t.assert.deepStrictEqual(body, { id: 2 })
|
|
71
|
-
app.close()
|
|
72
|
-
done()
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
|
-
})
|
|
58
|
+
// GET request
|
|
59
|
+
const result3 = await fetch(fastifyServer, {
|
|
60
|
+
method: 'GET'
|
|
76
61
|
})
|
|
62
|
+
t.assert.ok(result3.ok)
|
|
63
|
+
t.assert.strictEqual(result3.status, 200)
|
|
64
|
+
t.assert.deepStrictEqual(await result3.json(), { id: 2 })
|
|
77
65
|
})
|
package/test/async-await.test.js
CHANGED
|
@@ -6,6 +6,7 @@ const Fastify = require('..')
|
|
|
6
6
|
const split = require('split2')
|
|
7
7
|
const pino = require('pino')
|
|
8
8
|
const { sleep } = require('./helper')
|
|
9
|
+
const { waitForCb } = require('./toolkit')
|
|
9
10
|
const statusCodes = require('node:http').STATUS_CODES
|
|
10
11
|
|
|
11
12
|
const opts = {
|
|
@@ -43,7 +44,7 @@ const optsWithHostnameAndPort = {
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
|
-
test('async await', (t,
|
|
47
|
+
test('async await', (t, testDone) => {
|
|
47
48
|
t.plan(16)
|
|
48
49
|
const fastify = Fastify()
|
|
49
50
|
try {
|
|
@@ -79,6 +80,10 @@ test('async await', (t, done) => {
|
|
|
79
80
|
t.assert.ifError(err)
|
|
80
81
|
t.after(() => { fastify.close() })
|
|
81
82
|
|
|
83
|
+
const completion = waitForCb({
|
|
84
|
+
steps: 3
|
|
85
|
+
})
|
|
86
|
+
|
|
82
87
|
sget({
|
|
83
88
|
method: 'GET',
|
|
84
89
|
url: 'http://localhost:' + fastify.server.address().port
|
|
@@ -87,6 +92,7 @@ test('async await', (t, done) => {
|
|
|
87
92
|
t.assert.strictEqual(response.statusCode, 200)
|
|
88
93
|
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
89
94
|
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
95
|
+
completion.stepIn()
|
|
90
96
|
})
|
|
91
97
|
|
|
92
98
|
sget({
|
|
@@ -97,6 +103,7 @@ test('async await', (t, done) => {
|
|
|
97
103
|
t.assert.strictEqual(response.statusCode, 200)
|
|
98
104
|
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
99
105
|
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
106
|
+
completion.stepIn()
|
|
100
107
|
})
|
|
101
108
|
|
|
102
109
|
sget({
|
|
@@ -108,8 +115,10 @@ test('async await', (t, done) => {
|
|
|
108
115
|
const parsedBody = JSON.parse(body)
|
|
109
116
|
t.assert.strictEqual(parsedBody.hostname, 'localhost')
|
|
110
117
|
t.assert.strictEqual(parseInt(parsedBody.port), fastify.server.address().port)
|
|
111
|
-
|
|
118
|
+
completion.stepIn()
|
|
112
119
|
})
|
|
120
|
+
|
|
121
|
+
completion.patience.then(testDone)
|
|
113
122
|
})
|
|
114
123
|
})
|
|
115
124
|
|
package/test/body-limit.test.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const Fastify = require('../fastify')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const zlib = require('node:zlib')
|
|
6
5
|
const { test } = require('node:test')
|
|
7
6
|
|
|
8
|
-
test('bodyLimit',
|
|
9
|
-
t.plan(
|
|
7
|
+
test('bodyLimit', async t => {
|
|
8
|
+
t.plan(4)
|
|
10
9
|
|
|
11
10
|
try {
|
|
12
11
|
Fastify({ bodyLimit: 1.3 })
|
|
@@ -28,22 +27,17 @@ test('bodyLimit', (t, done) => {
|
|
|
28
27
|
reply.send({ error: 'handler should not be called' })
|
|
29
28
|
})
|
|
30
29
|
|
|
31
|
-
fastify.listen({ port: 0 }
|
|
32
|
-
|
|
33
|
-
t.after(() => { fastify.close() })
|
|
30
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
31
|
+
t.after(() => { fastify.close() })
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
body: [],
|
|
40
|
-
json: true
|
|
41
|
-
}, (err, response, body) => {
|
|
42
|
-
t.assert.ifError(err)
|
|
43
|
-
t.assert.strictEqual(response.statusCode, 413)
|
|
44
|
-
done()
|
|
45
|
-
})
|
|
33
|
+
const result = await fetch(fastifyServer, {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: { 'Content-Type': 'application/json' },
|
|
36
|
+
body: JSON.stringify([])
|
|
46
37
|
})
|
|
38
|
+
|
|
39
|
+
t.assert.ok(!result.ok)
|
|
40
|
+
t.assert.strictEqual(result.status, 413)
|
|
47
41
|
})
|
|
48
42
|
|
|
49
43
|
test('bodyLimit is applied to decoded content', async (t) => {
|
|
@@ -114,8 +108,8 @@ test('bodyLimit is applied to decoded content', async (t) => {
|
|
|
114
108
|
})
|
|
115
109
|
})
|
|
116
110
|
|
|
117
|
-
test('default request.routeOptions.bodyLimit should be 1048576',
|
|
118
|
-
t.plan(
|
|
111
|
+
test('default request.routeOptions.bodyLimit should be 1048576', async t => {
|
|
112
|
+
t.plan(3)
|
|
119
113
|
const fastify = Fastify()
|
|
120
114
|
fastify.post('/default-bodylimit', {
|
|
121
115
|
handler (request, reply) {
|
|
@@ -123,26 +117,20 @@ test('default request.routeOptions.bodyLimit should be 1048576', (t, done) => {
|
|
|
123
117
|
reply.send({ })
|
|
124
118
|
}
|
|
125
119
|
})
|
|
126
|
-
fastify.listen({ port: 0 }
|
|
127
|
-
|
|
128
|
-
t.after(() => { fastify.close() })
|
|
120
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
121
|
+
t.after(() => { fastify.close() })
|
|
129
122
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
body: [],
|
|
135
|
-
json: true
|
|
136
|
-
}, (err, response, body) => {
|
|
137
|
-
t.assert.ifError(err)
|
|
138
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
139
|
-
done()
|
|
140
|
-
})
|
|
123
|
+
const result = await fetch(fastifyServer + '/default-bodylimit', {
|
|
124
|
+
method: 'POST',
|
|
125
|
+
headers: { 'Content-Type': 'application/json' },
|
|
126
|
+
body: JSON.stringify([])
|
|
141
127
|
})
|
|
128
|
+
t.assert.ok(result.ok)
|
|
129
|
+
t.assert.strictEqual(result.status, 200)
|
|
142
130
|
})
|
|
143
131
|
|
|
144
|
-
test('request.routeOptions.bodyLimit should be equal to route limit',
|
|
145
|
-
t.plan(
|
|
132
|
+
test('request.routeOptions.bodyLimit should be equal to route limit', async t => {
|
|
133
|
+
t.plan(3)
|
|
146
134
|
const fastify = Fastify({ bodyLimit: 1 })
|
|
147
135
|
fastify.post('/route-limit', {
|
|
148
136
|
bodyLimit: 1000,
|
|
@@ -151,26 +139,20 @@ test('request.routeOptions.bodyLimit should be equal to route limit', (t, done)
|
|
|
151
139
|
reply.send({})
|
|
152
140
|
}
|
|
153
141
|
})
|
|
154
|
-
fastify.listen({ port: 0 }
|
|
155
|
-
|
|
156
|
-
t.after(() => { fastify.close() })
|
|
142
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
143
|
+
t.after(() => { fastify.close() })
|
|
157
144
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
body: [],
|
|
163
|
-
json: true
|
|
164
|
-
}, (err, response, body) => {
|
|
165
|
-
t.assert.ifError(err)
|
|
166
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
167
|
-
done()
|
|
168
|
-
})
|
|
145
|
+
const result = await fetch(fastifyServer + '/route-limit', {
|
|
146
|
+
method: 'POST',
|
|
147
|
+
headers: { 'Content-Type': 'application/json' },
|
|
148
|
+
body: JSON.stringify([])
|
|
169
149
|
})
|
|
150
|
+
t.assert.ok(result.ok)
|
|
151
|
+
t.assert.strictEqual(result.status, 200)
|
|
170
152
|
})
|
|
171
153
|
|
|
172
|
-
test('request.routeOptions.bodyLimit should be equal to server limit',
|
|
173
|
-
t.plan(
|
|
154
|
+
test('request.routeOptions.bodyLimit should be equal to server limit', async t => {
|
|
155
|
+
t.plan(3)
|
|
174
156
|
const fastify = Fastify({ bodyLimit: 100 })
|
|
175
157
|
fastify.post('/server-limit', {
|
|
176
158
|
handler (request, reply) {
|
|
@@ -178,20 +160,14 @@ test('request.routeOptions.bodyLimit should be equal to server limit', (t, done)
|
|
|
178
160
|
reply.send({})
|
|
179
161
|
}
|
|
180
162
|
})
|
|
181
|
-
fastify.listen({ port: 0 }
|
|
182
|
-
|
|
183
|
-
t.after(() => { fastify.close() })
|
|
163
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
164
|
+
t.after(() => { fastify.close() })
|
|
184
165
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
body: [],
|
|
190
|
-
json: true
|
|
191
|
-
}, (err, response, body) => {
|
|
192
|
-
t.assert.ifError(err)
|
|
193
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
194
|
-
done()
|
|
195
|
-
})
|
|
166
|
+
const result = await fetch(fastifyServer + '/server-limit', {
|
|
167
|
+
method: 'POST',
|
|
168
|
+
headers: { 'Content-Type': 'application/json' },
|
|
169
|
+
body: JSON.stringify([])
|
|
196
170
|
})
|
|
171
|
+
t.assert.ok(result.ok)
|
|
172
|
+
t.assert.strictEqual(result.status, 200)
|
|
197
173
|
})
|
|
@@ -91,7 +91,7 @@ function selfCert (opts) {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
function buildCertificate () {
|
|
95
95
|
// "global" is used in here because "t.context" is only supported by "t.beforeEach" and "t.afterEach"
|
|
96
96
|
// For the test case which execute this code which will be using `t.before` and it can reduce the
|
|
97
97
|
// number of times executing it.
|
|
@@ -59,10 +59,11 @@ test('Should close the socket abruptly - pipelining - return503OnClosing: false'
|
|
|
59
59
|
instance.request({ path: '/', method: 'GET' })
|
|
60
60
|
])
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
t.assert.strictEqual(
|
|
62
|
+
const fulfilled = responses.filter(r => r.status === 'fulfilled')
|
|
63
|
+
const rejected = responses.filter(r => r.status === 'rejected')
|
|
64
|
+
|
|
65
|
+
t.assert.strictEqual(fulfilled.length, 2)
|
|
66
|
+
t.assert.strictEqual(rejected.length, 2)
|
|
66
67
|
|
|
67
68
|
await instance.close()
|
|
68
69
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const Fastify = require('../fastify')
|
|
6
5
|
|
|
7
6
|
process.removeAllListeners('warning')
|
|
@@ -24,41 +23,37 @@ test('contentTypeParser should add a custom async parser', async t => {
|
|
|
24
23
|
})
|
|
25
24
|
|
|
26
25
|
t.after(() => fastify.close())
|
|
27
|
-
await fastify.listen({ port: 0 })
|
|
26
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
28
27
|
|
|
29
|
-
await t.test('in POST',
|
|
28
|
+
await t.test('in POST', async t => {
|
|
30
29
|
t.plan(3)
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
const result = await fetch(fastifyServer, {
|
|
33
32
|
method: 'POST',
|
|
34
|
-
url: 'http://localhost:' + fastify.server.address().port,
|
|
35
|
-
body: '{"hello":"world"}',
|
|
36
33
|
headers: {
|
|
37
34
|
'Content-Type': 'application/jsoff'
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
t.assert.ifError(err)
|
|
41
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
42
|
-
t.assert.deepStrictEqual(body.toString(), JSON.stringify({ hello: 'world' }))
|
|
43
|
-
done()
|
|
35
|
+
},
|
|
36
|
+
body: '{"hello":"world"}'
|
|
44
37
|
})
|
|
38
|
+
|
|
39
|
+
t.assert.ok(result.ok)
|
|
40
|
+
t.assert.strictEqual(result.status, 200)
|
|
41
|
+
t.assert.deepStrictEqual(await result.json(), { hello: 'world' })
|
|
45
42
|
})
|
|
46
43
|
|
|
47
|
-
await t.test('in OPTIONS',
|
|
44
|
+
await t.test('in OPTIONS', async t => {
|
|
48
45
|
t.plan(3)
|
|
49
46
|
|
|
50
|
-
|
|
47
|
+
const result = await fetch(fastifyServer, {
|
|
51
48
|
method: 'OPTIONS',
|
|
52
|
-
url: 'http://localhost:' + fastify.server.address().port,
|
|
53
|
-
body: '{"hello":"world"}',
|
|
54
49
|
headers: {
|
|
55
50
|
'Content-Type': 'application/jsoff'
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
t.assert.ifError(err)
|
|
59
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
60
|
-
t.assert.deepStrictEqual(body.toString(), JSON.stringify({ hello: 'world' }))
|
|
61
|
-
done()
|
|
51
|
+
},
|
|
52
|
+
body: '{"hello":"world"}'
|
|
62
53
|
})
|
|
54
|
+
|
|
55
|
+
t.assert.ok(result.ok)
|
|
56
|
+
t.assert.strictEqual(result.status, 200)
|
|
57
|
+
t.assert.deepStrictEqual(await result.json(), { hello: 'world' })
|
|
63
58
|
})
|
|
64
59
|
})
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/* eslint no-prototype-builtins: 0 */
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const test = t.test
|
|
5
|
+
const { test } = require('node:test')
|
|
7
6
|
const Fastify = require('..')
|
|
8
7
|
const fp = require('fastify-plugin')
|
|
9
8
|
|
|
@@ -24,8 +23,8 @@ test('plugin namespace', async t => {
|
|
|
24
23
|
}, { namepace: 'foo' })
|
|
25
24
|
|
|
26
25
|
// ! but outside the plugin the decorator would be app.foo.utility()
|
|
27
|
-
t.ok(app.foo.utility)
|
|
26
|
+
t.assert.ok(app.foo.utility)
|
|
28
27
|
|
|
29
28
|
const res = await app.inject('/')
|
|
30
|
-
t.
|
|
29
|
+
t.assert.deepStrictEqual(res.json(), { utility: 'utility' })
|
|
31
30
|
})
|