2021-08-25 09:08:37 -04:00
|
|
|
|
|
|
|
import { createServer, Server } from 'http'
|
2021-08-27 08:32:44 -04:00
|
|
|
import proxy from 'proxy'
|
2021-10-22 08:31:38 -04:00
|
|
|
import { getPort, terminateServer } from './utils'
|
2021-08-25 09:08:37 -04:00
|
|
|
|
|
|
|
class MockProxy {
|
|
|
|
private server: Server
|
|
|
|
|
|
|
|
initialize () {
|
|
|
|
return new Promise<number>(res => {
|
|
|
|
this.server = proxy(createServer())
|
2021-10-22 08:31:38 -04:00
|
|
|
this.server.listen(0, () => res(getPort(this.server)))
|
2021-08-25 09:08:37 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
terminate () {
|
2021-09-06 02:13:11 -04:00
|
|
|
return terminateServer(this.server)
|
2021-08-25 09:08:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
MockProxy
|
|
|
|
}
|