aboutsummaryrefslogblamecommitdiffhomepage
path: root/shared/extra-utils/mock-servers/mock-proxy.ts
blob: 75ac790551a274348481646c3d7b43daba38a19c (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                                           
                         
                                                  





                                       
                                         
                                                            



                
                                       







                                                                              
import { createServer, Server } from 'http'
import proxy from 'proxy'
import { getPort, terminateServer } from './utils'

class MockProxy {
  private server: Server

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

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

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

export {
  MockProxy
}