← 返回列表
全部 Skill›工具 Tools›app-e2e-tests

app-e2e-tests

作者 @anomalyco · 语言 en
Use when writing, changing, reviewing, or debugging Playwright e2e tests in packages/app/e2e (regression keepers and user stories). Covers the mocked opencode server harness and the Bun static server, per-test isolation, page-load and route cost, the suite-wide service-worker block, races with first mount, hover, measurement, clock, dialogs and shortcuts, projects, shards and worker scheduling, rehearsing Windows timing locally, and diagnosing a CI flake from its artifacts. Not for component tests (stories mounted on packages/stories) or the strobe benchmarks in packages/app/perf.
工具 Tools调试工具通用访问网络读写文件待翻译
最近源活动
—
检测 SKILL.md 语言
en
星标 ★
229,002
分支 Fork
0
安装选项
提示
指令
使用 AI 助手安装
将下面的提示复制到你正在使用的 AI 助手中。
下载完整 Skill 目录(含全部配套文件)。 下载压缩包 ↓
SKILL.md 原文预览

App e2e tests

Read packages/app/e2e/AGENTS.md and the Tests section of packages/app/AGENTS.md first. They define what to test, which locators to use, and how to assert. packages/app/README.md (E2E Testing) documents run modes and env vars. This skill covers what makes these tests slow or flaky in CI, which runs the suite as two shards per OS on 4-vCPU runners (.github/workflows/check-test.yml:217-240). Most races below were found on Windows.

All paths below are relative to packages/app unless they start with packages/, services/ or .github/.

What a test runs against

  • No opencode backend. Each shard leg runs bun --cwd packages/app test:e2e:built --shard=<n>/2 (check-test.yml:287-292). It builds once and starts one Bun static server, e2e/utils/serve.ts, on 127.0.0.1:${PLAYWRIGHT_PORT ?? 3000}. All 5 workers share it (playwright.config.ts:23-27).
  • serve.ts keeps vite preview's SPA fallback rules. Do not move built e2e back to vite preview. On case-insensitive file systems it synchronously reads the whole dist/_assets directory (about 3,100 files) for every asset request, so every worker's page loads wait in line.
  • The API is an in-memory mock per page, running in the test worker. mockOpenCodeServer (e2e/utils/mock-server.ts:202):
  • answers page.route("/api/") with an Effect HttpApi handler;
  • fakes /api/event SSE with an init-script fetch override;
  • serves PTY sockets through routeWebSocket.
  • Unmocked routes fail the test with a 501 and Unmocked API request (mock-server.ts:403-411). Add the route to mock-server.ts once instead of routing around it in a spec.
  • Build pages with the helpers:
  • mockWorkspace, openSession, openDraft, openWorktreeDraft, mockRemoteServer, openSettings (e2e/utils/workspace.ts);
  • setupTimeline (e2e/utils/timeline.ts:209) for streamed timelines, mockServers (mock-server.ts:495) for several origins;
  • seed (e2e/utils/app.ts:61) for storage, holdRoute (app.ts:207) to hold requests until you release them.
  • Deliver events with the mock's push, which buffers until the app connects, or with installSseTransport (e2e/utils/sse-transport.ts:60), whose send resolves on delivery. After page.reload(), await transport.waitForConnection() before sending (e2e/regression/timeline-stream.spec.ts:1700-1702).
  • Windows-only failures are races, not Windows code paths. Mock directories are C:/OpenCode/<name> on every OS (workspace.ts:33), and nothing touches the disk. Lazy chunks, stylesheets and responses finish out of order more often on the Windows runners.

Isolation

  • No shared state between tests. Each test gets a fresh context, mock handler and init scripts. Outside e2e/service-worker, which runs under its own config and shares builds through a worker fixture (e2e/service-worker/cache.spec.ts:21, :74), app e2e has no beforeAll, serial mode, test.extend or worker fixtures. Keep it that way so -g and PLAYWRIGHT_FULLY_PARALLEL=1 keep working.
  • Handlers mutate the objects you pass. Creating a session pushes into sessions (mock-server.ts:839). Renaming writes session.title (:1340), and VCS init writes project.vcs (:1019).
  • Call session()/project() inside the test.
  • mockWorkspace and openSession copy what you pass (workspace.ts:36-48).
  • mockOpenCodeServer and mockServers use your objects as they are. Module-level fixtures like multi-server.spec.ts:10-19 are therefore shared by every test in the file.
  • Timeline builders keep state per test attempt (timeline.ts:165-198). Call stateful builders such as assistantMessage or partUpdated inside the test. Only pure ones such as toolPart belong at module scope.
  • Seed before the first goto. seed writes storage once per tab behind a sessionStorage marker, so reloads keep what the app stored (app.ts:59-90). It cannot reset state mid-test.

Keep it fast

  • Navigate once. Every goto or reload is a cold load of the production bundle: about 150 requests per session open, about 125 of them static files. Each test has a new context, and any page.route disables the HTTP cache. Reach later states through the UI or through pushed events. Reload only when surviving a reload is the contract.
  • Service workers are already blocked suite-wide (serviceWorkers: "block", playwright.config.ts:66-67). Do not add a per-file block; the 11 in e2e/regression are redundant.
  • Production registers /sw.js on load (src/entry.tsx:54-55) and precaches about 1,600 files (globPatterns: ["**/*"], vite.pwa.ts:34). e2e/service-worker/ covers it under its own config. The main config ignores that directory (playwright.config.ts:33-36), and CI runs it after shard 2 (check-test.yml:294-298).
  • Opt back in with test.use({ serviceWorkers: "allow" }) only when the worker is the contract. It never controls the first load (clientsClaim: false, vite.pwa.ts:26-28). After a reload it can control the page, and page routes may then miss its requests.
  • Every built-mode page load logs Playwright's block warning. Console collectors must ignore it, as captureConsoleWarnings does (e2e/utils/command-palette.ts:15-26).
  • **Match new routes with a RegExp or a query-aware glob, not a function.
评论
Aanomalyco
anomalyco
anomalyco/opencode
查看 GitHub 仓库 查看作者的其他 Skill
来源信息
作者@anomalyco
所属大类工具 Tools / 调试工具
国内可用性通用
最近源活动—
风险提示访问网络、读写文件
提示:风险标签为程序静态扫描结果,仅作提示,不代表安全认证。安装前请阅读 SKILL.md 及其引用的脚本、权限,自行判断是否可信。