Add fast API unit tests for pre-commit hooks

Resolved 💬 1 comment Opened Aug 26, 2025 by jacksoncage Closed Aug 26, 2025

Overview

Implement fast unit tests that can run in pre-commit hooks to catch API issues before commits. Current tests are too slow for pre-commit use.

Requirements

  • Tests should complete in < 3 seconds
  • Test all 60+ API endpoints
  • Validate schemas and route registration
  • Mock external dependencies (DB, Redis)
  • Run only on changed files when possible

Recommended Implementation

Use Vitest with mocked dependencies for speed (~1-2ms per endpoint)

Tasks

  • [ ] Install Vitest and testing dependencies
  • [ ] Create vitest.config.ts with optimized settings
  • [ ] Write fast endpoint tests using OpenAPI spec
  • [ ] Mock database and Redis connections
  • [ ] Add pre-commit hook with Husky
  • [ ] Configure lint-staged for selective testing
  • [ ] Add test:pre-commit script to package.json
  • [ ] Document testing approach in README

Expected Outcome

  • Pre-commit tests run in < 3 seconds
  • All endpoints validated against OpenAPI spec
  • Schema validation without external dependencies
  • Catches breaking changes before commit

Performance Targets

  • Unit tests: < 5 seconds for full suite
  • Changed files only: < 1 second
  • Pre-commit hook: < 3 seconds total

Related: #testing #dx #performance

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗