node-minecraft-protocol/test/common/util.js
Jordan Jones 4d5dbb118e
automatic port "discovery" for packets and server tests (#870)
* automatic port "discovery" for packets and server tests

* Semi-colon begone!

* move getport to commons file - u9g

* Merge code
2021-06-28 22:58:21 -04:00

12 lines
290 B
JavaScript

const net = require('net')
const getPort = () => new Promise(resolve => {
const server = net.createServer()
server.listen(0, '127.0.0.1')
server.on('listening', () => {
const { port } = server.address()
server.close(() => resolve(port))
})
})
module.exports = { getPort }