diff options
Diffstat (limited to 'shared/extra-utils/mock-servers/utils.ts')
-rw-r--r-- | shared/extra-utils/mock-servers/utils.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/shared/extra-utils/mock-servers/utils.ts b/shared/extra-utils/mock-servers/utils.ts index 64d94c868..235642439 100644 --- a/shared/extra-utils/mock-servers/utils.ts +++ b/shared/extra-utils/mock-servers/utils.ts | |||
@@ -1,4 +1,18 @@ | |||
1 | import { Express } from 'express' | ||
1 | import { Server } from 'http' | 2 | import { Server } from 'http' |
3 | import { AddressInfo } from 'net' | ||
4 | |||
5 | function randomListen (app: Express) { | ||
6 | return new Promise<Server>(res => { | ||
7 | const server = app.listen(0, () => res(server)) | ||
8 | }) | ||
9 | } | ||
10 | |||
11 | function getPort (server: Server) { | ||
12 | const address = server.address() as AddressInfo | ||
13 | |||
14 | return address.port | ||
15 | } | ||
2 | 16 | ||
3 | function terminateServer (server: Server) { | 17 | function terminateServer (server: Server) { |
4 | if (!server) return Promise.resolve() | 18 | if (!server) return Promise.resolve() |
@@ -13,5 +27,7 @@ function terminateServer (server: Server) { | |||
13 | } | 27 | } |
14 | 28 | ||
15 | export { | 29 | export { |
30 | randomListen, | ||
31 | getPort, | ||
16 | terminateServer | 32 | terminateServer |
17 | } | 33 | } |