aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/mock-servers/utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-22 14:31:38 +0200
committerChocobozzz <me@florianbigard.com>2021-10-22 14:31:38 +0200
commitd1bfbdeb203b0e4f37e9468861c690171156ee29 (patch)
tree2a6051ef212b964eb2ded1021a625acd0ba32053 /shared/extra-utils/mock-servers/utils.ts
parent5480933b7f088bf099b25fb467faace814f0da58 (diff)
downloadPeerTube-d1bfbdeb203b0e4f37e9468861c690171156ee29.tar.gz
PeerTube-d1bfbdeb203b0e4f37e9468861c690171156ee29.tar.zst
PeerTube-d1bfbdeb203b0e4f37e9468861c690171156ee29.zip
Random listen for mocked servers
Diffstat (limited to 'shared/extra-utils/mock-servers/utils.ts')
-rw-r--r--shared/extra-utils/mock-servers/utils.ts16
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 @@
1import { Express } from 'express'
1import { Server } from 'http' 2import { Server } from 'http'
3import { AddressInfo } from 'net'
4
5function randomListen (app: Express) {
6 return new Promise<Server>(res => {
7 const server = app.listen(0, () => res(server))
8 })
9}
10
11function getPort (server: Server) {
12 const address = server.address() as AddressInfo
13
14 return address.port
15}
2 16
3function terminateServer (server: Server) { 17function 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
15export { 29export {
30 randomListen,
31 getPort,
16 terminateServer 32 terminateServer
17} 33}