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

component-tests

作者 @anomalyco · 语言 en
Use when writing, changing, debugging, or reviewing the Playwright component tests that mount stories. That covers specs in packages/app/component-tests or packages/session-ui/component-tests, `*.fixture.tsx` files there or beside source (such as packages/gui-plugins/src/browser/panel.fixture.tsx), the stories they mount, and the shared harness in packages/stories (playwright/config.ts, playwright/story.ts, vite.config.ts, src/frame.tsx, src/index-plugin.ts, mocks). Also use when a component test is flaky, passed on retry, or fails with "Execution context was destroyed", "Failed to fetch dynamically imported module", or `#story-root` hidden. Covers mount args, source modules imported by URL, Vite dependency pre-bundling and reloads, a cold vs warm story server, mobile drawers, geometry, and checks before pushing.
工具 Tools调试工具通用执行命令访问网络读写文件待翻译
最近源活动
2026-11-21 22:10
检测 SKILL.md 语言
en
星标 ★
229,002
分支 Fork
31,017
安装选项
提示
指令
使用 AI 助手安装
将下面的提示复制到你正在使用的 AI 助手中。
下载完整 Skill 目录(含全部配套文件)。 下载压缩包 ↓
SKILL.md 原文预览

Component tests

Each package suite starts one story server, a plain Vite dev server for packages/stories, and every worker shares it (packages/stories/playwright/config.ts:17-26; CI uses 2 workers, config.ts:15). With fullyParallel (config.ts:12), the tests of one file run on several workers in any order. There is no backend: server, SDK and sync modules are in-page mocks. Every test gets a fresh context, and mount is a full page navigation to the frame (packages/stories/playwright/story.ts:37). Slow or flaky component tests in CI have come from five sources: the shared server's dependency optimizer, module resolution that depended on the install layout, a cold first story, a product race (the mobile drawer), or an action that ran before the UI reached the state it needed.

Read these first rather than repeating them:

  • packages/stories/playwright/README.md covers layout, run commands and "Adding a test".
  • packages/app/AGENTS.md "Tests" decides whether a test should exist, when theme or direction cases are allowed, and that a regression test must fail before the fix.
  • packages/app/e2e/AGENTS.md "Test Hygiene" applies here unchanged.

Stories and mount

  • Location. Put the story next to the production component under src/ of ui, session-ui, app or gui-plugins. The story server indexes *.stories.tsx files in those four trees (packages/stories/vite.config.ts, src/index-plugin.ts), reading each file's export default { title, id } and its export const stories from source.
  • Story ID. It is the meta id if one is set (packages/session-ui/src/components/session-review.stories.tsx:25). Otherwise it is the kebab-cased title, then --, then the kebab-cased export. Check it at http://127.0.0.1:6006/?id=<id> on a running story server (bun --cwd packages/stories dev). A wrong ID renders nothing (the page throws No story has the id …), so mount waits out its full 30 s root wait (story.ts:39) and then fails.
  • URL args. mount(id, { args, globals }) writes them into the URL as key:value pairs (story.ts:20-36). The frame reads every one: a value becomes a boolean or number when the story's own default for that key is one, !true/!false/!null/!undefined keep Storybook's meaning, and anything else stays text.
  • Give every arg a typed default. With args: { split: false } (session-review.stories.tsx:129), split:false arrives as a boolean.
  • A value containing ; would split the pair list, so pick such values inside the story, from a scenario-style arg.
  • Globals are theme (default light), direction and locale (packages/stories/src/frame.tsx).
  • Portaled UI. mount returns #story-root. Dialogs, menus and drawers render outside it, so locate them from page (packages/app/component-tests/composer.spec.ts:101-107).
  • Server state comes from the resolve.alias list in packages/stories/vite.config.ts, which points app server, SDK and sync modules at packages/stories/mocks/app/**. Extend a mock rather than adding a server. The app's components lab renders the same stories inside the real app instead, so a story must not depend on a mock-only export. Tests reset mock state on every mount.
  • Requests the mocks do not answer. Route them with page.route. That includes server endpoints such as /api/fs/read (packages/session-ui/component-tests/read-image.spec.ts:20) and external URLs such as favicons (packages/session-ui/component-tests/markdown.spec.ts:217).

Fixtures imported by URL

Use these when the contract is not visible in a story, such as construction counts, unmount races or cache state.

  • Fixture file. Put a *.fixture.tsx file in component-tests/ or beside the source it drives (packages/gui-plugins/src/browser/panel.fixture.tsx). It exports a mountX() that renders into a host with a data-testid (packages/session-ui/component-tests/basic-tool.fixture.tsx:7-46). Never end the name in .spec or .test.
  • Mount it in three steps.
  1. Mount a light story first, so that the app styles load.
  2. Import the fixture and call it inside page.evaluate.
  3. Locate it with page.getByTestId (packages/session-ui/component-tests/basic-tool.spec.ts:30-36).

It renders outside the frame's decorators, so it must supply its own providers (packages/app/component-tests/browser-pane-restore.spec.ts:69-83).

  • Module URLs. Build each one with sourceURL(new URL("<relative path with extension>", import.meta.url)) (story.ts:10), written as a string literal in the spec (browser-pane-restore.spec.ts:6-24). Any other spelling either fails to load or loads a second module instance whose contexts the page never provides; a hand-written /@fs//... is the documented second-instance case (story.ts:6-9). The literal also matters for pre-bundling (next section).
  • Aliases. A module imported by URL is the real file. App code that reaches the same module through a vite.config.ts alias gets the mock (browser-pane-restore.spec.ts:95-96). Decide which of the two the contract needs.
  • **Spec imp
评论
Aanomalyco
anomalyco
anomalyco/opencode
查看 GitHub 仓库 查看作者的其他 Skill
来源信息
作者@anomalyco
所属大类工具 Tools / 调试工具
国内可用性通用
最近源活动2026-11-21 22:10
风险提示执行命令、访问网络、读写文件
提示:风险标签为程序静态扫描结果,仅作提示,不代表安全认证。安装前请阅读 SKILL.md 及其引用的脚本、权限,自行判断是否可信。