2.0 KiB
test-samurai-mocha-runner
Mocha.js runner for the test-samurai Neovim plugin.
Features
- Detects Mocha test files by checking
package.jsondependencies. - Supports nearest, file, all, and failed-only commands.
- Streams results via a custom NDJSON reporter.
- Provides quickfix locations and per-test output.
- Uses
--grepwith escaped patterns to match titles safely, even when running throughnpm test. - Executes tests via
npx mochawith the bundled UI + reporter so projects need no extra setup. TSamAllrunstest/**/*.{test,spec}.{t,j}sto discover tests reliably.
Full Name Convention
The runner builds stable full names using the active suite stack joined by /,
followed by the test title:
Suite/Subsuite/Test
This convention is used consistently in results.*, parse_test_output, and
collect_failed_locations. Failed-only runs translate / back to spaces for
Mocha's --grep matching. Avoid / in your titles if you rely on that mapping.
When the custom reporter provides titlePath, it is used to build full names
without ambiguity (titles may contain spaces).
Reporter Payload
The runner uses the bundled NDJSON reporter at scripts/mocha-ndjson-reporter.cjs,
which emits one JSON object per line:
{
"event": "run-begin" | "run-end" | "suite" | "test",
"status": "passed" | "failed" | "pending" | "skipped",
"title": "Test or suite title",
"fullTitle": "Mocha full title",
"titlePath": ["Parent", "Child", "Test"],
"file": "/path/to/test.js",
"location": { "file": "/path/to/test.js", "line": 10, "column": 5 },
"error": { "message": "string", "stack": "string" }
}
The UI wrapper scripts/bdd-with-location.cjs attaches test/suite locations so
Quickfix and per-test output are consistent.
Usage
Add the module to your test-samurai configuration:
require("test-samurai").setup({
runner_modules = {
"test-samurai-mocha-runner",
},
})
Development
Run tests:
bash run_test.sh