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/logger.test.js
CHANGED
|
@@ -56,7 +56,7 @@ test('defaults to info level', t => {
|
|
|
56
56
|
reply.send({ hello: 'world' })
|
|
57
57
|
})
|
|
58
58
|
|
|
59
|
-
fastify.listen(0, err => {
|
|
59
|
+
fastify.listen({ port: 0 }, err => {
|
|
60
60
|
t.error(err)
|
|
61
61
|
fastify.server.unref()
|
|
62
62
|
|
|
@@ -118,7 +118,7 @@ test('test log stream', t => {
|
|
|
118
118
|
reply.send({ hello: 'world' })
|
|
119
119
|
})
|
|
120
120
|
|
|
121
|
-
fastify.listen(0, localhost, err => {
|
|
121
|
+
fastify.listen({ port: 0, host: localhost }, err => {
|
|
122
122
|
t.error(err)
|
|
123
123
|
fastify.server.unref()
|
|
124
124
|
|
|
@@ -165,7 +165,7 @@ test('test error log stream', t => {
|
|
|
165
165
|
reply.send(new Error('kaboom'))
|
|
166
166
|
})
|
|
167
167
|
|
|
168
|
-
fastify.listen(0, localhost, err => {
|
|
168
|
+
fastify.listen({ port: 0, host: localhost }, err => {
|
|
169
169
|
t.error(err)
|
|
170
170
|
fastify.server.unref()
|
|
171
171
|
|
|
@@ -210,7 +210,7 @@ test('can use external logger instance', t => {
|
|
|
210
210
|
reply.send({ hello: 'world' })
|
|
211
211
|
})
|
|
212
212
|
|
|
213
|
-
localFastify.listen(0, localhost, err => {
|
|
213
|
+
localFastify.listen({ port: 0, host: localhost }, err => {
|
|
214
214
|
t.error(err)
|
|
215
215
|
http.get(`http://${localhostForURL}:` + localFastify.server.address().port + '/foo', (res) => {
|
|
216
216
|
res.resume()
|
|
@@ -255,7 +255,7 @@ test('can use external logger instance with custom serializer', t => {
|
|
|
255
255
|
reply.send({ hello: 'world' })
|
|
256
256
|
})
|
|
257
257
|
|
|
258
|
-
localFastify.listen(0, localhost, err => {
|
|
258
|
+
localFastify.listen({ port: 0, host: localhost }, err => {
|
|
259
259
|
t.error(err)
|
|
260
260
|
http.get(`http://${localhostForURL}:` + localFastify.server.address().port + '/foo', (res) => {
|
|
261
261
|
res.resume()
|
|
@@ -459,7 +459,7 @@ test('The logger should accept custom serializer', t => {
|
|
|
459
459
|
reply.send(new Error('kaboom'))
|
|
460
460
|
})
|
|
461
461
|
|
|
462
|
-
fastify.listen(0, localhost, err => {
|
|
462
|
+
fastify.listen({ port: 0, host: localhost }, err => {
|
|
463
463
|
t.error(err)
|
|
464
464
|
fastify.server.unref()
|
|
465
465
|
|
|
@@ -1175,7 +1175,7 @@ test('should serialize request and response', t => {
|
|
|
1175
1175
|
level: 'info'
|
|
1176
1176
|
}
|
|
1177
1177
|
})
|
|
1178
|
-
fastify.listen(0, ipv6, err => {
|
|
1178
|
+
fastify.listen({ port: 0, host: ipv6 }, err => {
|
|
1179
1179
|
t.error(err)
|
|
1180
1180
|
stream.once('data', line => {
|
|
1181
1181
|
const expected = 'Server listening at http://[' + ipv6 + ']:' +
|
|
@@ -1197,7 +1197,7 @@ test('Do not wrap IPv4 address', t => {
|
|
|
1197
1197
|
level: 'info'
|
|
1198
1198
|
}
|
|
1199
1199
|
})
|
|
1200
|
-
fastify.listen(0, '127.0.0.1', err => {
|
|
1200
|
+
fastify.listen({ port: 0, host: '127.0.0.1' }, err => {
|
|
1201
1201
|
t.error(err)
|
|
1202
1202
|
stream.once('data', line => {
|
|
1203
1203
|
const expected = 'Server listening at http://127.0.0.1:' +
|
|
@@ -1224,7 +1224,7 @@ test('file option', t => {
|
|
|
1224
1224
|
reply.send({ hello: 'world' })
|
|
1225
1225
|
})
|
|
1226
1226
|
|
|
1227
|
-
fastify.listen(0, localhost, err => {
|
|
1227
|
+
fastify.listen({ port: 0, host: localhost }, err => {
|
|
1228
1228
|
t.error(err)
|
|
1229
1229
|
fastify.server.unref()
|
|
1230
1230
|
|
|
@@ -1269,7 +1269,7 @@ test('should log the error if no error handler is defined', t => {
|
|
|
1269
1269
|
t.ok(req.log)
|
|
1270
1270
|
reply.send(new Error('a generic error'))
|
|
1271
1271
|
})
|
|
1272
|
-
fastify.listen(0, localhost, err => {
|
|
1272
|
+
fastify.listen({ port: 0, host: localhost }, err => {
|
|
1273
1273
|
t.error(err)
|
|
1274
1274
|
fastify.server.unref()
|
|
1275
1275
|
http.get(`http://${localhostForURL}:` + fastify.server.address().port + '/error')
|
|
@@ -1307,7 +1307,7 @@ test('should log as info if error status code >= 400 and < 500 if no error handl
|
|
|
1307
1307
|
t.ok(req.log)
|
|
1308
1308
|
reply.send(Object.assign(new Error('a 503 error'), { statusCode: 503 }))
|
|
1309
1309
|
})
|
|
1310
|
-
fastify.listen(0, localhost, err => {
|
|
1310
|
+
fastify.listen({ port: 0, host: localhost }, err => {
|
|
1311
1311
|
t.error(err)
|
|
1312
1312
|
fastify.server.unref()
|
|
1313
1313
|
http.get(`http://${localhostForURL}:` + fastify.server.address().port + '/400')
|
|
@@ -1341,7 +1341,7 @@ test('should log as error if error status code >= 500 if no error handler is def
|
|
|
1341
1341
|
t.ok(req.log)
|
|
1342
1342
|
reply.send(Object.assign(new Error('a 503 error'), { statusCode: 503 }))
|
|
1343
1343
|
})
|
|
1344
|
-
fastify.listen(0, localhost, err => {
|
|
1344
|
+
fastify.listen({ port: 0, host: localhost }, err => {
|
|
1345
1345
|
t.error(err)
|
|
1346
1346
|
fastify.server.unref()
|
|
1347
1347
|
http.get(`http://${localhostForURL}:` + fastify.server.address().port + '/503')
|
|
@@ -1379,7 +1379,7 @@ test('should not log the error if error handler is defined and it does not error
|
|
|
1379
1379
|
t.ok(err)
|
|
1380
1380
|
reply.send('something bad happened')
|
|
1381
1381
|
})
|
|
1382
|
-
fastify.listen(0, localhost, err => {
|
|
1382
|
+
fastify.listen({ port: 0, host: localhost }, err => {
|
|
1383
1383
|
t.error(err)
|
|
1384
1384
|
fastify.server.unref()
|
|
1385
1385
|
http.get(`http://${localhostForURL}:` + fastify.server.address().port + '/error')
|
|
@@ -1410,7 +1410,7 @@ test('should not rely on raw request to log errors', t => {
|
|
|
1410
1410
|
t.ok(req.log)
|
|
1411
1411
|
reply.status(415).send(new Error('something happened'))
|
|
1412
1412
|
})
|
|
1413
|
-
fastify.listen(0, localhost, err => {
|
|
1413
|
+
fastify.listen({ port: 0, host: localhost }, err => {
|
|
1414
1414
|
t.error(err)
|
|
1415
1415
|
fastify.server.unref()
|
|
1416
1416
|
http.get(`http://${localhostForURL}:` + fastify.server.address().port + '/error')
|
|
@@ -1460,7 +1460,7 @@ test('should redact the authorization header if so specified', t => {
|
|
|
1460
1460
|
t.equal(line.req.headers.authorization, '[Redacted]', 'authorization is redacted')
|
|
1461
1461
|
})
|
|
1462
1462
|
})
|
|
1463
|
-
fastify.listen(0, localhost, err => {
|
|
1463
|
+
fastify.listen({ port: 0, host: localhost }, err => {
|
|
1464
1464
|
t.error(err)
|
|
1465
1465
|
fastify.server.unref()
|
|
1466
1466
|
sget({
|
|
@@ -17,7 +17,7 @@ test('maxRequestsPerSocket on node version >= 16.10.0', { skip }, t => {
|
|
|
17
17
|
|
|
18
18
|
t.teardown(fastify.close.bind(fastify))
|
|
19
19
|
|
|
20
|
-
fastify.listen(0, function (err) {
|
|
20
|
+
fastify.listen({ port: 0 }, function (err) {
|
|
21
21
|
t.error(err)
|
|
22
22
|
|
|
23
23
|
const port = fastify.server.address().port
|
|
@@ -58,7 +58,7 @@ test('maxRequestsPerSocket zero should behave same as null', { skip }, t => {
|
|
|
58
58
|
|
|
59
59
|
t.teardown(fastify.close.bind(fastify))
|
|
60
60
|
|
|
61
|
-
fastify.listen(0, function (err) {
|
|
61
|
+
fastify.listen({ port: 0 }, function (err) {
|
|
62
62
|
t.error(err)
|
|
63
63
|
|
|
64
64
|
const port = fastify.server.address().port
|
|
@@ -88,7 +88,7 @@ test('object or null body', t => {
|
|
|
88
88
|
}
|
|
89
89
|
})
|
|
90
90
|
|
|
91
|
-
fastify.listen(0, (err) => {
|
|
91
|
+
fastify.listen({ port: 0 }, (err) => {
|
|
92
92
|
fastify.server.unref()
|
|
93
93
|
t.error(err)
|
|
94
94
|
|
|
@@ -140,7 +140,7 @@ test('nullable body', t => {
|
|
|
140
140
|
}
|
|
141
141
|
})
|
|
142
142
|
|
|
143
|
-
fastify.listen(0, (err) => {
|
|
143
|
+
fastify.listen({ port: 0 }, (err) => {
|
|
144
144
|
fastify.server.unref()
|
|
145
145
|
t.error(err)
|
|
146
146
|
|
|
@@ -181,7 +181,7 @@ test('Nullable body with 204', t => {
|
|
|
181
181
|
}
|
|
182
182
|
})
|
|
183
183
|
|
|
184
|
-
fastify.listen(0, (err) => {
|
|
184
|
+
fastify.listen({ port: 0 }, (err) => {
|
|
185
185
|
fastify.server.unref()
|
|
186
186
|
t.error(err)
|
|
187
187
|
|
package/test/plugin.test.js
CHANGED
|
@@ -89,7 +89,7 @@ test('fastify.register with fastify-plugin should not encapsulate his code', t =
|
|
|
89
89
|
t.notOk(fastify.test)
|
|
90
90
|
})
|
|
91
91
|
|
|
92
|
-
fastify.listen(0, err => {
|
|
92
|
+
fastify.listen({ port: 0 }, err => {
|
|
93
93
|
t.error(err)
|
|
94
94
|
fastify.server.unref()
|
|
95
95
|
|
|
@@ -168,7 +168,7 @@ test('fastify.register with fastify-plugin should provide access to external fas
|
|
|
168
168
|
t.notOk(fastify.global)
|
|
169
169
|
})
|
|
170
170
|
|
|
171
|
-
fastify.listen(0, err => {
|
|
171
|
+
fastify.listen({ port: 0 }, err => {
|
|
172
172
|
t.error(err)
|
|
173
173
|
fastify.server.unref()
|
|
174
174
|
|
|
@@ -223,7 +223,7 @@ test('fastify.register with fastify-plugin registers root level plugins', t => {
|
|
|
223
223
|
reply.send({ test: fastify.test })
|
|
224
224
|
})
|
|
225
225
|
|
|
226
|
-
fastify.listen(0, err => {
|
|
226
|
+
fastify.listen({ port: 0 }, err => {
|
|
227
227
|
t.error(err)
|
|
228
228
|
fastify.server.unref()
|
|
229
229
|
|
|
@@ -285,7 +285,7 @@ test('check dependencies - should not throw', t => {
|
|
|
285
285
|
t.notOk(fastify.otherTest)
|
|
286
286
|
})
|
|
287
287
|
|
|
288
|
-
fastify.listen(0, err => {
|
|
288
|
+
fastify.listen({ port: 0 }, err => {
|
|
289
289
|
t.error(err)
|
|
290
290
|
fastify.server.unref()
|
|
291
291
|
|
|
@@ -337,7 +337,7 @@ test('check dependencies - should throw', t => {
|
|
|
337
337
|
t.notOk(fastify.test)
|
|
338
338
|
})
|
|
339
339
|
|
|
340
|
-
fastify.listen(0, err => {
|
|
340
|
+
fastify.listen({ port: 0 }, err => {
|
|
341
341
|
t.error(err)
|
|
342
342
|
fastify.server.unref()
|
|
343
343
|
|
|
@@ -375,7 +375,7 @@ test('set the plugin name based on the plugin displayName symbol', t => {
|
|
|
375
375
|
done()
|
|
376
376
|
}, { name: 'plugin-B' }))
|
|
377
377
|
|
|
378
|
-
fastify.listen(0, err => {
|
|
378
|
+
fastify.listen({ port: 0 }, err => {
|
|
379
379
|
t.error(err)
|
|
380
380
|
fastify.close()
|
|
381
381
|
})
|
|
@@ -405,7 +405,7 @@ test('plugin name will change when using no encapsulation', t => {
|
|
|
405
405
|
done()
|
|
406
406
|
}, { name: 'plugin-A' }))
|
|
407
407
|
|
|
408
|
-
fastify.listen(0, err => {
|
|
408
|
+
fastify.listen({ port: 0 }, err => {
|
|
409
409
|
t.error(err)
|
|
410
410
|
fastify.close()
|
|
411
411
|
})
|
|
@@ -417,7 +417,7 @@ test('plugin name is undefined when accessing in no plugin context', t => {
|
|
|
417
417
|
|
|
418
418
|
t.equal(fastify.pluginName, undefined)
|
|
419
419
|
|
|
420
|
-
fastify.listen(0, err => {
|
|
420
|
+
fastify.listen({ port: 0 }, err => {
|
|
421
421
|
t.error(err)
|
|
422
422
|
fastify.close()
|
|
423
423
|
})
|
|
@@ -445,7 +445,7 @@ test('set the plugin name based on the plugin function name', t => {
|
|
|
445
445
|
done()
|
|
446
446
|
})
|
|
447
447
|
|
|
448
|
-
fastify.listen(0, err => {
|
|
448
|
+
fastify.listen({ port: 0 }, err => {
|
|
449
449
|
t.error(err)
|
|
450
450
|
fastify.close()
|
|
451
451
|
})
|
|
@@ -472,7 +472,7 @@ test('approximate a plugin name when no meta data is available', t => {
|
|
|
472
472
|
done()
|
|
473
473
|
})
|
|
474
474
|
|
|
475
|
-
fastify.listen(0, err => {
|
|
475
|
+
fastify.listen({ port: 0 }, err => {
|
|
476
476
|
t.error(err)
|
|
477
477
|
fastify.close()
|
|
478
478
|
})
|
|
@@ -495,7 +495,7 @@ test('approximate a plugin name also when fastify-plugin has no meta data', t =>
|
|
|
495
495
|
done()
|
|
496
496
|
}))
|
|
497
497
|
|
|
498
|
-
fastify.listen(0, err => {
|
|
498
|
+
fastify.listen({ port: 0 }, err => {
|
|
499
499
|
t.error(err)
|
|
500
500
|
fastify.close()
|
|
501
501
|
})
|
|
@@ -535,7 +535,7 @@ test('plugin encapsulation', t => {
|
|
|
535
535
|
t.notOk(fastify.test)
|
|
536
536
|
})
|
|
537
537
|
|
|
538
|
-
fastify.listen(0, err => {
|
|
538
|
+
fastify.listen({ port: 0 }, err => {
|
|
539
539
|
t.error(err)
|
|
540
540
|
fastify.server.unref()
|
|
541
541
|
|
|
@@ -569,7 +569,7 @@ test('if a plugin raises an error and there is not a callback to handle it, the
|
|
|
569
569
|
done(new Error('err'))
|
|
570
570
|
})
|
|
571
571
|
|
|
572
|
-
fastify.listen(0, err => {
|
|
572
|
+
fastify.listen({ port: 0 }, err => {
|
|
573
573
|
t.ok(err instanceof Error)
|
|
574
574
|
t.equal(err.message, 'err')
|
|
575
575
|
})
|
|
@@ -612,7 +612,7 @@ test('add hooks after route declaration', t => {
|
|
|
612
612
|
done()
|
|
613
613
|
})
|
|
614
614
|
|
|
615
|
-
fastify.listen(0, err => {
|
|
615
|
+
fastify.listen({ port: 0 }, err => {
|
|
616
616
|
t.error(err)
|
|
617
617
|
|
|
618
618
|
sget({
|
|
@@ -651,7 +651,7 @@ test('nested plugins', t => {
|
|
|
651
651
|
done()
|
|
652
652
|
}, { prefix: '/parent' })
|
|
653
653
|
|
|
654
|
-
fastify.listen(0, err => {
|
|
654
|
+
fastify.listen({ port: 0 }, err => {
|
|
655
655
|
t.error(err)
|
|
656
656
|
|
|
657
657
|
sget({
|
|
@@ -693,7 +693,7 @@ test('nested plugins awaited', t => {
|
|
|
693
693
|
}, { prefix: '/child2' })
|
|
694
694
|
}, { prefix: '/parent' })
|
|
695
695
|
|
|
696
|
-
fastify.listen(0, err => {
|
|
696
|
+
fastify.listen({ port: 0 }, err => {
|
|
697
697
|
t.error(err)
|
|
698
698
|
|
|
699
699
|
sget({
|
package/test/promises.test.js
CHANGED
|
@@ -15,7 +15,7 @@ test('proto-poisoning error', t => {
|
|
|
15
15
|
t.fail('handler should not be called')
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
fastify.listen(0, function (err) {
|
|
18
|
+
fastify.listen({ port: 0 }, function (err) {
|
|
19
19
|
t.error(err)
|
|
20
20
|
|
|
21
21
|
sget({
|
|
@@ -41,7 +41,7 @@ test('proto-poisoning remove', t => {
|
|
|
41
41
|
reply.send({ ok: true })
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
fastify.listen(0, function (err) {
|
|
44
|
+
fastify.listen({ port: 0 }, function (err) {
|
|
45
45
|
t.error(err)
|
|
46
46
|
|
|
47
47
|
sget({
|
|
@@ -67,7 +67,7 @@ test('proto-poisoning ignore', t => {
|
|
|
67
67
|
reply.send({ ok: true })
|
|
68
68
|
})
|
|
69
69
|
|
|
70
|
-
fastify.listen(0, function (err) {
|
|
70
|
+
fastify.listen({ port: 0 }, function (err) {
|
|
71
71
|
t.error(err)
|
|
72
72
|
|
|
73
73
|
sget({
|
|
@@ -92,7 +92,7 @@ test('constructor-poisoning error (default in v3)', t => {
|
|
|
92
92
|
reply.send('ok')
|
|
93
93
|
})
|
|
94
94
|
|
|
95
|
-
fastify.listen(0, function (err) {
|
|
95
|
+
fastify.listen({ port: 0 }, function (err) {
|
|
96
96
|
t.error(err)
|
|
97
97
|
|
|
98
98
|
sget({
|
|
@@ -117,7 +117,7 @@ test('constructor-poisoning error', t => {
|
|
|
117
117
|
t.fail('handler should not be called')
|
|
118
118
|
})
|
|
119
119
|
|
|
120
|
-
fastify.listen(0, function (err) {
|
|
120
|
+
fastify.listen({ port: 0 }, function (err) {
|
|
121
121
|
t.error(err)
|
|
122
122
|
|
|
123
123
|
sget({
|
|
@@ -143,7 +143,7 @@ test('constructor-poisoning remove', t => {
|
|
|
143
143
|
reply.send({ ok: true })
|
|
144
144
|
})
|
|
145
145
|
|
|
146
|
-
fastify.listen(0, function (err) {
|
|
146
|
+
fastify.listen({ port: 0 }, function (err) {
|
|
147
147
|
t.error(err)
|
|
148
148
|
|
|
149
149
|
sget({
|
package/test/register.test.js
CHANGED
|
@@ -38,7 +38,7 @@ test('register', t => {
|
|
|
38
38
|
done()
|
|
39
39
|
})
|
|
40
40
|
|
|
41
|
-
fastify.listen(0, err => {
|
|
41
|
+
fastify.listen({ port: 0 }, err => {
|
|
42
42
|
t.error(err)
|
|
43
43
|
fastify.server.unref()
|
|
44
44
|
|
|
@@ -71,7 +71,7 @@ test('internal route declaration should pass the error generated by the register
|
|
|
71
71
|
reply.send({ hello: 'world' })
|
|
72
72
|
})
|
|
73
73
|
|
|
74
|
-
fastify.listen(0, err => {
|
|
74
|
+
fastify.listen({ port: 0 }, err => {
|
|
75
75
|
fastify.close()
|
|
76
76
|
t.equal(err.message, 'kaboom')
|
|
77
77
|
})
|
|
@@ -93,7 +93,7 @@ test('internal route declaration should pass the error generated by the register
|
|
|
93
93
|
t.equal(err.message, 'kaboom')
|
|
94
94
|
})
|
|
95
95
|
|
|
96
|
-
fastify.listen(0, err => {
|
|
96
|
+
fastify.listen({ port: 0 }, err => {
|
|
97
97
|
fastify.close()
|
|
98
98
|
t.error(err)
|
|
99
99
|
})
|
package/test/reply-error.test.js
CHANGED
|
@@ -107,7 +107,7 @@ test('Should reply 400 on client error', t => {
|
|
|
107
107
|
t.plan(2)
|
|
108
108
|
|
|
109
109
|
const fastify = Fastify()
|
|
110
|
-
fastify.listen(0, err => {
|
|
110
|
+
fastify.listen({ port: 0 }, err => {
|
|
111
111
|
t.error(err)
|
|
112
112
|
|
|
113
113
|
const client = net.connect(fastify.server.address().port)
|
|
@@ -156,7 +156,7 @@ test('Should set the response from client error handler', t => {
|
|
|
156
156
|
}
|
|
157
157
|
})
|
|
158
158
|
|
|
159
|
-
fastify.listen(0, err => {
|
|
159
|
+
fastify.listen({ port: 0 }, err => {
|
|
160
160
|
t.error(err)
|
|
161
161
|
|
|
162
162
|
const client = net.connect(fastify.server.address().port)
|
|
@@ -671,7 +671,7 @@ test('setting content-type on reply object should not hang the server case 2', a
|
|
|
671
671
|
})
|
|
672
672
|
|
|
673
673
|
try {
|
|
674
|
-
await fastify.listen(0)
|
|
674
|
+
await fastify.listen({ port: 0 })
|
|
675
675
|
const res = await fastify.inject({
|
|
676
676
|
url: '/',
|
|
677
677
|
method: 'GET'
|
package/test/route-hooks.test.js
CHANGED
package/test/route.test.js
CHANGED
|
@@ -113,7 +113,7 @@ test('route', t => {
|
|
|
113
113
|
}
|
|
114
114
|
})
|
|
115
115
|
|
|
116
|
-
fastify.listen(0, function (err) {
|
|
116
|
+
fastify.listen({ port: 0 }, function (err) {
|
|
117
117
|
if (err) t.error(err)
|
|
118
118
|
fastify.server.unref()
|
|
119
119
|
|
|
@@ -1005,7 +1005,7 @@ test('no warning for exposeHeadRoute', async t => {
|
|
|
1005
1005
|
|
|
1006
1006
|
process.on('warning', listener)
|
|
1007
1007
|
|
|
1008
|
-
await fastify.listen(0)
|
|
1008
|
+
await fastify.listen({ port: 0 })
|
|
1009
1009
|
|
|
1010
1010
|
process.removeListener('warning', listener)
|
|
1011
1011
|
|
|
@@ -1439,7 +1439,7 @@ test('route with non-english characters', t => {
|
|
|
1439
1439
|
reply.send('here /föö')
|
|
1440
1440
|
})
|
|
1441
1441
|
|
|
1442
|
-
fastify.listen(0, err => {
|
|
1442
|
+
fastify.listen({ port: 0 }, err => {
|
|
1443
1443
|
t.error(err)
|
|
1444
1444
|
fastify.server.unref()
|
|
1445
1445
|
|
|
@@ -23,7 +23,7 @@ const echoBody = (req, reply) => { reply.send(req.body) }
|
|
|
23
23
|
t.plan(2)
|
|
24
24
|
const fastify = Fastify()
|
|
25
25
|
t.teardown(fastify.close.bind(fastify))
|
|
26
|
-
fastify.listen(0, err => {
|
|
26
|
+
fastify.listen({ port: 0 }, err => {
|
|
27
27
|
t.error(err)
|
|
28
28
|
try {
|
|
29
29
|
fastify[f](() => { })
|
|
@@ -8,87 +8,6 @@ const Fastify = require('..')
|
|
|
8
8
|
const ajvMergePatch = require('ajv-merge-patch')
|
|
9
9
|
const ajvErrors = require('ajv-errors')
|
|
10
10
|
|
|
11
|
-
const buildValidatorAJV6 = require('@fastify/ajv-compiler-6')
|
|
12
|
-
|
|
13
|
-
test('Ajv6 usage instead of the bundle one', t => {
|
|
14
|
-
t.plan(2)
|
|
15
|
-
|
|
16
|
-
t.test('use old ajv6 option', t => {
|
|
17
|
-
t.plan(2)
|
|
18
|
-
const fastify = Fastify({
|
|
19
|
-
ajv: {
|
|
20
|
-
customOptions: { jsonPointers: true }
|
|
21
|
-
},
|
|
22
|
-
schemaController: {
|
|
23
|
-
compilersFactory: {
|
|
24
|
-
buildValidator: buildValidatorAJV6()
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
fastify.post('/', {
|
|
30
|
-
schema: {
|
|
31
|
-
body: {
|
|
32
|
-
type: 'object',
|
|
33
|
-
required: ['missing'],
|
|
34
|
-
properties: {
|
|
35
|
-
foo: {
|
|
36
|
-
type: 'string'
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
handler (req, reply) { reply.send({ ok: 1 }) }
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
fastify.ready(err => {
|
|
45
|
-
t.error(err)
|
|
46
|
-
t.pass('the removed ajv6 option let the startup pass')
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
t.test('use old ajv6 option within a response schema', t => {
|
|
51
|
-
t.plan(2)
|
|
52
|
-
const fastify = Fastify({
|
|
53
|
-
schemaController: {
|
|
54
|
-
compilersFactory: {
|
|
55
|
-
buildValidator: buildValidatorAJV6()
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
fastify.post('/', {
|
|
61
|
-
schema: {
|
|
62
|
-
body: {
|
|
63
|
-
type: 'object',
|
|
64
|
-
required: ['missing'],
|
|
65
|
-
properties: {
|
|
66
|
-
foo: {
|
|
67
|
-
type: 'string'
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
response: {
|
|
72
|
-
'2xx': {
|
|
73
|
-
type: 'object',
|
|
74
|
-
properties: {
|
|
75
|
-
ok: {
|
|
76
|
-
type: 'integer'
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
handler (req, reply) { reply.send({ ok: 1 }) }
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
fastify.ready(err => {
|
|
86
|
-
t.error(err)
|
|
87
|
-
t.pass('startup successful')
|
|
88
|
-
})
|
|
89
|
-
})
|
|
90
|
-
})
|
|
91
|
-
|
|
92
11
|
test('Ajv plugins array parameter', t => {
|
|
93
12
|
t.plan(3)
|
|
94
13
|
const fastify = Fastify({
|
|
@@ -201,7 +201,7 @@ function testHandlerOrBeforeHandlerHook (test, hookOrHandler) {
|
|
|
201
201
|
|
|
202
202
|
nextHooks.forEach(h => app.addHook(h, async (req, reply) => t.fail(`${h} should not be called`)))
|
|
203
203
|
|
|
204
|
-
app.listen(0, err => {
|
|
204
|
+
app.listen({ port: 0 }, err => {
|
|
205
205
|
t.error(err)
|
|
206
206
|
const client = net.createConnection({ port: (app.server.address()).port }, () => {
|
|
207
207
|
client.write('GET / HTTP/1.1\r\n\r\n')
|