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

25 lines
523 B
TypeScript
Raw Normal View History

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