/
server.test.js
62 lines (52 loc) · 1.55 KB
/
server.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict'
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)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen({ port: null }, (err) => {
t.error(err)
})
})
test('listen should accept undefined port', t => {
t.plan(1)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen({ port: undefined }, (err) => {
t.error(err)
})
})
test('listen should accept stringified number port', t => {
t.plan(1)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen({ port: '1234' }, (err) => {
t.error(err)
})
})
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) {
if (semver.lt(process.version, '19.1.0')) {
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) {
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').")
}
}
})