chore: cleanup

This commit is contained in:
Adam
2026-01-19 05:22:35 -06:00
parent f1daf3b430
commit 182c43a78f
7 changed files with 57 additions and 32 deletions

View File

@@ -0,0 +1,40 @@
import { test as base, expect } from "@playwright/test"
import { createSdk, dirSlug, getWorktree, promptSelector, sessionPath } from "./utils"
type TestFixtures = {
sdk: ReturnType<typeof createSdk>
gotoSession: (sessionID?: string) => Promise<void>
}
type WorkerFixtures = {
directory: string
slug: string
}
export const test = base.extend<TestFixtures, WorkerFixtures>({
directory: [
async ({}, use) => {
const directory = await getWorktree()
await use(directory)
},
{ scope: "worker" },
],
slug: [
async ({ directory }, use) => {
await use(dirSlug(directory))
},
{ scope: "worker" },
],
sdk: async ({ directory }, use) => {
await use(createSdk(directory))
},
gotoSession: async ({ page, directory }, use) => {
const gotoSession = async (sessionID?: string) => {
await page.goto(sessionPath(directory, sessionID))
await expect(page.locator(promptSelector)).toBeVisible()
}
await use(gotoSession)
},
})
export { expect }

View File

@@ -1,4 +1,4 @@
import { test, expect } from "@playwright/test"
import { test, expect } from "./fixtures"
import { serverName } from "./utils"
test("home renders and shows core entrypoints", async ({ page }) => {

View File

@@ -1,11 +1,9 @@
import { test, expect } from "@playwright/test"
import { dirPath, dirSlug, getWorktree, promptSelector } from "./utils"
test("project route redirects to /session", async ({ page }) => {
const directory = await getWorktree()
const slug = dirSlug(directory)
import { test, expect } from "./fixtures"
import { dirPath, promptSelector } from "./utils"
test("project route redirects to /session", async ({ page, directory, slug }) => {
await page.goto(dirPath(directory))
await expect(page).toHaveURL(new RegExp(`/${slug}/session`))
await expect(page.locator(promptSelector)).toBeVisible()
})

View File

@@ -1,9 +1,8 @@
import { test, expect } from "@playwright/test"
import { gotoSession, modKey, promptSelector } from "./utils"
import { test, expect } from "./fixtures"
import { modKey } from "./utils"
test("search palette opens and closes", async ({ page }) => {
await gotoSession(page)
await expect(page.locator(promptSelector)).toBeVisible()
test("search palette opens and closes", async ({ page, gotoSession }) => {
await gotoSession()
await page.keyboard.press(`${modKey}+P`)

View File

@@ -1,9 +1,7 @@
import { test, expect } from "@playwright/test"
import { createSdk, getWorktree, promptSelector, sessionPath } from "./utils"
import { test, expect } from "./fixtures"
import { promptSelector } from "./utils"
test("can open an existing session and type into the prompt", async ({ page }) => {
const directory = await getWorktree()
const sdk = createSdk(directory)
test("can open an existing session and type into the prompt", async ({ page, sdk, gotoSession }) => {
const title = `e2e smoke ${Date.now()}`
const created = await sdk.session.create({ title }).then((r) => r.data)
@@ -11,11 +9,9 @@ test("can open an existing session and type into the prompt", async ({ page }) =
const sessionID = created.id
try {
await page.goto(sessionPath(directory, sessionID))
await gotoSession(sessionID)
const prompt = page.locator(promptSelector)
await expect(prompt).toBeVisible()
await prompt.click()
await page.keyboard.type("hello from e2e")
await expect(prompt).toContainText("hello from e2e")

View File

@@ -1,9 +1,8 @@
import { test, expect } from "@playwright/test"
import { gotoSession, promptSelector, terminalSelector, terminalToggleKey } from "./utils"
import { test, expect } from "./fixtures"
import { terminalSelector, terminalToggleKey } from "./utils"
test("terminal panel can be toggled", async ({ page }) => {
await gotoSession(page)
await expect(page.locator(promptSelector)).toBeVisible()
test("terminal panel can be toggled", async ({ page, gotoSession }) => {
await gotoSession()
const terminal = page.locator(terminalSelector)
const initiallyOpen = await terminal.isVisible()

View File

@@ -1,6 +1,5 @@
import { createOpencodeClient } from "@opencode-ai/sdk/v2/client"
import { base64Encode } from "@opencode-ai/util/encode"
import type { Page } from "@playwright/test"
export const serverHost = process.env.PLAYWRIGHT_SERVER_HOST ?? "localhost"
export const serverPort = process.env.PLAYWRIGHT_SERVER_PORT ?? "4096"
@@ -37,9 +36,3 @@ export function dirPath(directory: string) {
export function sessionPath(directory: string, sessionID?: string) {
return `${dirPath(directory)}/session${sessionID ? `/${sessionID}` : ""}`
}
export async function gotoSession(page: Page, sessionID?: string) {
const directory = await getWorktree()
await page.goto(sessionPath(directory, sessionID))
return { directory, slug: dirSlug(directory) }
}