Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix node 19.1.0 port validation test #4427

Merged
merged 3 commits into from Nov 18, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions test/server.test.js
Expand Up @@ -3,6 +3,7 @@
const t = require('tap')
const test = t.test
const Fastify = require('..')
const semver = require('semver')

test('listen should accept null port', t => {
t.plan(1)
Expand Down Expand Up @@ -36,19 +37,26 @@ test('listen should accept stringified number port', t => {

test('listen should reject string port', async (t) => {
t.plan(2)

const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))

try {
await fastify.listen({ port: 'hello-world' })
} catch (error) {
t.same(error.message, 'options.port should be >= 0 and < 65536. Received hello-world.')
if (semver.lt(process.version, '19.1.0')) {
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
t.same(error.message, 'options.port should be >= 0 and < 65536. Received hello-world.')
} else {
t.same(error.message, "options.port should be >= 0 and < 65536. Received type string ('hello-world').")
}
}

try {
await fastify.listen({ port: '1234hello' })
} catch (error) {
t.same(error.message, 'options.port should be >= 0 and < 65536. Received 1234hello.')
if (semver.lt(process.version, '19.1.0')) {
t.same(error.message, 'options.port should be >= 0 and < 65536. Received 1234hello.')
} else {
t.same(error.message, "options.port should be >= 0 and < 65536. Received type string ('1234hello').")
}
}
})