Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/local/lib/node_modules/homebridge-config-ui-x/node_modules/fastify/test/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 'use strict'
const http = require('http')
const test = require('tap').test
const fastify = require('../')
test('handlers receive correct `this` context', (t) => {
t.plan(4)
// simulate plugin that uses fastify-plugin
const plugin = function (instance, opts, done) {
instance.decorate('foo', 'foo')
done()
}
plugin[Symbol.for('skip-override')] = true
const instance = fastify()
instance.register(plugin)
instance.get('/', function (req, reply) {
t.ok(this.foo)
t.equal(this.foo, 'foo')
reply.send()
})
instance.listen(0, (err) => {
instance.server.unref()
if (err) t.threw(err)
t.ok(instance.foo)
t.equal(instance.foo, 'foo')
const address = `http://127.0.0.1:${instance.server.address().port}/`
http.get(address, () => {}).on('error', t.threw)
})
})
test('handlers have access to the internal context', (t) => {
t.plan(5)
const instance = fastify()
instance.get('/', { config: { foo: 'bar' } }, function (req, reply) {
t.ok(reply.context)
t.ok(reply.context.config)
t.type(reply.context.config, Object)
t.ok(reply.context.config.foo)
t.equal(reply.context.config.foo, 'bar')
reply.send()
})
instance.listen(0, (err) => {
instance.server.unref()
if (err) t.threw(err)
const address = `http://127.0.0.1:${instance.server.address().port}/`
http.get(address, () => {}).on('error', t.threw)
})
})
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0119 ]-- |