aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/extra-utils/mock-servers/mock-proxy.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/shared/extra-utils/mock-servers/mock-proxy.ts b/shared/extra-utils/mock-servers/mock-proxy.ts
new file mode 100644
index 000000000..5365f87d1
--- /dev/null
+++ b/shared/extra-utils/mock-servers/mock-proxy.ts
@@ -0,0 +1,27 @@
1
2import { createServer, Server } from 'http'
3import * as proxy from 'proxy'
4import { randomInt } from '@shared/core-utils'
5
6class MockProxy {
7 private server: Server
8
9 initialize () {
10 return new Promise<number>(res => {
11 const port = 42501 + randomInt(1, 100)
12
13 this.server = proxy(createServer())
14 this.server.listen(port, () => res(port))
15 })
16 }
17
18 terminate () {
19 if (this.server) this.server.close()
20 }
21}
22
23// ---------------------------------------------------------------------------
24
25export {
26 MockProxy
27}