analyze_coverage
Analyze test coverage for a target file or directory to find untested lines, functions, branches, and statements. Delivers actionable insights and metrics to improve test quality.
Instructions
Perform comprehensive test coverage analysis with line-by-line gap identification, actionable insights, and detailed metrics for lines, functions, branches, and statements. Runs the tests that import the target (wherever they live, e.g. ./test or tests) and reports coverage for the target only, including files no test touches. Automatically excludes common non-production files (stories, mocks, e2e tests). Detects and prevents analysis on test files themselves. Requires set_project_root to be called first. Coverage thresholds are read from the Vitest config.
USE WHEN: User wants to check test coverage, identify untested code, improve test coverage, asks "what's not tested", "coverage report", "how well tested", or mentions coverage/testing quality. Essential when "vitest-mcp:" prefix is used with coverage-related requests. Prefer this over raw vitest coverage commands for actionable insights.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | Output format: "summary" (basic metrics), "detailed" (comprehensive analysis with file details) | summary |
| target | Yes | Source file path or directory to analyze coverage for. Should target the actual source code files, NOT test files. Can be a specific source file (e.g., "./src/utils/helper.ts") or directory (e.g., "./src/components"). Relative paths resolved from project root. Required to prevent accidental full project analysis which can be slow and resource-intensive. | |
| exclude | No | Glob patterns to exclude from coverage analysis. Examples: ["**/*.stories.*", "**/e2e/**"]. Useful for excluding stories, mocks, or other non-production code from coverage calculations. | |
| project | No | Optional name of a Vitest project (from the `projects` array in vitest.config) whose tests should be used to measure coverage, e.g. "unit". Defaults to all projects. |