Skip to content
Latchkey

Mocha "0 passing" / no tests executed in CI

Mocha started and exited cleanly but executed nothing: it reports "0 passing". Either no files matched the spec glob, or the files loaded but registered no it cases.

What this error means

The Mocha step prints "0 passing (1ms)" and exits 0, so CI reports green while nothing was actually tested. It commonly follows moving test files or changing the spec path.

Mocha output
  0 passing (1ms)

(no test files were matched, or no it() blocks registered)

Common causes

The spec glob matched no files

Mocha defaults to ./test/*.spec.js; if your tests live elsewhere or use a different extension, nothing is loaded.

Files loaded but defined no tests

A setup-only file, a skipped suite, or a syntax path that never reaches it() leaves Mocha with zero registered tests.

How to fix it

Point Mocha at the real spec paths

  1. Set the spec glob in .mocharc or on the command line to match your test files.
  2. Include the right extensions and recursive directories.
  3. Re-run and confirm the passing count is non-zero.
.mocharc.json
// .mocharc.json
{
  "spec": "test/**/*.test.js",
  "recursive": true
}

Fail the build when zero tests run

Have CI treat an empty run as a failure so a green "0 passing" cannot hide a misconfigured path.

Terminal
npx mocha 'test/**/*.test.js' --recursive

How to prevent it

  • Define spec explicitly in .mocharc so test discovery is deterministic.
  • Treat zero collected tests as a failure in CI.
  • Keep the spec glob in sync when you move test files.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →