aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts')
-rw-r--r--shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts35
1 files changed, 18 insertions, 17 deletions
diff --git a/shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts b/shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts
index 79be31f61..e7906ea56 100644
--- a/shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts
+++ b/shared/extra-utils/mock-servers/mock-joinpeertube-versions.ts
@@ -1,30 +1,31 @@
1import express from 'express' 1import express from 'express'
2import { randomInt } from '@shared/core-utils' 2import { Server } from 'http'
3import { getPort, randomListen } from './utils'
3 4
4export class MockJoinPeerTubeVersions { 5export class MockJoinPeerTubeVersions {
6 private server: Server
5 private latestVersion: string 7 private latestVersion: string
6 8
7 initialize () { 9 async initialize () {
8 return new Promise<number>(res => { 10 const app = express()
9 const app = express()
10 11
11 app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { 12 app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
12 if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url) 13 if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url)
13 14
14 return next() 15 return next()
15 }) 16 })
16 17
17 app.get('/versions.json', (req: express.Request, res: express.Response) => { 18 app.get('/versions.json', (req: express.Request, res: express.Response) => {
18 return res.json({ 19 return res.json({
19 peertube: { 20 peertube: {
20 latestVersion: this.latestVersion 21 latestVersion: this.latestVersion
21 } 22 }
22 })
23 }) 23 })
24
25 const port = 43000 + randomInt(1, 1000)
26 app.listen(port, () => res(port))
27 }) 24 })
25
26 this.server = await randomListen(app)
27
28 return getPort(this.server)
28 } 29 }
29 30
30 setLatestVersion (latestVersion: string) { 31 setLatestVersion (latestVersion: string) {