aboutsummaryrefslogblamecommitdiffhomepage
path: root/shared/extra-utils/mock-servers/mock-proxy.ts
blob: eb5f177c71d525dd32a1f60b168610b145f74ed6 (plain) (tree)
1
2
3

                                           
                         























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

class MockProxy {
  private server: Server

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

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

  terminate () {
    if (this.server) this.server.close()
  }
}

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

export {
  MockProxy
}