diff options
Diffstat (limited to 'packages/tests/src/shared/mock-servers/mock-proxy.ts')
-rw-r--r-- | packages/tests/src/shared/mock-servers/mock-proxy.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/tests/src/shared/mock-servers/mock-proxy.ts b/packages/tests/src/shared/mock-servers/mock-proxy.ts new file mode 100644 index 000000000..e731670d8 --- /dev/null +++ b/packages/tests/src/shared/mock-servers/mock-proxy.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import { createServer, Server } from 'http' | ||
2 | import { createProxy } from 'proxy' | ||
3 | import { getPort, terminateServer } from './shared.js' | ||
4 | |||
5 | class MockProxy { | ||
6 | private server: Server | ||
7 | |||
8 | initialize () { | ||
9 | return new Promise<number>(res => { | ||
10 | this.server = createProxy(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 | } | ||