Skip to content

Reports and custom reporters ​

V8 built-in reports (V8 data only):

  • v8
    • Features:
      • A Brand-New V8 Coverage Report User Interface
      • Support for Native Byte Statistics
      • Support processing big data with high performance
      • Coverage for Any Runtime Code
      • CSS Coverage Support
      • Better Support for Sourcemap Conversion
    • Demos: V8 and more

Istanbul built-in reports (both V8 and Istanbul data):

Other built-in reports (both V8 and Istanbul data):

  • codecov Save coverage data to a json file with Codecov format (defaults to codecov.json), see example.

  • codacy Save coverage data to a json file with Codacy API format (defaults to codacy.json).

  • console-summary shows coverage summary in the console.

  • console-details Show coverage details in the console. Like text, but for V8. For Github actions, we can enforce color with env: FORCE_COLOR: true.

  • markdown-summary Save coverage summary to a markdown file (defaults to coverage-summary.md). For Github actions, we can show the markdown content to a job summary
sh
cat path-to/coverage-summary.md >> $GITHUB_STEP_SUMMARY

  • markdown-details Save coverage details to a markdown file (defaults to coverage-details.md).

  • raw only keep all original data, which can be used for other reports input with inputDir. see Merge Coverage Reports

  • Custom Reporter

    js
    const coverageOptions = {
        reports: [
            [path.resolve('./test/custom-istanbul-reporter.js'), {
                type: 'istanbul',
                file: 'custom-istanbul-coverage.text'
            }],
            [path.resolve('./test/custom-v8-reporter.js'), {
                type: 'v8',
                outputFile: 'custom-v8-coverage.json'
            }],
            [path.resolve('./test/custom-v8-reporter.mjs'), {
                type: 'both'
            }]
        ]
    };
    • Istanbul custom reporter

    example: ./test/custom-istanbul-reporter.js, see istanbul built-in reporters' implementation for reference.

    • V8 custom reporter

    example: ./test/custom-v8-reporter.js

    The type option selects the reporter interface and when it runs:

    • 'istanbul' — uses the Istanbul reporter interface: new Reporter(reportOptions) followed by execute(context). The context provides Istanbul report trees and source lookup. V8 input is converted to Istanbul coverage first.
    • 'v8' (default) — uses new Reporter(reportOptions, globalOptions) followed by await generate(reportData) for V8 input. reportData is the V8 coverage result, with type, summary and files; each file contains V8 ranges and summaries.
    • 'both' — uses the same generate(reportData) interface for either V8 or Istanbul input. Check reportData.type to handle the corresponding result structure. This does not supply both raw formats together; there are no v8Data or istanbulData properties.

    Reporters are loaded with native ESM import(). Use export default Reporter for ESM; Node's built-in interoperability also accepts CommonJS module.exports = Reporter (use .cjs inside an ESM project). Local paths must include the file extension; extensionless paths and directory entries are not resolved. No separate CommonJS loader is provided. Reporter loading and initialization errors reject report generation instead of silently skipping the reporter.

Multiple Reports: ​

js
import { MCR } from 'monocart-coverage-reports';
const coverageOptions = {
    outputDir: './coverage-reports',
    reports: [
        // built-in reports
        ['console-summary'],
        ['v8'],
        ['html', {
            subdir: 'istanbul'
        }],
        ['json', {
            file: 'my-json-file.json'
        }],
        'lcovonly',

        // custom reports
        // Specify reporter name with the NPM package
        ['custom-reporter-1'],
        ['custom-reporter-2', {
            type: 'istanbul',
            key: 'value'
        }],
        // Specify reporter name with local path
        ['/absolute/path/to/custom-reporter.js']
    ]
};
const mcr = MCR(coverageOptions);