use vitest for tests
This commit is contained in:
2
.github/workflows/the.yml
vendored
2
.github/workflows/the.yml
vendored
@@ -16,7 +16,7 @@ jobs:
|
|||||||
ci:
|
ci:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
script-name: [test-coverage, lint, typecheck]
|
script-name: [test, lint, typecheck]
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
name: ${{ matrix.script-name }}
|
name: ${{ matrix.script-name }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
39
package.json
39
package.json
@@ -8,20 +8,16 @@
|
|||||||
"lint-fix": "pnpm lint -- --fix",
|
"lint-fix": "pnpm lint -- --fix",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"test": "pnpm build && pnpm test-only",
|
"test": "pnpm build && pnpm test-only",
|
||||||
"test-only": "ava",
|
"test-only": "vitest",
|
||||||
"test-coverage": "pnpm build && c8 pnpm test-only",
|
"coverage": "pnpm build && vitest --coverage",
|
||||||
"typecheck": "pnpm build && tsc --noEmit"
|
"typecheck": "pnpm build && tsc --noEmit"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@itsmapleleaf/configs": "^1.1.0",
|
"@itsmapleleaf/configs": "^1.1.2",
|
||||||
"@types/node": "*",
|
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.6.0",
|
"@typescript-eslint/parser": "^5.8.0",
|
||||||
"@typescript-eslint/parser": "^5.6.0",
|
|
||||||
"ava": "^4.0.0-rc.1",
|
|
||||||
"c8": "^7.10.0",
|
"c8": "^7.10.0",
|
||||||
"esbuild": "^0.14.2",
|
"eslint": "^8.5.0",
|
||||||
"esbuild-node-loader": "^0.6.3",
|
|
||||||
"eslint": "^8.4.1",
|
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
"eslint-import-resolver-typescript": "^2.5.0",
|
"eslint-import-resolver-typescript": "^2.5.0",
|
||||||
"eslint-plugin-import": "^2.25.3",
|
"eslint-plugin-import": "^2.25.3",
|
||||||
@@ -29,9 +25,10 @@
|
|||||||
"eslint-plugin-react": "^7.27.1",
|
"eslint-plugin-react": "^7.27.1",
|
||||||
"eslint-plugin-react-hooks": "^4.3.0",
|
"eslint-plugin-react-hooks": "^4.3.0",
|
||||||
"eslint-plugin-unicorn": "^39.0.0",
|
"eslint-plugin-unicorn": "^39.0.0",
|
||||||
"npm-run-all": "^4.1.5",
|
|
||||||
"prettier": "^2.5.1",
|
"prettier": "^2.5.1",
|
||||||
"typescript": "^4.5.4"
|
"typescript": "^4.5.4",
|
||||||
|
"vite": "^2.7.4",
|
||||||
|
"vitest": "^0.0.102"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": [
|
"extends": [
|
||||||
@@ -47,21 +44,5 @@
|
|||||||
"project": "./tsconfig.json"
|
"project": "./tsconfig.json"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"prettier": "@itsmapleleaf/configs/prettier",
|
"prettier": "@itsmapleleaf/configs/prettier"
|
||||||
"ava": {
|
|
||||||
"files": [
|
|
||||||
"**/*.test.{ts,tsx}",
|
|
||||||
"!**/{node_modules,dist,coverage}/**"
|
|
||||||
],
|
|
||||||
"nodeArguments": [
|
|
||||||
"--loader=esbuild-node-loader",
|
|
||||||
"--experimental-specifier-resolution=node",
|
|
||||||
"--no-warnings",
|
|
||||||
"--enable-source-maps"
|
|
||||||
],
|
|
||||||
"extensions": {
|
|
||||||
"ts": "module",
|
|
||||||
"tsx": "module"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
import test from "ava"
|
import { expect, test } from "vitest"
|
||||||
import { createDeferred } from "./deferred.js"
|
import { createDeferred } from "./deferred.js"
|
||||||
|
|
||||||
test("resolve", async (t) => {
|
test("resolve", async () => {
|
||||||
const deferred = createDeferred<string>()
|
const deferred = createDeferred<string>()
|
||||||
setTimeout(() => deferred.resolve("hi"))
|
setTimeout(() => deferred.resolve("hi"))
|
||||||
t.is(await deferred, "hi")
|
expect(await deferred).toBe("hi")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("reject", async (t) => {
|
test("reject", async () => {
|
||||||
const deferred = createDeferred()
|
const deferred = createDeferred()
|
||||||
setTimeout(() => deferred.reject(new Error("oops")))
|
const error = new Error("oops")
|
||||||
await t.throwsAsync(() => deferred, { instanceOf: Error, message: "oops" })
|
setTimeout(() => deferred.reject(error))
|
||||||
|
const caught = await Promise.resolve(deferred).catch((error) => error)
|
||||||
|
expect(caught).toBe(error)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,66 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "reacord-integration-tests",
|
"name": "reacord-integration-tests",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"dependencies": {
|
||||||
"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": "*",
|
"@types/react": "*",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.6.0",
|
"@types/node": "^17.0.1",
|
||||||
"@typescript-eslint/parser": "^5.6.0",
|
|
||||||
"ava": "^4.0.0-rc.1",
|
|
||||||
"c8": "^7.10.0",
|
|
||||||
"discord.js": "^13.3.1",
|
"discord.js": "^13.3.1",
|
||||||
"dotenv": "^10.0.0",
|
"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": "workspace:*",
|
||||||
"reacord-helpers": "workspace:*",
|
"reacord-helpers": "workspace:*",
|
||||||
"react": "^17.0.2",
|
"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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
/* eslint-disable unicorn/numeric-separators-style */
|
|
||||||
/* eslint-disable unicorn/no-null */
|
/* eslint-disable unicorn/no-null */
|
||||||
import type { ExecutionContext } from "ava"
|
|
||||||
import test from "ava"
|
|
||||||
import type { Message } from "discord.js"
|
import type { Message } from "discord.js"
|
||||||
import { Client, TextChannel } from "discord.js"
|
import { Client, TextChannel } from "discord.js"
|
||||||
import type { ReacordRoot } from "reacord"
|
import type { ReacordRoot } from "reacord"
|
||||||
@@ -9,6 +6,7 @@ import { createRoot, Embed, EmbedAuthor, Text } from "reacord"
|
|||||||
import { pick } from "reacord-helpers/pick.js"
|
import { pick } from "reacord-helpers/pick.js"
|
||||||
import { raise } from "reacord-helpers/raise.js"
|
import { raise } from "reacord-helpers/raise.js"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
|
import { afterAll, beforeAll, expect, test } from "vitest"
|
||||||
import { testBotToken, testChannelId } from "./test-environment.js"
|
import { testBotToken, testChannelId } from "./test-environment.js"
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
@@ -18,7 +16,7 @@ const client = new Client({
|
|||||||
let channel: TextChannel
|
let channel: TextChannel
|
||||||
let root: ReacordRoot
|
let root: ReacordRoot
|
||||||
|
|
||||||
test.serial.before(async () => {
|
beforeAll(async () => {
|
||||||
await client.login(testBotToken)
|
await client.login(testBotToken)
|
||||||
|
|
||||||
const result =
|
const result =
|
||||||
@@ -31,31 +29,27 @@ test.serial.before(async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
channel = result
|
channel = result
|
||||||
root = createRoot(channel)
|
|
||||||
|
|
||||||
for (const [, message] of await channel.messages.fetch()) {
|
for (const [, message] of await channel.messages.fetch()) {
|
||||||
await message.delete()
|
await message.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
root = createRoot(channel)
|
||||||
})
|
})
|
||||||
|
|
||||||
test.after(() => {
|
afterAll(() => {
|
||||||
client.destroy()
|
client.destroy()
|
||||||
})
|
})
|
||||||
|
|
||||||
// test.serial.beforeEach(async () => {
|
test("rapid updates", async () => {
|
||||||
// const messages = await channel.messages.fetch()
|
|
||||||
// await Promise.all(messages.map((message) => message.delete()))
|
|
||||||
// })
|
|
||||||
|
|
||||||
test.serial("rapid updates", async (t) => {
|
|
||||||
// rapid updates
|
// rapid updates
|
||||||
void root.render("hi world")
|
void root.render("hi world")
|
||||||
void root.render("hi the")
|
void root.render("hi the")
|
||||||
await root.render("hi moon")
|
await root.render("hi moon")
|
||||||
await assertMessages(t, [{ content: "hi moon" }])
|
await assertMessages([{ content: "hi moon" }])
|
||||||
})
|
})
|
||||||
|
|
||||||
test.serial("nested text", async (t) => {
|
test("nested text", async () => {
|
||||||
await root.render(
|
await root.render(
|
||||||
<Text>
|
<Text>
|
||||||
<Text>hi world</Text>{" "}
|
<Text>hi world</Text>{" "}
|
||||||
@@ -64,35 +58,35 @@ test.serial("nested text", async (t) => {
|
|||||||
</Text>
|
</Text>
|
||||||
</Text>,
|
</Text>,
|
||||||
)
|
)
|
||||||
await assertMessages(t, [{ content: "hi world hi moon hi sun" }])
|
await assertMessages([{ content: "hi world hi moon hi sun" }])
|
||||||
})
|
})
|
||||||
|
|
||||||
test.serial("empty embed fallback", async (t) => {
|
test("empty embed fallback", async () => {
|
||||||
await root.render(<Embed />)
|
await root.render(<Embed />)
|
||||||
await assertMessages(t, [{ embeds: [{ description: "_ _" }] }])
|
await assertMessages([{ embeds: [{ description: "_ _" }] }])
|
||||||
})
|
})
|
||||||
|
|
||||||
test.serial("embed with only author", async (t) => {
|
test("embed with only author", async () => {
|
||||||
await root.render(
|
await root.render(
|
||||||
<Embed>
|
<Embed>
|
||||||
<EmbedAuthor>only author</EmbedAuthor>
|
<EmbedAuthor>only author</EmbedAuthor>
|
||||||
</Embed>,
|
</Embed>,
|
||||||
)
|
)
|
||||||
await assertMessages(t, [
|
await assertMessages([
|
||||||
{ embeds: [{ description: "_ _", author: { name: "only author" } }] },
|
{ embeds: [{ description: "_ _", author: { name: "only author" } }] },
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
test.serial("empty embed author", async (t) => {
|
test("empty embed author", async () => {
|
||||||
await root.render(
|
await root.render(
|
||||||
<Embed>
|
<Embed>
|
||||||
<EmbedAuthor />
|
<EmbedAuthor />
|
||||||
</Embed>,
|
</Embed>,
|
||||||
)
|
)
|
||||||
await assertMessages(t, [{ embeds: [{ description: "_ _" }] }])
|
await assertMessages([{ embeds: [{ description: "_ _" }] }])
|
||||||
})
|
})
|
||||||
|
|
||||||
test.serial("kitchen sink", async (t) => {
|
test("kitchen sink", async () => {
|
||||||
await root.render(
|
await root.render(
|
||||||
<>
|
<>
|
||||||
message <Text>content</Text>
|
message <Text>content</Text>
|
||||||
@@ -111,12 +105,12 @@ test.serial("kitchen sink", async (t) => {
|
|||||||
</Embed>
|
</Embed>
|
||||||
</>,
|
</>,
|
||||||
)
|
)
|
||||||
await assertMessages(t, [
|
await assertMessages([
|
||||||
{
|
{
|
||||||
content: "message contentno space",
|
content: "message contentno space",
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
color: 0xfeeeef,
|
color: 0xfe_ee_ef,
|
||||||
description: "description more description",
|
description: "description more description",
|
||||||
author: {
|
author: {
|
||||||
name: "hi craw",
|
name: "hi craw",
|
||||||
@@ -131,9 +125,9 @@ test.serial("kitchen sink", async (t) => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
test.serial("destroy", async (t) => {
|
test("destroy", async () => {
|
||||||
await root.destroy()
|
await root.destroy()
|
||||||
await assertMessages(t, [])
|
await assertMessages([])
|
||||||
})
|
})
|
||||||
|
|
||||||
type MessageData = ReturnType<typeof extractMessageData>
|
type MessageData = ReturnType<typeof extractMessageData>
|
||||||
@@ -149,14 +143,10 @@ function extractMessageData(message: Message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function assertMessages(
|
async function assertMessages(expected: Array<DeepPartial<MessageData>>) {
|
||||||
t: ExecutionContext<unknown>,
|
|
||||||
expected: Array<DeepPartial<MessageData>>,
|
|
||||||
) {
|
|
||||||
const messages = await channel.messages.fetch()
|
const messages = await channel.messages.fetch()
|
||||||
|
|
||||||
t.deepEqual(
|
expect(messages.map((message) => extractMessageData(message))).toEqual(
|
||||||
messages.map((message) => extractMessageData(message)),
|
|
||||||
expected.map((message) => ({
|
expected.map((message) => ({
|
||||||
content: "",
|
content: "",
|
||||||
...message,
|
...message,
|
||||||
|
|||||||
4
packages/integration-tests/tsconfig.json
Normal file
4
packages/integration-tests/tsconfig.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig",
|
||||||
|
"include": ["**/*", "node_modules/reacord/dist"]
|
||||||
|
}
|
||||||
@@ -31,10 +31,10 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"discord.js": "^13.3.1",
|
"discord.js": "^13.3.1",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"esbuild": "^0.14.2",
|
"esbuild": "^0.14.6",
|
||||||
"nanoid": "^3.1.30",
|
"nanoid": "^3.1.30",
|
||||||
"reacord-helpers": "workspace:*",
|
"reacord-helpers": "workspace:*",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"tsup": "^5.10.3"
|
"tsup": "^5.11.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1197
pnpm-lock.yaml
generated
1197
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user