]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | import { createServer, Server } from 'http' | |
3 | import proxy from 'proxy' | |
4 | import { randomInt } from '@shared/core-utils' | |
5 | import { terminateServer } from './utils' | |
6 | ||
7 | class MockProxy { | |
8 | private server: Server | |
9 | ||
10 | initialize () { | |
11 | return new Promise<number>(res => { | |
12 | const port = 46000 + randomInt(1, 1000) | |
13 | ||
14 | this.server = proxy(createServer()) | |
15 | this.server.listen(port, () => res(port)) | |
16 | }) | |
17 | } | |
18 | ||
19 | terminate () { | |
20 | return terminateServer(this.server) | |
21 | } | |
22 | } | |
23 | ||
24 | // --------------------------------------------------------------------------- | |
25 | ||
26 | export { | |
27 | MockProxy | |
28 | } |