terminal-reconnect.spec.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import type { Page } from "@playwright/test"
  2. import { disconnectTerminal, runTerminal, terminalConnects, waitTerminalReady } from "../actions"
  3. import { test, expect } from "../fixtures"
  4. import { terminalSelector } from "../selectors"
  5. import { terminalToggleKey } from "../utils"
  6. async function open(page: Page) {
  7. const term = page.locator(terminalSelector).first()
  8. const visible = await term.isVisible().catch(() => false)
  9. if (!visible) await page.keyboard.press(terminalToggleKey)
  10. await waitTerminalReady(page, { term })
  11. return term
  12. }
  13. test("terminal reconnects without replacing the pty", async ({ page, project }) => {
  14. await project.open()
  15. const name = `OPENCODE_E2E_RECONNECT_${Date.now()}`
  16. const token = `E2E_RECONNECT_${Date.now()}`
  17. await project.gotoSession()
  18. const term = await open(page)
  19. const id = await term.getAttribute("data-pty-id")
  20. if (!id) throw new Error("Active terminal missing data-pty-id")
  21. const prev = await terminalConnects(page, { term })
  22. await runTerminal(page, {
  23. term,
  24. cmd: `export ${name}=${token}; echo ${token}`,
  25. token,
  26. })
  27. await disconnectTerminal(page, { term })
  28. await expect.poll(() => terminalConnects(page, { term }), { timeout: 15_000 }).toBeGreaterThan(prev)
  29. await expect.poll(() => term.getAttribute("data-pty-id"), { timeout: 5_000 }).toBe(id)
  30. await runTerminal(page, {
  31. term,
  32. cmd: `echo $${name}`,
  33. token,
  34. timeout: 15_000,
  35. })
  36. })