diff options
Diffstat (limited to 'shared/extra-utils/mock-servers/mock-plugin-blocklist.ts')
-rw-r--r-- | shared/extra-utils/mock-servers/mock-plugin-blocklist.ts | 20 |
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 @@ | |||
1 | import express, { Request, Response } from 'express' | 1 | import express, { Request, Response } from 'express' |
2 | import { Server } from 'http' | 2 | import { Server } from 'http' |
3 | import { randomInt } from '@shared/core-utils' | 3 | import { getPort, randomListen, terminateServer } from './utils' |
4 | import { terminateServer } from './utils' | ||
5 | 4 | ||
6 | type BlocklistResponse = { | 5 | type 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) { |