aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/mock-servers/mock-plugin-blocklist.ts')
-rw-r--r--shared/extra-utils/mock-servers/mock-plugin-blocklist.ts20
1 files changed, 9 insertions, 11 deletions
diff --git a/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts b/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
index 344d4bdbb..f8a271cba 100644
--- a/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
+++ b/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
@@ -1,7 +1,6 @@
1import express, { Request, Response } from 'express' 1import express, { Request, Response } from 'express'
2import { Server } from 'http' 2import { Server } from 'http'
3import { randomInt } from '@shared/core-utils' 3import { getPort, randomListen, terminateServer } from './utils'
4import { terminateServer } from './utils'
5 4
6type BlocklistResponse = { 5type BlocklistResponse = {
7 data: { 6 data: {
@@ -15,17 +14,16 @@ export class MockBlocklist {
15 private body: BlocklistResponse 14 private body: BlocklistResponse
16 private server: Server 15 private server: Server
17 16
18 initialize () { 17 async initialize () {
19 return new Promise<number>(res => { 18 const app = express()
20 const app = express()
21 19
22 app.get('/blocklist', (req: Request, res: Response) => { 20 app.get('/blocklist', (req: Request, res: Response) => {
23 return res.json(this.body) 21 return res.json(this.body)
24 })
25
26 const port = 45000 + randomInt(1, 1000)
27 this.server = app.listen(port, () => res(port))
28 }) 22 })
23
24 this.server = await randomListen(app)
25
26 return getPort(this.server)
29 } 27 }
30 28
31 replace (body: BlocklistResponse) { 29 replace (body: BlocklistResponse) {