From 7820a54e5e168195e58209a4051dd5ecbbec93cf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 Jun 2020 14:50:40 +0200 Subject: [PATCH] Close mock blocklit server when tests end --- server/tests/external-plugins/auto-block-videos.ts | 2 ++ server/tests/external-plugins/auto-mute.ts | 2 ++ shared/extra-utils/plugins/mock-blocklist.ts | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/server/tests/external-plugins/auto-block-videos.ts b/server/tests/external-plugins/auto-block-videos.ts index 3ec03d558..1b91d141e 100644 --- a/server/tests/external-plugins/auto-block-videos.ts +++ b/server/tests/external-plugins/auto-block-videos.ts @@ -185,6 +185,8 @@ describe('Official plugin auto-block videos', function () { }) after(async function () { + await blocklistServer.terminate() + await cleanupTests(servers) }) }) diff --git a/server/tests/external-plugins/auto-mute.ts b/server/tests/external-plugins/auto-mute.ts index bfdbee80a..8ead34a2b 100644 --- a/server/tests/external-plugins/auto-mute.ts +++ b/server/tests/external-plugins/auto-mute.ts @@ -238,6 +238,8 @@ describe('Official plugin auto-mute', function () { }) after(async function () { + await blocklistServer.terminate() + await cleanupTests(servers) }) }) diff --git a/shared/extra-utils/plugins/mock-blocklist.ts b/shared/extra-utils/plugins/mock-blocklist.ts index 6fe3dee9f..07c8c5122 100644 --- a/shared/extra-utils/plugins/mock-blocklist.ts +++ b/shared/extra-utils/plugins/mock-blocklist.ts @@ -1,4 +1,5 @@ import * as express from 'express' +import { Server } from 'http' type BlocklistResponse = { data: { @@ -10,6 +11,7 @@ type BlocklistResponse = { export class MockBlocklist { private body: BlocklistResponse + private server: Server initialize () { return new Promise(res => { @@ -19,11 +21,15 @@ export class MockBlocklist { return res.json(this.body) }) - app.listen(42100, () => res()) + this.server = app.listen(42100, () => res()) }) } replace (body: BlocklistResponse) { this.body = body } + + terminate () { + if (this.server) this.server.close() + } } -- 2.41.0