Skip to content

Commit

Permalink
warning test on deprecate request.connection usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafal Augustyniak committed Oct 15, 2020
1 parent 9d05ba0 commit 0a24ffb
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/emit-warning.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const sget = require('simple-get').concat
const { test } = require('tap')
const Fastify = require('..')
const semver = require('semver')

process.removeAllListeners('warning')

Expand Down Expand Up @@ -129,3 +130,33 @@ test('Should emit a warning when using payload less preParsing hook', t => {
})
})
})

if (semver.gte(process.versions.node, '13.0.0')) {
test('Should emit a warning when accessing request.connection instead of request.socket on Node process greater than 13.0.0', t => {
t.plan(4)

process.on('warning', onWarning)
function onWarning (warning) {
t.strictEqual(warning.name, 'FastifyDeprecation')
t.strictEqual(warning.code, 'FSTDEP005')
t.strictEqual(warning.message, 'You are accessing the deprecated "request.connection" property. Use "request.socket" instead.')

// removed listener before light-my-request emit second warning
process.removeListener('warning', onWarning)
}

const fastify = Fastify()

fastify.get('/', (request, reply) => {
reply.send(request.connection)
})

fastify.inject({
method: 'GET',
path: '/'
}, (err, res) => {
t.error(err)
process.removeListener('warning', onWarning)
})
})
}

0 comments on commit 0a24ffb

Please sign in to comment.