test(app): e2e utilities

This commit is contained in:
Adam
2026-01-18 05:43:34 -06:00
parent f5eb90514a
commit dd19c3d8f2
6 changed files with 69 additions and 87 deletions

View File

@@ -1,24 +1,11 @@
import { test, expect } from "@playwright/test"
import { createOpencodeClient } from "@opencode-ai/sdk/v2/client"
import { base64Encode } from "@opencode-ai/util/encode"
const host = process.env.PLAYWRIGHT_SERVER_HOST ?? "localhost"
const port = process.env.PLAYWRIGHT_SERVER_PORT ?? "4096"
const url = `http://${host}:${port}`
async function getWorktree() {
const sdk = createOpencodeClient({ baseUrl: url, throwOnError: true })
const result = await sdk.path.get()
const data = result.data
if (!data?.worktree) throw new Error(`Failed to resolve a worktree from ${url}/path`)
return data.worktree
}
import { dirPath, dirSlug, getWorktree, promptSelector } from "./utils"
test("project route redirects to /session", async ({ page }) => {
const directory = await getWorktree()
const slug = base64Encode(directory)
const slug = dirSlug(directory)
await page.goto(`/${slug}`)
await page.goto(dirPath(directory))
await expect(page).toHaveURL(new RegExp(`/${slug}/session`))
await expect(page.locator('[data-component="prompt-input"]')).toBeVisible()
await expect(page.locator(promptSelector)).toBeVisible()
})