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

  1. Mock External Services: All tests mock Razorpay, Cloudinary, Resend, Prisma
  2. Isolation: Each test is independent and can run in any order
  3. Fast Execution: Unit tests complete in < 5 seconds
  4. 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:

  1. Lint & Type Check

    • ESLint validation
    • TypeScript type checking
    • Fast feedback (< 1 minute)
  2. Unit Tests

    • Jest test suite
    • Coverage report upload to Codecov
    • Fails if coverage drops below threshold
  3. Build

    • Production Next.js build
    • Prisma client generation
    • Build artifacts uploaded for E2E tests
  4. E2E Tests

    • PostgreSQL service container
    • Database seeding
    • Playwright tests (Chromium + Firefox)
    • Test reports uploaded as artifacts

Environment Variables (GitHub Secrets):

  • DATABASE_URL, DIRECT_URL
  • NEXTAUTH_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:

  1. Deploy to Production

    • Full CI checks
    • Deploy to Vercel with --prod flag
    • Smoke tests against production URL
    • Manual approval required (environment protection rule)
  2. Deploy Preview

    • Auto-deploy for non-main branches
    • Preview URL generated by Vercel

Required Secrets:

  • VERCEL_TOKEN
  • VERCEL_ORG_ID
  • VERCEL_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:

  1. Dependabot creates PR with version bump
  2. CI runs automatically on PR
  3. If tests pass, maintainers can merge
  4. 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

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

  1. Linting Errors

    • Run npm run lint locally
    • Fix auto-fixable issues: npm run lint -- --fix
  2. Type Errors

    • Run npm run type-check locally
    • Check for strict mode violations
  3. Test Failures

    • Run npm test locally
    • Check test logs in GitHub Actions artifacts
  4. Build Failures

    • Ensure DATABASE_URL secret is set
    • Check for missing environment variables
    • Run npm run build locally
  5. E2E Test Failures

    • Download Playwright report from artifacts
    • Check screenshots of failures
    • Run locally with npm run test:e2e:headed to 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
  1. Uptime Monitoring - UptimeRobot or Pingdom
  2. Database Monitoring - Supabase built-in metrics
  3. API Performance - Sentry Performance Monitoring
  4. Log Aggregation - Logtail or Papertrail
  5. 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
  • 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