bun-testing

Testing guidelines for Bun/TypeScript projects using bun:test framework. Use when writing tests, creating test files, debugging test failures, setting up mocks, or reviewing test code. Triggers on *.test.ts files, test-related questions, mocking patterns, and coverage discussions.

16 stars

Best use case

bun-testing is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Testing guidelines for Bun/TypeScript projects using bun:test framework. Use when writing tests, creating test files, debugging test failures, setting up mocks, or reviewing test code. Triggers on *.test.ts files, test-related questions, mocking patterns, and coverage discussions.

Teams using bun-testing should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/bun-testing/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/development/bun-testing/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/bun-testing/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How bun-testing Compares

Feature / Agentbun-testingStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Testing guidelines for Bun/TypeScript projects using bun:test framework. Use when writing tests, creating test files, debugging test failures, setting up mocks, or reviewing test code. Triggers on *.test.ts files, test-related questions, mocking patterns, and coverage discussions.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Bun Testing Skill

## Quick Reference

- **Framework**: bun:test
- **File pattern**: `*.test.ts` inside `__tests__` directories
- **Module mocking**: Use `ModuleMocker` from `@/__tests__` (see [patterns](references/mocking-patterns.md))
- **Coverage target**: 60–80% (focus on important logic, not 100%)
- **Config**: `.env.test` for test environment variables

## Test Utilities (src/__tests__/)

Before writing custom test helpers, check existing utilities:

- **`createTestApp(basePath, route, middleware[])`** - Creates test Hono app with error handler, logger, and optional middleware
- **`ModuleMocker(import.meta.url)`** - Module mocking utility (see [mocking patterns](references/mocking-patterns.md))
- **`post(app, url, body, headers)`** - POST request helper
- **`get(app, url, headers)`** - GET request helper
- **`doRequest(app, url, method, body, headers)`** - Generic request helper

Example:

```typescript
import { createTestApp, post } from '@/__tests__'

const app = createTestApp('/api/v1/auth', signupRoute, [captchaMiddleware()])
const response = await post(app, '/api/v1/auth/signup', {
  email: 'test@example.com',
  password: 'SecurePass123!'
})
```

## Test Types

- **Unit tests**: Mock all dependencies (repositories, services, APIs)
- **Integration tests**: Use real database, mock external APIs only
- **Endpoint tests**: Use `createTestApp()` with mocked services

## Test Priorities

1. Correct scenario(s)
2. Error handling
3. Boundary inputs
4. Failure scenarios

## Environment Setup

- Use `.env.test` for test-specific variables
- Bun handles env loading natively — no manual dotenv needed
- Minimize mocking `@/env` — only mock for special/invalid configs

## Mocking Strategy

- Mock only business logic dependencies (repositories, external APIs)
- Use global mocks for shared services (CAPTCHA, email) — don't redefine per test
- No real database or network calls — all I/O must be mocked
- Don't mock encapsulated dependencies — mock the public API/wrapper only

## Type Safety

- Minimize `any` — prefer proper TypeScript types
- Use type inference when possible
- Use `Partial<T>` for mock objects
- Exception: Use `any` only for complex mocks where full typing adds unnecessary complexity

## Test Structure

Use arrange → act → assert pattern with descriptive test names:

```typescript
describe('UserService', () => {
  it('should return user when found by email', async () => {
    // Arrange
    const mockUser = { id: 1, email: 'test@example.com' }
    mockUserRepo.findByEmail.mockResolvedValue(mockUser)

    // Act
    const result = await userService.findByEmail('test@example.com')

    // Assert
    expect(result).toEqual(mockUser)
  })
})
```

## Mocking Patterns

For detailed mocking patterns including variable ordering, `beforeEach` setup, and ModuleMocker usage, see [references/mocking-patterns.md](references/mocking-patterns.md).

## Cleanup

Always clean up side effects after each test:

```typescript
afterEach(async () => {
  await moduleMocker.clear() // restore mocked modules
  vi.clearAllMocks() // or mock.mockClear() for individual mocks
})
```

Related Skills

browser-testing

16
from diegosouzapw/awesome-omni-skill

Use when testing web applications, debugging browser console errors, automating form interactions, or verifying UI implementations. Load for localhost testing, authenticated app testing (Gmail, Notion), or recording demo GIFs. Requires Chrome extension 1.0.36+, Claude Code 2.0.73+, paid plan.

backend-testing

16
from diegosouzapw/awesome-omni-skill

Write comprehensive backend tests including unit tests, integration tests, and API tests. Use when testing REST APIs, database operations, authentication flows, or business logic. Handles Jest, Pytest, Mocha, testing strategies, mocking, and test coverage.

ClaudeChatGPTGemini

Appium Mobile Testing

16
from diegosouzapw/awesome-omni-skill

Mobile app testing automation for iOS and Android with Appium

api-testing

16
from diegosouzapw/awesome-omni-skill

REST and GraphQL API testing with Playwright. Use when testing APIs, mocking endpoints, validating responses, or integrating API tests with E2E flows.

API Testing Expert

16
from diegosouzapw/awesome-omni-skill

API testing - Postman, REST clients, contract testing, mock servers

always-works-testing

16
from diegosouzapw/awesome-omni-skill

Default testing standard for all implementation work - ensures code actually works through mandatory execution validation before confirming to user. Applies automatically whenever writing, modifying, debugging, or implementing any code (scripts, APIs, UI, configs, data operations, logic changes). This is the baseline expectation, not an optional extra - every implementation must be verified through actual execution, not assumed correct.

dotnet-ui-testing-core

16
from diegosouzapw/awesome-omni-skill

Tests UI across frameworks. Page objects, test selectors, async waits, accessibility.

accessibility-testing

16
from diegosouzapw/awesome-omni-skill

Guide for conducting comprehensive accessibility audits of code to identify WCAG compliance issues and barriers to inclusive design. This skill should be used when reviewing accessibility, ARIA implementation, keyboard navigation, or screen reader compatibility.

minitest-testing

16
from diegosouzapw/awesome-omni-skill

Write, review, and improve Minitest tests for Ruby on Rails applications. Covers model tests, controller tests, system tests, fixtures, and best practices from Rails Testing Guide.

ai-powered-pentesting

16
from diegosouzapw/awesome-omni-skill

Guide for AI-powered penetration testing tools, red teaming frameworks, and autonomous security agents.

ab-testing-analyzer

16
from diegosouzapw/awesome-omni-skill

全面的AB测试分析工具,支持实验设计、统计检验、用户分群分析和可视化报告生成。用于分析产品改版、营销活动、功能优化等AB测试结果,提供统计显著性检验和深度洞察。

cli-e2e-testing

16
from diegosouzapw/awesome-omni-skill

CLI E2E testing patterns with BATS - parallelization, state sharing, and timeout management