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,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
|
|
6
5
|
const Ajv = require('ajv')
|
|
7
6
|
const ajv = new Ajv({ coerceTypes: true })
|
|
@@ -13,11 +12,11 @@ const { kSchemaVisited } = require('../../lib/symbols')
|
|
|
13
12
|
|
|
14
13
|
test('Symbols', t => {
|
|
15
14
|
t.plan(5)
|
|
16
|
-
t.
|
|
17
|
-
t.
|
|
18
|
-
t.
|
|
19
|
-
t.
|
|
20
|
-
t.
|
|
15
|
+
t.assert.strictEqual(typeof symbols.responseSchema, 'symbol')
|
|
16
|
+
t.assert.strictEqual(typeof symbols.bodySchema, 'symbol')
|
|
17
|
+
t.assert.strictEqual(typeof symbols.querystringSchema, 'symbol')
|
|
18
|
+
t.assert.strictEqual(typeof symbols.paramsSchema, 'symbol')
|
|
19
|
+
t.assert.strictEqual(typeof symbols.headersSchema, 'symbol')
|
|
21
20
|
})
|
|
22
21
|
|
|
23
22
|
;['compileSchemasForValidation',
|
|
@@ -26,15 +25,15 @@ test('Symbols', t => {
|
|
|
26
25
|
t.plan(2)
|
|
27
26
|
const context = {}
|
|
28
27
|
validation[func](context)
|
|
29
|
-
t.
|
|
30
|
-
t.
|
|
28
|
+
t.assert.strictEqual(typeof context[symbols.bodySchema], 'undefined')
|
|
29
|
+
t.assert.strictEqual(typeof context[symbols.responseSchema], 'undefined')
|
|
31
30
|
})
|
|
32
31
|
|
|
33
32
|
test(`${func} schema - missing output schema`, t => {
|
|
34
33
|
t.plan(1)
|
|
35
34
|
const context = { schema: {} }
|
|
36
35
|
validation[func](context, null)
|
|
37
|
-
t.
|
|
36
|
+
t.assert.strictEqual(typeof context[symbols.responseSchema], 'undefined')
|
|
38
37
|
})
|
|
39
38
|
})
|
|
40
39
|
|
|
@@ -59,8 +58,8 @@ test('build schema - output schema', t => {
|
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
validation.compileSchemasForSerialization(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
|
|
62
|
-
t.
|
|
63
|
-
t.
|
|
61
|
+
t.assert.strictEqual(typeof opts[symbols.responseSchema]['2xx'], 'function')
|
|
62
|
+
t.assert.strictEqual(typeof opts[symbols.responseSchema]['201'], 'function')
|
|
64
63
|
})
|
|
65
64
|
|
|
66
65
|
test('build schema - body schema', t => {
|
|
@@ -76,7 +75,7 @@ test('build schema - body schema', t => {
|
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
77
|
validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
|
|
79
|
-
t.
|
|
78
|
+
t.assert.strictEqual(typeof opts[symbols.bodySchema], 'function')
|
|
80
79
|
})
|
|
81
80
|
|
|
82
81
|
test('build schema - body with multiple content type schemas', t => {
|
|
@@ -101,8 +100,8 @@ test('build schema - body with multiple content type schemas', t => {
|
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
102
|
validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
|
|
104
|
-
t.
|
|
105
|
-
t.
|
|
103
|
+
t.assert.ok(opts[symbols.bodySchema]['application/json'], 'function')
|
|
104
|
+
t.assert.ok(opts[symbols.bodySchema]['text/plain'], 'function')
|
|
106
105
|
})
|
|
107
106
|
|
|
108
107
|
test('build schema - avoid repeated normalize schema', t => {
|
|
@@ -119,9 +118,9 @@ test('build schema - avoid repeated normalize schema', t => {
|
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
120
|
opts.schema = normalizeSchema(opts.schema, serverConfig)
|
|
122
|
-
t.
|
|
123
|
-
t.
|
|
124
|
-
t.
|
|
121
|
+
t.assert.notStrictEqual(kSchemaVisited, undefined)
|
|
122
|
+
t.assert.strictEqual(opts.schema[kSchemaVisited], true)
|
|
123
|
+
t.assert.strictEqual(opts.schema, normalizeSchema(opts.schema, serverConfig))
|
|
125
124
|
})
|
|
126
125
|
|
|
127
126
|
test('build schema - query schema', t => {
|
|
@@ -139,8 +138,8 @@ test('build schema - query schema', t => {
|
|
|
139
138
|
}
|
|
140
139
|
opts.schema = normalizeSchema(opts.schema, serverConfig)
|
|
141
140
|
validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
|
|
142
|
-
t.
|
|
143
|
-
t.
|
|
141
|
+
t.assert.ok(typeof opts[symbols.querystringSchema].schema.type === 'string')
|
|
142
|
+
t.assert.strictEqual(typeof opts[symbols.querystringSchema], 'function')
|
|
144
143
|
})
|
|
145
144
|
|
|
146
145
|
test('build schema - query schema abbreviated', t => {
|
|
@@ -158,8 +157,8 @@ test('build schema - query schema abbreviated', t => {
|
|
|
158
157
|
}
|
|
159
158
|
opts.schema = normalizeSchema(opts.schema, serverConfig)
|
|
160
159
|
validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
|
|
161
|
-
t.
|
|
162
|
-
t.
|
|
160
|
+
t.assert.ok(typeof opts[symbols.querystringSchema].schema.type === 'string')
|
|
161
|
+
t.assert.strictEqual(typeof opts[symbols.querystringSchema], 'function')
|
|
163
162
|
})
|
|
164
163
|
|
|
165
164
|
test('build schema - querystring schema', t => {
|
|
@@ -175,8 +174,8 @@ test('build schema - querystring schema', t => {
|
|
|
175
174
|
}
|
|
176
175
|
}
|
|
177
176
|
validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
|
|
178
|
-
t.
|
|
179
|
-
t.
|
|
177
|
+
t.assert.ok(typeof opts[symbols.querystringSchema].schema.type === 'string')
|
|
178
|
+
t.assert.strictEqual(typeof opts[symbols.querystringSchema], 'function')
|
|
180
179
|
})
|
|
181
180
|
|
|
182
181
|
test('build schema - querystring schema abbreviated', t => {
|
|
@@ -194,8 +193,8 @@ test('build schema - querystring schema abbreviated', t => {
|
|
|
194
193
|
}
|
|
195
194
|
opts.schema = normalizeSchema(opts.schema, serverConfig)
|
|
196
195
|
validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
|
|
197
|
-
t.
|
|
198
|
-
t.
|
|
196
|
+
t.assert.ok(typeof opts[symbols.querystringSchema].schema.type === 'string')
|
|
197
|
+
t.assert.strictEqual(typeof opts[symbols.querystringSchema], 'function')
|
|
199
198
|
})
|
|
200
199
|
|
|
201
200
|
test('build schema - must throw if querystring and query schema exist', t => {
|
|
@@ -220,8 +219,8 @@ test('build schema - must throw if querystring and query schema exist', t => {
|
|
|
220
219
|
}
|
|
221
220
|
opts.schema = normalizeSchema(opts.schema, serverConfig)
|
|
222
221
|
} catch (err) {
|
|
223
|
-
t.
|
|
224
|
-
t.
|
|
222
|
+
t.assert.strictEqual(err.code, 'FST_ERR_SCH_DUPLICATE')
|
|
223
|
+
t.assert.strictEqual(err.message, 'Schema with \'querystring\' already present!')
|
|
225
224
|
}
|
|
226
225
|
})
|
|
227
226
|
|
|
@@ -238,7 +237,7 @@ test('build schema - params schema', t => {
|
|
|
238
237
|
}
|
|
239
238
|
}
|
|
240
239
|
validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
|
|
241
|
-
t.
|
|
240
|
+
t.assert.strictEqual(typeof opts[symbols.paramsSchema], 'function')
|
|
242
241
|
})
|
|
243
242
|
|
|
244
243
|
test('build schema - headers schema', t => {
|
|
@@ -254,7 +253,7 @@ test('build schema - headers schema', t => {
|
|
|
254
253
|
}
|
|
255
254
|
}
|
|
256
255
|
validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
|
|
257
|
-
t.
|
|
256
|
+
t.assert.strictEqual(typeof opts[symbols.headersSchema], 'function')
|
|
258
257
|
})
|
|
259
258
|
|
|
260
259
|
test('build schema - headers are lowercase', t => {
|
|
@@ -270,7 +269,7 @@ test('build schema - headers are lowercase', t => {
|
|
|
270
269
|
}
|
|
271
270
|
}
|
|
272
271
|
validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => {
|
|
273
|
-
t.ok(schema.properties['content-type'], 'lowercase content-type exists')
|
|
272
|
+
t.assert.ok(schema.properties['content-type'], 'lowercase content-type exists')
|
|
274
273
|
return () => { }
|
|
275
274
|
})
|
|
276
275
|
})
|
|
@@ -285,7 +284,7 @@ test('build schema - headers are not lowercased in case of custom object', t =>
|
|
|
285
284
|
}
|
|
286
285
|
}
|
|
287
286
|
validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => {
|
|
288
|
-
t.
|
|
287
|
+
t.assert.ok(schema, Headers)
|
|
289
288
|
return () => { }
|
|
290
289
|
})
|
|
291
290
|
})
|
|
@@ -300,7 +299,7 @@ test('build schema - headers are not lowercased in case of custom validator prov
|
|
|
300
299
|
}
|
|
301
300
|
}
|
|
302
301
|
validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => {
|
|
303
|
-
t.
|
|
302
|
+
t.assert.ok(schema, Headers)
|
|
304
303
|
return () => { }
|
|
305
304
|
}, true)
|
|
306
305
|
})
|
|
@@ -318,7 +317,7 @@ test('build schema - uppercased headers are not included', t => {
|
|
|
318
317
|
}
|
|
319
318
|
}
|
|
320
319
|
validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => {
|
|
321
|
-
t.
|
|
320
|
+
t.assert.ok(!('Content-Type' in schema.properties), 'uppercase does not exist')
|
|
322
321
|
return () => { }
|
|
323
322
|
})
|
|
324
323
|
})
|
|
@@ -333,7 +332,7 @@ test('build schema - mixed schema types are individually skipped or normalized',
|
|
|
333
332
|
body: new CustomSchemaClass()
|
|
334
333
|
},
|
|
335
334
|
assertions: (schema) => {
|
|
336
|
-
t.
|
|
335
|
+
t.assert.ok(schema.body, CustomSchemaClass)
|
|
337
336
|
}
|
|
338
337
|
}, {
|
|
339
338
|
schema: {
|
|
@@ -342,7 +341,7 @@ test('build schema - mixed schema types are individually skipped or normalized',
|
|
|
342
341
|
}
|
|
343
342
|
},
|
|
344
343
|
assertions: (schema) => {
|
|
345
|
-
t.
|
|
344
|
+
t.assert.ok(schema.response[200], CustomSchemaClass)
|
|
346
345
|
}
|
|
347
346
|
}]
|
|
348
347
|
|
|
@@ -2,34 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
const Fastify = require('..')
|
|
4
4
|
const http = require('node:http')
|
|
5
|
-
const
|
|
6
|
-
const test = t.test
|
|
5
|
+
const { test } = require('node:test')
|
|
7
6
|
|
|
8
7
|
test('keepAliveTimeout', t => {
|
|
9
8
|
t.plan(6)
|
|
10
9
|
|
|
11
10
|
try {
|
|
12
11
|
Fastify({ keepAliveTimeout: 1.3 })
|
|
13
|
-
t.fail('option must be an integer')
|
|
12
|
+
t.assert.fail('option must be an integer')
|
|
14
13
|
} catch (err) {
|
|
15
|
-
t.ok(err)
|
|
14
|
+
t.assert.ok(err)
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
try {
|
|
19
18
|
Fastify({ keepAliveTimeout: [] })
|
|
20
|
-
t.fail('option must be an integer')
|
|
19
|
+
t.assert.fail('option must be an integer')
|
|
21
20
|
} catch (err) {
|
|
22
|
-
t.ok(err)
|
|
21
|
+
t.assert.ok(err)
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
const httpServer = Fastify({ keepAliveTimeout: 1 }).server
|
|
26
|
-
t.
|
|
25
|
+
t.assert.strictEqual(httpServer.keepAliveTimeout, 1)
|
|
27
26
|
|
|
28
27
|
const httpsServer = Fastify({ keepAliveTimeout: 2, https: {} }).server
|
|
29
|
-
t.
|
|
28
|
+
t.assert.strictEqual(httpsServer.keepAliveTimeout, 2)
|
|
30
29
|
|
|
31
30
|
const http2Server = Fastify({ keepAliveTimeout: 3, http2: true }).server
|
|
32
|
-
t.
|
|
31
|
+
t.assert.notStrictEqual(http2Server.keepAliveTimeout, 3)
|
|
33
32
|
|
|
34
33
|
const serverFactory = (handler, _) => {
|
|
35
34
|
const server = http.createServer((req, res) => {
|
|
@@ -39,5 +38,5 @@ test('keepAliveTimeout', t => {
|
|
|
39
38
|
return server
|
|
40
39
|
}
|
|
41
40
|
const customServer = Fastify({ keepAliveTimeout: 4, serverFactory }).server
|
|
42
|
-
t.
|
|
41
|
+
t.assert.strictEqual(customServer.keepAliveTimeout, 5)
|
|
43
42
|
})
|
package/test/listen.5.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { test } = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const net = require('node:net')
|
|
5
5
|
const Fastify = require('../fastify')
|
|
6
6
|
const { once } = require('node:events')
|
|
@@ -26,9 +26,9 @@ test('same port conflict and success should not fire callback multiple times - c
|
|
|
26
26
|
switch (count) {
|
|
27
27
|
case 6: {
|
|
28
28
|
// success in here
|
|
29
|
-
t.
|
|
29
|
+
t.assert.ifError(err)
|
|
30
30
|
fastify.close((err) => {
|
|
31
|
-
t.
|
|
31
|
+
t.assert.ifError(err)
|
|
32
32
|
promise.resolve()
|
|
33
33
|
})
|
|
34
34
|
break
|
|
@@ -42,7 +42,7 @@ test('same port conflict and success should not fire callback multiple times - c
|
|
|
42
42
|
}
|
|
43
43
|
default: {
|
|
44
44
|
// expect error
|
|
45
|
-
t.
|
|
45
|
+
t.assert.strictEqual(err.code, 'EADDRINUSE')
|
|
46
46
|
setTimeout(() => {
|
|
47
47
|
fastify.listen(option, callback)
|
|
48
48
|
}, 100)
|
|
@@ -65,27 +65,27 @@ test('same port conflict and success should not fire callback multiple times - p
|
|
|
65
65
|
try {
|
|
66
66
|
await fastify.listen(option)
|
|
67
67
|
} catch (err) {
|
|
68
|
-
t.
|
|
68
|
+
t.assert.strictEqual(err.code, 'EADDRINUSE')
|
|
69
69
|
}
|
|
70
70
|
try {
|
|
71
71
|
await fastify.listen(option)
|
|
72
72
|
} catch (err) {
|
|
73
|
-
t.
|
|
73
|
+
t.assert.strictEqual(err.code, 'EADDRINUSE')
|
|
74
74
|
}
|
|
75
75
|
try {
|
|
76
76
|
await fastify.listen(option)
|
|
77
77
|
} catch (err) {
|
|
78
|
-
t.
|
|
78
|
+
t.assert.strictEqual(err.code, 'EADDRINUSE')
|
|
79
79
|
}
|
|
80
80
|
try {
|
|
81
81
|
await fastify.listen(option)
|
|
82
82
|
} catch (err) {
|
|
83
|
-
t.
|
|
83
|
+
t.assert.strictEqual(err.code, 'EADDRINUSE')
|
|
84
84
|
}
|
|
85
85
|
try {
|
|
86
86
|
await fastify.listen(option)
|
|
87
87
|
} catch (err) {
|
|
88
|
-
t.
|
|
88
|
+
t.assert.strictEqual(err.code, 'EADDRINUSE')
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
server.close()
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const net = require('node:net')
|
|
4
|
-
const { test } = require('
|
|
5
|
-
const Fastify = require('
|
|
4
|
+
const { test } = require('node:test')
|
|
5
|
+
const Fastify = require('..')
|
|
6
6
|
|
|
7
|
-
test('maxRequestsPerSocket', t => {
|
|
7
|
+
test('maxRequestsPerSocket', (t, done) => {
|
|
8
8
|
t.plan(8)
|
|
9
9
|
|
|
10
10
|
const fastify = Fastify({ maxRequestsPerSocket: 2 })
|
|
@@ -12,32 +12,32 @@ test('maxRequestsPerSocket', t => {
|
|
|
12
12
|
reply.send({ hello: 'world' })
|
|
13
13
|
})
|
|
14
14
|
|
|
15
|
-
t.teardown(fastify.close.bind(fastify))
|
|
16
|
-
|
|
17
15
|
fastify.listen({ port: 0 }, function (err) {
|
|
18
|
-
t.
|
|
16
|
+
t.assert.ifError(err)
|
|
19
17
|
|
|
20
18
|
const port = fastify.server.address().port
|
|
21
19
|
const client = net.createConnection({ port }, () => {
|
|
22
20
|
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
|
|
23
21
|
|
|
24
22
|
client.once('data', data => {
|
|
25
|
-
t.match(data.toString(), /Connection:\s*keep-alive/i)
|
|
26
|
-
t.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
|
|
27
|
-
t.match(data.toString(), /200 OK/i)
|
|
23
|
+
t.assert.match(data.toString(), /Connection:\s*keep-alive/i)
|
|
24
|
+
t.assert.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
|
|
25
|
+
t.assert.match(data.toString(), /200 OK/i)
|
|
28
26
|
|
|
29
27
|
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
|
|
30
28
|
|
|
31
29
|
client.once('data', data => {
|
|
32
|
-
t.match(data.toString(), /Connection:\s*close/i)
|
|
33
|
-
t.match(data.toString(), /200 OK/i)
|
|
30
|
+
t.assert.match(data.toString(), /Connection:\s*close/i)
|
|
31
|
+
t.assert.match(data.toString(), /200 OK/i)
|
|
34
32
|
|
|
35
33
|
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
|
|
36
34
|
|
|
37
35
|
client.once('data', data => {
|
|
38
|
-
t.match(data.toString(), /Connection:\s*close/i)
|
|
39
|
-
t.match(data.toString(), /503 Service Unavailable/i)
|
|
36
|
+
t.assert.match(data.toString(), /Connection:\s*close/i)
|
|
37
|
+
t.assert.match(data.toString(), /503 Service Unavailable/i)
|
|
40
38
|
client.end()
|
|
39
|
+
fastify.close()
|
|
40
|
+
done()
|
|
41
41
|
})
|
|
42
42
|
})
|
|
43
43
|
})
|
|
@@ -45,7 +45,7 @@ test('maxRequestsPerSocket', t => {
|
|
|
45
45
|
})
|
|
46
46
|
})
|
|
47
47
|
|
|
48
|
-
test('maxRequestsPerSocket zero should behave same as null', t => {
|
|
48
|
+
test('maxRequestsPerSocket zero should behave same as null', (t, done) => {
|
|
49
49
|
t.plan(10)
|
|
50
50
|
|
|
51
51
|
const fastify = Fastify({ maxRequestsPerSocket: 0 })
|
|
@@ -53,34 +53,34 @@ test('maxRequestsPerSocket zero should behave same as null', t => {
|
|
|
53
53
|
reply.send({ hello: 'world' })
|
|
54
54
|
})
|
|
55
55
|
|
|
56
|
-
t.teardown(fastify.close.bind(fastify))
|
|
57
|
-
|
|
58
56
|
fastify.listen({ port: 0 }, function (err) {
|
|
59
|
-
t.
|
|
57
|
+
t.assert.ifError(err)
|
|
60
58
|
|
|
61
59
|
const port = fastify.server.address().port
|
|
62
60
|
const client = net.createConnection({ port }, () => {
|
|
63
61
|
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
|
|
64
62
|
|
|
65
63
|
client.once('data', data => {
|
|
66
|
-
t.match(data.toString(), /Connection:\s*keep-alive/i)
|
|
67
|
-
t.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
|
|
68
|
-
t.match(data.toString(), /200 OK/i)
|
|
64
|
+
t.assert.match(data.toString(), /Connection:\s*keep-alive/i)
|
|
65
|
+
t.assert.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
|
|
66
|
+
t.assert.match(data.toString(), /200 OK/i)
|
|
69
67
|
|
|
70
68
|
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
|
|
71
69
|
|
|
72
70
|
client.once('data', data => {
|
|
73
|
-
t.match(data.toString(), /Connection:\s*keep-alive/i)
|
|
74
|
-
t.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
|
|
75
|
-
t.match(data.toString(), /200 OK/i)
|
|
71
|
+
t.assert.match(data.toString(), /Connection:\s*keep-alive/i)
|
|
72
|
+
t.assert.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
|
|
73
|
+
t.assert.match(data.toString(), /200 OK/i)
|
|
76
74
|
|
|
77
75
|
client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
|
|
78
76
|
|
|
79
77
|
client.once('data', data => {
|
|
80
|
-
t.match(data.toString(), /Connection:\s*keep-alive/i)
|
|
81
|
-
t.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
|
|
82
|
-
t.match(data.toString(), /200 OK/i)
|
|
78
|
+
t.assert.match(data.toString(), /Connection:\s*keep-alive/i)
|
|
79
|
+
t.assert.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
|
|
80
|
+
t.assert.match(data.toString(), /200 OK/i)
|
|
83
81
|
client.end()
|
|
82
|
+
fastify.close()
|
|
83
|
+
done()
|
|
84
84
|
})
|
|
85
85
|
})
|
|
86
86
|
})
|
|
@@ -92,22 +92,22 @@ test('maxRequestsPerSocket should be set', async (t) => {
|
|
|
92
92
|
t.plan(1)
|
|
93
93
|
|
|
94
94
|
const initialConfig = Fastify({ maxRequestsPerSocket: 5 }).initialConfig
|
|
95
|
-
t.
|
|
95
|
+
t.assert.deepStrictEqual(initialConfig.maxRequestsPerSocket, 5)
|
|
96
96
|
})
|
|
97
97
|
|
|
98
98
|
test('maxRequestsPerSocket should 0', async (t) => {
|
|
99
99
|
t.plan(1)
|
|
100
100
|
|
|
101
101
|
const initialConfig = Fastify().initialConfig
|
|
102
|
-
t.
|
|
102
|
+
t.assert.deepStrictEqual(initialConfig.maxRequestsPerSocket, 0)
|
|
103
103
|
})
|
|
104
104
|
|
|
105
105
|
test('requestTimeout passed to server', t => {
|
|
106
106
|
t.plan(2)
|
|
107
107
|
|
|
108
108
|
const httpServer = Fastify({ maxRequestsPerSocket: 5 }).server
|
|
109
|
-
t.
|
|
109
|
+
t.assert.strictEqual(httpServer.maxRequestsPerSocket, 5)
|
|
110
110
|
|
|
111
111
|
const httpsServer = Fastify({ maxRequestsPerSocket: 5, https: true }).server
|
|
112
|
-
t.
|
|
112
|
+
t.assert.strictEqual(httpsServer.maxRequestsPerSocket, 5)
|
|
113
113
|
})
|
package/test/middleware.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { test } = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const Fastify = require('..')
|
|
5
5
|
const {
|
|
6
6
|
FST_ERR_DEC_ALREADY_PRESENT
|
|
@@ -10,7 +10,7 @@ test('Should be able to override the default use API', t => {
|
|
|
10
10
|
t.plan(1)
|
|
11
11
|
const fastify = Fastify()
|
|
12
12
|
fastify.decorate('use', () => true)
|
|
13
|
-
t.
|
|
13
|
+
t.assert.strictEqual(fastify.use(), true)
|
|
14
14
|
})
|
|
15
15
|
|
|
16
16
|
test('Cannot decorate use twice', t => {
|
|
@@ -20,17 +20,16 @@ test('Cannot decorate use twice', t => {
|
|
|
20
20
|
try {
|
|
21
21
|
fastify.decorate('use', () => true)
|
|
22
22
|
} catch (err) {
|
|
23
|
-
t.ok(err instanceof FST_ERR_DEC_ALREADY_PRESENT)
|
|
23
|
+
t.assert.ok(err instanceof FST_ERR_DEC_ALREADY_PRESENT)
|
|
24
24
|
}
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
test('Encapsulation works', t => {
|
|
28
|
-
t.plan(1)
|
|
29
28
|
const fastify = Fastify()
|
|
30
29
|
|
|
31
30
|
fastify.register((instance, opts, done) => {
|
|
32
31
|
instance.decorate('use', () => true)
|
|
33
|
-
t.
|
|
32
|
+
t.assert.strictEqual(instance.use(), true)
|
|
34
33
|
done()
|
|
35
34
|
})
|
|
36
35
|
|
package/test/noop-set.test.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const noopSet = require('../lib/noop-set')
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
test('does a lot of nothing', async t => {
|
|
7
7
|
const aSet = noopSet()
|
|
8
|
-
t.
|
|
8
|
+
t.assert.ok(aSet, 'object')
|
|
9
9
|
|
|
10
10
|
const item = {}
|
|
11
11
|
aSet.add(item)
|
|
12
12
|
aSet.add({ another: 'item' })
|
|
13
13
|
aSet.delete(item)
|
|
14
|
-
t.
|
|
14
|
+
t.assert.strictEqual(aSet.has(item), true)
|
|
15
15
|
|
|
16
16
|
for (const i of aSet) {
|
|
17
|
-
t.fail('should not have any items'
|
|
17
|
+
t.assert.fail('should not have any items: ' + i)
|
|
18
18
|
}
|
|
19
19
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { test } = require('
|
|
4
|
-
const
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const Fastify = require('..')
|
|
5
5
|
const { request, setGlobalDispatcher, Agent } = require('undici')
|
|
6
6
|
|
|
7
7
|
setGlobalDispatcher(new Agent({
|
|
@@ -9,23 +9,30 @@ setGlobalDispatcher(new Agent({
|
|
|
9
9
|
keepAliveMaxTimeout: 10
|
|
10
10
|
}))
|
|
11
11
|
|
|
12
|
-
test('post empty body', async t => {
|
|
13
|
-
const
|
|
14
|
-
|
|
12
|
+
test('post empty body', { timeout: 3_000 }, async t => {
|
|
13
|
+
const fastify = Fastify({ forceCloseConnections: true })
|
|
14
|
+
const abortController = new AbortController()
|
|
15
|
+
const { signal } = abortController
|
|
16
|
+
t.after(() => {
|
|
17
|
+
fastify.close()
|
|
18
|
+
abortController.abort()
|
|
19
|
+
})
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
fastify.post('/bug', async () => {
|
|
22
|
+
// This function must be async and return nothing
|
|
17
23
|
})
|
|
18
24
|
|
|
19
|
-
await
|
|
25
|
+
await fastify.listen({ port: 0 })
|
|
20
26
|
|
|
21
|
-
const res = await request(`http://
|
|
27
|
+
const res = await request(`http://localhost:${fastify.server.address().port}/bug`, {
|
|
22
28
|
method: 'POST',
|
|
23
29
|
headers: {
|
|
24
30
|
'Content-Type': 'application/json'
|
|
25
31
|
},
|
|
26
|
-
body: JSON.stringify({ foo: 'bar' })
|
|
32
|
+
body: JSON.stringify({ foo: 'bar' }),
|
|
33
|
+
signal
|
|
27
34
|
})
|
|
28
35
|
|
|
29
|
-
t.
|
|
30
|
-
t.
|
|
36
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
37
|
+
t.assert.strictEqual(await res.body.text(), '')
|
|
31
38
|
})
|