Files
test-samurai-mocha-runner/README.md
M.Schirmer 29ddc34add
All checks were successful
tests / test (push) Successful in 10s
fix TSamNearest and fully support jump Keymap
2026-01-05 08:58:48 +01:00

71 lines
2.0 KiB
Markdown

# test-samurai-mocha-runner
Mocha.js runner for the test-samurai Neovim plugin.
## Features
- Detects Mocha test files by checking `package.json` dependencies.
- Supports nearest, file, all, and failed-only commands.
- Streams results via a custom NDJSON reporter.
- Provides quickfix locations and per-test output.
- Uses `--grep` with escaped patterns to match titles safely, even when running through `npm test`.
- Executes tests via `npx mocha` with the bundled UI + reporter so projects need no extra setup.
- `TSamAll` runs `test/**/*.{test,spec}.{t,j}s` to 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:
```lua
require("test-samurai").setup({
runner_modules = {
"test-samurai-mocha-runner",
},
})
```
## Development
Run tests:
```bash
bash run_test.sh
```