node --test "no tests found" / Cannot Find Tests - Fix node:test Runner in CI
Node’s built-in test runner (node --test) discovers test files by a fixed set of naming conventions. If your files do not match - or you point it at nothing - it reports no tests and exits, which CI may treat as a silent pass or a failure depending on configuration.
What this error means
node --test runs but reports zero tests (or "cannot find any files"), so a suite you expected to execute never does. Files named outside Node’s default patterns (e.g. not *.test.js / under a test/ dir) are not picked up.
$ node --test
ℹ tests 0
ℹ pass 0
ℹ fail 0
# no test files matched the default patternsDiagnose it: the shell in CI is not your shell
Package scripts run under a different shell, a different PATH, and a non-interactive environment on a runner. Most scripts that fail only in CI are relying on something the login shell gave them locally: a tool on PATH, an environment variable from a dotfile, or a TTY.
# what the script can actually see
npm run env | grep -E "^(PATH|NODE_ENV|CI)="
# is the binary on PATH for the script, not just for you?
npm exec -- which <tool> || echo "not resolvable from npm scripts"
# run the exact script with tracing
sh -x -c "$(node -p "require('./package.json').scripts.build")"Common causes
Test files do not match the default discovery patterns
Without explicit paths, node --test looks for files matching its conventions (e.g. *.test.*, files under test/). Differently named files are ignored, so nothing runs.
Pointed at the wrong directory or no path
Running the command from the wrong cwd, or relying on defaults that do not match your layout, yields an empty run.
TypeScript tests without a loader
TS test files need a loader (tsx/ts-node) registered; otherwise they are skipped or fail to parse, so the runner finds nothing to execute.
How to fix it
Point the runner at your tests explicitly
Pass the files/globs or use the test directory the runner expects.
# explicit paths
node --test test/
# or a glob (Node 21+ supports --test with patterns)
node --test "src/**/*.test.js"Make TS tests runnable
- Register a loader for TypeScript (
node --import tsx --test ...). - Name test files with a
.testsegment so default discovery finds them. - Run with a non-zero exit on empty if you want CI to fail when no tests match.
Make failures fail the job
A multi-command script can report success while a middle command failed, which produces the worst kind of CI result: a green build that shipped something broken.
# pipefail is NOT set by default in every runner shell
- name: Build
shell: bash
run: |
set -euo pipefail
npm run build | tee build.logHow to prevent it
- Follow node:test’s default naming or pass explicit paths.
- Run the test command from the project root.
- Register a loader when testing TypeScript with node:test.