aboutsummaryrefslogblamecommitdiffhomepage
path: root/packages/tests/src/shared/mock-servers/mock-proxy.ts
blob: e731670d87ae36523fc03b13cf8e3d42a6266c65 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                           
                                   
                                                      





                                       
                                               
                                                            



                
                                       







                                                                              
import { createServer, Server } from 'http'
import { createProxy } from 'proxy'
import { getPort, terminateServer } from './shared.js'

class MockProxy {
  private server: Server

  initialize () {
    return new Promise<number>(res => {
      this.server = createProxy(createServer())
      this.server.listen(0, () => res(getPort(this.server)))
    })
  }

  terminate () {
    return terminateServer(this.server)
  }
}

// ---------------------------------------------------------------------------

export {
  MockProxy
}