aboutsummaryrefslogblamecommitdiffhomepage
path: root/packages/tests/src/shared/mock-servers/mock-http.ts
blob: bc1a9ce9155051c86446b6c6a81fdda69dd3da70 (plain) (tree)
1
2
3

                             
                                                                    



















                                                                                                
import express from 'express'
import { Server } from 'http'
import { getPort, randomListen, terminateServer } from './shared.js'

export class MockHTTP {
  private server: Server

  async initialize () {
    const app = express()

    app.get('/*', (req: express.Request, res: express.Response, next: express.NextFunction) => {
      return res.sendStatus(200)
    })

    this.server = await randomListen(app)

    return getPort(this.server)
  }

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