From 97b182a901c33c89210a83299eba0f31222a1ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vorburger=20=E2=9B=91=EF=B8=8F?= Date: Sun, 28 Aug 2022 07:28:07 +0200 Subject: [PATCH] Revert "Improved Mineflayer tests timeout handling (#410)" This reverts commit 8a69e721073597ce18f4119641fb0d11a8d84843. --- test-mineflayer/storeys.test.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/test-mineflayer/storeys.test.js b/test-mineflayer/storeys.test.js index 7a6d4fce..547acf02 100644 --- a/test-mineflayer/storeys.test.js +++ b/test-mineflayer/storeys.test.js @@ -13,42 +13,46 @@ const createBot = (command) => { return bot; } -describe("Storeys plugin test", () => { - let bot; +const handleError = (bot, done) => { + bot.on("error", (e) => { + done(e); + }); +} - const handleError = (done) => { - bot.on("error", (e) => { - done(e); - }); - } - - afterEach(() => bot.quit()); +describe("Storeys plugin test", () => { + beforeAll(() => { + // Prevent jest from complaining about an import after the test is done (You are trying to `import` a file after the Jest environment has been torn down.) + jest.useFakeTimers('legacy'); + console.log = () => { }; + }); test("should connect to minecraft server and execute /make", (done) => { // given - bot = createBot("/make"); + const bot = createBot("/make"); // then bot.on('messagestr', (msg) => { if (msg !== "Player joined the game") { expect(msg).toEqual("Click here to open Scratch and MAKE actions"); done(); + bot.quit(); } }); - handleError(done); + handleError(bot, done); }, TIMEOUT); test("should execute /new", (done) => { // given - bot = createBot("/new"); + const bot = createBot("/new"); // then bot.on('title', (msg) => { expect(msg).toEqual("{\"text\":\"Hello\"}"); done(); + bot.quit(); }); - handleError(done); + handleError(bot, done); }, TIMEOUT); });