Testing & CI/CD Setup Guide
March 30, 2026 · View on GitHub
Overview
This document describes the testing infrastructure and CI/CD pipelines implemented for the PGLife (Gharam) project.
Testing Framework
Unit & Integration Tests (Jest)
Framework: Jest + React Testing Library
Test Location: src/__tests__/
Configuration: jest.config.js, jest.setup.js
Running Tests
# Run all tests
npm test
# Watch mode (auto-rerun on changes)
npm run test:watch
# Generate coverage report
npm run test:coverage
Test Structure
src/__tests__/
├── lib/ # Library utilities tests
│ ├── schemas.test.ts # Zod validation tests (36 tests)
│ ├── auth.test.ts # Password hashing tests
│ └── email.test.ts # Email template tests
├── api/ # API route tests (to be added)
└── components/ # Component tests (to be added)
Coverage Targets
- Global: 70% minimum on branches, functions, lines, statements
- Critical Paths: Auth, payments, bookings should aim for 80%+
Best Practices
- Mock External Services: All tests mock Razorpay, Cloudinary, Resend, Prisma
- Isolation: Each test is independent and can run in any order
- Fast Execution: Unit tests complete in < 5 seconds
- Descriptive Names: Test names clearly state what they verify
E2E Tests (Playwright)
Framework: Playwright
Test Location: tests/e2e/
Configuration: playwright.config.ts
Running E2E Tests
# Run all E2E tests (headless)
npm run test:e2e
# Run with browser UI visible
npm run test:e2e:headed
# Debug mode with Playwright Inspector
npm run test:e2e:debug
Test Coverage (Planned)
- ✅ Authentication flows (signup, login, password reset)
- ✅ Property listing creation wizard
- ✅ Booking flow with Razorpay payment
- ✅ Admin approval workflow
- ✅ Profile management and KYC upload
Browser Support
- Chromium (Chrome/Edge)
- Firefox
- WebKit disabled (can be enabled for macOS/iOS testing)
CI/CD Pipelines
GitHub Actions Workflows
1. CI Workflow (.github/workflows/ci.yml)
Triggers: Push to main/develop, Pull Requests
Jobs:
-
Lint & Type Check
- ESLint validation
- TypeScript type checking
- Fast feedback (< 1 minute)
-
Unit Tests
- Jest test suite
- Coverage report upload to Codecov
- Fails if coverage drops below threshold
-
Build
- Production Next.js build
- Prisma client generation
- Build artifacts uploaded for E2E tests
-
E2E Tests
- PostgreSQL service container
- Database seeding
- Playwright tests (Chromium + Firefox)
- Test reports uploaded as artifacts
Environment Variables (GitHub Secrets):
DATABASE_URL,DIRECT_URLNEXTAUTH_SECRET,NEXTAUTH_URL- All third-party API keys (Razorpay, Cloudinary, etc.)
2. Deploy Workflow (.github/workflows/deploy.yml)
Triggers: Push to main, Manual dispatch
Jobs:
-
Deploy to Production
- Full CI checks
- Deploy to Vercel with
--prodflag - Smoke tests against production URL
- Manual approval required (environment protection rule)
-
Deploy Preview
- Auto-deploy for non-main branches
- Preview URL generated by Vercel
Required Secrets:
VERCEL_TOKENVERCEL_ORG_IDVERCEL_PROJECT_ID
Dependency Management
Dependabot (.github/dependabot.yml)
Configuration:
- npm dependencies: Weekly updates (Mondays 9 AM)
- GitHub Actions: Weekly updates
- Grouping: Patch and minor updates grouped separately
- Auto-labels:
dependencies,npm,github-actions - Security updates: Immediate PRs
Workflow:
- Dependabot creates PR with version bump
- CI runs automatically on PR
- If tests pass, maintainers can merge
- Consider auto-merge for patch updates (safe)
Performance Monitoring
Vercel Analytics
Integration: @vercel/analytics/next
Location: src/app/layout.tsx
Tracks:
- Page views
- User sessions
- Geographic distribution
- Device/browser breakdown
Vercel Speed Insights
Integration: @vercel/speed-insights/next
Location: src/app/layout.tsx
Core Web Vitals Tracked:
- LCP (Largest Contentful Paint) - Target: < 2.5s
- FID (First Input Delay) - Target: < 100ms
- CLS (Cumulative Layout Shift) - Target: < 0.1
- TTFB (Time to First Byte) - Target: < 600ms
- FCP (First Contentful Paint) - Target: < 1.8s
Dashboard: Available in Vercel project dashboard
Branch Protection Rules
Recommended Settings (GitHub Repository Settings)
For main branch:
- ✅ Require pull request reviews (minimum 1 approval)
- ✅ Require status checks to pass (all CI jobs)
- ✅ Require branches to be up to date before merging
- ✅ Prevent force pushes
- ✅ Prevent deletion
- ✅ Require signed commits (recommended for security)
CODEOWNERS (.github/CODEOWNERS)
# Critical files require specific reviewers
/prisma/schema.prisma @maintainers
/src/lib/auth.ts @security-team
/src/app/api/payments/ @payments-team
/.github/workflows/ @devops-team
Local Development Workflow
Before Committing
# 1. Lint your code
npm run lint
# 2. Type check
npm run type-check
# 3. Run unit tests
npm test
# 4. Run E2E tests (optional, but recommended for major changes)
npm run test:e2e
Pre-commit Hooks (Optional)
Install Husky for automatic pre-commit checks:
npm install -D husky lint-staged
npx husky init
Add to .husky/pre-commit:
npx lint-staged
Add to package.json:
{
"lint-staged": {
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{json,md}": ["prettier --write"]
}
}
Debugging Failed CI Runs
Common Issues
-
Linting Errors
- Run
npm run lintlocally - Fix auto-fixable issues:
npm run lint -- --fix
- Run
-
Type Errors
- Run
npm run type-checklocally - Check for strict mode violations
- Run
-
Test Failures
- Run
npm testlocally - Check test logs in GitHub Actions artifacts
- Run
-
Build Failures
- Ensure
DATABASE_URLsecret is set - Check for missing environment variables
- Run
npm run buildlocally
- Ensure
-
E2E Test Failures
- Download Playwright report from artifacts
- Check screenshots of failures
- Run locally with
npm run test:e2e:headedto see browser
Monitoring & Alerts
Current Setup
- ✅ Vercel Analytics - User behavior and page views
- ✅ Speed Insights - Core Web Vitals
- ✅ Sentry - Error tracking (already configured)
- ✅ GitHub Actions - CI/CD status emails
Recommended Additions
- Uptime Monitoring - UptimeRobot or Pingdom
- Database Monitoring - Supabase built-in metrics
- API Performance - Sentry Performance Monitoring
- Log Aggregation - Logtail or Papertrail
- Alerting - PagerDuty or Slack webhooks
Cost Considerations
Free Tiers Used
- Vercel Analytics: 100k events/month (free)
- Vercel Speed Insights: Unlimited (free)
- GitHub Actions: 2,000 minutes/month (free for public repos)
- Codecov: Unlimited for open source
Paid Services
- Vercel Pro: $20/month (if needed for team features)
- GitHub Teams: $4/user/month (for private repos with advanced features)
Future Enhancements
Phase 2 (Not Yet Implemented)
- DigiLocker KYC Integration
- OAuth flow implementation
- Document fetching API
- UI updates for DigiLocker verification
Testing Improvements
- Visual regression testing (Percy or Chromatic)
- API contract testing (Pact or Dredd)
- Load testing (k6 or Artillery)
- Accessibility testing (axe-core)
CI/CD Improvements
- Database migration workflow
- Automated rollback on deployment failure
- Canary deployments
- A/B testing infrastructure
Getting Help
- CI/CD Issues: Check GitHub Actions logs
- Test Failures: Run locally first, then check artifacts
- Deployment Issues: Check Vercel deployment logs
- Performance Issues: Review Speed Insights dashboard
Documentation: Next.js Testing | Playwright Docs | GitHub Actions
Last Updated: 2026-03-30
Version: 1.0
Maintained by: Development Team