* Initial plan * Add Vitest and component tests for web frontend - Install Vitest, React Testing Library, and jsdom - Create Vitest configuration with coverage support - Add test setup with Next.js and next-intl mocks - Create component tests for LoadingSpinner, ErrorMessage, and Toast - Add test scripts to package.json (test, test:watch, test:coverage) - All 24 component tests passing Co-authored-by: PatrickFanella <61631520+PatrickFanella@users.noreply.github.com> * Enable E2E tests in CI and add web tests to main CI pipeline - Update e2e-tests.yml to run on pull_request and push to main - Keep workflow_dispatch for manual runs - Update ci.yml to include web component tests - Rename web job to 'Web (Lint, TypeScript, Tests)' Co-authored-by: PatrickFanella <61631520+PatrickFanella@users.noreply.github.com> * Add comprehensive component tests for web frontend - Add tests for VerificationBadge (18 tests) - Add tests for LanguageSwitcher (10 tests) - Install @vitest/coverage-v8 for coverage reporting - Update vitest config for better coverage tracking - Total: 52 component tests passing across 5 components Co-authored-by: PatrickFanella <61631520+PatrickFanella@users.noreply.github.com> * Update testing documentation with component test coverage - Rename E2E_TESTING.md to TESTING.md to cover all testing - Add component testing section with Vitest and React Testing Library - Document 52 component tests across 5 components - Update CI integration section with new web test job - Document E2E tests now run on PR and push to main Co-authored-by: PatrickFanella <61631520+PatrickFanella@users.noreply.github.com> * Fix timer cleanup and update comment in test files - Add vi.clearAllTimers() and vi.useRealTimers() in Toast.test.tsx afterEach to prevent timer leaks - Update comment in VerificationBadge.test.tsx to accurately reflect Next.js navigation mock Co-authored-by: PatrickFanella <61631520+PatrickFanella@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: PatrickFanella <61631520+PatrickFanella@users.noreply.github.com>
180 lines
5.0 KiB
YAML
180 lines
5.0 KiB
YAML
name: E2E Tests
|
|
|
|
# Run E2E tests on:
|
|
# 1. Pull requests targeting main branch
|
|
# 2. Pushes to main branch
|
|
# 3. Manual trigger (workflow_dispatch)
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
inputs:
|
|
base_url:
|
|
description: "Base URL to test against (default: http://localhost:3000)"
|
|
required: false
|
|
default: "http://localhost:3000"
|
|
api_base_url:
|
|
description: "API Base URL (default: http://localhost:3001)"
|
|
required: false
|
|
default: "http://localhost:3001"
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
e2e:
|
|
name: E2E Tests (Playwright)
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 30
|
|
|
|
services:
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
env:
|
|
POSTGRES_USER: internetid
|
|
POSTGRES_PASSWORD: internetid
|
|
POSTGRES_DB: internetid_test
|
|
ports:
|
|
- 5432:5432
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
|
|
env:
|
|
DATABASE_URL: postgresql://internetid:internetid@localhost:5432/internetid_test?schema=public
|
|
BASE_URL: ${{ github.event.inputs.base_url || 'http://localhost:3000' }}
|
|
NEXT_PUBLIC_API_BASE: ${{ github.event.inputs.api_base_url || 'http://localhost:3001' }}
|
|
CI: true
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "20"
|
|
cache: "npm"
|
|
|
|
- name: Install root dependencies
|
|
run: npm ci --legacy-peer-deps
|
|
|
|
- name: Install web dependencies
|
|
working-directory: web
|
|
run: npm ci --legacy-peer-deps
|
|
|
|
- name: Install Playwright browsers
|
|
working-directory: web
|
|
run: npx playwright install --with-deps chromium firefox webkit
|
|
|
|
- name: Generate Prisma client
|
|
run: npm run db:generate
|
|
|
|
- name: Run database migrations
|
|
run: npx prisma migrate deploy
|
|
|
|
- name: Build Next.js app
|
|
working-directory: web
|
|
run: npm run build
|
|
env:
|
|
NEXTAUTH_SECRET: test-secret-for-ci-only
|
|
NEXTAUTH_URL: http://localhost:3000
|
|
|
|
- name: Start API server in background
|
|
run: |
|
|
npm run start:api &
|
|
echo "Waiting for API server to start..."
|
|
timeout 30 bash -c 'until curl -f http://localhost:3001/api/health; do sleep 2; done' || true
|
|
env:
|
|
NODE_ENV: test
|
|
API_KEY: test-api-key
|
|
|
|
- name: Start Next.js server in background
|
|
working-directory: web
|
|
run: |
|
|
npm run start &
|
|
echo "Waiting for Next.js server to start..."
|
|
timeout 60 bash -c 'until curl -f http://localhost:3000; do sleep 2; done'
|
|
env:
|
|
NEXTAUTH_SECRET: test-secret-for-ci-only
|
|
NEXTAUTH_URL: http://localhost:3000
|
|
NODE_ENV: production
|
|
|
|
- name: Run E2E tests
|
|
working-directory: web
|
|
run: npm run test:e2e
|
|
env:
|
|
BASE_URL: http://localhost:3000
|
|
|
|
- name: Upload test results
|
|
if: always()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: playwright-report
|
|
path: web/playwright-report/
|
|
retention-days: 30
|
|
|
|
- name: Upload test screenshots
|
|
if: failure()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: playwright-screenshots
|
|
path: web/test-results/
|
|
retention-days: 7
|
|
|
|
# Optional: Run E2E tests against preview deployment
|
|
# Requires Vercel/Netlify deployment setup
|
|
e2e-preview:
|
|
name: E2E Tests (Preview Deployment)
|
|
runs-on: ubuntu-latest
|
|
# Only run if preview deployment URL is available
|
|
if: github.event_name == 'pull_request' && false # Disabled by default
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "20"
|
|
cache: "npm"
|
|
|
|
- name: Install web dependencies
|
|
working-directory: web
|
|
run: npm ci --legacy-peer-deps
|
|
|
|
- name: Install Playwright browsers
|
|
working-directory: web
|
|
run: npx playwright install --with-deps chromium firefox webkit
|
|
|
|
# Wait for preview deployment (example for Vercel)
|
|
# Requires VERCEL_TOKEN secret
|
|
# - name: Wait for Vercel preview deployment
|
|
# uses: patrickedqvist/wait-for-vercel-preview@v1.3.1
|
|
# with:
|
|
# token: ${{ secrets.GITHUB_TOKEN }}
|
|
# max_timeout: 300
|
|
|
|
- name: Run E2E tests against preview
|
|
working-directory: web
|
|
run: npm run test:e2e
|
|
env:
|
|
# BASE_URL: ${{ steps.wait-for-vercel.outputs.url }}
|
|
BASE_URL: https://preview-deployment.example.com
|
|
CI: true
|
|
|
|
- name: Upload test results
|
|
if: always()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: playwright-report-preview
|
|
path: web/playwright-report/
|
|
retention-days: 30
|