Quick start
MCR 3.x requires Node.js >= 22.15.0 for all APIs and CLI commands, including ordinary commands,
mergeandtest.
Upgrading from 2.x: See the 3.x migration guide.
- Install as a dev dependency
sh
npm i monocart-coverage-reports -D- CLI
sh
# Run tests with the Node.js test runner and collect native V8 coverage
npx mcr test "./test/**/*.test.js" -r v8,console-summary -o ./coverage-reports
# Or run any Node.js command with coverage
npx mcr node my-app.js -r v8,console-detailsFor more information, see Command Line and Run Tests with mcr test
- API
js
import { MCR } from 'monocart-coverage-reports';
const mcr = MCR({
name: 'My Coverage Report - 2024-02-28',
outputDir: './coverage-reports',
reports: ['v8', 'console-details'],
cleanCache: true
});
await mcr.add(coverageData);
await mcr.generate();Using import and load options from config file
js
import { CoverageReport } from 'monocart-coverage-reports';
const mcr = new CoverageReport();
await mcr.loadConfig();Both
MCR({...})andnew CoverageReport()create the same instance.MCR()is a shorthand factory function; usenew CoverageReport()when you prefer class instantiation or need to callloadConfig()separately.
For more information, see Multiprocessing Support