import { Express } from 'express' ; import { Server } from 'http' ; import { AddressInfo } from 'net' ; function randomListen ( app ) { return new Promise < Server > ( res => { const server = app . listen ( 0 , ( ) => res ( server ) ) ; } ) ; } function getPort ( server ) { const address = server . address ( ) as AddressInfo ; return address . port ; } function terminateServer ( server ) { if ( ! server ) return Promise . resolve ( ) ; return new Promise < void > ( ( res , rej ) => { server . close ( err => { if ( err ) return rej ( err ) ; return res ( ) ; } ) ; } ) ; } export { randomListen , getPort , terminateServer } ;