From e0bf5f369300a05a8786acb8817bbc7665c5fdb4 Mon Sep 17 00:00:00 2001 From: Helloyunho Date: Sun, 19 May 2024 01:05:46 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20fix(core/test):=20wait=20for=20gate?= =?UTF-8?q?way=20to=20be=20closed=20cuz=20deno=20doesnt=20really=20like=20?= =?UTF-8?q?events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/test/manager.test.ts | 4 +++- core/test/wait.ts | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 core/test/wait.ts diff --git a/core/test/manager.test.ts b/core/test/manager.test.ts index 4f684191..75197756 100644 --- a/core/test/manager.test.ts +++ b/core/test/manager.test.ts @@ -1,4 +1,5 @@ import { APIManager } from "../src/manager.ts"; +import { wait } from "./wait.ts"; Deno.test("mix rest and gateway", async () => { const client = new APIManager(Deno.env.get("BOT_TOKEN")!, { @@ -8,7 +9,6 @@ Deno.test("mix rest and gateway", async () => { }); client.on("READY", async () => { - console.log("READY"); await client.post(`/channels/749139969192230995/messages`, { body: { content: "test", @@ -18,4 +18,6 @@ Deno.test("mix rest and gateway", async () => { }); await client.spawnAndRunAll(); + + await wait(); }); diff --git a/core/test/wait.ts b/core/test/wait.ts new file mode 100644 index 00000000..7f99600a --- /dev/null +++ b/core/test/wait.ts @@ -0,0 +1,11 @@ +/** + * Wait for a given amount of time. This is here because Deno test can't properly handle events. + * @param ms The amount of time to wait in milliseconds. + * @returns A promise that resolves after the given amount of time. + */ +export const wait = async (ms: number = 1000): Promise => { + let id: number = 0; + await new Promise((resolve) => id = setTimeout(resolve, ms)); + clearTimeout(id); + return; +};