Skip to content
Latchkey

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 output
$ node --test
ℹ tests 0
ℹ pass 0
ℹ fail 0
# no test files matched the default patterns

Diagnose 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.

Terminal
# 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.

Terminal
# explicit paths
node --test test/

# or a glob (Node 21+ supports --test with patterns)
node --test "src/**/*.test.js"

Make TS tests runnable

  1. Register a loader for TypeScript (node --import tsx --test ...).
  2. Name test files with a .test segment so default discovery finds them.
  3. 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.

.github/workflows/ci.yml
# pipefail is NOT set by default in every runner shell
- name: Build
  shell: bash
  run: |
    set -euo pipefail
    npm run build | tee build.log

How 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.

Frequently asked questions

What causes node --test "no tests found" / cannot find tests?
There are 3 common causes: test files do not match the default discovery patterns, pointed at the wrong directory or no path, and typescript tests without a loader. Without explicit paths, node --test looks for files matching its conventions (e.g.
How do I fix node --test "no tests found" / cannot find tests?
There are 2 fixes depending on which cause you have: point the runner at your tests explicitly and make ts tests runnable. Work through them in order, since the first is the most common.
What does node --test "no tests found" / cannot find tests actually mean?
node --test runs but reports zero tests (or "cannot find any files"), so a suite you expected to execute never does.
How do I stop node --test "no tests found" / cannot find tests happening again?
Follow node:test’s default naming or pass explicit paths. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card