Skip to content

Commit

Permalink
✅ fix(core/test): wait for gateway to be closed cuz deno doesnt reall…
Browse files Browse the repository at this point in the history
…y like events
  • Loading branch information
Helloyunho committed May 18, 2024
1 parent 84f43e2 commit e0bf5f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/test/manager.test.ts
Original file line number Diff line number Diff line change
@@ -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")!, {
Expand All @@ -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",
Expand All @@ -18,4 +18,6 @@ Deno.test("mix rest and gateway", async () => {
});

await client.spawnAndRunAll();

await wait();
});
11 changes: 11 additions & 0 deletions core/test/wait.ts
Original file line number Diff line number Diff line change
@@ -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<void> => {
let id: number = 0;
await new Promise((resolve) => id = setTimeout(resolve, ms));
clearTimeout(id);
return;
};

0 comments on commit e0bf5f3

Please sign in to comment.