]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/mock-servers/mock-instances-index.ts
Add peertube short link import test
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / mock-servers / mock-instances-index.ts
index c9e33087de4ce693500617d5cde6604634b5a106..43c2e9f6ec6466a9d6e7f47b278d444ad8aa5517 100644 (file)
@@ -1,7 +1,11 @@
-import * as express from 'express'
+import express from 'express'
+import { Server } from 'http'
 import { randomInt } from '@shared/core-utils'
+import { terminateServer } from './utils'
 
 export class MockInstancesIndex {
+  private server: Server
+
   private readonly indexInstances: { host: string, createdAt: string }[] = []
 
   initialize () {
@@ -29,12 +33,16 @@ export class MockInstancesIndex {
         })
       })
 
-      const port = 42101 + randomInt(1, 100)
-      app.listen(port, () => res(port))
+      const port = 42000 + randomInt(1, 1000)
+      this.server = app.listen(port, () => res(port))
     })
   }
 
   addInstance (host: string) {
     this.indexInstances.push({ host, createdAt: new Date().toISOString() })
   }
+
+  terminate () {
+    return terminateServer(this.server)
+  }
 }