Skip to main content
ClaudeWave
Skill196 repo starsupdated 2d ago

bun-test-coverage

bun-test-coverage configures code coverage reporting for the Bun test runner using the built-in coverage feature with command-line flags, bunfig.toml configuration, and multiple reporter formats including lcov for CI integration. Use this skill when setting up test coverage measurement, enforcing minimum coverage thresholds across metrics like lines and functions, generating reports for continuous integration pipelines like GitHub Actions, and excluding specific files or patterns from coverage analysis.

Install in Claude Code
Copy
git clone --depth 1 https://github.com/secondsky/claude-skills /tmp/bun-test-coverage && cp -r /tmp/bun-test-coverage/plugins/bun/skills/bun-test-coverage ~/.claude/skills/bun-test-coverage
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# Bun Test Coverage

Bun has built-in code coverage reporting without additional dependencies.

## Enabling Coverage

```bash
# Enable coverage
bun test --coverage

# With threshold (fail if below)
bun test --coverage --coverage-threshold 80
```

## Configuration in bunfig.toml

```toml
[test]
coverage = true
coverageThreshold = 0.8  # 80% minimum
coverageDir = "./coverage"

# Patterns to ignore
coverageSkipTestFiles = true
```

## Coverage Output

```
------------------|---------|---------|-------------------
File              | % Funcs | % Lines | Uncovered Line #s
------------------|---------|---------|-------------------
All files         |   85.71 |   89.23 |
 src/index.ts     |  100.00 |  100.00 |
 src/utils.ts     |   75.00 |   82.35 | 23-25, 41-43
 src/api.ts       |   80.00 |   85.00 | 67, 89-92
------------------|---------|---------|-------------------
```

## Coverage Reporters

```bash
# Default console output
bun test --coverage

# Generate lcov report
bun test --coverage --coverage-reporter=lcov

# Multiple reporters
bun test --coverage --coverage-reporter=text --coverage-reporter=lcov
```

### Available Reporters

| Reporter | Output |
|----------|--------|
| `text` | Console table (default) |
| `lcov` | `coverage/lcov.info` for CI tools |
| `json` | `coverage/coverage.json` |

## Coverage Thresholds

Set minimum coverage requirements:

```bash
# Fail if coverage < 80%
bun test --coverage --coverage-threshold 80

# Per-metric thresholds in bunfig.toml
```

```toml
[test]
coverage = true
coverageThreshold = {
  lines = 80,
  functions = 75,
  branches = 70
}
```

## Excluding Files

```toml
[test]
coverage = true

# Skip test files from coverage
coverageSkipTestFiles = true

# Patterns to exclude
coverageIgnore = [
  "**/*.test.ts",
  "**/fixtures/**",
  "**/mocks/**"
]
```

## CI Integration

### GitHub Actions

```yaml
- name: Run tests with coverage
  run: bun test --coverage --coverage-reporter=lcov

- name: Upload coverage to Codecov
  uses: codecov/codecov-action@v5
  with:
    files: ./coverage/lcov.info
```

### Output Directory

```bash
# Custom output directory
bun test --coverage --coverage-dir=./reports/coverage
```

## Programmatic Coverage

```typescript
import { test, expect } from "bun:test";

// Get coverage data programmatically
const coverage = Bun.coverage;

// Access after tests complete
process.on("exit", () => {
  console.log(coverage.getCoverageData());
});
```

## Common Errors

| Error | Cause | Fix |
|-------|-------|-----|
| `Coverage threshold not met` | Coverage below threshold | Increase test coverage |
| `No coverage data` | Files not executed | Check test includes file |
| `lcov not found` | Missing reporter | Add `--coverage-reporter=lcov` |

## Best Practices

1. **Set realistic thresholds** - Start at 60%, increase gradually
2. **Exclude generated files** - Mock files, type definitions
3. **Focus on critical paths** - Business logic over boilerplate
4. **Run in CI** - Prevent coverage regression

## When to Load References

Load `references/reporters.md` when:
- Custom reporter configuration
- CI/CD integration details
- Codecov/Coveralls setup
access-control-rbacSkill

Role-based access control (RBAC) with permissions and policies. Use for admin dashboards, enterprise access, multi-tenant apps, fine-grained authorization, or encountering permission hierarchies, role inheritance, policy conflicts.

aceternity-uiSkill

100+ animated React components (Aceternity UI) for Next.js with Tailwind. Use for hero sections, parallax, 3D effects, or encountering animation, shadcn CLI integration errors.

ai-elements-chatbotSkill

shadcn/ui AI chat components for conversational interfaces. Use for streaming chat, tool/function displays, reasoning visualization, or encountering Next.js App Router setup, Tailwind v4 integration, AI SDK v5 migration errors.

ai-sdk-coreSkill

Vercel AI SDK v5 for backend AI (text generation, structured output, tools, agents). Multi-provider. Use for server-side AI or encountering AI_APICallError, AI_NoObjectGeneratedError, streaming failures.

ai-sdk-uiSkill

Vercel AI SDK v5 React hooks (useChat, useCompletion, useObject) for AI chat interfaces. Use for React/Next.js AI apps or encountering parse stream errors, no response, streaming issues.

api-authenticationSkill

Secure API authentication with JWT, OAuth 2.0, API keys. Use for authentication systems, third-party integrations, service-to-service communication, or encountering token management, security headers, auth flow errors.

api-changelog-versioningSkill

Creates comprehensive API changelogs documenting breaking changes, deprecations, and migration strategies for API consumers. Use when managing API versions, communicating breaking changes, or creating upgrade guides.

api-contract-testingSkill

Verifies API contracts between services using consumer-driven contracts, schema validation, and tools like Pact. Use when testing microservices communication, preventing breaking changes, or validating OpenAPI specifications.