aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/mock-servers/mock-instances-index.ts10
1 files changed, 9 insertions, 1 deletions
diff --git a/shared/extra-utils/mock-servers/mock-instances-index.ts b/shared/extra-utils/mock-servers/mock-instances-index.ts
index 5baec00de..43c2e9f6e 100644
--- a/shared/extra-utils/mock-servers/mock-instances-index.ts
+++ b/shared/extra-utils/mock-servers/mock-instances-index.ts
@@ -1,7 +1,11 @@
1import express from 'express' 1import express from 'express'
2import { Server } from 'http'
2import { randomInt } from '@shared/core-utils' 3import { randomInt } from '@shared/core-utils'
4import { terminateServer } from './utils'
3 5
4export class MockInstancesIndex { 6export class MockInstancesIndex {
7 private server: Server
8
5 private readonly indexInstances: { host: string, createdAt: string }[] = [] 9 private readonly indexInstances: { host: string, createdAt: string }[] = []
6 10
7 initialize () { 11 initialize () {
@@ -30,11 +34,15 @@ export class MockInstancesIndex {
30 }) 34 })
31 35
32 const port = 42000 + randomInt(1, 1000) 36 const port = 42000 + randomInt(1, 1000)
33 app.listen(port, () => res(port)) 37 this.server = app.listen(port, () => res(port))
34 }) 38 })
35 } 39 }
36 40
37 addInstance (host: string) { 41 addInstance (host: string) {
38 this.indexInstances.push({ host, createdAt: new Date().toISOString() }) 42 this.indexInstances.push({ host, createdAt: new Date().toISOString() })
39 } 43 }
44
45 terminate () {
46 return terminateServer(this.server)
47 }
40} 48}