Awesome-omni-skill 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.
install
source · Clone the upstream repo
git clone https://github.com/diegosouzapw/awesome-omni-skill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/development/bun-testing" ~/.claude/skills/diegosouzapw-awesome-omni-skill-bun-testing && rm -rf "$T"
manifest:
skills/development/bun-testing/SKILL.mdsource content
Bun Testing Skill
Quick Reference
- Framework: bun:test
- File pattern:
inside*.test.ts
directories__tests__ - Module mocking: Use
fromModuleMocker
(see patterns)@/__tests__ - Coverage target: 60–80% (focus on important logic, not 100%)
- Config:
for test environment variables.env.test
Test Utilities (src/tests/)
Before writing custom test helpers, check existing utilities:
- Creates test Hono app with error handler, logger, and optional middlewarecreateTestApp(basePath, route, middleware[])
- Module mocking utility (see mocking patterns)ModuleMocker(import.meta.url)
- POST request helperpost(app, url, body, headers)
- GET request helperget(app, url, headers)
- Generic request helperdoRequest(app, url, method, body, headers)
Example:
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
with mocked servicescreateTestApp()
Test Priorities
- Correct scenario(s)
- Error handling
- Boundary inputs
- Failure scenarios
Environment Setup
- Use
for test-specific variables.env.test - Bun handles env loading natively — no manual dotenv needed
- Minimize mocking
— only mock for special/invalid configs@/env
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
— prefer proper TypeScript typesany - Use type inference when possible
- Use
for mock objectsPartial<T> - Exception: Use
only for complex mocks where full typing adds unnecessary complexityany
Test Structure
Use arrange → act → assert pattern with descriptive test names:
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.
Cleanup
Always clean up side effects after each test:
afterEach(async () => { await moduleMocker.clear() // restore mocked modules vi.clearAllMocks() // or mock.mockClear() for individual mocks })