1.5 KiB
1.5 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 Mocha's
json-streamreporter. - Provides quickfix locations and per-test output.
- Uses
--grepwith escaped patterns to match titles safely, even when running throughnpm test. - Executes tests via
npx mochafor direct Mocha invocation. 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.
Reporter Payload
The runner expects Mocha's built-in json-stream reporter, which emits one JSON
object per line. It consumes the following fields when present:
{
"event": "suite" | "suite end" | "pass" | "fail" | "pending",
"title": "Test or suite title",
"fullTitle": "Mocha full title",
"file": "/path/to/test.js",
"err": { "message": "string", "stack": "string" }
}
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