JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8870
  • Score
    100M100P100Q140233F
  • License MIT

A Tool to Show Code Coverage for Modified Lines in a Diff

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (diff-cover) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    diff-cover-ts

    License: MIT npm version npm downloads CI TypeScript Bun Code Style

    A high-performance TypeScript port of the diff_cover tool.

    Automatically find lines of code in your git diff that are missing test coverage or quality checks.

    English | 简体中文


    📖 Table of Contents

    🚀 Introduction

    diff_cover_ts helps you maintain high code quality by focusing on what matters most: the code you just changed. Instead of failing builds because of low legacy coverage, this tool ensures that every new commit meets your quality standards.

    It works by comparing your current branch with a base branch (e.g., origin/main) and reporting coverage/quality gaps only for the modified lines.

    ✨ Features

    • 🎯 Precision Coverage: Report code coverage only for modified lines in your git diff.
    • 🛡️ Quality Gate: Enforce linting checks only on changed code.
    • 🤖 Auto-Configuration: Seamlessly detects vite.config.ts/js or vitest.config.ts/js to find coverage reports.
    • 📊 Multi-Format Support: Compatible with lcov, cobertura, clover, jacoco, and generic XML reports.
    • ⚡ Git Integration: Built-in git history analysis to identify modified lines accurately.
    • 🚫 Fail-Under Checks: Set thresholds to fail CI/CD pipelines if coverage/quality is too low.

    📦 Installation

    # Using npm (Global)
    npm install -g diff-cover
    
    # Using Bun (Global)
    bun add -g diff-cover
    
    # Using npm (Dev Dependency)
    npm install diff-cover --save-dev

    🛠 Usage

    Diff Cover

    Automatically identify lines in your diff that lack test coverage.

    If you are using Vite or Vitest, simply run:

    diff-cover

    The tool will intelligently parse your configuration files to locate the coverage report and determine the format.

    📝 Manual Usage

    You can explicitly specify the coverage report files:

    diff-cover coverage/lcov.info
    # OR
    diff-cover coverage/cobertura.xml

    ⚙️ Options

    Option Description Default
    --compare-branch <branch> Branch to compare against origin/main
    --fail-under <score> Returns a non-zero exit code if coverage is below this value 0
    --show-uncovered Print uncovered lines to the console false
    --expand-coverage-report Append missing lines based on previous line hits false
    --ignore-staged Ignore staged changes in the diff false
    --ignore-unstaged Ignore unstaged changes in the diff false
    --include-untracked Include untracked files in the analysis false
    --exclude <patterns...> Exclude files matching glob patterns []
    --include <patterns...> Include files matching glob patterns []
    --html-report <file> Generate an HTML report at the specified path null
    --json-report <file> Generate a JSON report at the specified path null

    Diff Quality

    Run static analysis tools and report violations only on modified lines.

    diff-quality report.txt --violations <driver>

    🔌 Supported Drivers

    • eslint
    • pylint
    • flake8
    • shellcheck
    • cppcheck
    • checkstyle
    • findbugs

    ⚙️ Options

    Option Description Default
    --compare-branch <branch> Branch to compare against origin/main
    --fail-under <score> Returns a non-zero exit code if quality score is below value 0
    --include-untracked Include untracked files false
    --exclude <patterns...> Exclude files matching glob patterns []
    --html-report <file> Generate an HTML report at the specified path null

    💻 Development

    Setup

    # Install dependencies
    bun install

    Testing

    # Run test suite
    bun test
    
    # Run tests with coverage
    bun test --coverage

    Code Quality

    We use oxlint for linting and oxfmt for formatting. Pre-commit hooks via husky ensure code quality.

    # Lint code
    bun run lint
    
    # Format code
    bun run format

    📄 License

    This project is licensed under the MIT License.