fastify 3.9.2 → 3.12.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/GOVERNANCE.md +1 -1
- package/README.md +12 -8
- package/SECURITY.md +3 -3
- package/docs/ContentTypeParser.md +1 -1
- package/docs/Ecosystem.md +16 -6
- package/docs/Encapsulation.md +5 -2
- package/docs/Fluent-Schema.md +4 -4
- package/docs/Getting-Started.md +1 -1
- package/docs/Hooks.md +28 -1
- package/docs/Lifecycle.md +8 -1
- package/docs/Middleware.md +5 -4
- package/docs/Reply.md +13 -4
- package/docs/Routes.md +4 -3
- package/docs/Server.md +78 -4
- package/docs/Serverless.md +23 -51
- package/docs/TypeScript.md +35 -18
- package/docs/Validation-and-Serialization.md +4 -4
- package/docs/Write-Plugin.md +4 -4
- package/examples/hooks-benchmark.js +12 -12
- package/examples/hooks.js +16 -16
- package/examples/plugin.js +2 -2
- package/examples/route-prefix.js +4 -4
- package/fastify.d.ts +16 -1
- package/fastify.js +33 -16
- package/isolate-0x426d1e0-1227-v8.log +4019 -0
- package/isolate-0x4d4c7e0-1988-v8.log +4081 -0
- package/lib/errors.js +6 -0
- package/lib/headRoute.js +31 -0
- package/lib/pluginOverride.js +5 -5
- package/lib/pluginUtils.js +7 -6
- package/lib/reply.js +14 -2
- package/lib/reqIdGenFactory.js +5 -0
- package/lib/request.js +1 -1
- package/lib/route.js +66 -41
- package/lib/schema-compilers.js +5 -3
- package/lib/schema-controller.js +106 -0
- package/lib/schemas.js +14 -24
- package/lib/server.js +1 -0
- package/lib/symbols.js +1 -3
- package/lib/warnings.js +2 -0
- package/lib/wrapThenable.js +2 -1
- package/package.json +25 -21
- package/test/404s.test.js +120 -120
- package/test/500s.test.js +8 -8
- package/test/async-await.test.js +29 -1
- package/test/close.test.js +8 -8
- package/test/context-config.test.js +52 -0
- package/test/custom-parser.test.js +8 -8
- package/test/decorator.test.js +49 -49
- package/test/default-route.test.js +43 -0
- package/test/fastify-instance.test.js +2 -2
- package/test/fluent-schema.test.js +3 -3
- package/test/handler-context.test.js +2 -2
- package/test/hooks-async.test.js +3 -3
- package/test/hooks.on-ready.test.js +12 -12
- package/test/hooks.test.js +75 -32
- package/test/http2/closing.test.js +23 -1
- package/test/inject.test.js +6 -6
- package/test/input-validation.js +2 -2
- package/test/internals/hookRunner.test.js +50 -50
- package/test/internals/reply.test.js +47 -22
- package/test/internals/request.test.js +3 -9
- package/test/internals/version.test.js +2 -2
- package/test/logger.test.js +30 -30
- package/test/middleware.test.js +4 -4
- package/test/plugin.helper.js +2 -2
- package/test/plugin.test.js +154 -99
- package/test/register.test.js +11 -11
- package/test/request-error.test.js +2 -2
- package/test/route-hooks.test.js +24 -24
- package/test/route-prefix.test.js +81 -52
- package/test/route.test.js +568 -0
- package/test/schema-feature.test.js +168 -38
- package/test/schema-serialization.test.js +4 -4
- package/test/schema-special-usage.test.js +136 -0
- package/test/schema-validation.test.js +7 -7
- package/test/skip-reply-send.test.js +315 -0
- package/test/stream.test.js +6 -6
- package/test/throw.test.js +4 -4
- package/test/types/instance.test-d.ts +5 -3
- package/test/types/plugin.test-d.ts +7 -7
- package/test/types/reply.test-d.ts +1 -0
- package/test/types/schema.test-d.ts +15 -0
- package/test/validation-error-handling.test.js +5 -5
- package/test/versioned-routes.test.js +1 -1
- package/types/content-type-parser.d.ts +1 -1
- package/types/instance.d.ts +6 -3
- package/types/plugin.d.ts +1 -1
- package/types/reply.d.ts +1 -0
- package/types/route.d.ts +8 -2
- package/types/schema.d.ts +3 -0
- package/test/skip-reply-send.js +0 -98
|
@@ -90,22 +90,22 @@ t.test('listen and onReady order', async t => {
|
|
|
90
90
|
const fastify = Fastify()
|
|
91
91
|
let order = 0
|
|
92
92
|
|
|
93
|
-
fastify.register((instance, opts,
|
|
93
|
+
fastify.register((instance, opts, done) => {
|
|
94
94
|
instance.ready(checkOrder.bind(null, 0))
|
|
95
95
|
instance.addHook('onReady', checkOrder.bind(null, 4))
|
|
96
96
|
|
|
97
|
-
instance.register((subinstance, opts,
|
|
97
|
+
instance.register((subinstance, opts, done) => {
|
|
98
98
|
subinstance.ready(checkOrder.bind(null, 1))
|
|
99
99
|
subinstance.addHook('onReady', checkOrder.bind(null, 5))
|
|
100
100
|
|
|
101
|
-
subinstance.register((realSubInstance, opts,
|
|
101
|
+
subinstance.register((realSubInstance, opts, done) => {
|
|
102
102
|
realSubInstance.ready(checkOrder.bind(null, 2))
|
|
103
103
|
realSubInstance.addHook('onReady', checkOrder.bind(null, 6))
|
|
104
|
-
|
|
104
|
+
done()
|
|
105
105
|
})
|
|
106
|
-
|
|
106
|
+
done()
|
|
107
107
|
})
|
|
108
|
-
|
|
108
|
+
done()
|
|
109
109
|
})
|
|
110
110
|
|
|
111
111
|
fastify.addHook('onReady', checkOrder.bind(null, 3))
|
|
@@ -347,19 +347,19 @@ t.test('ready return registered', t => {
|
|
|
347
347
|
t.plan(4)
|
|
348
348
|
const fastify = Fastify()
|
|
349
349
|
|
|
350
|
-
fastify.register((one, opts,
|
|
350
|
+
fastify.register((one, opts, done) => {
|
|
351
351
|
one.ready().then(itself => { t.deepEquals(itself, one) })
|
|
352
|
-
|
|
352
|
+
done()
|
|
353
353
|
})
|
|
354
354
|
|
|
355
|
-
fastify.register((two, opts,
|
|
355
|
+
fastify.register((two, opts, done) => {
|
|
356
356
|
two.ready().then(itself => { t.deepEquals(itself, two) })
|
|
357
357
|
|
|
358
|
-
two.register((twoDotOne, opts,
|
|
358
|
+
two.register((twoDotOne, opts, done) => {
|
|
359
359
|
twoDotOne.ready().then(itself => { t.deepEquals(itself, twoDotOne) })
|
|
360
|
-
|
|
360
|
+
done()
|
|
361
361
|
})
|
|
362
|
-
|
|
362
|
+
done()
|
|
363
363
|
})
|
|
364
364
|
|
|
365
365
|
fastify.ready()
|
package/test/hooks.test.js
CHANGED
|
@@ -429,14 +429,14 @@ test('onRoute hook should be called (encapsulation support) / 4', t => {
|
|
|
429
429
|
t.pass()
|
|
430
430
|
})
|
|
431
431
|
|
|
432
|
-
fastify.register((instance, opts,
|
|
432
|
+
fastify.register((instance, opts, done) => {
|
|
433
433
|
instance.addHook('onRoute', () => {
|
|
434
434
|
t.pass()
|
|
435
435
|
})
|
|
436
436
|
instance.get('/nested', opts, function (req, reply) {
|
|
437
437
|
reply.send()
|
|
438
438
|
})
|
|
439
|
-
|
|
439
|
+
done()
|
|
440
440
|
})
|
|
441
441
|
|
|
442
442
|
fastify.get('/', function (req, reply) {
|
|
@@ -456,14 +456,14 @@ test('onRoute hook should be called (encapsulation support) / 5', t => {
|
|
|
456
456
|
reply.send()
|
|
457
457
|
})
|
|
458
458
|
|
|
459
|
-
fastify.register((instance, opts,
|
|
459
|
+
fastify.register((instance, opts, done) => {
|
|
460
460
|
instance.addHook('onRoute', () => {
|
|
461
461
|
t.pass()
|
|
462
462
|
})
|
|
463
463
|
instance.get('/nested', opts, function (req, reply) {
|
|
464
464
|
reply.send()
|
|
465
465
|
})
|
|
466
|
-
|
|
466
|
+
done()
|
|
467
467
|
})
|
|
468
468
|
|
|
469
469
|
fastify.get('/second', function (req, reply) {
|
|
@@ -664,12 +664,55 @@ test('onRoute hook should preserve handler function in options of shorthand rout
|
|
|
664
664
|
})
|
|
665
665
|
})
|
|
666
666
|
|
|
667
|
+
// issue ref https://github.com/fastify/fastify-compress/issues/140
|
|
668
|
+
test('onRoute hook should be called once when prefixTrailingSlash', t => {
|
|
669
|
+
t.plan(3)
|
|
670
|
+
|
|
671
|
+
let onRouteCalled = 0
|
|
672
|
+
let routePatched = 0
|
|
673
|
+
|
|
674
|
+
const fastify = Fastify({ ignoreTrailingSlash: false })
|
|
675
|
+
|
|
676
|
+
// a plugin that patches route options, similar to fastify-compress
|
|
677
|
+
fastify.register(fp(function myPlugin (instance, opts, next) {
|
|
678
|
+
function patchTheRoute () {
|
|
679
|
+
routePatched++
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
instance.addHook('onRoute', function (routeOptions) {
|
|
683
|
+
onRouteCalled++
|
|
684
|
+
patchTheRoute(routeOptions)
|
|
685
|
+
})
|
|
686
|
+
|
|
687
|
+
next()
|
|
688
|
+
}))
|
|
689
|
+
|
|
690
|
+
fastify.register(function routes (instance, opts, next) {
|
|
691
|
+
instance.route({
|
|
692
|
+
method: 'GET',
|
|
693
|
+
url: '/',
|
|
694
|
+
prefixTrailingSlash: 'both',
|
|
695
|
+
handler: (req, reply) => {
|
|
696
|
+
reply.send({ hello: 'world' })
|
|
697
|
+
}
|
|
698
|
+
})
|
|
699
|
+
|
|
700
|
+
next()
|
|
701
|
+
}, { prefix: '/prefix' })
|
|
702
|
+
|
|
703
|
+
fastify.ready(err => {
|
|
704
|
+
t.error(err)
|
|
705
|
+
t.is(onRouteCalled, 1) // onRoute hook was called once
|
|
706
|
+
t.is(routePatched, 1) // and plugin acted once and avoided redundaunt route patching
|
|
707
|
+
})
|
|
708
|
+
})
|
|
709
|
+
|
|
667
710
|
test('onRoute hook should able to change the route url', t => {
|
|
668
711
|
t.plan(5)
|
|
669
712
|
|
|
670
713
|
const fastify = Fastify()
|
|
671
714
|
|
|
672
|
-
fastify.register((instance, opts,
|
|
715
|
+
fastify.register((instance, opts, done) => {
|
|
673
716
|
instance.addHook('onRoute', (route) => {
|
|
674
717
|
t.strictEqual(route.url, '/föö')
|
|
675
718
|
route.url = encodeURI(route.url)
|
|
@@ -679,7 +722,7 @@ test('onRoute hook should able to change the route url', t => {
|
|
|
679
722
|
reply.send('here /föö')
|
|
680
723
|
})
|
|
681
724
|
|
|
682
|
-
|
|
725
|
+
done()
|
|
683
726
|
})
|
|
684
727
|
|
|
685
728
|
fastify.listen(0, err => {
|
|
@@ -701,14 +744,14 @@ test('onRoute hook that throws should be caught ', t => {
|
|
|
701
744
|
t.plan(1)
|
|
702
745
|
const fastify = Fastify()
|
|
703
746
|
|
|
704
|
-
fastify.register((instance, opts,
|
|
747
|
+
fastify.register((instance, opts, done) => {
|
|
705
748
|
instance.addHook('onRoute', () => {
|
|
706
749
|
throw new Error('snap')
|
|
707
750
|
})
|
|
708
751
|
instance.get('/', opts, function (req, reply) {
|
|
709
752
|
reply.send()
|
|
710
753
|
})
|
|
711
|
-
|
|
754
|
+
done()
|
|
712
755
|
})
|
|
713
756
|
|
|
714
757
|
fastify.ready(err => {
|
|
@@ -726,17 +769,17 @@ test('onRoute hook with many prefix', t => {
|
|
|
726
769
|
{ routePath: '/aPath', prefix: '/one', url: '/one/aPath' }
|
|
727
770
|
]
|
|
728
771
|
|
|
729
|
-
fastify.register((instance, opts,
|
|
772
|
+
fastify.register((instance, opts, done) => {
|
|
730
773
|
instance.addHook('onRoute', (route) => {
|
|
731
774
|
t.like(route, onRouteChecks.pop())
|
|
732
775
|
})
|
|
733
776
|
instance.route({ method: 'GET', url: '/aPath', handler })
|
|
734
777
|
|
|
735
|
-
instance.register((instance, opts,
|
|
778
|
+
instance.register((instance, opts, done) => {
|
|
736
779
|
instance.route({ method: 'GET', path: '/anotherPath', handler })
|
|
737
|
-
|
|
780
|
+
done()
|
|
738
781
|
}, { prefix: '/two' })
|
|
739
|
-
|
|
782
|
+
done()
|
|
740
783
|
}, { prefix: '/one' })
|
|
741
784
|
|
|
742
785
|
fastify.ready(err => { t.error(err) })
|
|
@@ -1619,7 +1662,7 @@ test('preHandler respond with a stream', t => {
|
|
|
1619
1662
|
})
|
|
1620
1663
|
|
|
1621
1664
|
// we are calling `reply.send` inside the `preHandler` hook with a stream,
|
|
1622
|
-
// this triggers the `onSend` hook event if `
|
|
1665
|
+
// this triggers the `onSend` hook event if `preHandler` has not yet finished
|
|
1623
1666
|
const order = [1, 2]
|
|
1624
1667
|
|
|
1625
1668
|
fastify.addHook('preHandler', (req, reply, done) => {
|
|
@@ -2941,8 +2984,8 @@ test('onRegister hook should be called / 1', t => {
|
|
|
2941
2984
|
})
|
|
2942
2985
|
|
|
2943
2986
|
const pluginOpts = { prefix: 'hello', custom: 'world' }
|
|
2944
|
-
fastify.register((instance, opts,
|
|
2945
|
-
|
|
2987
|
+
fastify.register((instance, opts, done) => {
|
|
2988
|
+
done()
|
|
2946
2989
|
}, pluginOpts)
|
|
2947
2990
|
|
|
2948
2991
|
fastify.ready(err => { t.error(err) })
|
|
@@ -2957,15 +3000,15 @@ test('onRegister hook should be called / 2', t => {
|
|
|
2957
3000
|
t.ok(instance.addHook)
|
|
2958
3001
|
})
|
|
2959
3002
|
|
|
2960
|
-
fastify.register((instance, opts,
|
|
2961
|
-
instance.register((instance, opts,
|
|
2962
|
-
|
|
3003
|
+
fastify.register((instance, opts, done) => {
|
|
3004
|
+
instance.register((instance, opts, done) => {
|
|
3005
|
+
done()
|
|
2963
3006
|
})
|
|
2964
|
-
|
|
3007
|
+
done()
|
|
2965
3008
|
})
|
|
2966
3009
|
|
|
2967
|
-
fastify.register((instance, opts,
|
|
2968
|
-
|
|
3010
|
+
fastify.register((instance, opts, done) => {
|
|
3011
|
+
done()
|
|
2969
3012
|
})
|
|
2970
3013
|
|
|
2971
3014
|
fastify.ready(err => {
|
|
@@ -2983,20 +3026,20 @@ test('onRegister hook should be called / 3', t => {
|
|
|
2983
3026
|
instance.data = instance.data.slice()
|
|
2984
3027
|
})
|
|
2985
3028
|
|
|
2986
|
-
fastify.register((instance, opts,
|
|
3029
|
+
fastify.register((instance, opts, done) => {
|
|
2987
3030
|
instance.data.push(1)
|
|
2988
|
-
instance.register((instance, opts,
|
|
3031
|
+
instance.register((instance, opts, done) => {
|
|
2989
3032
|
instance.data.push(2)
|
|
2990
3033
|
t.deepEqual(instance.data, [1, 2])
|
|
2991
|
-
|
|
3034
|
+
done()
|
|
2992
3035
|
})
|
|
2993
3036
|
t.deepEqual(instance.data, [1])
|
|
2994
|
-
|
|
3037
|
+
done()
|
|
2995
3038
|
})
|
|
2996
3039
|
|
|
2997
|
-
fastify.register((instance, opts,
|
|
3040
|
+
fastify.register((instance, opts, done) => {
|
|
2998
3041
|
t.deepEqual(instance.data, [])
|
|
2999
|
-
|
|
3042
|
+
done()
|
|
3000
3043
|
})
|
|
3001
3044
|
|
|
3002
3045
|
fastify.ready(err => {
|
|
@@ -3008,8 +3051,8 @@ test('onRegister hook should be called (encapsulation)', t => {
|
|
|
3008
3051
|
t.plan(1)
|
|
3009
3052
|
const fastify = Fastify()
|
|
3010
3053
|
|
|
3011
|
-
function plugin (instance, opts,
|
|
3012
|
-
|
|
3054
|
+
function plugin (instance, opts, done) {
|
|
3055
|
+
done()
|
|
3013
3056
|
}
|
|
3014
3057
|
plugin[Symbol.for('skip-override')] = true
|
|
3015
3058
|
|
|
@@ -3051,7 +3094,7 @@ test('reply.send should throw if undefined error is thrown', t => {
|
|
|
3051
3094
|
t.plan(3)
|
|
3052
3095
|
const fastify = Fastify()
|
|
3053
3096
|
|
|
3054
|
-
fastify.addHook('onRequest', function (req, reply,
|
|
3097
|
+
fastify.addHook('onRequest', function (req, reply, done) {
|
|
3055
3098
|
return Promise.reject()
|
|
3056
3099
|
})
|
|
3057
3100
|
|
|
@@ -3078,9 +3121,9 @@ test('onTimeout should be triggered', t => {
|
|
|
3078
3121
|
t.plan(6)
|
|
3079
3122
|
const fastify = Fastify({ connectionTimeout: 500 })
|
|
3080
3123
|
|
|
3081
|
-
fastify.addHook('onTimeout', function (req, res,
|
|
3124
|
+
fastify.addHook('onTimeout', function (req, res, done) {
|
|
3082
3125
|
t.ok('called', 'onTimeout')
|
|
3083
|
-
|
|
3126
|
+
done()
|
|
3084
3127
|
})
|
|
3085
3128
|
|
|
3086
3129
|
fastify.get('/', async (req, reply) => {
|
|
@@ -4,9 +4,11 @@ const t = require('tap')
|
|
|
4
4
|
const Fastify = require('../..')
|
|
5
5
|
const http2 = require('http2')
|
|
6
6
|
const semver = require('semver')
|
|
7
|
+
const fs = require('fs')
|
|
8
|
+
const path = require('path')
|
|
7
9
|
const { promisify } = require('util')
|
|
8
10
|
const connect = promisify(http2.connect)
|
|
9
|
-
const once = require('events
|
|
11
|
+
const { once } = require('events')
|
|
10
12
|
|
|
11
13
|
t.test('http/2 request while fastify closing', t => {
|
|
12
14
|
let fastify
|
|
@@ -119,6 +121,26 @@ t.test('http/2 closes successfully with async await', { skip: semver.lt(process.
|
|
|
119
121
|
await fastify.close()
|
|
120
122
|
})
|
|
121
123
|
|
|
124
|
+
// Skipped because there is likely a bug on Node 8.
|
|
125
|
+
t.test('https/2 closes successfully with async await', { skip: semver.lt(process.versions.node, '10.15.0') }, async t => {
|
|
126
|
+
const fastify = Fastify({
|
|
127
|
+
http2SessionTimeout: 100,
|
|
128
|
+
http2: true,
|
|
129
|
+
https: {
|
|
130
|
+
key: fs.readFileSync(path.join(__dirname, '..', 'https', 'fastify.key')),
|
|
131
|
+
cert: fs.readFileSync(path.join(__dirname, '..', 'https', 'fastify.cert'))
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
await fastify.listen(0)
|
|
136
|
+
|
|
137
|
+
const url = `http://127.0.0.1:${fastify.server.address().port}`
|
|
138
|
+
const session = await connect(url)
|
|
139
|
+
// An error might or might not happen, as it's OS dependent.
|
|
140
|
+
session.on('error', () => {})
|
|
141
|
+
await fastify.close()
|
|
142
|
+
})
|
|
143
|
+
|
|
122
144
|
// Skipped because there is likely a bug on Node 8.
|
|
123
145
|
t.test('http/2 server side session emits a timeout event', { skip: semver.lt(process.versions.node, '10.15.0') }, async t => {
|
|
124
146
|
let _resolve
|
package/test/inject.test.js
CHANGED
|
@@ -19,12 +19,12 @@ test('should wait for the ready event', t => {
|
|
|
19
19
|
const fastify = Fastify()
|
|
20
20
|
const payload = { hello: 'world' }
|
|
21
21
|
|
|
22
|
-
fastify.register((instance, opts,
|
|
22
|
+
fastify.register((instance, opts, done) => {
|
|
23
23
|
instance.get('/', (req, reply) => {
|
|
24
24
|
reply.send(payload)
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
-
setTimeout(
|
|
27
|
+
setTimeout(done, 500)
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
fastify.inject({
|
|
@@ -311,8 +311,8 @@ test('should reject in error case', t => {
|
|
|
311
311
|
const fastify = Fastify()
|
|
312
312
|
|
|
313
313
|
const error = new Error('DOOM!')
|
|
314
|
-
fastify.register((instance, opts,
|
|
315
|
-
setTimeout(
|
|
314
|
+
fastify.register((instance, opts, done) => {
|
|
315
|
+
setTimeout(done, 500, error)
|
|
316
316
|
})
|
|
317
317
|
|
|
318
318
|
fastify.inject({
|
|
@@ -444,8 +444,8 @@ test('should support builder-style injection with non-ready app', async (t) => {
|
|
|
444
444
|
test('should handle errors in builder-style injection correctly', async (t) => {
|
|
445
445
|
t.plan(2)
|
|
446
446
|
const fastify = Fastify()
|
|
447
|
-
fastify.register((instance, opts,
|
|
448
|
-
|
|
447
|
+
fastify.register((instance, opts, done) => {
|
|
448
|
+
done(new Error('Kaboom'))
|
|
449
449
|
})
|
|
450
450
|
|
|
451
451
|
try {
|
package/test/input-validation.js
CHANGED
|
@@ -94,7 +94,7 @@ module.exports.payloadMethod = function (method, t) {
|
|
|
94
94
|
reply.send(req.body)
|
|
95
95
|
})
|
|
96
96
|
|
|
97
|
-
fastify.register(function (fastify2, opts,
|
|
97
|
+
fastify.register(function (fastify2, opts, done) {
|
|
98
98
|
fastify2.setValidatorCompiler(function schema ({ schema, method, url, httpPart }) {
|
|
99
99
|
return body => ({ error: new Error('From custom schema compiler!') })
|
|
100
100
|
})
|
|
@@ -125,7 +125,7 @@ module.exports.payloadMethod = function (method, t) {
|
|
|
125
125
|
}
|
|
126
126
|
fastify2[loMethod]('/plugin/custom', optsWithCustomValidator2, (req, reply) => reply.send({ hello: 'never here!' }))
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
done()
|
|
129
129
|
})
|
|
130
130
|
t.pass()
|
|
131
131
|
} catch (e) {
|
|
@@ -9,26 +9,26 @@ test('hookRunner - Basic', t => {
|
|
|
9
9
|
|
|
10
10
|
hookRunner([fn1, fn2, fn3], iterator, 'a', 'b', done)
|
|
11
11
|
|
|
12
|
-
function iterator (fn, a, b,
|
|
13
|
-
return fn(a, b,
|
|
12
|
+
function iterator (fn, a, b, done) {
|
|
13
|
+
return fn(a, b, done)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
function fn1 (a, b,
|
|
16
|
+
function fn1 (a, b, done) {
|
|
17
17
|
t.strictEqual(a, 'a')
|
|
18
18
|
t.strictEqual(b, 'b')
|
|
19
|
-
|
|
19
|
+
done()
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
function fn2 (a, b,
|
|
22
|
+
function fn2 (a, b, done) {
|
|
23
23
|
t.strictEqual(a, 'a')
|
|
24
24
|
t.strictEqual(b, 'b')
|
|
25
|
-
|
|
25
|
+
done()
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function fn3 (a, b,
|
|
28
|
+
function fn3 (a, b, done) {
|
|
29
29
|
t.strictEqual(a, 'a')
|
|
30
30
|
t.strictEqual(b, 'b')
|
|
31
|
-
|
|
31
|
+
done()
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function done (err, a, b) {
|
|
@@ -43,20 +43,20 @@ test('hookRunner - In case of error should skip to done', t => {
|
|
|
43
43
|
|
|
44
44
|
hookRunner([fn1, fn2, fn3], iterator, 'a', 'b', done)
|
|
45
45
|
|
|
46
|
-
function iterator (fn, a, b,
|
|
47
|
-
return fn(a, b,
|
|
46
|
+
function iterator (fn, a, b, done) {
|
|
47
|
+
return fn(a, b, done)
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
function fn1 (a, b,
|
|
50
|
+
function fn1 (a, b, done) {
|
|
51
51
|
t.strictEqual(a, 'a')
|
|
52
52
|
t.strictEqual(b, 'b')
|
|
53
|
-
|
|
53
|
+
done()
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
function fn2 (a, b,
|
|
56
|
+
function fn2 (a, b, done) {
|
|
57
57
|
t.strictEqual(a, 'a')
|
|
58
58
|
t.strictEqual(b, 'b')
|
|
59
|
-
|
|
59
|
+
done(new Error('kaboom'))
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
function fn3 () {
|
|
@@ -75,17 +75,17 @@ test('hookRunner - Should handle throw', t => {
|
|
|
75
75
|
|
|
76
76
|
hookRunner([fn1, fn2, fn3], iterator, 'a', 'b', done)
|
|
77
77
|
|
|
78
|
-
function iterator (fn, a, b,
|
|
79
|
-
return fn(a, b,
|
|
78
|
+
function iterator (fn, a, b, done) {
|
|
79
|
+
return fn(a, b, done)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
function fn1 (a, b,
|
|
82
|
+
function fn1 (a, b, done) {
|
|
83
83
|
t.strictEqual(a, 'a')
|
|
84
84
|
t.strictEqual(b, 'b')
|
|
85
|
-
|
|
85
|
+
done()
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
function fn2 (a, b,
|
|
88
|
+
function fn2 (a, b, done) {
|
|
89
89
|
t.strictEqual(a, 'a')
|
|
90
90
|
t.strictEqual(b, 'b')
|
|
91
91
|
throw new Error('kaboom')
|
|
@@ -107,8 +107,8 @@ test('hookRunner - Should handle promises', t => {
|
|
|
107
107
|
|
|
108
108
|
hookRunner([fn1, fn2, fn3], iterator, 'a', 'b', done)
|
|
109
109
|
|
|
110
|
-
function iterator (fn, a, b,
|
|
111
|
-
return fn(a, b,
|
|
110
|
+
function iterator (fn, a, b, done) {
|
|
111
|
+
return fn(a, b, done)
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
function fn1 (a, b) {
|
|
@@ -141,8 +141,8 @@ test('hookRunner - In case of error should skip to done (with promises)', t => {
|
|
|
141
141
|
|
|
142
142
|
hookRunner([fn1, fn2, fn3], iterator, 'a', 'b', done)
|
|
143
143
|
|
|
144
|
-
function iterator (fn, a, b,
|
|
145
|
-
return fn(a, b,
|
|
144
|
+
function iterator (fn, a, b, done) {
|
|
145
|
+
return fn(a, b, done)
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
function fn1 (a, b) {
|
|
@@ -174,17 +174,17 @@ test('hookRunner - Be able to exit before its natural end', t => {
|
|
|
174
174
|
let shouldStop = false
|
|
175
175
|
hookRunner([fn1, fn2, fn3], iterator, 'a', 'b', done)
|
|
176
176
|
|
|
177
|
-
function iterator (fn, a, b,
|
|
177
|
+
function iterator (fn, a, b, done) {
|
|
178
178
|
if (shouldStop) {
|
|
179
179
|
return undefined
|
|
180
180
|
}
|
|
181
|
-
return fn(a, b,
|
|
181
|
+
return fn(a, b, done)
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
function fn1 (a, b,
|
|
184
|
+
function fn1 (a, b, done) {
|
|
185
185
|
t.strictEqual(a, 'a')
|
|
186
186
|
t.strictEqual(b, 'b')
|
|
187
|
-
|
|
187
|
+
done()
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
function fn2 (a, b) {
|
|
@@ -210,21 +210,21 @@ test('hookRunner - Promises that resolve to a value do not change the state', t
|
|
|
210
210
|
|
|
211
211
|
hookRunner([fn1, fn2, fn3], iterator, originalState, 'b', done)
|
|
212
212
|
|
|
213
|
-
function iterator (fn, state, b,
|
|
214
|
-
return fn(state, b,
|
|
213
|
+
function iterator (fn, state, b, done) {
|
|
214
|
+
return fn(state, b, done)
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
function fn1 (state, b,
|
|
217
|
+
function fn1 (state, b, done) {
|
|
218
218
|
t.strictEqual(state, originalState)
|
|
219
219
|
return Promise.resolve(null)
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
function fn2 (state, b,
|
|
222
|
+
function fn2 (state, b, done) {
|
|
223
223
|
t.strictEqual(state, originalState)
|
|
224
224
|
return Promise.resolve('string')
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
function fn3 (state, b,
|
|
227
|
+
function fn3 (state, b, done) {
|
|
228
228
|
t.strictEqual(state, originalState)
|
|
229
229
|
return Promise.resolve({ object: true })
|
|
230
230
|
}
|
|
@@ -244,25 +244,25 @@ test('onSendHookRunner - Basic', t => {
|
|
|
244
244
|
|
|
245
245
|
onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, originalPayload, done)
|
|
246
246
|
|
|
247
|
-
function fn1 (request, reply, payload,
|
|
247
|
+
function fn1 (request, reply, payload, done) {
|
|
248
248
|
t.deepEqual(request, originalRequest)
|
|
249
249
|
t.deepEqual(reply, originalReply)
|
|
250
250
|
t.strictEqual(payload, originalPayload)
|
|
251
|
-
|
|
251
|
+
done()
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
function fn2 (request, reply, payload,
|
|
254
|
+
function fn2 (request, reply, payload, done) {
|
|
255
255
|
t.deepEqual(request, originalRequest)
|
|
256
256
|
t.deepEqual(reply, originalReply)
|
|
257
257
|
t.strictEqual(payload, originalPayload)
|
|
258
|
-
|
|
258
|
+
done()
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
function fn3 (request, reply, payload,
|
|
261
|
+
function fn3 (request, reply, payload, done) {
|
|
262
262
|
t.deepEqual(request, originalRequest)
|
|
263
263
|
t.deepEqual(reply, originalReply)
|
|
264
264
|
t.strictEqual(payload, originalPayload)
|
|
265
|
-
|
|
265
|
+
done()
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
function done (err, request, reply, payload) {
|
|
@@ -285,19 +285,19 @@ test('onSendHookRunner - Can change the payload', t => {
|
|
|
285
285
|
|
|
286
286
|
onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done)
|
|
287
287
|
|
|
288
|
-
function fn1 (request, reply, payload,
|
|
288
|
+
function fn1 (request, reply, payload, done) {
|
|
289
289
|
t.deepEqual(payload, v1)
|
|
290
|
-
|
|
290
|
+
done(null, v2)
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
function fn2 (request, reply, payload,
|
|
293
|
+
function fn2 (request, reply, payload, done) {
|
|
294
294
|
t.deepEqual(payload, v2)
|
|
295
|
-
|
|
295
|
+
done(null, v3)
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
-
function fn3 (request, reply, payload,
|
|
298
|
+
function fn3 (request, reply, payload, done) {
|
|
299
299
|
t.deepEqual(payload, v3)
|
|
300
|
-
|
|
300
|
+
done(null, v4)
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
function done (err, request, reply, payload) {
|
|
@@ -318,14 +318,14 @@ test('onSendHookRunner - In case of error should skip to done', t => {
|
|
|
318
318
|
|
|
319
319
|
onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done)
|
|
320
320
|
|
|
321
|
-
function fn1 (request, reply, payload,
|
|
321
|
+
function fn1 (request, reply, payload, done) {
|
|
322
322
|
t.deepEqual(payload, v1)
|
|
323
|
-
|
|
323
|
+
done(null, v2)
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
-
function fn2 (request, reply, payload,
|
|
326
|
+
function fn2 (request, reply, payload, done) {
|
|
327
327
|
t.deepEqual(payload, v2)
|
|
328
|
-
|
|
328
|
+
done(new Error('kaboom'))
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
function fn3 () {
|
|
@@ -417,9 +417,9 @@ test('onSendHookRunner - Be able to exit before its natural end', t => {
|
|
|
417
417
|
|
|
418
418
|
onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done)
|
|
419
419
|
|
|
420
|
-
function fn1 (request, reply, payload,
|
|
420
|
+
function fn1 (request, reply, payload, done) {
|
|
421
421
|
t.deepEqual(payload, v1)
|
|
422
|
-
|
|
422
|
+
done(null, v2)
|
|
423
423
|
}
|
|
424
424
|
|
|
425
425
|
function fn2 (request, reply, payload) {
|