Changed files
JS and TS files changed versus a base ref, including every author’s commits, plus staged and unstaged edits.
Changed lines only
mo3ta-coverage finds changed JavaScript and TypeScript files, maps them to likely Jest tests, runs those tests, and fails when changed-line coverage is below your threshold.
One command, aimed at the diff. It does not try to re-grade the whole repository.
JS and TS files changed versus a base ref, including every author’s commits, plus staged and unstaged edits.
Maps each source file to likely tests by filename and reverse imports using the default native engine or opt-in --engine jest (HasteFS + DependencyResolver).
Runs the local Jest binary with coverage (using --runTestsByPath in --engine jest). --dryRun true prints paths and stops; --explain true shows why.
Reads coverage/lcov.info and counts only coverable lines that differ from the base. Default limit is 80%.
Smart is the default. It catches specs that reach a changed file through a barrel or a thin wrapper without walking the whole graph.
fast
Looks for .test and .spec files, __tests__, and a parallel src/tests layout. If the name misses, it scans test files that import the source directly.
smart
Same naming matches, then a reverse-import walk limited by --depth (default 2). Uses the zero-dependency native engine by default, or opt into --engine jest to reuse Jest 29/30 HasteFS and DependencyResolver.
full
Passes the changed source and test files to jest --findRelatedTests. There is no depth cap. --dryRun can only list the changed test files in this mode.
--engine jest)Opt into --engine jest in smart mode when your repo relies on Jest custom resolvers, moduleNameMapper, manual __mocks__, React Native platform extensions, multi-project configs, or .snap snapshot mapping.
| Mode + Engine | Discovery | Traversal | Jest features |
|---|---|---|---|
fast | Naming + direct import fallback | None | None |
smart + native (default) | Naming + tsconfig + workspace + regex graph | Bounded (--depth) | None (zero-dependency) |
smart + jest (opt-in) | Project-local Jest 29/30 HasteFS + DependencyResolver | Bounded (--depth) | moduleNameMapper, custom resolver, __mocks__, RN extensions, projects, .snap |
full | jest --findRelatedTests | Unbounded | Full Jest graph |
npm install --save-dev mo3ta-coverage npx mo3ta-coverage --mode smart --engine jest --depth 2 --base origin/main --limit 80
Use case 1
Resolves edges through Jest moduleNameMapper rules, custom resolver hooks, and manual __mocks__ directories using your project’s own DependencyResolver.
Use case 2
Honors Jest’s configured moduleFileExtensions and Haste settings for platform files like .ios.ts, .android.ts, and .native.js automatically.
Use case 3
Builds an independent graph per Jest project, honors --selectProjects / --ignoreProjects, and narrows named projects automatically with --runTestsByPath.
Use case 4
Maps changed .snap files back to their owning tests via Jest’s SnapshotResolver, and classifies tests using your testMatch and testRegex.
# Multi-project selection npx mo3ta-coverage --mode smart --engine jest --depth 2 --base origin/main --jest --config=jest.config.js --jest --selectProjects=web # Snapshot change mapped to its test npx mo3ta-coverage --mode smart --engine jest --files src/__snapshots__/card.test.js.snap --base origin/main # Resilient CI run with 4 discovery workers and native fallback npx mo3ta-coverage --mode smart --engine jest --discoveryWorkers 4 --fallback native --base origin/main --limit 80
$ npx mo3ta-coverage --mode smart --engine jest --depth 2 --dryRun true --explain true --files src/fileUtils.js --base origin/main 🧭 Dependency explanations: src/fileUtils.js -> src/fileUtils.test.js (depth 1, path: src/fileUtils.js -> src/fileUtils.test.js) src/fileUtils.js -> src/cli.test.js (depth 2, path: src/fileUtils.js -> src/cli.js -> src/cli.test.js) src/fileUtils.js -> src/api.test.js (depth 2, path: src/fileUtils.js -> src/api.js -> src/api.test.js) src/api.test.js src/cli.test.js src/fileUtils.test.js
--jest discovery/watch flags (such as --findRelatedTests, --watch, and --runTestsByPath). Cold runs build Jest’s HasteMap; warm caches are fast. Keep a full-suite CI check as a safety net for dynamic runtime imports or deleted files.
Install from npm as a dev dependency or globally, or run directly with npx.
# Local dev dependency (recommended for CI) npm install --save-dev mo3ta-coverage npx mo3ta-coverage --mode smart --base origin/main --limit 80 # Opt into the Jest discovery engine npx mo3ta-coverage --mode smart --engine jest --depth 2 --base origin/main --limit 80 # Global install npm install -g mo3ta-coverage
Save defaults in the project root. Later runs pick up base, mode, depth, engine, discoveryWorkers, fallback, jest, and filter from that file when you do not pass them.
npx mo3ta-coverage config --base origin/main --mode smart --engine jest --depth 2 --discoveryWorkers 4 --fallback native
| Flag | What it does | Default |
|---|---|---|
--base | Git ref to compare against | origin/main |
--mode | fast, smart, or full | smart |
--engine | Discovery engine for smart mode: native or jest | native |
--depth | Smart-mode reverse-import depth (1–10) | 2 |
--discoveryWorkers | HasteMap worker count for --engine jest (1–16) | 2 |
--explain [bool] | Show dependency chains from changed files to selected tests | false |
--fallback | Policy when --engine jest fails: error or native | error |
--limit | Minimum changed-line coverage | 80 |
--lcov | Path to the lcov report | coverage/lcov.info |
--files / --filesFrom | Scan this list instead of detecting changed files. --files is space- or comma-separated; --filesFrom is one path per line | — |
--jest | Extra Jest CLI flag (repeatable or comma-separated), e.g. --maxWorkers=2 | — |
--filter | Regex matched against the final selected spec paths | — |
--dryRun [bool] | Print selected test paths, one per line, and exit | false |
--ci [bool] | Write a markdown table (and print it) instead of the verbose log | false |
--ciReport | Where --ci saves that markdown table | coverage/mo3ta-coverage-report.md |
--quiet [bool] | Write Jest test execution output to coverage/mo3ta-coverage-tests.log instead of the terminal | false |
--showCovered [bool] | Also list covered changed lines | false |
Pass --files src/a.js src/b.ts or --files src/a.js,src/b.ts, or a newline-separated list via --filesFrom, when you want to choose the files yourself. Changed lines for those files are still computed against --base.
mo3ta-coverage-action runs the CLI on Node 20, turns on CI mode, and appends the markdown table to the job summary. Leave base empty and it picks the ref from the event.
| Event | Base used |
|---|---|
pull_request | The pull request’s base commit |
push | The previous commit (HEAD~1) |
| schedule, dispatch, other | origin/main |
name: Changed-line coverage
on:
pull_request:
push:
branches: [main]
jobs:
changed-line-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: npm ci
- uses: MahmoudMabrok/mo3ta-coverage-action@v1
with:
mode: smart
depth: 2
limit: 80
Checkout needs full history so the merge-base diff is available. Inputs are documented in the action README.
The same checks ship in mo3ta-coverage 1.3.0 and later as MCP tools over stdio. The bin is mo3ta-coverage-mcp. An agent can list the diff, see which tests would run, and read the uncovered lines it should cover. The server calls the CLI’s own functions. It needs Node.js 18 or newer.
list_changed_filesList JS/TS files changed versus a base ref, or an explicit list.map_related_testsMap those files to the tests fast, smart (native or jest), or full mode would run. Accepts engine, discoveryWorkers, explain, fallback, and filter.check_changed_line_coverageRun the changed-line check and return uncovered lines with source text. Accepts engine, discoveryWorkers, explain, fallback, jest, and filter. runTests: false grades an existing lcov.info instead.Each tool takes a root path. If you omit it, Claude Code’s CLAUDE_PROJECT_DIR is used when set, otherwise the server’s working directory. useConfig defaults to true, so base, mode, depth, engine, discoveryWorkers, fallback, jest, and filter come from .mo3ta-coverage.json when that file exists. check_changed_line_coverage runs the repo’s local Jest (default timeout 5 minutes) and writes coverage/ there. A missed threshold comes back as data, with the uncovered lines, rather than a crash. A missing git repo, a bad base ref, a missing Jest install, or a timeout comes back as a tool error.
Use npx as the command. The same JSON works in .cursor/mcp.json and in Claude Desktop’s claude_desktop_config.json.
{
"mcpServers": {
"mo3ta-coverage": {
"command": "npx",
"args": ["-y", "--package", "mo3ta-coverage", "mo3ta-coverage-mcp"]
}
}
}
claude mcp add mo3ta-coverage -- npx -y --package mo3ta-coverage mo3ta-coverage-mcp
The package name and the bin name differ, so npx needs --package mo3ta-coverage. From a checkout of this repo, node mcp/server.js starts the same server.