2021-08-25 08:08:37 -05:00
|
|
|
import { createServer, Server } from 'http'
|
2023-05-22 10:04:39 -05:00
|
|
|
import { createProxy } from 'proxy'
|
2021-12-17 04:58:15 -06:00
|
|
|
import { getPort, terminateServer } from './shared'
|
2021-08-25 08:08:37 -05:00
|
|
|
|
|
|
|
class MockProxy {
|
|
|
|
private server: Server
|
|
|
|
|
|
|
|
initialize () {
|
|
|
|
return new Promise<number>(res => {
|
2023-05-22 10:04:39 -05:00
|
|
|
this.server = createProxy(createServer())
|
2021-10-22 07:31:38 -05:00
|
|
|
this.server.listen(0, () => res(getPort(this.server)))
|
2021-08-25 08:08:37 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
terminate () {
|
2021-09-06 01:13:11 -05:00
|
|
|
return terminateServer(this.server)
|
2021-08-25 08:08:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
MockProxy
|
|
|
|
}
|