Skip to content
AdvancedDevOpsAutomationOpen Source

Run Your Tests Automatically with GitHub Actions

A minimal continuous-integration workflow that runs your test suite on every push and pull request.

25 min2 stepsPublished

GitHub logo
Photo: GitHub / Wikimedia Commons, MIT

Prerequisites

  • A GitHub repository
  • A Node.js project with an npm test script
  1. 1

    Add the workflow file

    Create .github/workflows/tests.yml:

    .github/workflows/tests.yml
    name: tests
    
    on:
      push:
        branches: [main]
      pull_request:
    
    jobs:
      test:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - uses: actions/setup-node@v4
            with:
              node-version: 22
              cache: npm
          - run: npm ci
          - run: npm test
  2. 2

    Read the results

    Push the file. Open the Actions tab of your repository to watch the run. A red cross on a pull request means a test failed — open the log to see which one.

Troubleshooting

npm ci fails

Commit your package-lock.json; `npm ci` requires it.

Check your understanding

Why use `npm ci` instead of `npm install` in CI?