From 1cbd5e9bfd1b5353ee56786f5381cad8e45da63c Mon Sep 17 00:00:00 2001 From: itsMapleLeaf <19603573+itsMapleLeaf@users.noreply.github.com> Date: Sat, 6 Aug 2022 00:05:30 -0500 Subject: [PATCH] throw together some scuffed integration testing infra --- package.json | 5 +- packages/reacord/package.json | 1 + packages/reacord/test/action-row.test.tsx | 63 +---- packages/reacord/test/embed.test.tsx | 316 +++++++++++----------- packages/reacord/test/global-setup.ts | 5 + packages/reacord/test/tester.ts | 85 ++++++ pnpm-lock.yaml | 33 ++- vitest.config.ts | 7 + 8 files changed, 293 insertions(+), 222 deletions(-) create mode 100644 packages/reacord/test/global-setup.ts create mode 100644 packages/reacord/test/tester.ts diff --git a/package.json b/package.json index 6bf9758..5b8bd4c 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "lint": "eslint --ext js,ts,tsx .", "lint-fix": "pnpm lint -- --fix", "test": "vitest --coverage --no-watch", - "test-dev": "vitest", + "test-dev": "vitest --ui", "format": "prettier --write .", "build": "pnpm -r run build", "start": "pnpm -C packages/website run start", @@ -16,11 +16,12 @@ "@itsmapleleaf/configs": "^1.1.5", "@rushstack/eslint-patch": "^1.1.4", "@types/eslint": "^8.4.5", + "@vitest/ui": "^0.21.0", + "c8": "^7.12.0", "eslint": "^8.20.0", "node": "^16.16.0", "prettier": "^2.7.1", "typescript": "^4.7.4", - "c8": "^7.12.0", "vitest": "^0.20.3" }, "resolutions": { diff --git a/packages/reacord/package.json b/packages/reacord/package.json index f6cec5e..2f611ef 100644 --- a/packages/reacord/package.json +++ b/packages/reacord/package.json @@ -74,6 +74,7 @@ "@reacord/helpers": "workspace:*", "@types/lodash-es": "^4.17.6", "@types/prettier": "^2.6.4", + "date-fns": "^2.29.1", "discord.js": "^14.1.2", "dotenv": "^16.0.1", "lodash-es": "^4.17.21", diff --git a/packages/reacord/test/action-row.test.tsx b/packages/reacord/test/action-row.test.tsx index fd373a4..3b26ef2 100644 --- a/packages/reacord/test/action-row.test.tsx +++ b/packages/reacord/test/action-row.test.tsx @@ -1,60 +1,17 @@ -import { raise } from "@reacord/helpers/raise" -import type { TextBasedChannel } from "discord.js" -import { - CategoryChannel, - ChannelType, - ComponentType, - GatewayIntentBits, -} from "discord.js" +import { ComponentType } from "discord.js" import React from "react" import { beforeAll, expect, test } from "vitest" -import { createDiscordClient } from "../library/create-discord-client" -import { - ActionRow, - Button, - Option, - ReacordClient, - Select, -} from "../library/main" -import { testEnv } from "./test-env" +import { ActionRow, Button, Option, Select } from "../library/main" +import { ReacordTester } from "./tester" -let channel: TextBasedChannel +let tester: ReacordTester beforeAll(async () => { - const client = await createDiscordClient(testEnv.TEST_BOT_TOKEN, { - intents: GatewayIntentBits.Guilds | GatewayIntentBits.GuildMessages, - }) - - const category = - client.channels.cache.get(testEnv.TEST_CATEGORY_ID) ?? - (await client.channels.fetch(testEnv.TEST_CATEGORY_ID)) - - if (!(category instanceof CategoryChannel)) { - throw new TypeError("Category channel not found") - } - - const channelName = "test-channel" - - let existing = category.children.cache.find((the) => the.name === channelName) - if (!existing || !existing.isTextBased()) { - existing = await category.children.create({ - type: ChannelType.GuildText, - name: channelName, - }) - } - channel = existing - - for (const [, message] of await channel.messages.fetch()) { - await message.delete() - } + tester = await ReacordTester.create() }) test("action row", async () => { - const reacord = new ReacordClient({ - token: testEnv.TEST_BOT_TOKEN, - }) - - reacord.send( - channel.id, + const { message } = await tester.render( + "action row", <>