aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/shared/mock-servers/mock-http.ts
blob: b7a019e0770d47434308c99993cb74354da3f6c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import express from 'express'
import { Server } from 'http'
import { getPort, randomListen, terminateServer } from './shared'

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)
  }
}