agentleFS
evrendomevrendom/opaline/.claude/skills/testing-bun/SKILL.md

testing-bun

Skill311 starsChanged 9 days agoApache-2.0View on GitHub

CRITICAL - Invoke BEFORE writing ANY test code. Use when creating new tests, adding test cases, modifying or removing existing tests, writing `it()` or `describe()` blocks, touching any `*.test.ts` or `*.spec.ts` file, or running the mutation-testing kill matrix. Enforces no try-catch in positive tests, no early returns, no test skipping, and that every test catches something no other test catches.

  • Reads credentials

2 other projects use a version of this; 2 new projects in the last 4 weeks, against 0 the 4 before.

Adopted by

Surging: 2 new projects took it in the last 4 weeks, none the 4 weeks before.thin data

Week of Oct 4: 0 new projectsWeek of Oct 11: 0 new projectsWeek of Oct 18: 0 new projectsWeek of Oct 25: 0 new projectsWeek of Nov 1: 0 new projectsWeek of Nov 8: 0 new projectsWeek of Nov 15: 0 new projectsWeek of Nov 22: 2 new projects
Oct 2026Nov 2026Nov 2026
New projects taking a version of this file each week, over the 8 weeks our latest run read: only 2 in all, so this is a hint, not a trend.

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. About 0 are common, 6 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use bun:test imports (describe, test, expect, etc.)

    line 10
  2. Very specific:

    Use Bun test runner, typically via workspace scripts (bun run test)

    line 11
  3. Distinctive:

    Do not introduce Vitest or Jest in this repo

    line 12
  4. Distinctive:

    Never mock services, DB clients, or external APIs: If a test would need a mock, write the integration test instead.

    line 17
  5. Very specific:

    Never use skip, skipIf, guard return, or branching that bypasses e2e execution when env vars are absent

    line 80
  6. Very specific:

    Prefer plain test(...) blocks with explicit setup

    line 119
  7. Very specific:

    Use package-level scripts (bun test src) for focused runs when needed

    line 120
  8. Distinctive:

    Keep a test only if it catches something no other test catches.

    line 123
  9. Very specific:

    Every mutant (swapped arithmetic, comparison, equality and logical operators, flipped booleans, negated conditions, changed literals, …

    line 132
  10. Distinctive:

    Remove the tests under Removable together, then rerun: the killed count must not drop.

    line 135
  11. Very specific:

    Test names must be static string literals, unique in their file.

    line 138
  12. Distinctive:

    When adding new env vars for tests, update:

    line 142
  13. Very specific:

    Run local e2e/integration suites with bun run test:integration

    line 145
  14. Distinctive:

    Treat missing vars as a hard failure, not a skip path

    line 146

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

Every Test Earns Its Place (Kill Matrix)

Keep a test only if it catches something no other test catches. Prove it with the mutation-testing kill matrix before adding tests to a module, and when trimming its suite:

bun run test:kill-matrix apps/desktop/server/src/services/analysis/find-cursor.ts
# Several modules, explicit test files, options, extra `bun test` flags after --
bun run test:kill-matrix <module.ts>... [--test <file.test.ts>]... [--jobs <n>] [--timeout-ms <n>] [--json <out.json>] [-- <bun test flags>]
  • Paths are relative to the repo root. Without --test, each module's sibling <name>.test.ts is used.
  • Every mutant (swapped arithmetic, comparison, equality and logical operators, flipped booleans, negated conditions, changed literals, removed statements, return undefined) runs against every test alone (bun test <file> --test-name-pattern '^<name>$'), so the matrix records exactly which tests kill it. A run past the time limit counts as a kill.
  • Mutants reach the tests through a bun test --preload hook; no file on disk is written, so an interrupted run leaves nothing behind.
  • The report lists the matrix, kills and unique kills per test, Tests that kill no unique mutant, Removable together, and the survived mutants.
  • Remove the tests under Removable together, then rerun: the killed count must not drop. Not every test without a unique kill can go: two tests that catch the same mutant both lack a unique kill, but one of them must stay.
  • The matrix only knows the modules you pass. Before removing a test that also exercises other modules, pass those too (<a.ts> <b.ts> --test <file.test.ts>): it may be their only killer. The git cursor test in find-cursor.test.ts kills nothing unique in find-cursor.ts but 9 mutants of packages/api-routes/src/analysis.ts.
  • A survived mutant is behaviour no test checks. Add a test only if that behaviour matters; some mutants change nothing observable.
  • Test names must be static string literals, unique in their file. test.each and test.if cannot be attributed and are refused.
  • Cost is one bun test process per mutant and test (find-cursor: 107 mutants × 5 tests in about 25 s with 5 jobs). Run it on unit-tested modules, not integration suites.

Environment Variables

When adding new env vars for tests, update:

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

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.