Staaarter

Code Coverage Report

A test coverage dashboard with an overall-percentage summary bar and a two-level expandable file tree below it: folders open to reveal files, and each file shows its statements, branches, functions, and lines coverage as small color-coded percentage chips. Built for CI dashboards, docs pages, and internal quality reports.

By Staaarter Team
DevTools
Docs
Live preview

Docs

Installation

A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its dependencies and any missing npm packages, and installs them straight into your project.

npx shadcn add https://staaarter.com/r/code-coverage-report.json

Prefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/devtools/devtools22.tsx instead.

Usage

The file also exports devtools22Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.

import { Devtools22, devtools22Demo } from "@/components/blocks/devtools/devtools22";

export default function Page() {
  return <Devtools22 {...devtools22Demo} />;
}

Props

PropTypeDefaultDescription
headingstring"Code Coverage Report"Section heading.
descriptionstringundefinedSection intro text below the heading.
overallOverallCoveragenoneAggregate percentages shown in the summary row above the tree.
foldersFolderCoverage[][]Top-level folders in the tree, each expandable to reveal its files.
defaultOpenFoldersstring[][]Folder names (matched against FolderCoverage.name) that render expanded on first render.
classNamestringnoneExtra classes for the outer section element.

Types

type FileCoverage = {
  name: string;
  statements: number;
  branches: number;
  functions: number;
  lines: number;
};

type FolderCoverage = { name: string; files: FileCoverage[] };

type OverallCoverage = {
  statements: number;
  branches: number;
  functions: number;
  lines: number;
};

Behavior notes

  • "use client" only for the folder expand/collapse state; expanding a folder is real local state, nothing else in the block is interactive.
  • defaultOpenFolders sets which folders start expanded via a lazy useState initializer read once on mount, not an effect, so it never fights with the user toggling folders afterward.
  • The tree is exactly two levels deep (folders, then files); there is no nested-subfolder recursion.
  • Coverage chip color thresholds are fixed: 80% and above is emerald, 50 to 79% is amber, below 50% is red, applied identically to the overall summary and every per-file chip.
  • The overall summary numbers are caller-supplied and are not computed by averaging the folders/files data, so they can be set independently of what the tree actually contains.