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,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { test } = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const handleRequest = require('../../lib/handleRequest')
|
|
5
5
|
const internals = require('../../lib/handleRequest')[Symbol.for('internals')]
|
|
6
6
|
const Request = require('../../lib/request')
|
|
@@ -28,14 +28,14 @@ test('handleRequest function - sent reply', t => {
|
|
|
28
28
|
const request = {}
|
|
29
29
|
const reply = { sent: true }
|
|
30
30
|
const res = handleRequest(null, request, reply)
|
|
31
|
-
t.
|
|
31
|
+
t.assert.strictEqual(res, undefined)
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
test('handleRequest function - invoke with error', t => {
|
|
35
35
|
t.plan(1)
|
|
36
36
|
const request = {}
|
|
37
37
|
const reply = {}
|
|
38
|
-
reply.send = (err) => t.
|
|
38
|
+
reply.send = (err) => t.assert.strictEqual(err.message, 'Kaboom')
|
|
39
39
|
handleRequest(new Error('Kaboom'), request, reply)
|
|
40
40
|
})
|
|
41
41
|
|
|
@@ -56,7 +56,7 @@ test('handler function - invalid schema', t => {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
|
-
errorHandler: { func: () => { t.
|
|
59
|
+
errorHandler: { func: () => { t.assert.ok('errorHandler called') } },
|
|
60
60
|
handler: () => {},
|
|
61
61
|
Reply,
|
|
62
62
|
Request,
|
|
@@ -79,13 +79,13 @@ test('handler function - reply', t => {
|
|
|
79
79
|
t.plan(3)
|
|
80
80
|
const res = {}
|
|
81
81
|
res.end = () => {
|
|
82
|
-
t.
|
|
83
|
-
t.
|
|
82
|
+
t.assert.strictEqual(res.statusCode, 204)
|
|
83
|
+
t.assert.ok(true)
|
|
84
84
|
}
|
|
85
85
|
res.writeHead = () => {}
|
|
86
86
|
const context = {
|
|
87
87
|
handler: (req, reply) => {
|
|
88
|
-
t.
|
|
88
|
+
t.assert.strictEqual(typeof reply, 'object')
|
|
89
89
|
reply.code(204)
|
|
90
90
|
reply.send(undefined)
|
|
91
91
|
},
|
|
@@ -110,12 +110,12 @@ test('handler function - preValidationCallback with finished response', t => {
|
|
|
110
110
|
// Be sure to check only `writableEnded` where is available
|
|
111
111
|
res.writableEnded = true
|
|
112
112
|
res.end = () => {
|
|
113
|
-
t.fail()
|
|
113
|
+
t.assert.fail()
|
|
114
114
|
}
|
|
115
115
|
res.writeHead = () => {}
|
|
116
116
|
const context = {
|
|
117
117
|
handler: (req, reply) => {
|
|
118
|
-
t.fail()
|
|
118
|
+
t.assert.fail()
|
|
119
119
|
reply.send(undefined)
|
|
120
120
|
},
|
|
121
121
|
Reply,
|
|
@@ -129,25 +129,28 @@ test('handler function - preValidationCallback with finished response', t => {
|
|
|
129
129
|
internals.handler({ [kRouteContext]: context }, new Reply(res, { [kRouteContext]: context }))
|
|
130
130
|
})
|
|
131
131
|
|
|
132
|
-
test('request should be defined in onSend Hook on post request with content type application/json', t => {
|
|
132
|
+
test('request should be defined in onSend Hook on post request with content type application/json', (t, done) => {
|
|
133
133
|
t.plan(8)
|
|
134
134
|
const fastify = require('../..')()
|
|
135
135
|
|
|
136
|
+
t.after(() => {
|
|
137
|
+
fastify.close()
|
|
138
|
+
})
|
|
139
|
+
|
|
136
140
|
fastify.addHook('onSend', (request, reply, payload, done) => {
|
|
137
|
-
t.ok(request)
|
|
138
|
-
t.ok(request.raw)
|
|
139
|
-
t.ok(request.id)
|
|
140
|
-
t.ok(request.params)
|
|
141
|
-
t.ok(request.query)
|
|
141
|
+
t.assert.ok(request)
|
|
142
|
+
t.assert.ok(request.raw)
|
|
143
|
+
t.assert.ok(request.id)
|
|
144
|
+
t.assert.ok(request.params)
|
|
145
|
+
t.assert.ok(request.query)
|
|
142
146
|
done()
|
|
143
147
|
})
|
|
144
148
|
fastify.post('/', (request, reply) => {
|
|
145
149
|
reply.send(200)
|
|
146
150
|
})
|
|
147
|
-
fastify.listen({ port: 0 }, err => {
|
|
148
|
-
t.error(err)
|
|
149
|
-
t.teardown(() => { fastify.close() })
|
|
150
151
|
|
|
152
|
+
fastify.listen({ port: 0 }, err => {
|
|
153
|
+
t.assert.ifError(err)
|
|
151
154
|
sget({
|
|
152
155
|
method: 'POST',
|
|
153
156
|
url: 'http://localhost:' + fastify.server.address().port,
|
|
@@ -155,30 +158,33 @@ test('request should be defined in onSend Hook on post request with content type
|
|
|
155
158
|
'content-type': 'application/json'
|
|
156
159
|
}
|
|
157
160
|
}, (err, response, body) => {
|
|
158
|
-
t.
|
|
161
|
+
t.assert.ifError(err)
|
|
159
162
|
// a 400 error is expected because of no body
|
|
160
|
-
t.
|
|
163
|
+
t.assert.strictEqual(response.statusCode, 400)
|
|
164
|
+
done()
|
|
161
165
|
})
|
|
162
166
|
})
|
|
163
167
|
})
|
|
164
168
|
|
|
165
|
-
test('request should be defined in onSend Hook on post request with content type application/x-www-form-urlencoded', t => {
|
|
169
|
+
test('request should be defined in onSend Hook on post request with content type application/x-www-form-urlencoded', (t, done) => {
|
|
166
170
|
t.plan(7)
|
|
167
171
|
const fastify = require('../..')()
|
|
168
172
|
|
|
173
|
+
t.after(() => { fastify.close() })
|
|
174
|
+
|
|
169
175
|
fastify.addHook('onSend', (request, reply, payload, done) => {
|
|
170
|
-
t.ok(request)
|
|
171
|
-
t.ok(request.raw)
|
|
172
|
-
t.ok(request.params)
|
|
173
|
-
t.ok(request.query)
|
|
176
|
+
t.assert.ok(request)
|
|
177
|
+
t.assert.ok(request.raw)
|
|
178
|
+
t.assert.ok(request.params)
|
|
179
|
+
t.assert.ok(request.query)
|
|
174
180
|
done()
|
|
175
181
|
})
|
|
176
182
|
fastify.post('/', (request, reply) => {
|
|
177
183
|
reply.send(200)
|
|
178
184
|
})
|
|
185
|
+
|
|
179
186
|
fastify.listen({ port: 0 }, err => {
|
|
180
|
-
t.
|
|
181
|
-
t.teardown(() => { fastify.close() })
|
|
187
|
+
t.assert.ifError(err)
|
|
182
188
|
|
|
183
189
|
sget({
|
|
184
190
|
method: 'POST',
|
|
@@ -187,30 +193,33 @@ test('request should be defined in onSend Hook on post request with content type
|
|
|
187
193
|
'content-type': 'application/x-www-form-urlencoded'
|
|
188
194
|
}
|
|
189
195
|
}, (err, response, body) => {
|
|
190
|
-
t.
|
|
196
|
+
t.assert.ifError(err)
|
|
191
197
|
// a 415 error is expected because of missing content type parser
|
|
192
|
-
t.
|
|
198
|
+
t.assert.strictEqual(response.statusCode, 415)
|
|
199
|
+
done()
|
|
193
200
|
})
|
|
194
201
|
})
|
|
195
202
|
})
|
|
196
203
|
|
|
197
|
-
test('request should be defined in onSend Hook on options request with content type application/x-www-form-urlencoded', t => {
|
|
204
|
+
test('request should be defined in onSend Hook on options request with content type application/x-www-form-urlencoded', (t, done) => {
|
|
198
205
|
t.plan(7)
|
|
199
206
|
const fastify = require('../..')()
|
|
200
207
|
|
|
208
|
+
t.after(() => { fastify.close() })
|
|
209
|
+
|
|
201
210
|
fastify.addHook('onSend', (request, reply, payload, done) => {
|
|
202
|
-
t.ok(request)
|
|
203
|
-
t.ok(request.raw)
|
|
204
|
-
t.ok(request.params)
|
|
205
|
-
t.ok(request.query)
|
|
211
|
+
t.assert.ok(request)
|
|
212
|
+
t.assert.ok(request.raw)
|
|
213
|
+
t.assert.ok(request.params)
|
|
214
|
+
t.assert.ok(request.query)
|
|
206
215
|
done()
|
|
207
216
|
})
|
|
208
217
|
fastify.options('/', (request, reply) => {
|
|
209
218
|
reply.send(200)
|
|
210
219
|
})
|
|
220
|
+
|
|
211
221
|
fastify.listen({ port: 0 }, err => {
|
|
212
|
-
t.
|
|
213
|
-
t.teardown(() => { fastify.close() })
|
|
222
|
+
t.assert.ifError(err)
|
|
214
223
|
|
|
215
224
|
sget({
|
|
216
225
|
method: 'OPTIONS',
|
|
@@ -219,14 +228,15 @@ test('request should be defined in onSend Hook on options request with content t
|
|
|
219
228
|
'content-type': 'application/x-www-form-urlencoded'
|
|
220
229
|
}
|
|
221
230
|
}, (err, response, body) => {
|
|
222
|
-
t.
|
|
231
|
+
t.assert.ifError(err)
|
|
223
232
|
// Body parsing skipped, so no body sent
|
|
224
|
-
t.
|
|
233
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
234
|
+
done()
|
|
225
235
|
})
|
|
226
236
|
})
|
|
227
237
|
})
|
|
228
238
|
|
|
229
|
-
test('request should respond with an error if an unserialized payload is sent inside an async handler', t => {
|
|
239
|
+
test('request should respond with an error if an unserialized payload is sent inside an async handler', (t, done) => {
|
|
230
240
|
t.plan(3)
|
|
231
241
|
|
|
232
242
|
const fastify = require('../..')()
|
|
@@ -240,13 +250,14 @@ test('request should respond with an error if an unserialized payload is sent in
|
|
|
240
250
|
method: 'GET',
|
|
241
251
|
url: '/'
|
|
242
252
|
}, (err, res) => {
|
|
243
|
-
t.
|
|
244
|
-
t.
|
|
245
|
-
t.
|
|
253
|
+
t.assert.ifError(err)
|
|
254
|
+
t.assert.strictEqual(res.statusCode, 500)
|
|
255
|
+
t.assert.deepStrictEqual(JSON.parse(res.payload), {
|
|
246
256
|
error: 'Internal Server Error',
|
|
247
257
|
code: 'FST_ERR_REP_INVALID_PAYLOAD_TYPE',
|
|
248
258
|
message: 'Attempted to send payload of invalid type \'object\'. Expected a string or Buffer.',
|
|
249
259
|
statusCode: 500
|
|
250
260
|
})
|
|
261
|
+
done()
|
|
251
262
|
})
|
|
252
263
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
const { hookRunnerGenerator, onSendHookRunner } = require('../../lib/hooks')
|
|
6
5
|
|
|
7
6
|
test('hookRunner - Basic', t => {
|
|
@@ -16,27 +15,27 @@ test('hookRunner - Basic', t => {
|
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
function fn1 (a, b, done) {
|
|
19
|
-
t.
|
|
20
|
-
t.
|
|
18
|
+
t.assert.strictEqual(a, 'a')
|
|
19
|
+
t.assert.strictEqual(b, 'b')
|
|
21
20
|
done()
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
function fn2 (a, b, done) {
|
|
25
|
-
t.
|
|
26
|
-
t.
|
|
24
|
+
t.assert.strictEqual(a, 'a')
|
|
25
|
+
t.assert.strictEqual(b, 'b')
|
|
27
26
|
done()
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
function fn3 (a, b, done) {
|
|
31
|
-
t.
|
|
32
|
-
t.
|
|
30
|
+
t.assert.strictEqual(a, 'a')
|
|
31
|
+
t.assert.strictEqual(b, 'b')
|
|
33
32
|
done()
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
function done (err, a, b) {
|
|
37
|
-
t.
|
|
38
|
-
t.
|
|
39
|
-
t.
|
|
36
|
+
t.assert.ifError(err)
|
|
37
|
+
t.assert.strictEqual(a, 'a')
|
|
38
|
+
t.assert.strictEqual(b, 'b')
|
|
40
39
|
}
|
|
41
40
|
})
|
|
42
41
|
|
|
@@ -52,25 +51,25 @@ test('hookRunner - In case of error should skip to done', t => {
|
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
function fn1 (a, b, done) {
|
|
55
|
-
t.
|
|
56
|
-
t.
|
|
54
|
+
t.assert.strictEqual(a, 'a')
|
|
55
|
+
t.assert.strictEqual(b, 'b')
|
|
57
56
|
done()
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
function fn2 (a, b, done) {
|
|
61
|
-
t.
|
|
62
|
-
t.
|
|
60
|
+
t.assert.strictEqual(a, 'a')
|
|
61
|
+
t.assert.strictEqual(b, 'b')
|
|
63
62
|
done(new Error('kaboom'))
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
function fn3 () {
|
|
67
|
-
t.fail('We should not be here')
|
|
66
|
+
t.assert.fail('We should not be here')
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
function done (err, a, b) {
|
|
71
|
-
t.
|
|
72
|
-
t.
|
|
73
|
-
t.
|
|
70
|
+
t.assert.strictEqual(err.message, 'kaboom')
|
|
71
|
+
t.assert.strictEqual(a, 'a')
|
|
72
|
+
t.assert.strictEqual(b, 'b')
|
|
74
73
|
}
|
|
75
74
|
})
|
|
76
75
|
|
|
@@ -86,25 +85,25 @@ test('hookRunner - Should handle throw', t => {
|
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
function fn1 (a, b, done) {
|
|
89
|
-
t.
|
|
90
|
-
t.
|
|
88
|
+
t.assert.strictEqual(a, 'a')
|
|
89
|
+
t.assert.strictEqual(b, 'b')
|
|
91
90
|
done()
|
|
92
91
|
}
|
|
93
92
|
|
|
94
93
|
function fn2 (a, b, done) {
|
|
95
|
-
t.
|
|
96
|
-
t.
|
|
94
|
+
t.assert.strictEqual(a, 'a')
|
|
95
|
+
t.assert.strictEqual(b, 'b')
|
|
97
96
|
throw new Error('kaboom')
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
function fn3 () {
|
|
101
|
-
t.fail('We should not be here')
|
|
100
|
+
t.assert.fail('We should not be here')
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
function done (err, a, b) {
|
|
105
|
-
t.
|
|
106
|
-
t.
|
|
107
|
-
t.
|
|
104
|
+
t.assert.strictEqual(err.message, 'kaboom')
|
|
105
|
+
t.assert.strictEqual(a, 'a')
|
|
106
|
+
t.assert.strictEqual(b, 'b')
|
|
108
107
|
}
|
|
109
108
|
})
|
|
110
109
|
|
|
@@ -120,27 +119,27 @@ test('hookRunner - Should handle promises', t => {
|
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
function fn1 (a, b) {
|
|
123
|
-
t.
|
|
124
|
-
t.
|
|
122
|
+
t.assert.strictEqual(a, 'a')
|
|
123
|
+
t.assert.strictEqual(b, 'b')
|
|
125
124
|
return Promise.resolve()
|
|
126
125
|
}
|
|
127
126
|
|
|
128
127
|
function fn2 (a, b) {
|
|
129
|
-
t.
|
|
130
|
-
t.
|
|
128
|
+
t.assert.strictEqual(a, 'a')
|
|
129
|
+
t.assert.strictEqual(b, 'b')
|
|
131
130
|
return Promise.resolve()
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
function fn3 (a, b) {
|
|
135
|
-
t.
|
|
136
|
-
t.
|
|
134
|
+
t.assert.strictEqual(a, 'a')
|
|
135
|
+
t.assert.strictEqual(b, 'b')
|
|
137
136
|
return Promise.resolve()
|
|
138
137
|
}
|
|
139
138
|
|
|
140
139
|
function done (err, a, b) {
|
|
141
|
-
t.
|
|
142
|
-
t.
|
|
143
|
-
t.
|
|
140
|
+
t.assert.ifError(err)
|
|
141
|
+
t.assert.strictEqual(a, 'a')
|
|
142
|
+
t.assert.strictEqual(b, 'b')
|
|
144
143
|
}
|
|
145
144
|
})
|
|
146
145
|
|
|
@@ -156,25 +155,25 @@ test('hookRunner - In case of error should skip to done (with promises)', t => {
|
|
|
156
155
|
}
|
|
157
156
|
|
|
158
157
|
function fn1 (a, b) {
|
|
159
|
-
t.
|
|
160
|
-
t.
|
|
158
|
+
t.assert.strictEqual(a, 'a')
|
|
159
|
+
t.assert.strictEqual(b, 'b')
|
|
161
160
|
return Promise.resolve()
|
|
162
161
|
}
|
|
163
162
|
|
|
164
163
|
function fn2 (a, b) {
|
|
165
|
-
t.
|
|
166
|
-
t.
|
|
164
|
+
t.assert.strictEqual(a, 'a')
|
|
165
|
+
t.assert.strictEqual(b, 'b')
|
|
167
166
|
return Promise.reject(new Error('kaboom'))
|
|
168
167
|
}
|
|
169
168
|
|
|
170
169
|
function fn3 () {
|
|
171
|
-
t.fail('We should not be here')
|
|
170
|
+
t.assert.fail('We should not be here')
|
|
172
171
|
}
|
|
173
172
|
|
|
174
173
|
function done (err, a, b) {
|
|
175
|
-
t.
|
|
176
|
-
t.
|
|
177
|
-
t.
|
|
174
|
+
t.assert.strictEqual(err.message, 'kaboom')
|
|
175
|
+
t.assert.strictEqual(a, 'a')
|
|
176
|
+
t.assert.strictEqual(b, 'b')
|
|
178
177
|
}
|
|
179
178
|
})
|
|
180
179
|
|
|
@@ -194,24 +193,24 @@ test('hookRunner - Be able to exit before its natural end', t => {
|
|
|
194
193
|
}
|
|
195
194
|
|
|
196
195
|
function fn1 (a, b, done) {
|
|
197
|
-
t.
|
|
198
|
-
t.
|
|
196
|
+
t.assert.strictEqual(a, 'a')
|
|
197
|
+
t.assert.strictEqual(b, 'b')
|
|
199
198
|
done()
|
|
200
199
|
}
|
|
201
200
|
|
|
202
201
|
function fn2 (a, b) {
|
|
203
|
-
t.
|
|
204
|
-
t.
|
|
202
|
+
t.assert.strictEqual(a, 'a')
|
|
203
|
+
t.assert.strictEqual(b, 'b')
|
|
205
204
|
shouldStop = true
|
|
206
205
|
return Promise.resolve()
|
|
207
206
|
}
|
|
208
207
|
|
|
209
208
|
function fn3 () {
|
|
210
|
-
t.fail('this should not be called')
|
|
209
|
+
t.assert.fail('this should not be called')
|
|
211
210
|
}
|
|
212
211
|
|
|
213
212
|
function done () {
|
|
214
|
-
t.fail('this should not be called')
|
|
213
|
+
t.assert.fail('this should not be called')
|
|
215
214
|
}
|
|
216
215
|
})
|
|
217
216
|
|
|
@@ -229,23 +228,23 @@ test('hookRunner - Promises that resolve to a value do not change the state', t
|
|
|
229
228
|
}
|
|
230
229
|
|
|
231
230
|
function fn1 (state, b, done) {
|
|
232
|
-
t.
|
|
231
|
+
t.assert.strictEqual(state, originalState)
|
|
233
232
|
return Promise.resolve(null)
|
|
234
233
|
}
|
|
235
234
|
|
|
236
235
|
function fn2 (state, b, done) {
|
|
237
|
-
t.
|
|
236
|
+
t.assert.strictEqual(state, originalState)
|
|
238
237
|
return Promise.resolve('string')
|
|
239
238
|
}
|
|
240
239
|
|
|
241
240
|
function fn3 (state, b, done) {
|
|
242
|
-
t.
|
|
241
|
+
t.assert.strictEqual(state, originalState)
|
|
243
242
|
return Promise.resolve({ object: true })
|
|
244
243
|
}
|
|
245
244
|
|
|
246
245
|
function done (err, state, b) {
|
|
247
|
-
t.
|
|
248
|
-
t.
|
|
246
|
+
t.assert.ifError(err)
|
|
247
|
+
t.assert.strictEqual(state, originalState)
|
|
249
248
|
}
|
|
250
249
|
})
|
|
251
250
|
|
|
@@ -259,31 +258,31 @@ test('onSendHookRunner - Basic', t => {
|
|
|
259
258
|
onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, originalPayload, done)
|
|
260
259
|
|
|
261
260
|
function fn1 (request, reply, payload, done) {
|
|
262
|
-
t.
|
|
263
|
-
t.
|
|
264
|
-
t.
|
|
261
|
+
t.assert.deepStrictEqual(request, originalRequest)
|
|
262
|
+
t.assert.deepStrictEqual(reply, originalReply)
|
|
263
|
+
t.assert.strictEqual(payload, originalPayload)
|
|
265
264
|
done()
|
|
266
265
|
}
|
|
267
266
|
|
|
268
267
|
function fn2 (request, reply, payload, done) {
|
|
269
|
-
t.
|
|
270
|
-
t.
|
|
271
|
-
t.
|
|
268
|
+
t.assert.deepStrictEqual(request, originalRequest)
|
|
269
|
+
t.assert.deepStrictEqual(reply, originalReply)
|
|
270
|
+
t.assert.strictEqual(payload, originalPayload)
|
|
272
271
|
done()
|
|
273
272
|
}
|
|
274
273
|
|
|
275
274
|
function fn3 (request, reply, payload, done) {
|
|
276
|
-
t.
|
|
277
|
-
t.
|
|
278
|
-
t.
|
|
275
|
+
t.assert.deepStrictEqual(request, originalRequest)
|
|
276
|
+
t.assert.deepStrictEqual(reply, originalReply)
|
|
277
|
+
t.assert.strictEqual(payload, originalPayload)
|
|
279
278
|
done()
|
|
280
279
|
}
|
|
281
280
|
|
|
282
281
|
function done (err, request, reply, payload) {
|
|
283
|
-
t.
|
|
284
|
-
t.
|
|
285
|
-
t.
|
|
286
|
-
t.
|
|
282
|
+
t.assert.ifError(err)
|
|
283
|
+
t.assert.deepStrictEqual(request, originalRequest)
|
|
284
|
+
t.assert.deepStrictEqual(reply, originalReply)
|
|
285
|
+
t.assert.strictEqual(payload, originalPayload)
|
|
287
286
|
}
|
|
288
287
|
})
|
|
289
288
|
|
|
@@ -300,25 +299,25 @@ test('onSendHookRunner - Can change the payload', t => {
|
|
|
300
299
|
onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done)
|
|
301
300
|
|
|
302
301
|
function fn1 (request, reply, payload, done) {
|
|
303
|
-
t.
|
|
302
|
+
t.assert.deepStrictEqual(payload, v1)
|
|
304
303
|
done(null, v2)
|
|
305
304
|
}
|
|
306
305
|
|
|
307
306
|
function fn2 (request, reply, payload, done) {
|
|
308
|
-
t.
|
|
307
|
+
t.assert.deepStrictEqual(payload, v2)
|
|
309
308
|
done(null, v3)
|
|
310
309
|
}
|
|
311
310
|
|
|
312
311
|
function fn3 (request, reply, payload, done) {
|
|
313
|
-
t.
|
|
312
|
+
t.assert.deepStrictEqual(payload, v3)
|
|
314
313
|
done(null, v4)
|
|
315
314
|
}
|
|
316
315
|
|
|
317
316
|
function done (err, request, reply, payload) {
|
|
318
|
-
t.
|
|
319
|
-
t.
|
|
320
|
-
t.
|
|
321
|
-
t.
|
|
317
|
+
t.assert.ifError(err)
|
|
318
|
+
t.assert.deepStrictEqual(request, originalRequest)
|
|
319
|
+
t.assert.deepStrictEqual(reply, originalReply)
|
|
320
|
+
t.assert.deepStrictEqual(payload, v4)
|
|
322
321
|
}
|
|
323
322
|
})
|
|
324
323
|
|
|
@@ -333,24 +332,24 @@ test('onSendHookRunner - In case of error should skip to done', t => {
|
|
|
333
332
|
onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done)
|
|
334
333
|
|
|
335
334
|
function fn1 (request, reply, payload, done) {
|
|
336
|
-
t.
|
|
335
|
+
t.assert.deepStrictEqual(payload, v1)
|
|
337
336
|
done(null, v2)
|
|
338
337
|
}
|
|
339
338
|
|
|
340
339
|
function fn2 (request, reply, payload, done) {
|
|
341
|
-
t.
|
|
340
|
+
t.assert.deepStrictEqual(payload, v2)
|
|
342
341
|
done(new Error('kaboom'))
|
|
343
342
|
}
|
|
344
343
|
|
|
345
344
|
function fn3 () {
|
|
346
|
-
t.fail('We should not be here')
|
|
345
|
+
t.assert.fail('We should not be here')
|
|
347
346
|
}
|
|
348
347
|
|
|
349
348
|
function done (err, request, reply, payload) {
|
|
350
|
-
t.
|
|
351
|
-
t.
|
|
352
|
-
t.
|
|
353
|
-
t.
|
|
349
|
+
t.assert.strictEqual(err.message, 'kaboom')
|
|
350
|
+
t.assert.deepStrictEqual(request, originalRequest)
|
|
351
|
+
t.assert.deepStrictEqual(reply, originalReply)
|
|
352
|
+
t.assert.deepStrictEqual(payload, v2)
|
|
354
353
|
}
|
|
355
354
|
})
|
|
356
355
|
|
|
@@ -367,25 +366,25 @@ test('onSendHookRunner - Should handle promises', t => {
|
|
|
367
366
|
onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done)
|
|
368
367
|
|
|
369
368
|
function fn1 (request, reply, payload) {
|
|
370
|
-
t.
|
|
369
|
+
t.assert.deepStrictEqual(payload, v1)
|
|
371
370
|
return Promise.resolve(v2)
|
|
372
371
|
}
|
|
373
372
|
|
|
374
373
|
function fn2 (request, reply, payload) {
|
|
375
|
-
t.
|
|
374
|
+
t.assert.deepStrictEqual(payload, v2)
|
|
376
375
|
return Promise.resolve(v3)
|
|
377
376
|
}
|
|
378
377
|
|
|
379
378
|
function fn3 (request, reply, payload) {
|
|
380
|
-
t.
|
|
379
|
+
t.assert.deepStrictEqual(payload, v3)
|
|
381
380
|
return Promise.resolve(v4)
|
|
382
381
|
}
|
|
383
382
|
|
|
384
383
|
function done (err, request, reply, payload) {
|
|
385
|
-
t.
|
|
386
|
-
t.
|
|
387
|
-
t.
|
|
388
|
-
t.
|
|
384
|
+
t.assert.ifError(err)
|
|
385
|
+
t.assert.deepStrictEqual(request, originalRequest)
|
|
386
|
+
t.assert.deepStrictEqual(reply, originalReply)
|
|
387
|
+
t.assert.deepStrictEqual(payload, v4)
|
|
389
388
|
}
|
|
390
389
|
})
|
|
391
390
|
|
|
@@ -400,24 +399,24 @@ test('onSendHookRunner - In case of error should skip to done (with promises)',
|
|
|
400
399
|
onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done)
|
|
401
400
|
|
|
402
401
|
function fn1 (request, reply, payload) {
|
|
403
|
-
t.
|
|
402
|
+
t.assert.deepStrictEqual(payload, v1)
|
|
404
403
|
return Promise.resolve(v2)
|
|
405
404
|
}
|
|
406
405
|
|
|
407
406
|
function fn2 (request, reply, payload) {
|
|
408
|
-
t.
|
|
407
|
+
t.assert.deepStrictEqual(payload, v2)
|
|
409
408
|
return Promise.reject(new Error('kaboom'))
|
|
410
409
|
}
|
|
411
410
|
|
|
412
411
|
function fn3 () {
|
|
413
|
-
t.fail('We should not be here')
|
|
412
|
+
t.assert.fail('We should not be here')
|
|
414
413
|
}
|
|
415
414
|
|
|
416
415
|
function done (err, request, reply, payload) {
|
|
417
|
-
t.
|
|
418
|
-
t.
|
|
419
|
-
t.
|
|
420
|
-
t.
|
|
416
|
+
t.assert.strictEqual(err.message, 'kaboom')
|
|
417
|
+
t.assert.deepStrictEqual(request, originalRequest)
|
|
418
|
+
t.assert.deepStrictEqual(reply, originalReply)
|
|
419
|
+
t.assert.deepStrictEqual(payload, v2)
|
|
421
420
|
}
|
|
422
421
|
})
|
|
423
422
|
|
|
@@ -432,19 +431,19 @@ test('onSendHookRunner - Be able to exit before its natural end', t => {
|
|
|
432
431
|
onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done)
|
|
433
432
|
|
|
434
433
|
function fn1 (request, reply, payload, done) {
|
|
435
|
-
t.
|
|
434
|
+
t.assert.deepStrictEqual(payload, v1)
|
|
436
435
|
done(null, v2)
|
|
437
436
|
}
|
|
438
437
|
|
|
439
438
|
function fn2 (request, reply, payload) {
|
|
440
|
-
t.
|
|
439
|
+
t.assert.deepStrictEqual(payload, v2)
|
|
441
440
|
}
|
|
442
441
|
|
|
443
442
|
function fn3 () {
|
|
444
|
-
t.fail('this should not be called')
|
|
443
|
+
t.assert.fail('this should not be called')
|
|
445
444
|
}
|
|
446
445
|
|
|
447
446
|
function done () {
|
|
448
|
-
t.fail('this should not be called')
|
|
447
|
+
t.assert.fail('this should not be called')
|
|
449
448
|
}
|
|
450
449
|
})
|