PeerTube/server/tests/shared/mock-servers/mock-proxy.ts

25 lines
507 B
TypeScript
Raw Normal View History

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