Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
Testing Requirements
Minimum Test Coverage: 80%
Test Types (ALL required):
- Unit Tests - Individual functions, utilities, services
- Integration Tests - API endpoints, database operations
- E2E Tests - Critical user flows
Running Tests
# Run tests for a specific project
pnpm nx run <project>:test
# Run E2E tests
pnpm nx run e2e:e2e
# Run affected tests
pnpm nx affected -t test
Test File Conventions
- Test files:
*.spec.ts, colocated with source files - Test runner: Vitest (via
@nx/vite:test) - E2E infrastructure: Docker Compose (
e2e/docker-compose.e2e.yml)
NestJS Testing Patterns
Unit testing services:
const module = await Test.createTestingModule({
providers: [
OrderService,
{ provide: OrderRepository, useValue: mockOrderRepository },
],
}).compile()
Unit testing controllers: Mock services, verify routing and VO transformation.
Repository tests: Test in integration/E2E only (repositories are thin wrappers over Mongoose).
Test-Driven Development
MANDATORY workflow:
- Write test first (RED)
- Run test - it should FAIL
- Write minimal implementation (GREEN)
- Run test - it should PASS
- Refactor (IMPROVE)
- Verify coverage (80%+)
Troubleshooting Test Failures
- Use tdd-guide agent
- Check test isolation
- Verify mocks are correct
- Fix implementation, not tests (unless tests are wrong)