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