cuckcoding.pro
Menu

Run Node.js tests in GitHub Actions and reproduce a failure locally

The agent says the tests are green. Which tests? In this exercise the answer fits on one line. A small module doubles a seat allocation, one test checks its result and GitHub Actions runs that exact test from a clean checkout. You will also make the test fail once to see what useful evidence looks like.

Before you start
Node.js 24, Git 2.28+ and a POSIX shell for the local exercise. To watch a hosted run, use a GitHub demo repository with Actions enabled. Start in an empty parent directory.
What to verify
Obtain one passing test, one deliberate failure, and a workflow committed alongside the exact test command that reproduces the result locally.

Make the smallest useful check

Create a directory with a function and one test. The .mjs extension selects JavaScript modules. Node supplies both the test runner and the strict assertion library, so this particular project has no package to install. Check the Node major version before continuing.

Terminal
mkdir chair-ci
cd chair-ci
node --version
printf '%s\n' 'export const double = n => n + n;' > seats.mjs
cat > seats.test.mjs <<'EOF'
import test from 'node:test';
import assert from 'node:assert/strict';
import { double } from './seats.mjs';

test('doubles the number of seats', () => {
  assert.equal(double(3), 6);
});
EOF
node --test seats.test.mjs

You should see one passing test. The input is three on purpose. An input of two would also produce four if the agent accidentally added two instead of doubling.

Make the promise fail once

Replace the implementation with a plausible mistake while keeping the test unchanged. Rerun precisely the command you used before. This is the same way you will reproduce the CI failure when someone sends you a log instead of a useful bug report.

Terminal
printf '%s\n' 'export const double = n => n + 2;' > seats.mjs
node --test seats.test.mjs

Expect an assertion failure with actual 5 and expected 6. This block ends with an intentional nonzero exit. If it still passes, check the file path in the command and the input inside the test.

Give GitHub the same command

Create a workflow in the repository’s workflow directory. Ask a hosted Ubuntu runner to check out the repository, select Node 24 and execute the same named test file. We give the job read access to repository content. There is no build output or deployment step to configure.

Terminal
mkdir -p .github/workflows
cat > .github/workflows/seats.yml <<'YAML'
name: Seat tests
on: [push, pull_request]
permissions:
  contents: read
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: '24'
      - run: node --test seats.test.mjs
YAML

For a push or pull request in a GitHub repository with Actions enabled, the Seat tests workflow exposes a job named test. Its final step contains the assertion output if the function is broken.

Fix the function and commit the whole recipe

Correct the implementation and run the test again. Commit the module, its test and the workflow together. Publishing this demo to your own empty GitHub repository will run the configured job on push. Local execution already exercises the entire calculation.

Terminal
printf '%s\n' 'export const double = n => n * 2;' > seats.mjs
node --test seats.test.mjs
git init -b main
git config user.name "Lab Reviewer"
git config user.email "reviewer@example.invalid"
git add seats.mjs seats.test.mjs .github/workflows/seats.yml
git commit -m "Run the seat test locally and in CI"
git ls-files

The final local run should report one pass. git ls-files should list three files, including the YAML file under .github/workflows. On GitHub, open Actions and select Seat tests to inspect the matching hosted run.

Try this prompt with your agent

Prompt
The failing command is node --test seats.test.mjs on Node 24. Reproduce the failure, tell me which input produced which two values and change only the implementation. Run the same command again and paste its summary.

A trap worth catching

If your real project imports third-party packages, a fresh runner will need their installation step. For an npm project that commits its package-lock.json, add npm ci before the tests. This lab’s dependency-free files let you concentrate on the first failing assertion.

Official documentation