Skip to content

Node.js - run tests on push & pull request #1055

Description

@Alex-is-Gonzalez

Dependency

Description

What it does: Runs npm ci and npm test automatically for pushes to main and for pull requests.

Step-by-step

  1. Create file at .github/workflows/ci-tests.yml with the content above.

  2. Commit & push:

git add .github/workflows/ci-tests.yml
git commit -m "ci: add Node.js test workflow"
git push
name: CI - Node.js Tests

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v4

      - name: Use Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'

      - name: Install dependencies
        run: npm ci

      - name: Run tests
        run: npm test
  1. Open the Actions tab in GitHub to see the workflow run.

  2. Expand the Run tests step to view logs and failures.

  3. Customize: change node-version, branch name, or the test command (e.g., npm run test:ci).

Absolutely, Finding! Here's a clear and structured Spec section for your GitHub Actions CI workflow issue:


✅ Spec: CI Workflow for Node.js Tests

🧾 What It Does

This GitHub Actions workflow ensures automated testing for a Node.js project by:

  • Installing dependencies using npm ci
  • Running tests using npm test
  • Triggering on:
    • Pushes to the main branch
    • Pull requests targeting the main branch

🎯 Acceptance Criteria

The implementation will be considered complete and successful when:

✅ Workflow Setup

  • A file named .github/workflows/ci-tests.yml exists in the repository
  • The workflow is named CI - Node.js Tests
  • It runs on ubuntu-latest environment
  • It uses Node.js version 18 via actions/setup-node@v4
  • It includes steps to:
    • Checkout the repository
    • Install dependencies using npm ci
    • Run tests using npm test

✅ Trigger Conditions

  • The workflow runs automatically on:
    • Pushes to the main branch
    • Pull requests targeting the main branch

✅ Execution & Visibility

  • Workflow appears under the Actions tab in GitHub
  • The Run tests step displays logs and any test failures
  • The workflow fails if any test fails

✅ Customization Support

  • The workflow allows easy modification of:
    • Node.js version
    • Branch name
    • Test command (e.g., npm run test:ci)

✅ Validation

  • YAML syntax is valid and passes GitHub Actions linting
  • No hardcoded secrets or credentials are present
  • Workflow completes within reasonable time (<5 minutes for typical test suite)

Copilot Prompts


🛠️ Setup & Configuration Prompts

  • “Can you help me write a GitHub Actions workflow that runs tests on Node.js 18?”
  • “What does npm ci do differently from npm install in CI workflows?”
  • “How do I trigger this workflow only on changes to the src/ folder?”
  • “Can you modify this workflow to run on Node.js 16 and 18 in parallel?”
  • “Add caching to this workflow to speed up npm installs.”

🧪 Debugging & Troubleshooting Prompts

  • “Why is my npm test step failing in GitHub Actions?”
  • “How do I view detailed logs from the ‘Run tests’ step?”
  • “My workflow isn’t triggering on pull requests—can you check the on: block?”
  • “What does the error ‘Cannot find module’ mean in the test logs?”
  • “How do I make the workflow fail if tests are skipped?”

🔧 Customization Prompts

  • “Change the workflow to run npm run test:ci instead of npm test.”
  • “Update the workflow to run only on pushes to develop instead of main.”
  • “Add a step to run eslint before tests.”
  • “Can you include a matrix to test on multiple operating systems?”
  • “Make the workflow send a Slack notification if tests fail.”

✅ Validation & Best Practices Prompts

  • “Is this workflow optimized for speed and reliability?”
  • “What are best practices for Node.js CI workflows on GitHub Actions?”
  • “Can you validate this YAML syntax?”
  • “How do I ensure this workflow doesn’t run on draft pull requests?”
  • “Can you add a badge to the README showing workflow status?”

Target Date: 📆 Sep 23, 2025

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions