Changed lines only

Coverage for the lines a pull request actually changed.

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.

Poster titled mo3ta-coverage. Tagline: Changed code. Related specs. Real coverage. Three modes: fast runs naming-convention matches plus a direct import scan; smart, the default, adds a reverse-import walk limited by --depth 2; full passes changed files to jest --findRelatedTests. Features: detect changed JS/TS files for all authors, run related tests, map specs by name and import graph, scan selected files, check changed-line coverage from lcov.info, fail below --limit, report uncovered changed lines, and work locally and in CI.
Modes and features. The sections below are the same behavior, with the commands to run it.

How it works

One command, aimed at the diff. It does not try to re-grade the whole repository.

01

Changed files

JS and TS files changed versus a base ref, including every author’s commits, plus staged and unstaged edits.

02

Related tests

Maps each source file to likely tests by filename and reverse imports using the default native engine or opt-in --engine jest (HasteFS + DependencyResolver).

03

Jest

Runs the local Jest binary with coverage (using --runTestsByPath in --engine jest). --dryRun true prints paths and stops; --explain true shows why.

04

Changed lines

Reads coverage/lcov.info and counts only coverable lines that differ from the base. Default limit is 80%.

Three ways to pick tests

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

Name, then a direct import

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.

Default

smart

Name plus reverse imports

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

Let Jest expand

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.

Jest engine (--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 + EngineDiscoveryTraversalJest features
fastNaming + direct import fallbackNoneNone
smart + native (default)Naming + tsconfig + workspace + regex graphBounded (--depth)None (zero-dependency)
smart + jest (opt-in)Project-local Jest 29/30 HasteFS + DependencyResolverBounded (--depth)moduleNameMapper, custom resolver, __mocks__, RN extensions, projects, .snap
fulljest --findRelatedTestsUnboundedFull Jest graph
shell — quick start (npm)
npm install --save-dev mo3ta-coverage
npx mo3ta-coverage --mode smart --engine jest --depth 2 --base origin/main --limit 80

Use case 1

Aliases, resolvers & mocks

Resolves edges through Jest moduleNameMapper rules, custom resolver hooks, and manual __mocks__ directories using your project’s own DependencyResolver.

Use case 2

React Native extensions

Honors Jest’s configured moduleFileExtensions and Haste settings for platform files like .ios.ts, .android.ts, and .native.js automatically.

Use case 3

Multi-project monorepos

Builds an independent graph per Jest project, honors --selectProjects / --ignoreProjects, and narrows named projects automatically with --runTestsByPath.

Use case 4

Snapshots & custom matchers

Maps changed .snap files back to their owning tests via Jest’s SnapshotResolver, and classifies tests using your testMatch and testRegex.

shell — multi-project, snapshot & CI samples
# 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
shell — preview & explain selections
$ 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
Compatibility & limitations: Resolves project-local Jest 29 or 30 (npm, yarn, pnpm) and refuses to load mo3ta’s own Jest. Rejects conflicting --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 and run

Install from npm as a dev dependency or globally, or run directly with npx.

shell
# 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.

.mo3ta-coverage.json
npx mo3ta-coverage config --base origin/main --mode smart --engine jest --depth 2 --discoveryWorkers 4 --fallback native
FlagWhat it doesDefault
--baseGit ref to compare againstorigin/main
--modefast, smart, or fullsmart
--engineDiscovery engine for smart mode: native or jestnative
--depthSmart-mode reverse-import depth (1–10)2
--discoveryWorkersHasteMap worker count for --engine jest (1–16)2
--explain [bool]Show dependency chains from changed files to selected testsfalse
--fallbackPolicy when --engine jest fails: error or nativeerror
--limitMinimum changed-line coverage80
--lcovPath to the lcov reportcoverage/lcov.info
--files / --filesFromScan this list instead of detecting changed files. --files is space- or comma-separated; --filesFrom is one path per line—
--jestExtra Jest CLI flag (repeatable or comma-separated), e.g. --maxWorkers=2—
--filterRegex matched against the final selected spec paths—
--dryRun [bool]Print selected test paths, one per line, and exitfalse
--ci [bool]Write a markdown table (and print it) instead of the verbose logfalse
--ciReportWhere --ci saves that markdown tablecoverage/mo3ta-coverage-report.md
--quiet [bool]Write Jest test execution output to coverage/mo3ta-coverage-tests.log instead of the terminalfalse
--showCovered [bool]Also list covered changed linesfalse

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.

GitHub Action

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.

EventBase used
pull_requestThe pull request’s base commit
pushThe previous commit (HEAD~1)
schedule, dispatch, otherorigin/main
.github/workflows/changed-line-coverage.yml
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.

MCP server for coding agents

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.

Cursor and other MCP clients

Use npx as the command. The same JSON works in .cursor/mcp.json and in Claude Desktop’s claude_desktop_config.json.

.cursor/mcp.json
{
  "mcpServers": {
    "mo3ta-coverage": {
      "command": "npx",
      "args": ["-y", "--package", "mo3ta-coverage", "mo3ta-coverage-mcp"]
    }
  }
}

Claude Code

shell
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.