AcademyPipeline Pilot: The CI/CD Flight ManualAltitude 4: Structural Integrity (Testing)

Running Tests in CI

The main goal of Continuous Integration is to catch bugs before they reach production. We do this by automatically running tests on every PR.

A Typical Node.js CI Pipeline

name: Run Tests
on: [pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm' # Speeds up builds by caching node_modules
          
      - name: Install Dependencies
        run: npm ci # Clean install, requires package-lock.json
        
      - name: Run Tests
        run: npm test

If npm test fails (exits with a non-zero code), the entire job fails, and GitHub will block the Pull Request from being merged.

booting...

Mission Control

Setup Node.js Action

Expected Command

echo 'uses: actions/setup-node@v4' > ci.yml