This document describes the comprehensive automated testing setup for the Color-Tech application, including local development testing and CI/CD pipeline integration.
npm run test:autoThis single command runs the complete test suite including:
- β Linting checks
- β TypeScript compilation
- β Unit tests
- β Integration tests
- β Coverage reporting
- β Build verification
# Run all tests
npm test
# Run tests in watch mode (for development)
npm run test:watch
# Run tests with coverage
npm run test:coverage# Unit tests only
npm run test:unit
# Integration tests only
npm run test:integration
# CI-specific test run (no watch mode)
npm run test:ci# Debug tests
npm run test:debug
# Update snapshots
npm run test:update-snapshots
# Run automated test suite
npm run test:auto- Config File:
jest.config.js - Setup:
src/tests/jest.setup.ts - TypeScript Config:
tsconfig.jest.json
- β TypeScript support
- β JSX/React testing
- β Automatic mocking for Next.js components
- β Coverage reporting with thresholds
- β Module path mapping (@/ aliases)
- Branches: 60%
- Functions: 60%
- Lines: 60%
- Statements: 60%
- File:
.github/workflows/test.yml - Triggers: Push to
main/developbranches, Pull Requests - Node.js Versions: 18.x, 20.x
- Checkout code
- Install dependencies
- Lint checking (
npm run lint) - Type checking (
npx tsc --noEmit) - Unit tests (
npm run test:unit) - Integration tests (
npm run test:integration) - Coverage report (
npm run test:coverage) - Build verification (
npm run build) - Security audit (
npm audit)
- Main Test Suite: Runs on Node 18.x and 20.x
- Security Audit: Runs independently
npm run test:coverage- HTML Report:
coverage/index.html - LCOV Report:
coverage/lcov.info - JSON Report:
coverage/coverage.json
- Automatically uploaded to Codecov
- Coverage status checks on PRs
- Historical coverage tracking
src/
βββ tests/ # Test files
β βββ setup.ts # Test database setup
β βββ jest.setup.ts # Jest configuration
β βββ *.test.ts # Unit tests
β βββ *.test.tsx # Component tests
β βββ *integration.test.ts # Integration tests
βββ components/ # Component source
βββ lib/ # Utility functions
βββ services/ # Business logic
- Test individual functions/components
- Fast execution
- No external dependencies
- Pattern:
*.test.ts,*.test.tsx
- Test component interactions
- API endpoint testing
- Database integration
- Pattern:
*integration.test.ts
- Next.js Router:
next/router - Next.js Image:
next/image - localStorage: Global mock
- fetch: Global mock
- IntersectionObserver: Browser API mock
- ResizeObserver: Browser API mock
- In-memory SQLite for tests
- Prisma mock layer
- Test data factories
- Set breakpoints in test files
- Run:
npm run test:debug - Attach VS Code debugger to Node process
- Use
describe.only()andit.only()for focus - Add
console.log()for debugging (removed in CI) - Check
coverage/index.htmlfor uncovered code
# Increase timeout in jest.config.js
testTimeout: 30000# Clear mocks between tests (automatic in setup)
jest.clearAllMocks()# Update coverage thresholds in jest.config.js
coverageThreshold: {
global: {
branches: 60,
functions: 60,
lines: 60,
statements: 60
}
}- Check Node.js version compatibility
- Verify all dependencies are in package.json
- Check environment variables
- Review GitHub Actions logs
- Use
jest --maxWorkers=50%for CI - Mock heavy external dependencies
- Keep test files focused and small
- Use test data factories for consistency
- Test execution time tracking
- Coverage calculation time
- CI pipeline duration monitoring
npm auditin CI pipelineaudit-cifor threshold enforcement- Dependency vulnerability scanning
# Run security audit
npm audit
# Run with specific severity level
npm audit --audit-level moderate
# Fix automatically (use with caution)
npm audit fixThe automated test suite ensures:
- β Code quality standards
- β Type safety
- β Functional correctness
- β Build success
- β Security compliance
- Push to main β Triggers tests
- Tests pass β Deployment allowed
- Tests fail β Deployment blocked
- Create test file:
*.test.tsor*.test.tsx - Follow naming convention:
ComponentName.test.tsx - Use describe blocks for organization
- Write descriptive test names
- Include both positive and negative cases
- Arrange, Act, Assert pattern
- One assertion per test (when possible)
- Descriptive test names
- Clean test data
- Mock external dependencies
For testing issues:
- Check this documentation
- Review test logs and error messages
- Check GitHub Issues for similar problems
- Contact development team
Happy Testing! π§ͺβ¨