monorepo
This commit is contained in:
66
packages/integration-tests/package.json
Normal file
66
packages/integration-tests/package.json
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"name": "reacord-integration-tests",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"lint": "eslint --ext js,ts,tsx .",
|
||||
"lint-fix": "pnpm lint -- --fix",
|
||||
"format": "prettier --write .",
|
||||
"test": "c8 ava",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@itsmapleleaf/configs": "^1.1.0",
|
||||
"@types/node": "*",
|
||||
"@types/react": "*",
|
||||
"@typescript-eslint/eslint-plugin": "^5.6.0",
|
||||
"@typescript-eslint/parser": "^5.6.0",
|
||||
"ava": "^4.0.0-rc.1",
|
||||
"c8": "^7.10.0",
|
||||
"discord.js": "^13.3.1",
|
||||
"dotenv": "^10.0.0",
|
||||
"esbuild": "^0.14.2",
|
||||
"esbuild-node-loader": "^0.6.3",
|
||||
"eslint": "^8.4.1",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-import-resolver-typescript": "^2.5.0",
|
||||
"eslint-plugin-import": "^2.25.3",
|
||||
"eslint-plugin-jsx-a11y": "^6.5.1",
|
||||
"eslint-plugin-react": "^7.27.1",
|
||||
"eslint-plugin-react-hooks": "^4.3.0",
|
||||
"eslint-plugin-unicorn": "^39.0.0",
|
||||
"nanoid": "^3.1.30",
|
||||
"prettier": "^2.5.1",
|
||||
"reacord": "workspace:*",
|
||||
"reacord-helpers": "workspace:*",
|
||||
"react": "^17.0.2",
|
||||
"typescript": "^4.5.4"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"./node_modules/@itsmapleleaf/configs/eslint"
|
||||
],
|
||||
"ignorePatterns": [
|
||||
"**/node_modules/**",
|
||||
"**/coverage/**",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.json"
|
||||
}
|
||||
},
|
||||
"prettier": "@itsmapleleaf/configs/prettier",
|
||||
"ava": {
|
||||
"files": [
|
||||
"**/*.test.{ts,tsx}"
|
||||
],
|
||||
"nodeArguments": [
|
||||
"--loader=esbuild-node-loader",
|
||||
"--experimental-specifier-resolution=node",
|
||||
"--no-warnings"
|
||||
],
|
||||
"extensions": {
|
||||
"ts": "module",
|
||||
"tsx": "module"
|
||||
}
|
||||
}
|
||||
}
|
||||
119
packages/integration-tests/tests/rendering.test.tsx
Normal file
119
packages/integration-tests/tests/rendering.test.tsx
Normal file
@@ -0,0 +1,119 @@
|
||||
import type { ExecutionContext } from "ava"
|
||||
import test from "ava"
|
||||
import { Client, TextChannel } from "discord.js"
|
||||
import { nanoid } from "nanoid"
|
||||
import { createRoot, Embed } from "reacord"
|
||||
import { raise } from "reacord-helpers/raise.js"
|
||||
import React, { useState } from "react"
|
||||
import { testBotToken, testChannelId } from "./test-environment.js"
|
||||
|
||||
const client = new Client({
|
||||
intents: ["GUILDS"],
|
||||
})
|
||||
|
||||
let channel: TextChannel
|
||||
|
||||
test.before(async () => {
|
||||
await client.login(testBotToken)
|
||||
|
||||
const result =
|
||||
client.channels.cache.get(testChannelId) ??
|
||||
(await client.channels.fetch(testChannelId)) ??
|
||||
raise("Channel not found")
|
||||
|
||||
if (!(result instanceof TextChannel)) {
|
||||
throw new TypeError("Channel must be a text channel")
|
||||
}
|
||||
|
||||
channel = result
|
||||
})
|
||||
|
||||
test.after(() => {
|
||||
client.destroy()
|
||||
})
|
||||
|
||||
test.only("test", async (t) => {
|
||||
const root = createRoot(channel)
|
||||
await root.render(
|
||||
<>
|
||||
<Embed color="BLUE">
|
||||
<Embed color="DARKER_GREY" />
|
||||
</Embed>
|
||||
<Embed color="DARKER_GREY" />
|
||||
</>,
|
||||
)
|
||||
t.pass()
|
||||
})
|
||||
|
||||
test("kitchen sink", async (t) => {
|
||||
const root = createRoot(channel)
|
||||
|
||||
const content = nanoid()
|
||||
await root.render(content)
|
||||
|
||||
await assertSomeMessageHasContent(t, content)
|
||||
|
||||
const newContent = nanoid()
|
||||
await root.render(newContent)
|
||||
|
||||
await assertSomeMessageHasContent(t, newContent)
|
||||
|
||||
await root.render(false)
|
||||
|
||||
await assertNoMessageHasContent(t, newContent)
|
||||
})
|
||||
|
||||
test("kitchen sink, rapid updates", async (t) => {
|
||||
const root = createRoot(channel)
|
||||
|
||||
const content = nanoid()
|
||||
const newContent = nanoid()
|
||||
|
||||
void root.render(content)
|
||||
await root.render(newContent)
|
||||
|
||||
await assertSomeMessageHasContent(t, newContent)
|
||||
|
||||
void root.render(content)
|
||||
await root.render(false)
|
||||
|
||||
await assertNoMessageHasContent(t, newContent)
|
||||
})
|
||||
|
||||
test("state", async (t) => {
|
||||
let setMessage: (message: string) => void
|
||||
|
||||
const initialMessage = nanoid()
|
||||
const newMessage = nanoid()
|
||||
|
||||
function Counter() {
|
||||
const [message, setMessage_] = useState(initialMessage)
|
||||
setMessage = setMessage_
|
||||
return `state: ${message}` as any
|
||||
}
|
||||
|
||||
const root = createRoot(channel)
|
||||
await root.render(<Counter />)
|
||||
|
||||
await assertSomeMessageHasContent(t, initialMessage)
|
||||
|
||||
setMessage!(newMessage)
|
||||
await root.completion()
|
||||
|
||||
await assertSomeMessageHasContent(t, newMessage)
|
||||
|
||||
await root.destroy()
|
||||
})
|
||||
|
||||
async function assertSomeMessageHasContent(
|
||||
t: ExecutionContext,
|
||||
content: string,
|
||||
) {
|
||||
const messages = await channel.messages.fetch()
|
||||
t.true(messages.some((m) => m.content.includes(content)))
|
||||
}
|
||||
|
||||
async function assertNoMessageHasContent(t: ExecutionContext, content: string) {
|
||||
const messages = await channel.messages.fetch()
|
||||
t.true(messages.every((m) => !m.content.includes(content)))
|
||||
}
|
||||
10
packages/integration-tests/tests/test-environment.ts
Normal file
10
packages/integration-tests/tests/test-environment.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import "dotenv/config.js"
|
||||
import { raise } from "reacord-helpers/raise.js"
|
||||
|
||||
function getEnvironmentValue(name: string) {
|
||||
return process.env[name] ?? raise(`Missing environment variable: ${name}`)
|
||||
}
|
||||
|
||||
export const testBotToken = getEnvironmentValue("TEST_BOT_TOKEN")
|
||||
// export const testGuildId = getEnvironmentValue("TEST_GUILD_ID")
|
||||
export const testChannelId = getEnvironmentValue("TEST_CHANNEL_ID")
|
||||
3
packages/integration-tests/tsconfig.json
Normal file
3
packages/integration-tests/tsconfig.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json"
|
||||
}
|
||||
Reference in New Issue
Block a user