Skip to content

Get started ​

Monocart Coverage Reports (MCR) turns JavaScript, TypeScript and CSS coverage data into HTML and other reports.

Installation ​

Requires Node.js >= 22.18.0.

sh
npm i monocart-coverage-reports -D

MCR is ESM-only since v3. CommonJS projects can load it with asynchronous import(); see the migration guide for usage and 2.x upgrades.

CLI ​

For projects using Node.js's built-in test runner, start with Run tests with mcr test: run tests, collect coverage and generate reports with one command, without a config file.

Generate your first report ​

If you do not have test files yet, create demo.js to try coverage with a simple script:

js
console.log('Hello, MCR!');

Run it with coverage:

sh
npx mcr node demo.js -r v8,console-summary -o ./coverage-reports

Open ./coverage-reports/index.html in your browser; the terminal also prints a coverage summary. Use a dedicated output directory: previous report output is cleaned by default.

Replace node demo.js with your own Node.js command. See CLI options for more.

API ​

If a browser fixture or test framework already collects coverage, pass that data to MCR. Use this example after collecting V8 coverage:

js
import { MCR } from 'monocart-coverage-reports';

const mcr = MCR({
    outputDir: './coverage-reports',
    reports: ['v8', 'console-summary'],
    cleanCache: true
});
await mcr.add(coverageData);
const coverageResults = await mcr.generate();
if (!coverageResults) {
    throw new Error('No coverage report was generated');
}
console.log(coverageResults.reportPath);

Coverage data and results ​

In this example, coverageData is an array of V8 coverage entries. For an Istanbul coverage object, use reports: ['html', 'console-summary'] instead.

coverageResults is the output returned by generate(); see CoverageResults for its fields.

Configuration ​

See configuration files, loading config with the API and configuration options.

Next steps ​