chore: cleanup
This commit is contained in:
40
packages/app/e2e/fixtures.ts
Normal file
40
packages/app/e2e/fixtures.ts
Normal 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 }
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { test, expect } from "@playwright/test"
|
import { test, expect } from "./fixtures"
|
||||||
import { serverName } from "./utils"
|
import { serverName } from "./utils"
|
||||||
|
|
||||||
test("home renders and shows core entrypoints", async ({ page }) => {
|
test("home renders and shows core entrypoints", async ({ page }) => {
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import { test, expect } from "@playwright/test"
|
import { test, expect } from "./fixtures"
|
||||||
import { dirPath, dirSlug, getWorktree, promptSelector } from "./utils"
|
import { dirPath, promptSelector } from "./utils"
|
||||||
|
|
||||||
test("project route redirects to /session", async ({ page }) => {
|
|
||||||
const directory = await getWorktree()
|
|
||||||
const slug = dirSlug(directory)
|
|
||||||
|
|
||||||
|
test("project route redirects to /session", async ({ page, directory, slug }) => {
|
||||||
await page.goto(dirPath(directory))
|
await page.goto(dirPath(directory))
|
||||||
|
|
||||||
await expect(page).toHaveURL(new RegExp(`/${slug}/session`))
|
await expect(page).toHaveURL(new RegExp(`/${slug}/session`))
|
||||||
await expect(page.locator(promptSelector)).toBeVisible()
|
await expect(page.locator(promptSelector)).toBeVisible()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { test, expect } from "@playwright/test"
|
import { test, expect } from "./fixtures"
|
||||||
import { gotoSession, modKey, promptSelector } from "./utils"
|
import { modKey } from "./utils"
|
||||||
|
|
||||||
test("search palette opens and closes", async ({ page }) => {
|
test("search palette opens and closes", async ({ page, gotoSession }) => {
|
||||||
await gotoSession(page)
|
await gotoSession()
|
||||||
await expect(page.locator(promptSelector)).toBeVisible()
|
|
||||||
|
|
||||||
await page.keyboard.press(`${modKey}+P`)
|
await page.keyboard.press(`${modKey}+P`)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import { test, expect } from "@playwright/test"
|
import { test, expect } from "./fixtures"
|
||||||
import { createSdk, getWorktree, promptSelector, sessionPath } from "./utils"
|
import { promptSelector } from "./utils"
|
||||||
|
|
||||||
test("can open an existing session and type into the prompt", async ({ page }) => {
|
test("can open an existing session and type into the prompt", async ({ page, sdk, gotoSession }) => {
|
||||||
const directory = await getWorktree()
|
|
||||||
const sdk = createSdk(directory)
|
|
||||||
const title = `e2e smoke ${Date.now()}`
|
const title = `e2e smoke ${Date.now()}`
|
||||||
const created = await sdk.session.create({ title }).then((r) => r.data)
|
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
|
const sessionID = created.id
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await page.goto(sessionPath(directory, sessionID))
|
await gotoSession(sessionID)
|
||||||
|
|
||||||
const prompt = page.locator(promptSelector)
|
const prompt = page.locator(promptSelector)
|
||||||
await expect(prompt).toBeVisible()
|
|
||||||
|
|
||||||
await prompt.click()
|
await prompt.click()
|
||||||
await page.keyboard.type("hello from e2e")
|
await page.keyboard.type("hello from e2e")
|
||||||
await expect(prompt).toContainText("hello from e2e")
|
await expect(prompt).toContainText("hello from e2e")
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { test, expect } from "@playwright/test"
|
import { test, expect } from "./fixtures"
|
||||||
import { gotoSession, promptSelector, terminalSelector, terminalToggleKey } from "./utils"
|
import { terminalSelector, terminalToggleKey } from "./utils"
|
||||||
|
|
||||||
test("terminal panel can be toggled", async ({ page }) => {
|
test("terminal panel can be toggled", async ({ page, gotoSession }) => {
|
||||||
await gotoSession(page)
|
await gotoSession()
|
||||||
await expect(page.locator(promptSelector)).toBeVisible()
|
|
||||||
|
|
||||||
const terminal = page.locator(terminalSelector)
|
const terminal = page.locator(terminalSelector)
|
||||||
const initiallyOpen = await terminal.isVisible()
|
const initiallyOpen = await terminal.isVisible()
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { createOpencodeClient } from "@opencode-ai/sdk/v2/client"
|
import { createOpencodeClient } from "@opencode-ai/sdk/v2/client"
|
||||||
import { base64Encode } from "@opencode-ai/util/encode"
|
import { base64Encode } from "@opencode-ai/util/encode"
|
||||||
import type { Page } from "@playwright/test"
|
|
||||||
|
|
||||||
export const serverHost = process.env.PLAYWRIGHT_SERVER_HOST ?? "localhost"
|
export const serverHost = process.env.PLAYWRIGHT_SERVER_HOST ?? "localhost"
|
||||||
export const serverPort = process.env.PLAYWRIGHT_SERVER_PORT ?? "4096"
|
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) {
|
export function sessionPath(directory: string, sessionID?: string) {
|
||||||
return `${dirPath(directory)}/session${sessionID ? `/${sessionID}` : ""}`
|
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) }
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user