Skip to main content

writing-tests

Use when writing or reviewing tests, or deciding whether a change needs one.

来源信息

仓库
bholmesdev/hubble.md
最近来源活动
2026年9月30日 19:13
检测到的 SKILL.md 语言
英语
星标
1,488
Forks
96

安装方式

默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。

检查来源文件

决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。

正在显示 SKILL.md

SKILL.md
来源说明 · 只读预览
name
writing-tests
description
Use when writing or reviewing tests, or deciding whether a change needs one.
# Writing tests Shape coverage like Kent C. Dodds' testing trophy: static checks at the base, a thin layer of unit tests, most confidence from integration tests, and the smallest budget for end-to-end tests. ## When a test is warranted A test is warranted when it catches a plausible regression that nothing else would. Prove it before keeping the test: 1. Revert the source change, keeping the test. Run it and confirm it goes red. 2. Read the failure. It should fail on the behavior in the test's name, not on a changed signature, a missing helper, or a setup error. 3. If the change touches several behaviors, revert each one separately and confirm a test goes red for each. A test that stays green on revert, or goes red for the wrong reason, is coupled to the code's shape instead of its behavior. Rewrite its assertion or delete it. Good candidates: bug fixes, tricky UI behavior (focus handoff, keyboard flows, races between async work and navigation), and edge cases in pure logic (Markdown parsing and serialization, paths, rename rules). Glue code, prop pass-through, and variations of an already-covered behavior get no test of their own. ## Pick the layer | Layer | Here | Use for | |---|---|---| | Static | Biome, tsc, `pnpm check:react-compiler` | Anything a type or lint rule can catch | | Unit | Vitest on pure functions | Parsers, serializers, path logic | | Integration (default) | Vitest + happy-dom, rendering real components against real stores | UI behavior, store actions | | End-to-end | Playwright driving Electron | A few core flows where a break loses users' work: opening, editing, and saving notes; creating and renaming files | happy-dom has no layout. Verify sticky, scroll, overflow, and positioning by hand with the `test-desktop-app` skill and put a screenshot in the PR, rather than asserting DOM structure. Most changes get no end-to-end test. ## Mock at the seam Fake only what crosses a process or time boundary: `desktopApi`/IPC, the filesystem, the network, timers, `requestAnimationFrame`. Keep stores, components, and the editor real. `apps/desktop/src/store/actions.test.ts` shows the pattern: a fake desktop API with the real store behind it. If a test needs to mock internal modules to reach the behavior, move it one layer up so those modules run for real.
在 GitHub 查看