diff options
| author | Kit Langton <[email protected]> | 2026-04-02 14:17:28 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-04-02 18:17:28 +0000 |
| commit | c3ef69c8664ab84464d720f75eb9bf35289c1847 (patch) | |
| tree | d7b1aa78355c39472804bdfbbd9db87722d0587b /packages/app/e2e/terminal | |
| parent | 363891126c9b2a909db0e724eb6377bd3d12b38b (diff) | |
| download | opencode-c3ef69c8664ab84464d720f75eb9bf35289c1847.tar.gz opencode-c3ef69c8664ab84464d720f75eb9bf35289c1847.zip | |
test(app): add a golden path for mocked e2e prompts (#20593)
Diffstat (limited to 'packages/app/e2e/terminal')
| -rw-r--r-- | packages/app/e2e/terminal/terminal-reconnect.spec.ts | 45 | ||||
| -rw-r--r-- | packages/app/e2e/terminal/terminal-tabs.spec.ts | 247 |
2 files changed, 144 insertions, 148 deletions
diff --git a/packages/app/e2e/terminal/terminal-reconnect.spec.ts b/packages/app/e2e/terminal/terminal-reconnect.spec.ts index b03ed8956..1a11a047a 100644 --- a/packages/app/e2e/terminal/terminal-reconnect.spec.ts +++ b/packages/app/e2e/terminal/terminal-reconnect.spec.ts @@ -12,35 +12,34 @@ async function open(page: Page) { return term } -test("terminal reconnects without replacing the pty", async ({ page, withProject }) => { - await withProject(async ({ gotoSession }) => { - const name = `OPENCODE_E2E_RECONNECT_${Date.now()}` - const token = `E2E_RECONNECT_${Date.now()}` +test("terminal reconnects without replacing the pty", async ({ page, project }) => { + await project.open() + const name = `OPENCODE_E2E_RECONNECT_${Date.now()}` + const token = `E2E_RECONNECT_${Date.now()}` - await gotoSession() + await project.gotoSession() - const term = await open(page) - const id = await term.getAttribute("data-pty-id") - if (!id) throw new Error("Active terminal missing data-pty-id") + const term = await open(page) + const id = await term.getAttribute("data-pty-id") + if (!id) throw new Error("Active terminal missing data-pty-id") - const prev = await terminalConnects(page, { term }) + const prev = await terminalConnects(page, { term }) - await runTerminal(page, { - term, - cmd: `export ${name}=${token}; echo ${token}`, - token, - }) + await runTerminal(page, { + term, + cmd: `export ${name}=${token}; echo ${token}`, + token, + }) - await disconnectTerminal(page, { term }) + await disconnectTerminal(page, { term }) - await expect.poll(() => terminalConnects(page, { term }), { timeout: 15_000 }).toBeGreaterThan(prev) - await expect.poll(() => term.getAttribute("data-pty-id"), { timeout: 5_000 }).toBe(id) + await expect.poll(() => terminalConnects(page, { term }), { timeout: 15_000 }).toBeGreaterThan(prev) + await expect.poll(() => term.getAttribute("data-pty-id"), { timeout: 5_000 }).toBe(id) - await runTerminal(page, { - term, - cmd: `echo $${name}`, - token, - timeout: 15_000, - }) + await runTerminal(page, { + term, + cmd: `echo $${name}`, + token, + timeout: 15_000, }) }) diff --git a/packages/app/e2e/terminal/terminal-tabs.spec.ts b/packages/app/e2e/terminal/terminal-tabs.spec.ts index 6b6fa4c62..5cb5bbf20 100644 --- a/packages/app/e2e/terminal/terminal-tabs.spec.ts +++ b/packages/app/e2e/terminal/terminal-tabs.spec.ts @@ -36,133 +36,130 @@ async function store(page: Page, key: string) { }, key) } -test("inactive terminal tab buffers persist across tab switches", async ({ page, withProject }) => { - await withProject(async ({ directory, gotoSession }) => { - const key = workspacePersistKey(directory, "terminal") - const one = `E2E_TERM_ONE_${Date.now()}` - const two = `E2E_TERM_TWO_${Date.now()}` - const tabs = page.locator('#terminal-panel [data-slot="tabs-trigger"]') - const first = tabs.filter({ hasText: /Terminal 1/ }).first() - const second = tabs.filter({ hasText: /Terminal 2/ }).first() - - await gotoSession() - await open(page) - - await runTerminal(page, { cmd: `echo ${one}`, token: one }) - - await page.getByRole("button", { name: /new terminal/i }).click() - await expect(tabs).toHaveCount(2) - - await runTerminal(page, { cmd: `echo ${two}`, token: two }) - - await first.click() - await expect(first).toHaveAttribute("aria-selected", "true") - - await expect - .poll( - async () => { - const state = await store(page, key) - const first = state?.all.find((item) => item.titleNumber === 1)?.buffer ?? "" - const second = state?.all.find((item) => item.titleNumber === 2)?.buffer ?? "" - return { - first: first.includes(one), - second: second.includes(two), - } - }, - { timeout: 5_000 }, - ) - .toEqual({ first: false, second: true }) - - await second.click() - await expect(second).toHaveAttribute("aria-selected", "true") - await expect - .poll( - async () => { - const state = await store(page, key) - const first = state?.all.find((item) => item.titleNumber === 1)?.buffer ?? "" - const second = state?.all.find((item) => item.titleNumber === 2)?.buffer ?? "" - return { - first: first.includes(one), - second: second.includes(two), - } - }, - { timeout: 5_000 }, - ) - .toEqual({ first: true, second: false }) - }) +test("inactive terminal tab buffers persist across tab switches", async ({ page, project }) => { + await project.open() + const key = workspacePersistKey(project.directory, "terminal") + const one = `E2E_TERM_ONE_${Date.now()}` + const two = `E2E_TERM_TWO_${Date.now()}` + const tabs = page.locator('#terminal-panel [data-slot="tabs-trigger"]') + const first = tabs.filter({ hasText: /Terminal 1/ }).first() + const second = tabs.filter({ hasText: /Terminal 2/ }).first() + + await project.gotoSession() + await open(page) + + await runTerminal(page, { cmd: `echo ${one}`, token: one }) + + await page.getByRole("button", { name: /new terminal/i }).click() + await expect(tabs).toHaveCount(2) + + await runTerminal(page, { cmd: `echo ${two}`, token: two }) + + await first.click() + await expect(first).toHaveAttribute("aria-selected", "true") + + await expect + .poll( + async () => { + const state = await store(page, key) + const first = state?.all.find((item) => item.titleNumber === 1)?.buffer ?? "" + const second = state?.all.find((item) => item.titleNumber === 2)?.buffer ?? "" + return { + first: first.includes(one), + second: second.includes(two), + } + }, + { timeout: 5_000 }, + ) + .toEqual({ first: false, second: true }) + + await second.click() + await expect(second).toHaveAttribute("aria-selected", "true") + await expect + .poll( + async () => { + const state = await store(page, key) + const first = state?.all.find((item) => item.titleNumber === 1)?.buffer ?? "" + const second = state?.all.find((item) => item.titleNumber === 2)?.buffer ?? "" + return { + first: first.includes(one), + second: second.includes(two), + } + }, + { timeout: 5_000 }, + ) + .toEqual({ first: true, second: false }) }) -test("closing the active terminal tab falls back to the previous tab", async ({ page, withProject }) => { - await withProject(async ({ directory, gotoSession }) => { - const key = workspacePersistKey(directory, "terminal") - const tabs = page.locator('#terminal-panel [data-slot="tabs-trigger"]') - - await gotoSession() - await open(page) - - await page.getByRole("button", { name: /new terminal/i }).click() - await expect(tabs).toHaveCount(2) - - const second = tabs.filter({ hasText: /Terminal 2/ }).first() - await second.click() - await expect(second).toHaveAttribute("aria-selected", "true") - - await second.hover() - await page - .getByRole("button", { name: /close terminal/i }) - .nth(1) - .click({ force: true }) - - const first = tabs.filter({ hasText: /Terminal 1/ }).first() - await expect(tabs).toHaveCount(1) - await expect(first).toHaveAttribute("aria-selected", "true") - await expect - .poll( - async () => { - const state = await store(page, key) - return { - count: state?.all.length ?? 0, - first: state?.all.some((item) => item.titleNumber === 1) ?? false, - } - }, - { timeout: 15_000 }, - ) - .toEqual({ count: 1, first: true }) - }) +test("closing the active terminal tab falls back to the previous tab", async ({ page, project }) => { + await project.open() + const key = workspacePersistKey(project.directory, "terminal") + const tabs = page.locator('#terminal-panel [data-slot="tabs-trigger"]') + + await project.gotoSession() + await open(page) + + await page.getByRole("button", { name: /new terminal/i }).click() + await expect(tabs).toHaveCount(2) + + const second = tabs.filter({ hasText: /Terminal 2/ }).first() + await second.click() + await expect(second).toHaveAttribute("aria-selected", "true") + + await second.hover() + await page + .getByRole("button", { name: /close terminal/i }) + .nth(1) + .click({ force: true }) + + const first = tabs.filter({ hasText: /Terminal 1/ }).first() + await expect(tabs).toHaveCount(1) + await expect(first).toHaveAttribute("aria-selected", "true") + await expect + .poll( + async () => { + const state = await store(page, key) + return { + count: state?.all.length ?? 0, + first: state?.all.some((item) => item.titleNumber === 1) ?? false, + } + }, + { timeout: 15_000 }, + ) + .toEqual({ count: 1, first: true }) }) -test("terminal tab can be renamed from the context menu", async ({ page, withProject }) => { - await withProject(async ({ directory, gotoSession }) => { - const key = workspacePersistKey(directory, "terminal") - const rename = `E2E term ${Date.now()}` - const tab = page.locator('#terminal-panel [data-slot="tabs-trigger"]').first() - - await gotoSession() - await open(page) - - await expect(tab).toContainText(/Terminal 1/) - await tab.click({ button: "right" }) - - const menu = page.locator(dropdownMenuContentSelector).first() - await expect(menu).toBeVisible() - await menu.getByRole("menuitem", { name: /^Rename$/i }).click() - await expect(menu).toHaveCount(0) - - const input = page.locator('#terminal-panel input[type="text"]').first() - await expect(input).toBeVisible() - await input.fill(rename) - await input.press("Enter") - - await expect(input).toHaveCount(0) - await expect(tab).toContainText(rename) - await expect - .poll( - async () => { - const state = await store(page, key) - return state?.all[0]?.title - }, - { timeout: 5_000 }, - ) - .toBe(rename) - }) +test("terminal tab can be renamed from the context menu", async ({ page, project }) => { + await project.open() + const key = workspacePersistKey(project.directory, "terminal") + const rename = `E2E term ${Date.now()}` + const tab = page.locator('#terminal-panel [data-slot="tabs-trigger"]').first() + + await project.gotoSession() + await open(page) + + await expect(tab).toContainText(/Terminal 1/) + await tab.click({ button: "right" }) + + const menu = page.locator(dropdownMenuContentSelector).first() + await expect(menu).toBeVisible() + await menu.getByRole("menuitem", { name: /^Rename$/i }).click() + await expect(menu).toHaveCount(0) + + const input = page.locator('#terminal-panel input[type="text"]').first() + await expect(input).toBeVisible() + await input.fill(rename) + await input.press("Enter") + + await expect(input).toHaveCount(0) + await expect(tab).toContainText(rename) + await expect + .poll( + async () => { + const state = await store(page, key) + return state?.all[0]?.title + }, + { timeout: 5_000 }, + ) + .toBe(rename) }) |
