move integration tests to their own folder

This commit is contained in:
MapleLeaf
2021-12-09 18:48:26 -06:00
parent ffe069eb31
commit 02e938ea56
5 changed files with 24 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
import "dotenv/config.js"
import { raise } from "./helpers/raise.js"
import { raise } from "../src/helpers/raise.js"
function getEnvironmentValue(name: string) {
return process.env[name] ?? raise(`Missing environment variable: ${name}`)

View File

@@ -1,8 +1,8 @@
import test from "ava"
import { Client, TextChannel } from "discord.js"
import { nanoid } from "nanoid"
import { ReacordContainer } from "./container.js"
import { raise } from "./helpers/raise.js"
import { raise } from "../src/helpers/raise.js"
import { createRoot } from "../src/render.js"
import { testBotToken, testChannelId } from "./test-environment.js"
const client = new Client({
@@ -31,10 +31,10 @@ test.after(() => {
})
test("rendering text", async (t) => {
const container = new ReacordContainer(channel)
const root = createRoot(channel)
const content = nanoid()
await container.render([content])
await root.render(content)
{
const messages = await channel.messages.fetch()
@@ -42,14 +42,14 @@ test("rendering text", async (t) => {
}
const newContent = nanoid()
await container.render([newContent])
await root.render(newContent)
{
const messages = await channel.messages.fetch()
t.true(messages.some((m) => m.content === newContent))
}
await container.render([])
await root.render(false)
{
const messages = await channel.messages.fetch()
@@ -58,21 +58,21 @@ test("rendering text", async (t) => {
})
test("rapid updates", async (t) => {
const container = new ReacordContainer(channel)
const root = createRoot(channel)
const content = nanoid()
const newContent = nanoid()
void container.render([content])
await container.render([newContent])
void root.render(content)
await root.render(newContent)
{
const messages = await channel.messages.fetch()
t.true(messages.some((m) => m.content === newContent))
}
void container.render([content])
await container.render([])
void root.render(content)
await root.render(false)
{
const messages = await channel.messages.fetch()

View File

@@ -86,7 +86,7 @@
"--no-warnings"
],
"files": [
"src/**/*.test.ts"
"{src,integration}/**/*.test.ts"
]
}
}

View File

@@ -8,7 +8,7 @@ export class ReacordContainer {
channel: TextBasedChannels
message?: Message
actions: Action[] = []
runningPromise?: PromiseLike<void>
runningPromise?: Promise<void>
constructor(channel: TextBasedChannels) {
this.channel = channel
@@ -75,4 +75,8 @@ export class ReacordContainer {
await this.runningPromise
this.runningPromise = undefined
}
awaitActions() {
return this.runningPromise ?? Promise.resolve()
}
}

View File

@@ -1,20 +1,22 @@
/* eslint-disable unicorn/no-null */
import type { TextBasedChannels } from "discord.js"
import type { ReactNode } from "react"
import { ReacordContainer } from "./container"
import { reconciler } from "./reconciler"
export type ReacordRenderTarget = TextBasedChannels
export function render(content: string, target: ReacordRenderTarget) {
export function createRoot(target: ReacordRenderTarget) {
const container = new ReacordContainer(target)
const containerId = reconciler.createContainer(container, 0, false, null)
reconciler.updateContainer(content, containerId)
return {
rerender: (newContent: string) => {
reconciler.updateContainer(newContent, containerId)
render: (content: ReactNode) => {
reconciler.updateContainer(content, containerId)
return container.awaitActions()
},
destroy: () => {
reconciler.updateContainer(null, containerId)
return container.awaitActions()
},
}
}