Skip to content

Commit

Permalink
fix: #3783 (#3784)
Browse files Browse the repository at this point in the history
  • Loading branch information
xtx1130 committed Mar 18, 2022
1 parent 48fc637 commit 538fe63
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function createServer (options, httpHandler) {
})
})
}
return listening
}

this.ready(listenCallback.call(this, server, listenOptions))
Expand Down
27 changes: 27 additions & 0 deletions test/listen.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ test('listen works without arguments', async t => {
t.ok(address.port > 0)
})

test('Async/await listen with arguments', async t => {
process.on('warning', () => {
t.fail('should not be deprecated')
})

t.plan(1)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
const addr = await fastify.listen({ port: 0, host: '0.0.0.0' })
const address = fastify.server.address()
t.equal(addr, `http://${address.address}:${address.port}`)
})

test('Promise listen with arguments', t => {
process.on('warning', () => {
t.fail('should not be deprecated')
})

t.plan(1)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen({ port: 0, host: '0.0.0.0' }).then(addr => {
const address = fastify.server.address()
t.equal(addr, `http://${address.address}:${address.port}`)
})
})

test('listen accepts a callback', t => {
process.on('warning', () => {
t.fail('should not be deprecated')
Expand Down

0 comments on commit 538fe63

Please sign in to comment.