diff options
Diffstat (limited to 'server/tests/shared/mock-servers/mock-proxy.ts')
-rw-r--r-- | server/tests/shared/mock-servers/mock-proxy.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/server/tests/shared/mock-servers/mock-proxy.ts b/server/tests/shared/mock-servers/mock-proxy.ts new file mode 100644 index 000000000..cbc7c4466 --- /dev/null +++ b/server/tests/shared/mock-servers/mock-proxy.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import { createServer, Server } from 'http' | ||
2 | import proxy from 'proxy' | ||
3 | import { getPort, terminateServer } from './shared' | ||
4 | |||
5 | class MockProxy { | ||
6 | private server: Server | ||
7 | |||
8 | initialize () { | ||
9 | return new Promise<number>(res => { | ||
10 | this.server = proxy(createServer()) | ||
11 | this.server.listen(0, () => res(getPort(this.server))) | ||
12 | }) | ||
13 | } | ||
14 | |||
15 | terminate () { | ||
16 | return terminateServer(this.server) | ||
17 | } | ||
18 | } | ||
19 | |||
20 | // --------------------------------------------------------------------------- | ||
21 | |||
22 | export { | ||
23 | MockProxy | ||
24 | } | ||