| 1 | # Testing Guide |
| 2 | |
| 3 | This project uses [Bun Test](https://bun.sh/docs/cli/test) for focused, high-value testing of core business logic. |
| 4 | |
| 5 | ## Running Tests |
| 6 | |
| 7 | ```bash |
| 8 | # Run all tests |
| 9 | bun test |
| 10 | |
| 11 | # Run tests in watch mode (for development) |
| 12 | bun test --watch |
| 13 | |
| 14 | # Run tests with coverage report |
| 15 | bun test --coverage |
| 16 | ``` |
| 17 | |
| 18 | ## Test Philosophy |
| 19 | |
| 20 | This project follows a **focused testing approach** that prioritizes: |
| 21 | |
| 22 | 1. **High Value**: Test core business logic and data validation |
| 23 | 2. **Fast Execution**: No slow I/O operations or complex mocking |
| 24 | 3. **Maintainability**: Simple, reliable tests that won't break with dependencies |
| 25 | 4. **Clarity**: Each test has a clear purpose and validates real behavior |
| 26 | |
| 27 | ## What We Test ✅ |
| 28 | |
| 29 | ### **Core Utilities** (100% Coverage) |
| 30 | - `src/utils/try-catch.test.ts` - Error handling wrapper functionality |
| 31 | - `src/utils/templates.test.ts` - Template configuration and Hono code generation |
| 32 | - `src/utils/constants.test.ts` - Application constants validation |
| 33 | - `src/types.test.ts` - TypeScript type definitions and interfaces |
| 34 | |
| 35 | ## What We DON'T Test ❌ |
| 36 | |
| 37 | **CLI Functions with External Dependencies:** |
| 38 | - File system operations (degit, fs-extra) |
| 39 | - Interactive prompts (consola) |
| 40 | - System commands (git, bun install) |
| 41 | - Process management (process.exit) |
| 42 | |
| 43 | **Why:** These functions are integration points with the OS and external tools. Testing them would require complex mocking that provides little value and high maintenance overhead. |
| 44 | |
| 45 | ## Test Configuration |
| 46 | |
| 47 | ### `bunfig.toml` |
| 48 | ```toml |
| 49 | [test] |
| 50 | coverage = true |
| 51 | timeout = 5000 |
| 52 | |
| 53 | [test.env] |
| 54 | NODE_ENV = "test" |
| 55 | ``` |
| 56 | |
| 57 | ### Package Scripts |
| 58 | - `bun test` - Run all tests |
| 59 | - `bun test --watch` - Watch mode for development |
| 60 | - `bun test --coverage` - Generate coverage reports |