一键导入
clean-tests
Use when writing, fixing, editing, or refactoring TypeScript tests. Enforces Clean Code principles—fast tests, boundary coverage, one assert per test.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when writing, fixing, editing, or refactoring TypeScript tests. Enforces Clean Code principles—fast tests, boundary coverage, one assert per test.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when fixing, editing, changing, debugging, or working with any Python code. Applies the Boy Scout Rule—always leave code cleaner than you found it. Orchestrates other clean code skills as needed.
Use when writing, fixing, editing, or reviewing Python comments and docstrings. Enforces Clean Code principles—no metadata, no redundancy, no commented-out code.
Use when writing, fixing, editing, or refactoring Python functions. Enforces Clean Code principles—maximum 3 arguments, single responsibility, no flag parameters.
Use when writing, fixing, editing, or reviewing Python code quality. Enforces Clean Code's core principles—DRY, single responsibility, clear intent, no magic numbers, proper abstractions.
Use when naming, renaming, or fixing names of variables, functions, classes, or modules in Python. Enforces Clean Code principles—descriptive names, appropriate length, no encodings.
Use when writing, fixing, editing, or refactoring Python tests. Enforces Clean Code principles—fast tests, boundary coverage, one assert per test.
| name | clean-tests |
| description | Use when writing, fixing, editing, or refactoring TypeScript tests. Enforces Clean Code principles—fast tests, boundary coverage, one assert per test. |
| when_to_use | Also trigger on: slow or flaky tests, `test.skip`/`it.skip`/`.todo` without a clear reason, `test.only` left in committed code, tests that only cover the happy path, tests with multiple assertions about different concepts, missing boundary cases (empty arrays, off-by-one, page zero), or asks about "coverage gap" / "edge case". |
Test everything that could possibly break. Use coverage tools as a guide, not a goal.
// Bad - only tests happy path
test("divide", () => {
expect(divide(10, 2)).toBe(5);
});
// Good - tests edge cases too
test("divide normal", () => {
expect(divide(10, 2)).toBe(5);
});
test("divide by zero", () => {
expect(() => divide(10, 0)).toThrow(RangeError);
});
test("divide negative", () => {
expect(divide(-10, 2)).toBe(-5);
});
Coverage tools report gaps in your testing strategy. Don't ignore them.
# Run with coverage
vitest run --coverage
# Aim for meaningful coverage, not 100%
Trivial tests document behavior and catch regressions. They're worth more than their cost.
// Worth having - documents expected behavior
test("user default role", () => {
const user = new User("Alice");
expect(user.role).toBe("member");
});
Don't use test.skip to hide problems. Either fix the test or delete it.
// Bad - hiding a problem
test.skip("async operation", () => {
// flaky, fix later
});
// Good - either fix it or document why it's skipped
test.skip("cache invalidation - requires Redis (see CONTRIBUTING.md)", () => {
});
Bugs congregate at boundaries. Test them explicitly.
test("pagination boundaries", () => {
const items = Array.from({ length: 100 }, (_, i) => i);
// First page
expect(paginate(items, 1, 10)).toEqual(items.slice(0, 10));
// Last page
expect(paginate(items, 10, 10)).toEqual(items.slice(90, 100));
// Beyond last page
expect(paginate(items, 11, 10)).toEqual([]);
// Page zero (invalid)
expect(() => paginate(items, 0, 10)).toThrow(RangeError);
// Empty list
expect(paginate([], 1, 10)).toEqual([]);
});
When you find a bug, write tests for all similar cases. Bugs cluster.
// Found bug: off-by-one in date calculation
// Now test ALL date boundaries
test("month boundaries", () => {
expect(lastDayOfMonth(2024, 1)).toBe(31); // January
expect(lastDayOfMonth(2024, 2)).toBe(29); // Leap year February
expect(lastDayOfMonth(2023, 2)).toBe(28); // Non-leap February
expect(lastDayOfMonth(2024, 4)).toBe(30); // 30-day month
expect(lastDayOfMonth(2024, 12)).toBe(31); // December
});
When tests fail, look for patterns. They often point to deeper issues.
// If all async tests fail intermittently,
// the problem isn't the tests—it's the async handling
Look at which code paths are untested. Often they reveal design problems.
// If you can't easily test a function, it probably does too much
// Refactor for testability
Slow tests don't get run. Keep unit tests under 100ms each.
// Bad - hits real database
test("user creation", async () => {
const db = await connectToDatabase(); // Slow!
const user = await db.createUser("Alice");
expect(user.name).toBe("Alice");
});
// Good - uses mock or in-memory
test("user creation", async () => {
const db = new InMemoryDatabase();
const user = await db.createUser("Alice");
expect(user.name).toBe("Alice");
});
// Bad - testing multiple things
test("user", () => {
const user = new User("Alice", "alice@example.com");
expect(user.name).toBe("Alice");
expect(user.email).toBe("alice@example.com");
expect(user.isValid()).toBe(true);
user.activate();
expect(user.isActive).toBe(true);
});
// Good - one concept each
test("user stores name", () => {
const user = new User("Alice", "alice@example.com");
expect(user.name).toBe("Alice");
});
test("user stores email", () => {
const user = new User("Alice", "alice@example.com");
expect(user.email).toBe("alice@example.com");
});
test("new user is valid", () => {
const user = new User("Alice", "alice@example.com");
expect(user.isValid()).toBe(true);
});
test("user can be activated", () => {
const user = new User("Alice", "alice@example.com");
user.activate();
expect(user.isActive).toBe(true);
});
| Rule | Principle |
|---|---|
| T1 | Test everything that could break |
| T2 | Use coverage tools |
| T3 | Don't skip trivial tests |
| T4 | Ignored test = ambiguity question |
| T5 | Test boundary conditions |
| T6 | Exhaustively test near bugs |
| T7 | Look for patterns in failures |
| T8 | Check coverage when debugging |
| T9 | Tests must be fast (<100ms) |