fastify 4.0.0-alpha.1 → 4.0.0-alpha.2
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/.taprc +3 -0
- package/README.md +2 -3
- package/docs/Guides/Database.md +320 -0
- package/docs/Guides/Getting-Started.md +7 -7
- package/docs/Guides/Plugins-Guide.md +1 -1
- package/docs/Guides/Serverless.md +3 -3
- package/docs/Guides/Testing.md +2 -2
- package/docs/Reference/Decorators.md +2 -2
- package/docs/Reference/Encapsulation.md +2 -2
- package/docs/Reference/HTTP2.md +3 -3
- package/docs/Reference/Plugins.md +3 -3
- package/docs/Reference/Routes.md +5 -5
- package/docs/Reference/Server.md +27 -62
- package/docs/Reference/TypeScript.md +9 -9
- package/docs/Reference/Validation-and-Serialization.md +4 -4
- package/docs/Type-Providers.md +2 -2
- package/examples/asyncawait.js +1 -1
- package/examples/benchmark/hooks-benchmark-async-await.js +1 -1
- package/examples/benchmark/hooks-benchmark.js +1 -1
- package/examples/benchmark/simple.js +1 -1
- package/examples/hooks.js +1 -1
- package/examples/http2.js +1 -1
- package/examples/https.js +1 -1
- package/examples/parser.js +1 -1
- package/examples/route-prefix.js +1 -1
- package/examples/shared-schema.js +1 -1
- package/examples/simple-stream.js +1 -1
- package/examples/simple.js +1 -1
- package/examples/simple.mjs +1 -1
- package/examples/typescript-server.ts +1 -1
- package/examples/use-plugin.js +1 -1
- package/fastify.js +4 -2
- package/lib/reply.js +1 -1
- package/lib/server.js +32 -10
- package/lib/warnings.js +2 -0
- package/package.json +13 -11
- package/test/404s.test.js +16 -16
- package/test/500s.test.js +1 -1
- package/test/als.test.js +1 -1
- package/test/async-await.test.js +7 -7
- package/test/bodyLimit.test.js +1 -1
- package/test/build-certificate.js +6 -7
- package/test/case-insensitive.test.js +4 -4
- package/test/close-pipelining.test.js +2 -2
- package/test/close.test.js +11 -11
- package/test/custom-http-server.test.js +1 -1
- package/test/custom-parser-async.test.js +1 -1
- package/test/custom-parser.test.js +38 -38
- package/test/custom-querystring-parser.test.js +3 -3
- package/test/decorator.test.js +10 -10
- package/test/delete.test.js +1 -1
- package/test/genReqId.test.js +1 -1
- package/test/get.test.js +1 -1
- package/test/handler-context.test.js +2 -2
- package/test/head.test.js +1 -1
- package/test/helper.js +1 -1
- package/test/hooks-async.test.js +1 -1
- package/test/hooks.on-ready.test.js +1 -1
- package/test/hooks.test.js +20 -20
- package/test/http2/closing.test.js +5 -5
- package/test/http2/constraint.test.js +1 -1
- package/test/http2/head.test.js +1 -1
- package/test/http2/plain.test.js +1 -1
- package/test/http2/secure-with-fallback.test.js +1 -1
- package/test/http2/secure.test.js +1 -1
- package/test/http2/unknown-http-method.test.js +1 -1
- package/test/https/custom-https-server.test.js +1 -1
- package/test/https/https.test.js +1 -1
- package/test/input-validation.js +1 -1
- package/test/internals/handleRequest.test.js +3 -3
- package/test/internals/initialConfig.test.js +9 -1
- package/test/internals/logger.test.js +2 -2
- package/test/internals/reply.test.js +41 -42
- package/test/internals/server.test.js +5 -5
- package/test/listen.deprecated.test.js +202 -0
- package/test/listen.test.js +41 -156
- package/test/logger.test.js +15 -15
- package/test/maxRequestsPerSocket.test.js +2 -2
- package/test/nullable-validation.test.js +3 -3
- package/test/output-validation.test.js +1 -1
- package/test/plugin.test.js +16 -16
- package/test/promises.test.js +1 -1
- package/test/proto-poisoning.test.js +6 -6
- package/test/register.test.js +3 -3
- package/test/reply-error.test.js +3 -3
- package/test/request-error.test.js +1 -1
- package/test/route-hooks.test.js +1 -1
- package/test/route.test.js +3 -3
- package/test/router-options.test.js +1 -1
- package/test/schema-feature.test.js +1 -1
- package/test/schema-special-usage.test.js +0 -81
- package/test/skip-reply-send.test.js +1 -1
- package/test/stream.test.js +60 -12
- package/test/trust-proxy.test.js +6 -6
- package/test/types/instance.test-d.ts +33 -3
- package/test/types/reply.test-d.ts +2 -1
- package/test/url-rewriting.test.js +3 -3
- package/test/versioned-routes.test.js +3 -3
- package/types/.eslintrc.json +3 -1
- package/types/instance.d.ts +120 -14
- package/types/reply.d.ts +2 -1
package/test/hooks.test.js
CHANGED
|
@@ -138,7 +138,7 @@ test('hooks', t => {
|
|
|
138
138
|
reply.code(200).send(payload)
|
|
139
139
|
})
|
|
140
140
|
|
|
141
|
-
fastify.listen(0, err => {
|
|
141
|
+
fastify.listen({ port: 0 }, err => {
|
|
142
142
|
t.error(err)
|
|
143
143
|
fastify.server.unref()
|
|
144
144
|
|
|
@@ -261,7 +261,7 @@ test('onRequest hook should support encapsulation / 3', t => {
|
|
|
261
261
|
done()
|
|
262
262
|
})
|
|
263
263
|
|
|
264
|
-
fastify.listen(0, err => {
|
|
264
|
+
fastify.listen({ port: 0 }, err => {
|
|
265
265
|
t.error(err)
|
|
266
266
|
fastify.server.unref()
|
|
267
267
|
|
|
@@ -322,7 +322,7 @@ test('preHandler hook should support encapsulation / 5', t => {
|
|
|
322
322
|
done()
|
|
323
323
|
})
|
|
324
324
|
|
|
325
|
-
fastify.listen(0, err => {
|
|
325
|
+
fastify.listen({ port: 0 }, err => {
|
|
326
326
|
t.error(err)
|
|
327
327
|
fastify.server.unref()
|
|
328
328
|
|
|
@@ -733,7 +733,7 @@ test('onRoute hook should able to change the route url', t => {
|
|
|
733
733
|
done()
|
|
734
734
|
})
|
|
735
735
|
|
|
736
|
-
fastify.listen(0, err => {
|
|
736
|
+
fastify.listen({ port: 0 }, err => {
|
|
737
737
|
t.error(err)
|
|
738
738
|
fastify.server.unref()
|
|
739
739
|
|
|
@@ -918,7 +918,7 @@ test('onResponse hook should support encapsulation / 3', t => {
|
|
|
918
918
|
done()
|
|
919
919
|
})
|
|
920
920
|
|
|
921
|
-
fastify.listen(0, err => {
|
|
921
|
+
fastify.listen({ port: 0 }, err => {
|
|
922
922
|
t.error(err)
|
|
923
923
|
fastify.server.unref()
|
|
924
924
|
|
|
@@ -995,7 +995,7 @@ test('onSend hook should support encapsulation / 2', t => {
|
|
|
995
995
|
done()
|
|
996
996
|
})
|
|
997
997
|
|
|
998
|
-
fastify.listen(0, err => {
|
|
998
|
+
fastify.listen({ port: 0 }, err => {
|
|
999
999
|
t.error(err)
|
|
1000
1000
|
fastify.server.unref()
|
|
1001
1001
|
|
|
@@ -1259,7 +1259,7 @@ test('onSend hook throws', t => {
|
|
|
1259
1259
|
reply.send({ hello: 'world' })
|
|
1260
1260
|
})
|
|
1261
1261
|
|
|
1262
|
-
fastify.listen(0, err => {
|
|
1262
|
+
fastify.listen({ port: 0 }, err => {
|
|
1263
1263
|
t.error(err)
|
|
1264
1264
|
fastify.server.unref()
|
|
1265
1265
|
sget({
|
|
@@ -1381,7 +1381,7 @@ test('cannot add hook after binding', t => {
|
|
|
1381
1381
|
reply.send({ hello: 'world' })
|
|
1382
1382
|
})
|
|
1383
1383
|
|
|
1384
|
-
instance.listen(0, err => {
|
|
1384
|
+
instance.listen({ port: 0 }, err => {
|
|
1385
1385
|
t.error(err)
|
|
1386
1386
|
t.teardown(instance.server.close.bind(instance.server))
|
|
1387
1387
|
|
|
@@ -2389,7 +2389,7 @@ test('preValidation hook should support encapsulation / 3', t => {
|
|
|
2389
2389
|
done()
|
|
2390
2390
|
})
|
|
2391
2391
|
|
|
2392
|
-
fastify.listen(0, err => {
|
|
2392
|
+
fastify.listen({ port: 0 }, err => {
|
|
2393
2393
|
t.error(err)
|
|
2394
2394
|
fastify.server.unref()
|
|
2395
2395
|
|
|
@@ -2536,7 +2536,7 @@ test('preParsing hook should run before parsing and be able to modify the payloa
|
|
|
2536
2536
|
}
|
|
2537
2537
|
})
|
|
2538
2538
|
|
|
2539
|
-
fastify.listen(0, err => {
|
|
2539
|
+
fastify.listen({ port: 0 }, err => {
|
|
2540
2540
|
t.error(err)
|
|
2541
2541
|
fastify.server.unref()
|
|
2542
2542
|
|
|
@@ -2579,7 +2579,7 @@ test('preParsing hooks should run in the order in which they are defined', t =>
|
|
|
2579
2579
|
}
|
|
2580
2580
|
})
|
|
2581
2581
|
|
|
2582
|
-
fastify.listen(0, err => {
|
|
2582
|
+
fastify.listen({ port: 0 }, err => {
|
|
2583
2583
|
t.error(err)
|
|
2584
2584
|
fastify.server.unref()
|
|
2585
2585
|
|
|
@@ -2629,7 +2629,7 @@ test('preParsing hooks should support encapsulation', t => {
|
|
|
2629
2629
|
done()
|
|
2630
2630
|
})
|
|
2631
2631
|
|
|
2632
|
-
fastify.listen(0, err => {
|
|
2632
|
+
fastify.listen({ port: 0 }, err => {
|
|
2633
2633
|
t.error(err)
|
|
2634
2634
|
fastify.server.unref()
|
|
2635
2635
|
|
|
@@ -2750,7 +2750,7 @@ test('preParsing hook should support encapsulation / 3', t => {
|
|
|
2750
2750
|
done()
|
|
2751
2751
|
})
|
|
2752
2752
|
|
|
2753
|
-
fastify.listen(0, err => {
|
|
2753
|
+
fastify.listen({ port: 0 }, err => {
|
|
2754
2754
|
t.error(err)
|
|
2755
2755
|
fastify.server.unref()
|
|
2756
2756
|
|
|
@@ -2812,7 +2812,7 @@ test('preSerialization hook should run before serialization and be able to modif
|
|
|
2812
2812
|
}
|
|
2813
2813
|
})
|
|
2814
2814
|
|
|
2815
|
-
fastify.listen(0, err => {
|
|
2815
|
+
fastify.listen({ port: 0 }, err => {
|
|
2816
2816
|
t.error(err)
|
|
2817
2817
|
fastify.server.unref()
|
|
2818
2818
|
|
|
@@ -2863,7 +2863,7 @@ test('preSerialization hook should be able to throw errors which are validated a
|
|
|
2863
2863
|
}
|
|
2864
2864
|
})
|
|
2865
2865
|
|
|
2866
|
-
fastify.listen(0, err => {
|
|
2866
|
+
fastify.listen({ port: 0 }, err => {
|
|
2867
2867
|
t.error(err)
|
|
2868
2868
|
fastify.server.unref()
|
|
2869
2869
|
|
|
@@ -2897,7 +2897,7 @@ test('preSerialization hook which returned error should still run onError hooks'
|
|
|
2897
2897
|
reply.send({ hello: 'world' })
|
|
2898
2898
|
})
|
|
2899
2899
|
|
|
2900
|
-
fastify.listen(0, err => {
|
|
2900
|
+
fastify.listen({ port: 0 }, err => {
|
|
2901
2901
|
t.error(err)
|
|
2902
2902
|
fastify.server.unref()
|
|
2903
2903
|
|
|
@@ -2931,7 +2931,7 @@ test('preSerialization hooks should run in the order in which they are defined',
|
|
|
2931
2931
|
reply.send(payload)
|
|
2932
2932
|
})
|
|
2933
2933
|
|
|
2934
|
-
fastify.listen(0, err => {
|
|
2934
|
+
fastify.listen({ port: 0 }, err => {
|
|
2935
2935
|
t.error(err)
|
|
2936
2936
|
fastify.server.unref()
|
|
2937
2937
|
|
|
@@ -2975,7 +2975,7 @@ test('preSerialization hooks should support encapsulation', t => {
|
|
|
2975
2975
|
done()
|
|
2976
2976
|
})
|
|
2977
2977
|
|
|
2978
|
-
fastify.listen(0, err => {
|
|
2978
|
+
fastify.listen({ port: 0 }, err => {
|
|
2979
2979
|
t.error(err)
|
|
2980
2980
|
fastify.server.unref()
|
|
2981
2981
|
|
|
@@ -3162,7 +3162,7 @@ test('onTimeout should be triggered', t => {
|
|
|
3162
3162
|
return reply
|
|
3163
3163
|
})
|
|
3164
3164
|
|
|
3165
|
-
fastify.listen(0, (err, address) => {
|
|
3165
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
3166
3166
|
t.error(err)
|
|
3167
3167
|
t.teardown(() => fastify.close())
|
|
3168
3168
|
|
|
@@ -3201,7 +3201,7 @@ test('onTimeout should be triggered and socket _meta is set', t => {
|
|
|
3201
3201
|
return reply
|
|
3202
3202
|
})
|
|
3203
3203
|
|
|
3204
|
-
fastify.listen(0, (err, address) => {
|
|
3204
|
+
fastify.listen({ port: 0 }, (err, address) => {
|
|
3205
3205
|
t.error(err)
|
|
3206
3206
|
t.teardown(() => fastify.close())
|
|
3207
3207
|
|
|
@@ -32,7 +32,7 @@ t.test('http/2 request while fastify closing', t => {
|
|
|
32
32
|
|
|
33
33
|
fastify.get('/', () => Promise.resolve({}))
|
|
34
34
|
|
|
35
|
-
fastify.listen(0, err => {
|
|
35
|
+
fastify.listen({ port: 0 }, err => {
|
|
36
36
|
t.error(err)
|
|
37
37
|
fastify.server.unref()
|
|
38
38
|
|
|
@@ -79,7 +79,7 @@ t.test('http/2 request while fastify closing - return503OnClosing: false', t =>
|
|
|
79
79
|
|
|
80
80
|
fastify.get('/', () => Promise.resolve({}))
|
|
81
81
|
|
|
82
|
-
fastify.listen(0, err => {
|
|
82
|
+
fastify.listen({ port: 0 }, err => {
|
|
83
83
|
t.error(err)
|
|
84
84
|
fastify.server.unref()
|
|
85
85
|
|
|
@@ -118,7 +118,7 @@ t.test('http/2 closes successfully with async await', async t => {
|
|
|
118
118
|
http2: true
|
|
119
119
|
})
|
|
120
120
|
|
|
121
|
-
await fastify.listen(0)
|
|
121
|
+
await fastify.listen({ port: 0 })
|
|
122
122
|
|
|
123
123
|
const url = getUrl(fastify)
|
|
124
124
|
const session = await connect(url)
|
|
@@ -137,7 +137,7 @@ t.test('https/2 closes successfully with async await', async t => {
|
|
|
137
137
|
}
|
|
138
138
|
})
|
|
139
139
|
|
|
140
|
-
await fastify.listen(0)
|
|
140
|
+
await fastify.listen({ port: 0 })
|
|
141
141
|
|
|
142
142
|
const url = getUrl(fastify)
|
|
143
143
|
const session = await connect(url)
|
|
@@ -160,7 +160,7 @@ t.test('http/2 server side session emits a timeout event', async t => {
|
|
|
160
160
|
return {}
|
|
161
161
|
})
|
|
162
162
|
|
|
163
|
-
await fastify.listen(0)
|
|
163
|
+
await fastify.listen({ port: 0 })
|
|
164
164
|
|
|
165
165
|
const url = getUrl(fastify)
|
|
166
166
|
const session = await connect(url)
|
package/test/http2/head.test.js
CHANGED
package/test/http2/plain.test.js
CHANGED
package/test/https/https.test.js
CHANGED
package/test/input-validation.js
CHANGED
|
@@ -139,7 +139,7 @@ test('request should be defined in onSend Hook on post request with content type
|
|
|
139
139
|
fastify.post('/', (request, reply) => {
|
|
140
140
|
reply.send(200)
|
|
141
141
|
})
|
|
142
|
-
fastify.listen(0, err => {
|
|
142
|
+
fastify.listen({ port: 0 }, err => {
|
|
143
143
|
fastify.server.unref()
|
|
144
144
|
t.error(err)
|
|
145
145
|
sget({
|
|
@@ -170,7 +170,7 @@ test('request should be defined in onSend Hook on post request with content type
|
|
|
170
170
|
fastify.post('/', (request, reply) => {
|
|
171
171
|
reply.send(200)
|
|
172
172
|
})
|
|
173
|
-
fastify.listen(0, err => {
|
|
173
|
+
fastify.listen({ port: 0 }, err => {
|
|
174
174
|
fastify.server.unref()
|
|
175
175
|
t.error(err)
|
|
176
176
|
sget({
|
|
@@ -201,7 +201,7 @@ test('request should be defined in onSend Hook on options request with content t
|
|
|
201
201
|
fastify.options('/', (request, reply) => {
|
|
202
202
|
reply.send(200)
|
|
203
203
|
})
|
|
204
|
-
fastify.listen(0, err => {
|
|
204
|
+
fastify.listen({ port: 0 }, err => {
|
|
205
205
|
fastify.server.unref()
|
|
206
206
|
t.error(err)
|
|
207
207
|
sget({
|
|
@@ -308,7 +308,7 @@ test('Should not have issues when passing stream options to Pino.js', t => {
|
|
|
308
308
|
})
|
|
309
309
|
})
|
|
310
310
|
|
|
311
|
-
fastify.listen(0, localhost, err => {
|
|
311
|
+
fastify.listen({ port: 0, host: localhost }, err => {
|
|
312
312
|
t.error(err)
|
|
313
313
|
fastify.server.unref()
|
|
314
314
|
|
|
@@ -377,3 +377,11 @@ test('Fastify.initialConfig should accept the deprecated versioning option', t =
|
|
|
377
377
|
t.end()
|
|
378
378
|
})
|
|
379
379
|
})
|
|
380
|
+
|
|
381
|
+
test('pluginTimeout should be parsed correctly', t => {
|
|
382
|
+
const withDisabledTimeout = Fastify({ pluginTimeout: '0' })
|
|
383
|
+
t.equal(withDisabledTimeout.initialConfig.pluginTimeout, 0)
|
|
384
|
+
const withInvalidTimeout = Fastify({ pluginTimeout: undefined })
|
|
385
|
+
t.equal(withInvalidTimeout.initialConfig.pluginTimeout, 10000)
|
|
386
|
+
t.end()
|
|
387
|
+
})
|
|
@@ -20,7 +20,7 @@ test('The logger should add a unique id for every request', t => {
|
|
|
20
20
|
reply.send({ id: req.id })
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
fastify.listen(0, err => {
|
|
23
|
+
fastify.listen({ port: 0 }, err => {
|
|
24
24
|
t.error(err)
|
|
25
25
|
const queue = new Queue()
|
|
26
26
|
for (let i = 0; i < 10; i++) {
|
|
@@ -53,7 +53,7 @@ test('The logger should reuse request id header for req.id', t => {
|
|
|
53
53
|
reply.send({ id: req.id })
|
|
54
54
|
})
|
|
55
55
|
|
|
56
|
-
fastify.listen(0, err => {
|
|
56
|
+
fastify.listen({ port: 0 }, err => {
|
|
57
57
|
t.error(err)
|
|
58
58
|
|
|
59
59
|
fastify.inject({
|
|
@@ -5,9 +5,8 @@ const test = t.test
|
|
|
5
5
|
const sget = require('simple-get').concat
|
|
6
6
|
const http = require('http')
|
|
7
7
|
const NotFound = require('http-errors').NotFound
|
|
8
|
-
const EventEmitter = require('events').EventEmitter
|
|
9
8
|
const Reply = require('../../lib/reply')
|
|
10
|
-
const { Writable } = require('stream')
|
|
9
|
+
const { Readable, Writable } = require('stream')
|
|
11
10
|
const {
|
|
12
11
|
kReplyErrorHandlerCalled,
|
|
13
12
|
kReplyHeaders,
|
|
@@ -55,30 +54,30 @@ test('Once called, Reply should return an object with methods', t => {
|
|
|
55
54
|
test('reply.send will logStream error and destroy the stream', t => {
|
|
56
55
|
t.plan(1)
|
|
57
56
|
let destroyCalled
|
|
58
|
-
const payload = new
|
|
57
|
+
const payload = new Readable({
|
|
58
|
+
read () {},
|
|
59
|
+
destroy (err, cb) {
|
|
60
|
+
destroyCalled = true
|
|
61
|
+
cb(err)
|
|
62
|
+
}
|
|
63
|
+
})
|
|
59
64
|
|
|
60
|
-
const response =
|
|
65
|
+
const response = new Writable()
|
|
66
|
+
Object.assign(response, {
|
|
61
67
|
setHeader: () => {},
|
|
62
68
|
hasHeader: () => false,
|
|
63
69
|
getHeader: () => undefined,
|
|
64
70
|
writeHead: () => {},
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
destroy: () => (destroyCalled = true),
|
|
68
|
-
on: () => {}
|
|
69
|
-
}
|
|
71
|
+
headersSent: true
|
|
72
|
+
})
|
|
70
73
|
|
|
71
74
|
const log = {
|
|
72
75
|
warn: () => {}
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
Object.assign(payload, {
|
|
76
|
-
pipe: () => {},
|
|
77
|
-
destroy: () => {}
|
|
78
|
-
})
|
|
79
78
|
const reply = new Reply(response, { context: { onSend: null } }, log)
|
|
80
79
|
reply.send(payload)
|
|
81
|
-
payload.
|
|
80
|
+
payload.destroy(new Error('stream error'))
|
|
82
81
|
|
|
83
82
|
t.equal(destroyCalled, true, 'Error not logged and not streamed')
|
|
84
83
|
})
|
|
@@ -263,7 +262,7 @@ test('within an instance', t => {
|
|
|
263
262
|
done()
|
|
264
263
|
})
|
|
265
264
|
|
|
266
|
-
fastify.listen(0, err => {
|
|
265
|
+
fastify.listen({ port: 0 }, err => {
|
|
267
266
|
t.error(err)
|
|
268
267
|
fastify.server.unref()
|
|
269
268
|
|
|
@@ -423,7 +422,7 @@ test('buffer without content type should send a application/octet-stream and raw
|
|
|
423
422
|
reply.send(Buffer.alloc(1024))
|
|
424
423
|
})
|
|
425
424
|
|
|
426
|
-
fastify.listen(0, err => {
|
|
425
|
+
fastify.listen({ port: 0 }, err => {
|
|
427
426
|
t.error(err)
|
|
428
427
|
fastify.server.unref()
|
|
429
428
|
|
|
@@ -448,7 +447,7 @@ test('buffer with content type should not send application/octet-stream', t => {
|
|
|
448
447
|
reply.send(Buffer.alloc(1024))
|
|
449
448
|
})
|
|
450
449
|
|
|
451
|
-
fastify.listen(0, err => {
|
|
450
|
+
fastify.listen({ port: 0 }, err => {
|
|
452
451
|
t.error(err)
|
|
453
452
|
fastify.server.unref()
|
|
454
453
|
|
|
@@ -476,7 +475,7 @@ test('stream with content type should not send application/octet-stream', t => {
|
|
|
476
475
|
reply.header('Content-Type', 'text/plain').send(stream)
|
|
477
476
|
})
|
|
478
477
|
|
|
479
|
-
fastify.listen(0, err => {
|
|
478
|
+
fastify.listen({ port: 0 }, err => {
|
|
480
479
|
t.error(err)
|
|
481
480
|
fastify.server.unref()
|
|
482
481
|
sget({
|
|
@@ -502,7 +501,7 @@ test('stream without content type should not send application/octet-stream', t =
|
|
|
502
501
|
reply.send(stream)
|
|
503
502
|
})
|
|
504
503
|
|
|
505
|
-
fastify.listen(0, err => {
|
|
504
|
+
fastify.listen({ port: 0 }, err => {
|
|
506
505
|
t.error(err)
|
|
507
506
|
fastify.server.unref()
|
|
508
507
|
sget({
|
|
@@ -537,7 +536,7 @@ test('stream using reply.raw.writeHead should return customize headers', t => {
|
|
|
537
536
|
reply.send(stream)
|
|
538
537
|
})
|
|
539
538
|
|
|
540
|
-
fastify.listen(0, err => {
|
|
539
|
+
fastify.listen({ port: 0 }, err => {
|
|
541
540
|
t.error(err)
|
|
542
541
|
fastify.server.unref()
|
|
543
542
|
sget({
|
|
@@ -561,7 +560,7 @@ test('plain string without content type should send a text/plain', t => {
|
|
|
561
560
|
reply.send('hello world!')
|
|
562
561
|
})
|
|
563
562
|
|
|
564
|
-
fastify.listen(0, err => {
|
|
563
|
+
fastify.listen({ port: 0 }, err => {
|
|
565
564
|
t.error(err)
|
|
566
565
|
fastify.server.unref()
|
|
567
566
|
|
|
@@ -585,7 +584,7 @@ test('plain string with content type should be sent unmodified', t => {
|
|
|
585
584
|
reply.type('text/css').send('hello world!')
|
|
586
585
|
})
|
|
587
586
|
|
|
588
|
-
fastify.listen(0, err => {
|
|
587
|
+
fastify.listen({ port: 0 }, err => {
|
|
589
588
|
t.error(err)
|
|
590
589
|
fastify.server.unref()
|
|
591
590
|
|
|
@@ -612,7 +611,7 @@ test('plain string with content type and custom serializer should be serialized'
|
|
|
612
611
|
.send('hello world!')
|
|
613
612
|
})
|
|
614
613
|
|
|
615
|
-
fastify.listen(0, err => {
|
|
614
|
+
fastify.listen({ port: 0 }, err => {
|
|
616
615
|
t.error(err)
|
|
617
616
|
fastify.server.unref()
|
|
618
617
|
|
|
@@ -636,7 +635,7 @@ test('plain string with content type application/json should NOT be serialized a
|
|
|
636
635
|
reply.type('application/json').send('{"key": "hello world!"}')
|
|
637
636
|
})
|
|
638
637
|
|
|
639
|
-
fastify.listen(0, err => {
|
|
638
|
+
fastify.listen({ port: 0 }, err => {
|
|
640
639
|
t.error(err)
|
|
641
640
|
fastify.server.unref()
|
|
642
641
|
|
|
@@ -689,7 +688,7 @@ test('plain string with custom json content type should NOT be serialized as jso
|
|
|
689
688
|
})
|
|
690
689
|
})
|
|
691
690
|
|
|
692
|
-
fastify.listen(0, err => {
|
|
691
|
+
fastify.listen({ port: 0 }, err => {
|
|
693
692
|
t.error(err)
|
|
694
693
|
fastify.server.unref()
|
|
695
694
|
|
|
@@ -715,7 +714,7 @@ test('non-string with content type application/json SHOULD be serialized as json
|
|
|
715
714
|
reply.type('application/json').send({ key: 'hello world!' })
|
|
716
715
|
})
|
|
717
716
|
|
|
718
|
-
fastify.listen(0, err => {
|
|
717
|
+
fastify.listen({ port: 0 }, err => {
|
|
719
718
|
t.error(err)
|
|
720
719
|
fastify.server.unref()
|
|
721
720
|
|
|
@@ -764,7 +763,7 @@ test('non-string with custom json content type SHOULD be serialized as json', t
|
|
|
764
763
|
})
|
|
765
764
|
})
|
|
766
765
|
|
|
767
|
-
fastify.listen(0, err => {
|
|
766
|
+
fastify.listen({ port: 0 }, err => {
|
|
768
767
|
t.error(err)
|
|
769
768
|
fastify.server.unref()
|
|
770
769
|
|
|
@@ -829,7 +828,7 @@ test('undefined payload should be sent as-is', t => {
|
|
|
829
828
|
reply.code(204).send()
|
|
830
829
|
})
|
|
831
830
|
|
|
832
|
-
fastify.listen(0, err => {
|
|
831
|
+
fastify.listen({ port: 0 }, err => {
|
|
833
832
|
t.error(err)
|
|
834
833
|
fastify.server.unref()
|
|
835
834
|
|
|
@@ -874,7 +873,7 @@ test('for HEAD method, no body should be sent but content-length should be', t =
|
|
|
874
873
|
reply.code(200).send(null)
|
|
875
874
|
})
|
|
876
875
|
|
|
877
|
-
fastify.listen(0, err => {
|
|
876
|
+
fastify.listen({ port: 0 }, err => {
|
|
878
877
|
t.error(err)
|
|
879
878
|
fastify.server.unref()
|
|
880
879
|
|
|
@@ -921,7 +920,7 @@ test('reply.send(new NotFound()) should not invoke the 404 handler', t => {
|
|
|
921
920
|
done()
|
|
922
921
|
}, { prefix: '/prefixed' })
|
|
923
922
|
|
|
924
|
-
fastify.listen(0, err => {
|
|
923
|
+
fastify.listen({ port: 0 }, err => {
|
|
925
924
|
t.error(err)
|
|
926
925
|
|
|
927
926
|
fastify.server.unref()
|
|
@@ -968,7 +967,7 @@ test('reply can set multiple instances of same header', t => {
|
|
|
968
967
|
.send({})
|
|
969
968
|
})
|
|
970
969
|
|
|
971
|
-
fastify.listen(0, err => {
|
|
970
|
+
fastify.listen({ port: 0 }, err => {
|
|
972
971
|
t.error(err)
|
|
973
972
|
fastify.server.unref()
|
|
974
973
|
|
|
@@ -995,7 +994,7 @@ test('reply.hasHeader returns correct values', t => {
|
|
|
995
994
|
reply.send()
|
|
996
995
|
})
|
|
997
996
|
|
|
998
|
-
fastify.listen(0, err => {
|
|
997
|
+
fastify.listen({ port: 0 }, err => {
|
|
999
998
|
t.error(err)
|
|
1000
999
|
fastify.server.unref()
|
|
1001
1000
|
sget({
|
|
@@ -1024,7 +1023,7 @@ test('reply.getHeader returns correct values', t => {
|
|
|
1024
1023
|
reply.send()
|
|
1025
1024
|
})
|
|
1026
1025
|
|
|
1027
|
-
fastify.listen(0, err => {
|
|
1026
|
+
fastify.listen({ port: 0 }, err => {
|
|
1028
1027
|
t.error(err)
|
|
1029
1028
|
fastify.server.unref()
|
|
1030
1029
|
sget({
|
|
@@ -1094,7 +1093,7 @@ test('reply.removeHeader can remove the value', t => {
|
|
|
1094
1093
|
reply.send()
|
|
1095
1094
|
})
|
|
1096
1095
|
|
|
1097
|
-
fastify.listen(0, err => {
|
|
1096
|
+
fastify.listen({ port: 0 }, err => {
|
|
1098
1097
|
t.error(err)
|
|
1099
1098
|
fastify.server.unref()
|
|
1100
1099
|
sget({
|
|
@@ -1121,7 +1120,7 @@ test('reply.header can reset the value', t => {
|
|
|
1121
1120
|
reply.send()
|
|
1122
1121
|
})
|
|
1123
1122
|
|
|
1124
|
-
fastify.listen(0, err => {
|
|
1123
|
+
fastify.listen({ port: 0 }, err => {
|
|
1125
1124
|
t.error(err)
|
|
1126
1125
|
fastify.server.unref()
|
|
1127
1126
|
sget({
|
|
@@ -1150,7 +1149,7 @@ test('reply.hasHeader computes raw and fastify headers', t => {
|
|
|
1150
1149
|
reply.send()
|
|
1151
1150
|
})
|
|
1152
1151
|
|
|
1153
|
-
fastify.listen(0, err => {
|
|
1152
|
+
fastify.listen({ port: 0 }, err => {
|
|
1154
1153
|
t.error(err)
|
|
1155
1154
|
fastify.server.unref()
|
|
1156
1155
|
sget({
|
|
@@ -1319,7 +1318,7 @@ test('reply.header setting multiple cookies as multiple Set-Cookie headers', t =
|
|
|
1319
1318
|
.send({})
|
|
1320
1319
|
})
|
|
1321
1320
|
|
|
1322
|
-
fastify.listen(0, err => {
|
|
1321
|
+
fastify.listen({ port: 0 }, err => {
|
|
1323
1322
|
t.error(err)
|
|
1324
1323
|
fastify.server.unref()
|
|
1325
1324
|
|
|
@@ -1692,7 +1691,7 @@ test('cannot set the replySerializer when the server is running', t => {
|
|
|
1692
1691
|
const fastify = require('../..')()
|
|
1693
1692
|
t.teardown(fastify.close.bind(fastify))
|
|
1694
1693
|
|
|
1695
|
-
fastify.listen(err => {
|
|
1694
|
+
fastify.listen({ port: 0 }, err => {
|
|
1696
1695
|
t.error(err)
|
|
1697
1696
|
try {
|
|
1698
1697
|
fastify.setReplySerializer(() => {})
|
|
@@ -1847,7 +1846,7 @@ test('redirect to an invalid URL should not crash the server', async t => {
|
|
|
1847
1846
|
}
|
|
1848
1847
|
})
|
|
1849
1848
|
|
|
1850
|
-
await fastify.listen(0)
|
|
1849
|
+
await fastify.listen({ port: 0 })
|
|
1851
1850
|
|
|
1852
1851
|
{
|
|
1853
1852
|
const { response, body } = await doGet(`http://localhost:${fastify.server.address().port}/redirect?useCase=1`)
|
|
@@ -1893,7 +1892,7 @@ test('invalid response headers should not crash the server', async t => {
|
|
|
1893
1892
|
}
|
|
1894
1893
|
})
|
|
1895
1894
|
|
|
1896
|
-
await fastify.listen(0)
|
|
1895
|
+
await fastify.listen({ port: 0 })
|
|
1897
1896
|
|
|
1898
1897
|
const { response, body } = await doGet(`http://localhost:${fastify.server.address().port}/bad-headers`)
|
|
1899
1898
|
t.equal(response.statusCode, 500)
|
|
@@ -1922,7 +1921,7 @@ test('invalid response headers when sending back an error', async t => {
|
|
|
1922
1921
|
}
|
|
1923
1922
|
})
|
|
1924
1923
|
|
|
1925
|
-
await fastify.listen(0)
|
|
1924
|
+
await fastify.listen({ port: 0 })
|
|
1926
1925
|
|
|
1927
1926
|
const { response, body } = await doGet(`http://localhost:${fastify.server.address().port}/bad-headers`)
|
|
1928
1927
|
t.equal(response.statusCode, 500)
|
|
@@ -1956,7 +1955,7 @@ test('invalid response headers and custom error handler', async t => {
|
|
|
1956
1955
|
reply.status(500).send({ ops: true })
|
|
1957
1956
|
})
|
|
1958
1957
|
|
|
1959
|
-
await fastify.listen(0)
|
|
1958
|
+
await fastify.listen({ port: 0 })
|
|
1960
1959
|
|
|
1961
1960
|
const { response, body } = await doGet(`http://localhost:${fastify.server.address().port}/bad-headers`)
|
|
1962
1961
|
t.equal(response.statusCode, 500)
|