unit-test
3
总安装量
2
周安装量
#57326
全站排名
安装命令
npx skills add https://github.com/gitarbor/gitarbor-tui --skill unit-test
Agent 安装分布
opencode
2
github-copilot
2
codex
2
kimi-cli
2
windsurf
2
gemini-cli
2
Skill 文档
When to use this skill
Use this skill when:
- User asks to create or write unit tests
- User mentions testing, test coverage, or Bun test
- User wants to test specific functions, modules, or components
- User asks to add test files or improve test coverage
- User mentions test frameworks, mocking, or assertions
What this skill does
This skill provides expertise in creating comprehensive, well-structured unit tests using Bun’s built-in testing framework. It covers test file creation, Bun test features, best practices, and RestMan-specific testing guidelines.
Core capabilities
1. Test File Creation
- Create test files with proper naming conventions:
*.test.ts,*_test.ts,*.spec.ts,*_spec.ts - Use TypeScript with proper types from
bun:test - Follow the project’s code style guidelines (single quotes, camelCase, etc.)
2. Bun Test Framework Features
Basic Testing
import { test, expect, describe } from 'bun:test';
describe('feature name', () => {
test('should do something', () => {
expect(result).toBe(expected);
});
});
Lifecycle Hooks
beforeAll– Setup before all testsbeforeEach– Setup before each testafterEach– Cleanup after each testafterAll– Cleanup after all tests
Mocking
import { test, expect, mock } from 'bun:test';
const mockFn = mock(() => 'mocked value');
// or
const mockFn = jest.fn(() => 'mocked value');
Snapshot Testing
test('snapshot', () => {
expect(data).toMatchSnapshot();
});
Concurrent Testing
test.concurrent('async test 1', async () => {
// runs in parallel
});
test.serial('sequential test', () => {
// runs sequentially even with --concurrent flag
});
3. Test Organization Best Practices
- Group related tests with
describeblocks - Use descriptive test names that explain behavior
- Follow AAA pattern: Arrange, Act, Assert
- Test edge cases and error conditions
- Use
beforeEach/afterEachfor test isolation - Mock external dependencies and side effects
4. RestMan-Specific Testing Guidelines
When testing RestMan code:
- Follow TypeScript strict mode requirements
- Handle
noUncheckedIndexedAccess: true(indexed access can be undefined) - Use async/await for asynchronous operations
- Mock file system operations (fs/promises)
- Mock terminal UI components when testing business logic
- Test error handling with
instanceof Errorchecks - Use proper types from the codebase
5. Running Tests
Available test commands:
bun test– Run all testsbun test <filter>– Run tests matching filterbun test --watch– Watch modebun test --coverage– Generate coverage reportbun test --timeout 20– Set timeout (default 5000ms)bun test --bail– Exit after first failurebun test --update-snapshots– Update snapshots
Workflow
When asked to create tests:
- Understand the code – Read and analyze the source file to test
- Identify test scenarios – Determine what needs to be tested:
- Happy path functionality
- Edge cases
- Error conditions
- Async behavior
- Side effects (mocking needed)
- Create test file – Use proper naming convention matching source file
- Write comprehensive tests – Cover identified scenarios
- Follow project conventions – Match RestMan code style
- Run tests – Execute with
bun testto verify they pass - Report results – Explain what was tested and any issues found
Key principles
- Test behavior, not implementation – Focus on what the code does, not how
- Keep tests simple and readable – Tests are documentation
- One assertion per test when possible – Makes failures clear
- Mock external dependencies – File I/O, network, terminal UI
- Test edge cases – null, undefined, empty arrays, errors
- Maintain test isolation – Tests should not depend on each other
- Use descriptive names – Test names should read like documentation
Example test structure
See test structure reference for detailed examples.
Remember
- Always ask clarifying questions if the testing scope is unclear
- Suggest additional test scenarios if you identify gaps
- Follow RestMan’s code style guidelines strictly
- Use TypeScript types properly
- Mock side effects appropriately
- Run tests after creating them to ensure they pass
- Be proactive about testing edge cases and error conditions