Force close the server once the test is finished

This commit is contained in:
delvedor
2018-11-09 18:09:29 +01:00
parent 0701a795c2
commit ca5e9ca743
6 changed files with 76 additions and 6 deletions

View File

@ -1,5 +1,7 @@
'use strict'
const stoppable = require('stoppable')
// allow self signed certificates for testing purposes
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0
@ -20,12 +22,11 @@ function buildServer (handler, opts, cb) {
}
const server = opts.secure
? https.createServer(secureOpts)
: http.createServer()
? stoppable(https.createServer(secureOpts))
: stoppable(http.createServer())
server.on('request', handler)
server.listen(0, () => {
server.unref()
const port = server.address().port
cb(Object.assign({}, secureOpts, { port }), server)
})