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

                                           
                         
                                              
                                         





                                       
                                             






                                               
                                       







                                                                              
import { createServer, Server } from 'http'
import proxy from 'proxy'
import { randomInt } from '@shared/core-utils'
import { terminateServer } from './utils'

class MockProxy {
  private server: Server

  initialize () {
    return new Promise<number>(res => {
      const port = 46000 + randomInt(1, 1000)

      this.server = proxy(createServer())
      this.server.listen(port, () => res(port))
    })
  }

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

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

export {
  MockProxy
}