Agent Skillsevrendom/rudel › testing-bun

testing-bun

GitHub

规范Bun测试编写标准,强制使用bun:test及真实基础设施集成测试,禁止Mock。核心规则包括:正例测试禁用try-catch和提前返回,缺失环境变量时直接报错而非跳过,优先内联初始化。

.claude/skills/testing-bun/SKILL.md evrendom/rudel

触发场景

创建新测试文件 (*.test.ts, *.spec.ts) 编写 it() 或 describe() 块 修改现有测试用例 涉及测试逻辑的代码变更

安装

npx skills add evrendom/rudel --skill testing-bun -g -y
更多选项

非标准路径

npx skills add https://github.com/evrendom/rudel/tree/main/.claude/skills/testing-bun -g -y

不安装直接使用

npx skills use evrendom/rudel@testing-bun

指定 Agent (Claude Code)

npx skills add evrendom/rudel --skill testing-bun -a claude-code -g -y

安装 repo 全部 skill

npx skills add evrendom/rudel --all -g -y

预览 repo 内 skill

npx skills add evrendom/rudel --list

SKILL.md

Frontmatter
{
    "name": "testing-bun",
    "description": "CRITICAL - Invoke BEFORE writing ANY test code. Use when creating new tests, adding test cases, modifying existing tests, writing `it()` or `describe()` blocks, or touching any `*.test.ts` or `*.spec.ts` file. Enforces no try-catch in positive tests, no early returns, no test skipping.",
    "allowed-tools": [
        "Read",
        "Edit",
        "Grep",
        "Glob",
        "Bash"
    ]
}

Testing Standards (Bun)

Framework

  • Use bun:test imports (describe, test, expect, etc.)
  • Use Bun test runner, typically via workspace scripts (bun run test)
  • Do not introduce Vitest or Jest in this repo
  • For local e2e/integration runs, provide required env vars through the shell or .env

Test Strategy

  • Default to API integration tests against real infrastructure (real Postgres, real ClickHouse). Call a real endpoint, let data flow through the API into the DB, then verify by calling another endpoint. This is "e2e" from the API perspective only — frontend is out of scope here.
  • Never mock services, DB clients, or external APIs. If a test would need a mock, write the integration test instead.
  • Unit tests are reserved for pure logical utilities (parsers, formatters, pure functions). A service that "needs" a unit test is a smell — prefer the integration path above.

Critical Rules

1. No Try/Catch in Positive Tests

// Bad - Hides real errors
test('creates user', async () => {
  try {
    const user = await createUser(input)
    expect(user.id).toBeDefined()
  } catch (error) {
    console.error(error)
  }
})

// Good - Let test framework handle errors
test('creates user', async () => {
  const user = await createUser(input)
  expect(user.id).toBeDefined()
})

// Good - Only for testing expected failures
test('rejects invalid input', async () => {
  await expect(createUser(invalid)).rejects.toThrow('Invalid email')
})

2. No Early Returns in Tests

// Bad - Silently skips test
test('calls API', async () => {
  if (!hasCredentials) return
  await callApi()
})

// Good - Fail when preconditions missing
test('calls API', async () => {
  expect(hasCredentials).toBe(true)
  await callApi()
})

3. No Hidden Skips for Missing Env Vars

// Bad
describe.skipIf(!process.env.CLICKHOUSE_URL)('integration', () => {})

// Bad
if (!process.env.CLICKHOUSE_URL) {
  test.skip('requires CLICKHOUSE_URL', () => {})
}

// Good - Let tests fail if env not configured
describe('integration', () => {
  const url = process.env.CLICKHOUSE_URL
  expect(url).toBeTruthy()
})

4. E2E Policy (Mandatory)

  • E2E tests must never be conditional on env availability
  • Never use skip, skipIf, guard return, or branching that bypasses e2e execution when env vars are absent
  • Missing required env vars must cause test failure immediately
  • Local e2e execution must provide the required vars through the shell or .env
# Required local command for env-dependent suites
bun run test:integration

5. Prefer Inline Setup Over beforeEach

// Bad - Unnecessary beforeEach
describe('Tests', () => {
  let queryBuilder: QueryBuilder
  beforeEach(() => {
    queryBuilder = new QueryBuilder(schema)
  })
})

// Good - Inline initialization
describe('Tests', () => {
  const queryBuilder = new QueryBuilder(schema)
})

// Good - Use beforeEach only for async cleanup
beforeEach(async () => {
  await client.query('DELETE FROM test_table')
})

Best Practices

Use assert() for Type Narrowing

// Good - Provides type narrowing
assert(checkoutRecord)

Keep Tests Deterministic and Isolated

  • Prefer plain test(...) blocks with explicit setup
  • Use package-level scripts (bun test src) for focused runs when needed

Environment Variables

When adding new env vars for tests, update:

  1. Package's turbo.jsonpassThroughEnv array
  2. .github/workflows/ci.ymlenv section
  3. Run local e2e/integration suites with bun run test:integration
  4. Treat missing vars as a hard failure, not a skip path

版本历史

  • 59fc2ed 当前 2026-08-02 20:51

    移除对Doppler环境管理工具的依赖,改为通过shell或.env提供环境变量;简化本地E2E执行命令说明。

  • 781a16e 2026-07-24 11:32

同 Skill 集合

.claude/skills/api-testing/SKILL.md
.claude/skills/clickhouse-architecture-advisor/SKILL.md
.claude/skills/clickhouse-best-practices/SKILL.md
.claude/skills/clickhouse-js-node-coding/SKILL.md
.claude/skills/clickhouse-query/SKILL.md
.claude/skills/code-architecture/SKILL.md
.claude/skills/environment-variables/SKILL.md
.claude/skills/library-docs/SKILL.md
.claude/skills/pr-creation/SKILL.md
.claude/skills/typescript-standards/SKILL.md
.claude/skills/clickhouse-js-node-troubleshooting/SKILL.md

元信息

文件数
0
版本
59fc2ed
Hash
af8b4590
收录时间
2026-07-24 11:32

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-08 06:02
浙ICP备14020137号-1 $访客地图$