From 0739826e7ad3f3655012e69c0db949ab8257d2c5 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Sat, 10 Apr 2021 23:37:24 +0200 Subject: [PATCH 1/3] tests: use delayUntil instead of delay --- tests/channels/category_children.ts | 14 +++++++------- tests/channels/create_channel.ts | 18 +++++++++--------- tests/channels/delete_channel.ts | 18 +++++++++--------- tests/guilds/create_guild.ts | 4 ++-- tests/guilds/delete_server.ts | 4 ++-- tests/messages/add_reaction.ts | 12 ++++++------ tests/messages/add_reactions.ts | 19 +++++++------------ tests/messages/create_message.ts | 13 ++++++------- tests/messages/delete_message.ts | 8 ++++---- tests/messages/delete_messages.ts | 23 +++++++++++------------ tests/messages/edit_message.ts | 9 ++++++--- tests/messages/get_message.ts | 5 +++-- tests/messages/get_messages.ts | 15 +++++++++++---- tests/messages/get_reactions.ts | 13 ++++--------- tests/messages/pin_message.ts | 7 ++++--- tests/messages/remove_all_reactions.ts | 14 ++++++++++---- tests/messages/remove_reaction.ts | 21 +++++++++++---------- tests/messages/remove_reaction_emoji.ts | 15 ++++++++++----- tests/messages/remove_user_reaction.ts | 17 +++++++++++------ tests/messages/unpin_message.ts | 9 +++++---- 20 files changed, 138 insertions(+), 120 deletions(-) diff --git a/tests/channels/category_children.ts b/tests/channels/category_children.ts index c286afc4f..11b67aae4 100644 --- a/tests/channels/category_children.ts +++ b/tests/channels/category_children.ts @@ -3,7 +3,7 @@ import { assertExists } from "../deps.ts"; import { cache } from "../../src/cache.ts"; import { categoryChildren, createChannel } from "../../src/helpers/mod.ts"; import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; -import { delay } from "../../src/util/utils.ts"; +import { delayUntil } from "../util/delay_until.ts"; Deno.test({ name: "[channel] category channel ids", @@ -16,11 +16,11 @@ Deno.test({ // Assertions assertExists(category); // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.channels.has(category.id)); if (!cache.channels.has(category.id)) { throw new Error( - "The channel seemed to be created but it was not cached." + "The channel seemed to be created but it was not cached.", ); } @@ -31,15 +31,15 @@ Deno.test({ name: `Discordeno-test-${num}`, parentId: category.id, }) - ) + ), ); // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => channels.every((c) => cache.channels.has(c.id))); // If every channel is not present in the cache, error out if (!channels.every((c) => cache.channels.has(c.id))) { throw new Error( - "The channels seemed to be created but it was not cached." + "The channels seemed to be created but it was not cached.", ); } @@ -49,7 +49,7 @@ Deno.test({ !channels.every((c) => ids.has(c.id)) ) { throw new Error( - "The category channel ids did not match with the category channels." + "The category channel ids did not match with the category channels.", ); } }, diff --git a/tests/channels/create_channel.ts b/tests/channels/create_channel.ts index a32849dc6..5548f2c81 100644 --- a/tests/channels/create_channel.ts +++ b/tests/channels/create_channel.ts @@ -3,8 +3,8 @@ import { assertEquals, assertExists } from "../deps.ts"; import { cache } from "../../src/cache.ts"; import { DiscordChannelTypes } from "../../src/types/channels/channel_types.ts"; import { CreateGuildChannel } from "../../src/types/guilds/create_guild_channel.ts"; -import { delay } from "../../src/util/utils.ts"; import { createChannel } from "../../src/helpers/channels/create_channel.ts"; +import { delayUntil } from "../util/delay_until.ts"; async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) { const channel = await createChannel(tempData.guildId, options); @@ -16,7 +16,7 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) { if (save) tempData.channelId = channel.id; // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.channels.has(channel.id)); if (!cache.channels.has(channel.id)) { throw new Error("The channel seemed to be created but it was not cached."); @@ -24,13 +24,13 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) { if (options.topic && channel.topic !== options.topic) { throw new Error( - "The channel was supposed to have a topic but it does not appear to be the same topic." + "The channel was supposed to have a topic but it does not appear to be the same topic.", ); } if (options.bitrate && channel.bitrate !== options.bitrate) { throw new Error( - "The channel was supposed to have a bitrate but it does not appear to be the same bitrate." + "The channel was supposed to have a bitrate but it does not appear to be the same bitrate.", ); } } @@ -51,7 +51,7 @@ Deno.test({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_CATEGORY, }, - true + true, ); }, ...defaultTestOptions, @@ -81,7 +81,7 @@ Deno.test({ name: "Discordeno-test", type: DiscordChannelTypes.GUILD_VOICE, }, - true + true, ); }, ...defaultTestOptions, @@ -96,7 +96,7 @@ Deno.test({ type: DiscordChannelTypes.GUILD_VOICE, bitrate: 32000, }, - true + true, ); }, ...defaultTestOptions, @@ -111,7 +111,7 @@ Deno.test({ type: DiscordChannelTypes.GUILD_VOICE, userLimit: 32, }, - true + true, ); }, ...defaultTestOptions, @@ -125,7 +125,7 @@ Deno.test({ name: "Discordeno-test", rateLimitPerUser: 2423, }, - true + true, ); }, ...defaultTestOptions, diff --git a/tests/channels/delete_channel.ts b/tests/channels/delete_channel.ts index b39445219..e93400ecd 100644 --- a/tests/channels/delete_channel.ts +++ b/tests/channels/delete_channel.ts @@ -1,8 +1,8 @@ import { cache } from "../../src/cache.ts"; import { createChannel } from "../../src/helpers/channels/create_channel.ts"; import { deleteChannel } from "../../src/helpers/channels/delete_channel.ts"; -import { delay } from "../../src/util/utils.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; +import { delayUntil } from "../util/delay_until.ts"; Deno.test({ name: "[channel] delete a channel without a reason.", @@ -12,22 +12,22 @@ Deno.test({ name: "delete-channel", }); // wait 5 seconds to give it time for CHANNEL_CREATE event - await delay(3000); + delayUntil(3000, () => cache.channels.has(channel.id)); // Make sure the channel was created. if (!cache.channels.has(channel.id)) { throw new Error( - "The channel should have been created but it is not in the cache." + "The channel should have been created but it is not in the cache.", ); } // Delete the channel now without a reason await deleteChannel(tempData.guildId, channel.id); // wait 5 seconds to give it time for CHANNEL_DELETE event - await delay(3000); + delayUntil(3000, () => !cache.channels.has(channel.id)); // Make sure it is gone from cache if (cache.channels.has(channel.id)) { throw new Error( - "The channel should have been deleted but it is still in cache." + "The channel should have been deleted but it is still in cache.", ); } }, @@ -42,22 +42,22 @@ Deno.test({ name: "delete-channel", }); // wait 5 seconds to give it time for CHANNEL_CREATE event - await delay(3000); + delayUntil(3000, () => cache.channels.has(channel.id)); // Make sure the channel was created. if (!cache.channels.has(channel.id)) { throw new Error( - "The channel should have been created but it is not in the cache." + "The channel should have been created but it is not in the cache.", ); } // Delete the channel now without a reason await deleteChannel(tempData.guildId, channel.id, "with a reason"); // wait 5 seconds to give it time for CHANNEL_DELETE event - await delay(3000); + delayUntil(3000, () => !cache.channels.has(channel.id)); // Make sure it is gone from cache if (cache.channels.has(channel.id)) { throw new Error( - "The channel should have been deleted but it is still in cache." + "The channel should have been deleted but it is still in cache.", ); } }, diff --git a/tests/guilds/create_guild.ts b/tests/guilds/create_guild.ts index d513c6d4b..ec52d695b 100644 --- a/tests/guilds/create_guild.ts +++ b/tests/guilds/create_guild.ts @@ -1,8 +1,8 @@ import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertExists } from "../deps.ts"; import { cache } from "../../src/cache.ts"; -import { delay } from "../../src/util/utils.ts"; import { createGuild } from "../../src/helpers/guilds/create_guild.ts"; +import { delayUntil } from "../util/delay_until.ts"; Deno.test({ name: "[guild] create a new guild", @@ -17,7 +17,7 @@ Deno.test({ tempData.guildId = guild.id; // Delay the execution by 5 seconds to allow GUILD_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.guilds.has(guild.id)); if (!cache.guilds.has(guild.id)) { throw new Error("The guild seemed to be created but it was not cached."); diff --git a/tests/guilds/delete_server.ts b/tests/guilds/delete_server.ts index 76c806782..07d1a9dcd 100644 --- a/tests/guilds/delete_server.ts +++ b/tests/guilds/delete_server.ts @@ -1,7 +1,7 @@ import { cache } from "../../src/cache.ts"; import { deleteServer } from "../../src/helpers/guilds/delete_server.ts"; -import { delay } from "../../src/util/utils.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; +import { delayUntil } from "../util/delay_until.ts"; Deno.test({ name: "[guild] delete a guild", @@ -14,7 +14,7 @@ Deno.test({ } await deleteServer(tempData.guildId); - await delay(3000); + delayUntil(3000, () => cache.guilds.has(tempData.guildId)); if (cache.guilds.has(tempData.guildId)) { throw new Error("The guild was not able to be deleted."); diff --git a/tests/messages/add_reaction.ts b/tests/messages/add_reaction.ts index de216d4a5..1ba3c0fc4 100644 --- a/tests/messages/add_reaction.ts +++ b/tests/messages/add_reaction.ts @@ -2,10 +2,10 @@ import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertEquals, assertExists } from "../deps.ts"; import { cache } from "../../src/cache.ts"; import { DiscordReaction } from "../../src/types/messages/reaction.ts"; -import { delay } from "../../src/util/utils.ts"; import { sendMessage } from "../../src/helpers/messages/send_message.ts"; import { addReaction } from "../../src/helpers/messages/add_reaction.ts"; import { createEmoji } from "../../src/helpers/emojis/create_emoji.ts"; +import { delayUntil } from "../util/delay_until.ts"; async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -14,7 +14,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -33,7 +33,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { name: "blamewolf", image: "https://cdn.discordapp.com/emojis/814955268123000832.png", roles: [], - } + }, ) ).id }>`; @@ -45,16 +45,16 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { await message.addReaction(emojiId); } - await delay(3000); + delayUntil(3000, () => cache.messages.get(message.id)?.reactions?.length > 0); assertEquals( await cache.messages .get(message.id) ?.reactions?.filter( (reaction: DiscordReaction) => - reaction.emoji?.name === (custom ? "blamewolf" : "❤") + reaction.emoji?.name === (custom ? "blamewolf" : "❤"), ).length, - 1 + 1, ); } diff --git a/tests/messages/add_reactions.ts b/tests/messages/add_reactions.ts index dc18b1494..7cade1f1f 100644 --- a/tests/messages/add_reactions.ts +++ b/tests/messages/add_reactions.ts @@ -1,17 +1,12 @@ -import { - addReactions, - cache, - createEmoji, - delay, - sendMessage, -} from "../../mod.ts"; +import { addReactions, cache, createEmoji, sendMessage } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertEquals, assertExists } from "../deps.ts"; +import { delayUntil } from "../util/delay_until.ts"; async function ifItFailsBlameWolf( type: "getter" | "raw", custom = false, - ordered = false + ordered = false, ) { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -19,7 +14,7 @@ async function ifItFailsBlameWolf( assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -39,7 +34,7 @@ async function ifItFailsBlameWolf( name: "blamewolf", image: "https://cdn.discordapp.com/emojis/814955268123000832.png", roles: [], - } + }, ) ).id }>`, @@ -53,7 +48,7 @@ async function ifItFailsBlameWolf( name: "blamewolf2", image: "https://cdn.discordapp.com/emojis/814955268123000832.png", roles: [], - } + }, ) ).id }>`, @@ -66,7 +61,7 @@ async function ifItFailsBlameWolf( await message.addReactions(emojiIds, ordered); } - await delay(3000); + delayUntil(3000, () => cache.messages.get(message.id)?.reactions?.length > 0); assertEquals(await cache.messages.get(message.id)?.reactions?.length, 2); } diff --git a/tests/messages/create_message.ts b/tests/messages/create_message.ts index 164c6587e..0be22ad98 100644 --- a/tests/messages/create_message.ts +++ b/tests/messages/create_message.ts @@ -1,9 +1,9 @@ import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertExists } from "../deps.ts"; import { cache } from "../../src/cache.ts"; -import { delay } from "../../src/util/utils.ts"; import { sendMessage } from "../../src/helpers/messages/send_message.ts"; import { createChannel } from "../../src/helpers/channels/create_channel.ts"; +import { delayUntil } from "../util/delay_until.ts"; async function ifItFailsBlameWolf(type: "getter" | "raw") { const channel = await createChannel(tempData.guildId, { @@ -12,18 +12,17 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { assertExists(channel); // Wait few seconds for the channel create event to arrive and cache it - await delay(3000); + delayUntil(3000, () => cache.channels.has(channel.id)); - const message = - type === "raw" - ? await sendMessage(channel.id, "Hello World!") - : await channel.send("Hello World!"); + const message = type === "raw" + ? await sendMessage(channel.id, "Hello World!") + : await channel.send("Hello World!"); // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); diff --git a/tests/messages/delete_message.ts b/tests/messages/delete_message.ts index ac80dd00d..353305ffb 100644 --- a/tests/messages/delete_message.ts +++ b/tests/messages/delete_message.ts @@ -1,9 +1,9 @@ import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertExists } from "../deps.ts"; import { cache } from "../../src/cache.ts"; -import { delay } from "../../src/util/utils.ts"; import { sendMessage } from "../../src/helpers/messages/send_message.ts"; import { deleteMessage } from "../../src/helpers/messages/delete_message.ts"; +import { delayUntil } from "../util/delay_until.ts"; async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -11,7 +11,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -25,11 +25,11 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) { } // Wait 5 seconds to give it time for MESSAGE_DELETE event - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); // Make sure it is gone from cache if (cache.messages.has(message.id)) { throw new Error( - "The message should have been deleted but it is still in cache." + "The message should have been deleted but it is still in cache.", ); } } diff --git a/tests/messages/delete_messages.ts b/tests/messages/delete_messages.ts index 5072aaba3..bdee39b80 100644 --- a/tests/messages/delete_messages.ts +++ b/tests/messages/delete_messages.ts @@ -1,12 +1,7 @@ -import { - cache, - delay, - deleteMessage, - deleteMessages, - sendMessage, -} from "../../mod.ts"; +import { cache, deleteMessages, sendMessage } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertExists } from "../deps.ts"; +import { delayUntil } from "../util/delay_until.ts"; async function ifItFailsBlameWolf(reason?: string) { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -14,7 +9,7 @@ async function ifItFailsBlameWolf(reason?: string) { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -25,7 +20,7 @@ async function ifItFailsBlameWolf(reason?: string) { // Assertions assertExists(secondMessage); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(secondMessage.id)); // Make sure the message was created. if (!cache.messages.has(secondMessage.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -35,15 +30,19 @@ async function ifItFailsBlameWolf(reason?: string) { await deleteMessages( tempData.channelId, [message.id, secondMessage.id], - reason + reason, ); // Wait 5 seconds to give it time for MESSAGE_DELETE event - await delay(3000); + delayUntil( + 3000, + () => + !cache.messages.has(message.id) && !cache.messages.has(secondMessage.id), + ); // Make sure it is gone from cache if (cache.messages.has(message.id) || cache.messages.has(secondMessage.id)) { throw new Error( - "The message should have been deleted but it is still in cache." + "The message should have been deleted but it is still in cache.", ); } } diff --git a/tests/messages/edit_message.ts b/tests/messages/edit_message.ts index 56d86d5cc..36b119c59 100644 --- a/tests/messages/edit_message.ts +++ b/tests/messages/edit_message.ts @@ -1,9 +1,9 @@ import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertEquals, assertExists } from "../deps.ts"; import { cache } from "../../src/cache.ts"; -import { delay } from "../../src/util/utils.ts"; import { sendMessage } from "../../src/helpers/messages/send_message.ts"; import { editMessage } from "../../src/helpers/messages/edit_message.ts"; +import { delayUntil } from "../util/delay_until.ts"; async function ifItFailsBlameWolf(type: "getter" | "raw") { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -11,7 +11,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -24,7 +24,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { await message.edit("Goodbye World!"); } // Wait 5 seconds to give it time for MESSAGE_UPDATE event - await delay(3000); + delayUntil( + 3000, + () => cache.messages.get(message.id)?.content === "Goodbye World!", + ); // Make sure it has been modified in cache assertEquals(cache.messages.get(message.id)?.content, "Goodbye World!"); diff --git a/tests/messages/get_message.ts b/tests/messages/get_message.ts index 6d8c603af..48e8131e3 100644 --- a/tests/messages/get_message.ts +++ b/tests/messages/get_message.ts @@ -1,6 +1,7 @@ -import { cache, delay, getMessage, sendMessage } from "../../mod.ts"; +import { cache, getMessage, sendMessage } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertEquals, assertExists } from "../deps.ts"; +import { delayUntil } from "../util/delay_until.ts"; Deno.test({ name: "[message] fetch a message", @@ -10,7 +11,7 @@ Deno.test({ // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); diff --git a/tests/messages/get_messages.ts b/tests/messages/get_messages.ts index d556fcc9f..6e2306eea 100644 --- a/tests/messages/get_messages.ts +++ b/tests/messages/get_messages.ts @@ -1,6 +1,7 @@ -import { cache, delay, getMessages, sendMessage } from "../../mod.ts"; +import { cache, getMessages, sendMessage } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertEquals, assertExists } from "../deps.ts"; +import { delayUntil } from "../util/delay_until.ts"; Deno.test({ name: "[message] fetch messages", @@ -8,11 +9,11 @@ Deno.test({ const message = await sendMessage(tempData.channelId, "Hello World!"); const secondMessage = await sendMessage( tempData.channelId, - "Hello World 2!" + "Hello World 2!", ); const thirdMessage = await sendMessage( tempData.channelId, - "Hello World 3!" + "Hello World 3!", ); // Assertions @@ -20,7 +21,13 @@ Deno.test({ assertExists(secondMessage); assertExists(thirdMessage); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil( + 3000, + () => + cache.messages.has(message.id) && + cache.messages.has(secondMessage.id) && + cache.messages.has(thirdMessage.id), + ); // Make sure the message was created. if ( !cache.messages.has(message.id) || diff --git a/tests/messages/get_reactions.ts b/tests/messages/get_reactions.ts index 5a6219f7e..f915093d0 100644 --- a/tests/messages/get_reactions.ts +++ b/tests/messages/get_reactions.ts @@ -1,12 +1,7 @@ -import { - addReaction, - cache, - delay, - getReactions, - sendMessage, -} from "../../mod.ts"; +import { addReaction, cache, getReactions, sendMessage } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertEquals, assertExists } from "../deps.ts"; +import { delayUntil } from "../util/delay_until.ts"; Deno.test({ name: "[message] fetch reactions", @@ -16,7 +11,7 @@ Deno.test({ // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -28,7 +23,7 @@ Deno.test({ const fetchedReactions = await getReactions( tempData.channelId, message.id, - "❤" + "❤", ); // Check if getMessage has worked assertEquals(fetchedReactions.size, 1); diff --git a/tests/messages/pin_message.ts b/tests/messages/pin_message.ts index d5ab28133..e40d9a54c 100644 --- a/tests/messages/pin_message.ts +++ b/tests/messages/pin_message.ts @@ -1,7 +1,8 @@ -import { cache, delay, getPins, pin, sendMessage } from "../../mod.ts"; +import { cache, getPins, pin, sendMessage } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertEquals, assertExists } from "../deps.ts"; import { DiscordenoMessage } from "../../src/structures/message.ts"; +import { delayUntil } from "../util/delay_until.ts"; async function ifItFailsBlameWolf(type: "getter" | "raw") { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -10,7 +11,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -25,7 +26,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { const pins = await getPins(tempData.channelId); assertEquals( pins.filter((msg: DiscordenoMessage) => msg.id === message.id).length, - 1 + 1, ); } diff --git a/tests/messages/remove_all_reactions.ts b/tests/messages/remove_all_reactions.ts index aedf3a8eb..9f0fb6744 100644 --- a/tests/messages/remove_all_reactions.ts +++ b/tests/messages/remove_all_reactions.ts @@ -1,12 +1,12 @@ import { addReactions, cache, - delay, removeAllReactions, sendMessage, } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertEquals, assertExists } from "../deps.ts"; +import { delayUntil } from "../util/delay_until.ts"; async function ifItFailsBlameWolf(type: "getter" | "raw") { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -14,7 +14,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -23,7 +23,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Add reactions to the message await addReactions(message.channelId, message.id, ["❤", "😃", "🤫"]); // Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed - await delay(3000); + delayUntil( + 3000, + () => cache.messages.get(message.id)?.reactions?.length === 3, + ); // Be sure that the message has the reactions assertEquals(await cache.messages.get(message.id)?.reactions?.length, 3); @@ -35,7 +38,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { } // Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed - await delay(3000); + delayUntil( + 3000, + () => cache.messages.get(message.id)?.reactions === undefined, + ); // Check if the reactions has been deleted assertEquals(await cache.messages.get(message.id)?.reactions, undefined); diff --git a/tests/messages/remove_reaction.ts b/tests/messages/remove_reaction.ts index 44bbc4f15..257117a15 100644 --- a/tests/messages/remove_reaction.ts +++ b/tests/messages/remove_reaction.ts @@ -1,12 +1,7 @@ -import { - addReaction, - cache, - delay, - removeReaction, - sendMessage, -} from "../../mod.ts"; +import { addReaction, cache, removeReaction, sendMessage } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertEquals, assertExists } from "../deps.ts"; +import { delayUntil } from "../util/delay_until.ts"; async function ifItFailsBlameWolf(type: "getter" | "raw") { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -14,7 +9,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -23,7 +18,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Add reactions to the message await addReaction(message.channelId, message.id, "❤"); // Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed - await delay(3000); + delayUntil( + 3000, + () => cache.messages.get(message.id)?.reactions?.length === 1, + ); // Be sure that the message has the reactions assertEquals(await cache.messages.get(message.id)?.reactions?.length, 1); @@ -35,7 +33,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { } // Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed - await delay(3000); + delayUntil( + 3000, + () => cache.messages.get(message.id)?.reactions === undefined, + ); // Check if the reactions has been deleted assertEquals(await cache.messages.get(message.id)?.reactions, undefined); diff --git a/tests/messages/remove_reaction_emoji.ts b/tests/messages/remove_reaction_emoji.ts index 86451a9bb..0c582ab78 100644 --- a/tests/messages/remove_reaction_emoji.ts +++ b/tests/messages/remove_reaction_emoji.ts @@ -1,13 +1,12 @@ import { addReaction, cache, - delay, - removeReaction, removeReactionEmoji, sendMessage, } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertEquals, assertExists } from "../deps.ts"; +import { delayUntil } from "../util/delay_until.ts"; async function ifItFailsBlameWolf(type: "getter" | "raw") { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -15,7 +14,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -24,7 +23,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Add reactions to the message await addReaction(message.channelId, message.id, "❤"); // Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed - await delay(3000); + delayUntil( + 3000, + () => cache.messages.get(message.id)?.reactions?.length === 1, + ); // Be sure that the message has the reactions assertEquals(await cache.messages.get(message.id)?.reactions?.length, 1); @@ -36,7 +38,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { } // Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed - await delay(3000); + delayUntil( + 3000, + () => cache.messages.get(message.id)?.reactions === undefined, + ); // Check if the reactions has been deleted assertEquals(cache.messages.get(message.id)?.reactions, undefined); diff --git a/tests/messages/remove_user_reaction.ts b/tests/messages/remove_user_reaction.ts index 8aeeb4925..e5f732d18 100644 --- a/tests/messages/remove_user_reaction.ts +++ b/tests/messages/remove_user_reaction.ts @@ -1,13 +1,12 @@ import { addReaction, cache, - delay, - removeReaction, removeUserReaction, sendMessage, } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertEquals, assertExists } from "../deps.ts"; +import { delayUntil } from "../util/delay_until.ts"; async function ifItFailsBlameWolf(type: "getter" | "raw") { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -15,7 +14,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -24,7 +23,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Add reactions to the message await addReaction(message.channelId, message.id, "❤"); // Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed - await delay(3000); + delayUntil( + 3000, + () => cache.messages.get(message.id)?.reactions?.length === 1, + ); // Be sure that the message has the reactions assertEquals(await cache.messages.get(message.id)?.reactions?.length, 1); @@ -34,14 +36,17 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { message.channelId, message.id, "❤", - message.author.id + message.author.id, ); } else { //await message.removeUserReaction("❤", message.author.id); } // Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed - await delay(3000); + delayUntil( + 3000, + () => cache.messages.get(message.id)?.reactions === undefined, + ); // Check if the reactions has been deleted assertEquals(await cache.messages.get(message.id)?.reactions, undefined); diff --git a/tests/messages/unpin_message.ts b/tests/messages/unpin_message.ts index 1637e779d..d42d64e3f 100644 --- a/tests/messages/unpin_message.ts +++ b/tests/messages/unpin_message.ts @@ -1,7 +1,8 @@ -import { cache, delay, getPins, pin, sendMessage, unpin } from "../../mod.ts"; +import { cache, getPins, pin, sendMessage, unpin } from "../../mod.ts"; import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; import { assertEquals, assertExists } from "../deps.ts"; import { DiscordenoMessage } from "../../src/structures/message.ts"; +import { delayUntil } from "../util/delay_until.ts"; async function ifItFailsBlameWolf(type: "getter" | "raw") { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -10,7 +11,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - await delay(3000); + delayUntil(3000, () => cache.messages.has(message.id)); if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -22,7 +23,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { const pins = await getPins(tempData.channelId); assertEquals( pins.filter((msg: DiscordenoMessage) => msg.id === message.id).length, - 1 + 1, ); if (type === "raw") { @@ -36,7 +37,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { assertEquals( removedPins.filter((msg: DiscordenoMessage) => msg.id === message.id) .length, - 0 + 0, ); } From aae106ab716c73cf93957b6321ba3ddef1d2fd88 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Sat, 10 Apr 2021 23:54:56 +0200 Subject: [PATCH 2/3] fix(tests): higher max delay --- tests/channels/category_children.ts | 4 ++-- tests/channels/create_channel.ts | 2 +- tests/channels/delete_channel.ts | 4 ++-- tests/guilds/create_guild.ts | 2 +- tests/guilds/delete_server.ts | 2 +- tests/messages/add_reaction.ts | 4 ++-- tests/messages/add_reactions.ts | 4 ++-- tests/messages/create_message.ts | 4 ++-- tests/messages/delete_message.ts | 4 ++-- tests/messages/delete_messages.ts | 6 +++--- tests/messages/edit_message.ts | 4 ++-- tests/messages/get_message.ts | 2 +- tests/messages/get_messages.ts | 2 +- tests/messages/get_reactions.ts | 2 +- tests/messages/pin_message.ts | 2 +- tests/messages/remove_all_reactions.ts | 6 +++--- tests/messages/remove_reaction.ts | 6 +++--- tests/messages/remove_reaction_emoji.ts | 6 +++--- tests/messages/remove_user_reaction.ts | 6 +++--- tests/messages/unpin_message.ts | 2 +- 20 files changed, 37 insertions(+), 37 deletions(-) diff --git a/tests/channels/category_children.ts b/tests/channels/category_children.ts index 11b67aae4..ef6110999 100644 --- a/tests/channels/category_children.ts +++ b/tests/channels/category_children.ts @@ -16,7 +16,7 @@ Deno.test({ // Assertions assertExists(category); // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - delayUntil(3000, () => cache.channels.has(category.id)); + delayUntil(10000, () => cache.channels.has(category.id)); if (!cache.channels.has(category.id)) { throw new Error( @@ -34,7 +34,7 @@ Deno.test({ ), ); // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - delayUntil(3000, () => channels.every((c) => cache.channels.has(c.id))); + delayUntil(10000, () => channels.every((c) => cache.channels.has(c.id))); // If every channel is not present in the cache, error out if (!channels.every((c) => cache.channels.has(c.id))) { diff --git a/tests/channels/create_channel.ts b/tests/channels/create_channel.ts index 5548f2c81..f1da767a3 100644 --- a/tests/channels/create_channel.ts +++ b/tests/channels/create_channel.ts @@ -16,7 +16,7 @@ async function ifItFailsBlameWolf(options: CreateGuildChannel, save = false) { if (save) tempData.channelId = channel.id; // Delay the execution by 5 seconds to allow CHANNEL_CREATE event to be processed - delayUntil(3000, () => cache.channels.has(channel.id)); + delayUntil(10000, () => cache.channels.has(channel.id)); if (!cache.channels.has(channel.id)) { throw new Error("The channel seemed to be created but it was not cached."); diff --git a/tests/channels/delete_channel.ts b/tests/channels/delete_channel.ts index e93400ecd..aeb086210 100644 --- a/tests/channels/delete_channel.ts +++ b/tests/channels/delete_channel.ts @@ -42,7 +42,7 @@ Deno.test({ name: "delete-channel", }); // wait 5 seconds to give it time for CHANNEL_CREATE event - delayUntil(3000, () => cache.channels.has(channel.id)); + delayUntil(10000, () => cache.channels.has(channel.id)); // Make sure the channel was created. if (!cache.channels.has(channel.id)) { throw new Error( @@ -53,7 +53,7 @@ Deno.test({ // Delete the channel now without a reason await deleteChannel(tempData.guildId, channel.id, "with a reason"); // wait 5 seconds to give it time for CHANNEL_DELETE event - delayUntil(3000, () => !cache.channels.has(channel.id)); + delayUntil(10000, () => !cache.channels.has(channel.id)); // Make sure it is gone from cache if (cache.channels.has(channel.id)) { throw new Error( diff --git a/tests/guilds/create_guild.ts b/tests/guilds/create_guild.ts index ec52d695b..b78189573 100644 --- a/tests/guilds/create_guild.ts +++ b/tests/guilds/create_guild.ts @@ -17,7 +17,7 @@ Deno.test({ tempData.guildId = guild.id; // Delay the execution by 5 seconds to allow GUILD_CREATE event to be processed - delayUntil(3000, () => cache.guilds.has(guild.id)); + delayUntil(10000, () => cache.guilds.has(guild.id)); if (!cache.guilds.has(guild.id)) { throw new Error("The guild seemed to be created but it was not cached."); diff --git a/tests/guilds/delete_server.ts b/tests/guilds/delete_server.ts index 07d1a9dcd..8867ea335 100644 --- a/tests/guilds/delete_server.ts +++ b/tests/guilds/delete_server.ts @@ -14,7 +14,7 @@ Deno.test({ } await deleteServer(tempData.guildId); - delayUntil(3000, () => cache.guilds.has(tempData.guildId)); + delayUntil(10000, () => cache.guilds.has(tempData.guildId)); if (cache.guilds.has(tempData.guildId)) { throw new Error("The guild was not able to be deleted."); diff --git a/tests/messages/add_reaction.ts b/tests/messages/add_reaction.ts index 1ba3c0fc4..666abcdb1 100644 --- a/tests/messages/add_reaction.ts +++ b/tests/messages/add_reaction.ts @@ -14,7 +14,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -45,7 +45,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { await message.addReaction(emojiId); } - delayUntil(3000, () => cache.messages.get(message.id)?.reactions?.length > 0); + delayUntil(10000, () => cache.messages.get(message.id)?.reactions?.length > 0); assertEquals( await cache.messages diff --git a/tests/messages/add_reactions.ts b/tests/messages/add_reactions.ts index 7cade1f1f..70bf31054 100644 --- a/tests/messages/add_reactions.ts +++ b/tests/messages/add_reactions.ts @@ -14,7 +14,7 @@ async function ifItFailsBlameWolf( assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -61,7 +61,7 @@ async function ifItFailsBlameWolf( await message.addReactions(emojiIds, ordered); } - delayUntil(3000, () => cache.messages.get(message.id)?.reactions?.length > 0); + delayUntil(10000, () => cache.messages.get(message.id)?.reactions?.length === 2); assertEquals(await cache.messages.get(message.id)?.reactions?.length, 2); } diff --git a/tests/messages/create_message.ts b/tests/messages/create_message.ts index 0be22ad98..2f88c6e85 100644 --- a/tests/messages/create_message.ts +++ b/tests/messages/create_message.ts @@ -12,7 +12,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { assertExists(channel); // Wait few seconds for the channel create event to arrive and cache it - delayUntil(3000, () => cache.channels.has(channel.id)); + delayUntil(10000, () => cache.channels.has(channel.id)); const message = type === "raw" ? await sendMessage(channel.id, "Hello World!") @@ -22,7 +22,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); diff --git a/tests/messages/delete_message.ts b/tests/messages/delete_message.ts index 353305ffb..3c1f963b8 100644 --- a/tests/messages/delete_message.ts +++ b/tests/messages/delete_message.ts @@ -11,7 +11,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -25,7 +25,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", reason?: string) { } // Wait 5 seconds to give it time for MESSAGE_DELETE event - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); // Make sure it is gone from cache if (cache.messages.has(message.id)) { throw new Error( diff --git a/tests/messages/delete_messages.ts b/tests/messages/delete_messages.ts index bdee39b80..453129ab3 100644 --- a/tests/messages/delete_messages.ts +++ b/tests/messages/delete_messages.ts @@ -9,7 +9,7 @@ async function ifItFailsBlameWolf(reason?: string) { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -20,7 +20,7 @@ async function ifItFailsBlameWolf(reason?: string) { // Assertions assertExists(secondMessage); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(secondMessage.id)); + delayUntil(10000, () => cache.messages.has(secondMessage.id)); // Make sure the message was created. if (!cache.messages.has(secondMessage.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -35,7 +35,7 @@ async function ifItFailsBlameWolf(reason?: string) { // Wait 5 seconds to give it time for MESSAGE_DELETE event delayUntil( - 3000, + 10000, () => !cache.messages.has(message.id) && !cache.messages.has(secondMessage.id), ); diff --git a/tests/messages/edit_message.ts b/tests/messages/edit_message.ts index 36b119c59..c3a617034 100644 --- a/tests/messages/edit_message.ts +++ b/tests/messages/edit_message.ts @@ -11,7 +11,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -25,7 +25,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { } // Wait 5 seconds to give it time for MESSAGE_UPDATE event delayUntil( - 3000, + 10000, () => cache.messages.get(message.id)?.content === "Goodbye World!", ); diff --git a/tests/messages/get_message.ts b/tests/messages/get_message.ts index 48e8131e3..14c82deef 100644 --- a/tests/messages/get_message.ts +++ b/tests/messages/get_message.ts @@ -11,7 +11,7 @@ Deno.test({ // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); diff --git a/tests/messages/get_messages.ts b/tests/messages/get_messages.ts index 6e2306eea..8d67ab7eb 100644 --- a/tests/messages/get_messages.ts +++ b/tests/messages/get_messages.ts @@ -22,7 +22,7 @@ Deno.test({ assertExists(thirdMessage); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed delayUntil( - 3000, + 10000, () => cache.messages.has(message.id) && cache.messages.has(secondMessage.id) && diff --git a/tests/messages/get_reactions.ts b/tests/messages/get_reactions.ts index f915093d0..3e0e88b33 100644 --- a/tests/messages/get_reactions.ts +++ b/tests/messages/get_reactions.ts @@ -11,7 +11,7 @@ Deno.test({ // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); diff --git a/tests/messages/pin_message.ts b/tests/messages/pin_message.ts index e40d9a54c..c88156c88 100644 --- a/tests/messages/pin_message.ts +++ b/tests/messages/pin_message.ts @@ -11,7 +11,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); diff --git a/tests/messages/remove_all_reactions.ts b/tests/messages/remove_all_reactions.ts index 9f0fb6744..4c7c6abd5 100644 --- a/tests/messages/remove_all_reactions.ts +++ b/tests/messages/remove_all_reactions.ts @@ -14,7 +14,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -24,7 +24,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { await addReactions(message.channelId, message.id, ["❤", "😃", "🤫"]); // Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed delayUntil( - 3000, + 10000, () => cache.messages.get(message.id)?.reactions?.length === 3, ); @@ -39,7 +39,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed delayUntil( - 3000, + 10000, () => cache.messages.get(message.id)?.reactions === undefined, ); diff --git a/tests/messages/remove_reaction.ts b/tests/messages/remove_reaction.ts index 257117a15..7598cfd7d 100644 --- a/tests/messages/remove_reaction.ts +++ b/tests/messages/remove_reaction.ts @@ -9,7 +9,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -19,7 +19,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { await addReaction(message.channelId, message.id, "❤"); // Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed delayUntil( - 3000, + 10000, () => cache.messages.get(message.id)?.reactions?.length === 1, ); @@ -34,7 +34,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed delayUntil( - 3000, + 10000, () => cache.messages.get(message.id)?.reactions === undefined, ); diff --git a/tests/messages/remove_reaction_emoji.ts b/tests/messages/remove_reaction_emoji.ts index 0c582ab78..28b513606 100644 --- a/tests/messages/remove_reaction_emoji.ts +++ b/tests/messages/remove_reaction_emoji.ts @@ -14,7 +14,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -24,7 +24,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { await addReaction(message.channelId, message.id, "❤"); // Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed delayUntil( - 3000, + 10000, () => cache.messages.get(message.id)?.reactions?.length === 1, ); @@ -39,7 +39,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed delayUntil( - 3000, + 10000, () => cache.messages.get(message.id)?.reactions === undefined, ); diff --git a/tests/messages/remove_user_reaction.ts b/tests/messages/remove_user_reaction.ts index e5f732d18..a60318a05 100644 --- a/tests/messages/remove_user_reaction.ts +++ b/tests/messages/remove_user_reaction.ts @@ -14,7 +14,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Assertions assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); // Make sure the message was created. if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); @@ -24,7 +24,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { await addReaction(message.channelId, message.id, "❤"); // Delay the execution by 5 seconds to allow MESSAGE_REACTION_ALL event to be processed delayUntil( - 3000, + 10000, () => cache.messages.get(message.id)?.reactions?.length === 1, ); @@ -44,7 +44,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { // Delay the execution by 5 seconds to allow MESSAGE_REACTION_REMOVE_ALL event to be processed delayUntil( - 3000, + 10000, () => cache.messages.get(message.id)?.reactions === undefined, ); diff --git a/tests/messages/unpin_message.ts b/tests/messages/unpin_message.ts index d42d64e3f..3dec8b9a0 100644 --- a/tests/messages/unpin_message.ts +++ b/tests/messages/unpin_message.ts @@ -11,7 +11,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { assertExists(message); // Delay the execution by 5 seconds to allow MESSAGE_CREATE event to be processed - delayUntil(3000, () => cache.messages.has(message.id)); + delayUntil(10000, () => cache.messages.has(message.id)); if (!cache.messages.has(message.id)) { throw new Error("The message seemed to be sent but it was not cached."); From 1b952b67136c6a86784050b2f57e65d5c87d0926 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Sat, 10 Apr 2021 23:58:36 +0200 Subject: [PATCH 3/3] fix(tests): higher max delay --- tests/messages/add_reaction.ts | 5 ++++- tests/messages/add_reactions.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/messages/add_reaction.ts b/tests/messages/add_reaction.ts index 666abcdb1..b39b1b925 100644 --- a/tests/messages/add_reaction.ts +++ b/tests/messages/add_reaction.ts @@ -45,7 +45,10 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) { await message.addReaction(emojiId); } - delayUntil(10000, () => cache.messages.get(message.id)?.reactions?.length > 0); + delayUntil( + 10000, + () => cache.messages.get(message.id)?.reactions?.length > 0, + ); assertEquals( await cache.messages diff --git a/tests/messages/add_reactions.ts b/tests/messages/add_reactions.ts index 70bf31054..427f23f3a 100644 --- a/tests/messages/add_reactions.ts +++ b/tests/messages/add_reactions.ts @@ -61,7 +61,10 @@ async function ifItFailsBlameWolf( await message.addReactions(emojiIds, ordered); } - delayUntil(10000, () => cache.messages.get(message.id)?.reactions?.length === 2); + delayUntil( + 10000, + () => cache.messages.get(message.id)?.reactions?.length === 2, + ); assertEquals(await cache.messages.get(message.id)?.reactions?.length, 2); }