Cheat SheetsCI/CD & GitHub ActionsTesting

Testing — Cheat Sheet

CI/CD & GitHub Actions · 1 topics. Download the PDF or the Instagram carousel and share it.

Cheat Sheet · AiCanCode.org
Testing
CI/CD & GitHub Actions1 topicsQuick revision reference
1

Testing in CI — Unit, Integration & E2E

Effective CI testing runs fast unit tests first, then slower integration tests with real dependencies (Docker), then E2E tests. Parallelisation, test splitting, and smart caching keep pipelines fast.

  • Test pyramid: unit tests first (fast, many), integration tests second, E2E last (slow, few).
  • GitHub services: block in jobs spins up Docker containers (Postgres, Redis) as sidecar services for integration tests.
  • Jest sharding (--shard=N/TOTAL) splits test files across parallel runners — linear speedup.
  • dorny/test-reporter posts JUnit results as PR comments — no external service needed.
  • Branch protection rules enforce required status checks — cannot merge without passing CI.
  • continue-on-error: true + explicit failure step lets you collect test artifacts before failing the job.
Test pyramid pipeline stages
# .github/workflows/test.yml

name: Test Suite



on: [push, pull_request]



jobs:

  # Stage 1: Fast checks (< 1 minute) — fail fast

  lint-and-typecheck:

    runs-on: ubuntu-latest

    steps:

      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4

        with: { node-version: '20', cache: 'npm' }

      - run: npm ci

      - run: npm run lint             # ESLint, Prettier

      - run: npm run typecheck        # TypeScript tsc --noEmit



  # Stage 2: Unit tests (< 3 minutes) — run if lint passes

  unit-tests:

    needs: lint-and-typecheck

    runs-on: ubuntu-latest

    steps:

      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4

        with: { node-version: '20', cache: 'npm' }

      - run: npm ci

      - run: npm test -- --coverage

      - name: Upload coverage to Codecov

        uses: codecov/codecov-action@v4

        with:

          token: ${{ secrets.CODECOV_TOKEN }}



  # Stage 3: Integration tests (< 5 minutes) — real DB/Redis

  integration-tests:

    needs: unit-tests

    runs-on: ubuntu-latest

    services:                         # GitHub-managed Docker services

      postgres:

        image: postgres:16-alpine

        env:

          POSTGRES_PASSWORD: test

          POSTGRES_DB: testdb

        ports: ['5432:5432']

        options: >-

          --health-cmd pg_isready

          --health-interval 10s

          --health-timeout 5s

          --health-retries 5

      redis:

        image: redis:7-alpine

        ports: ['6379:6379']

    steps:

      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4

        with: { node-version: '20', cache: 'npm' }

      - run: npm ci

      - run: npm run test:integration

        env:

          DATABASE_URL: postgres://postgres:test@localhost:5432/testdb

          REDIS_URL: redis://localhost:6379
Learn this free with Aria, your AI tutor → AiCanCode.org/learn/cicd