Git Product home page Git Product logo

jest-monocart-coverage's Introduction

jest-monocart-coverage

A Jest custom reporter for monocart coverage reports

Install

npm i jest-monocart-coverage

Usage

// jest.config.js
const config = {

    // Enable coverage
    collectCoverage: true,
    // Recommended to use `v8` to support the generation of native v8 coverage reports.
    coverageProvider: 'v8',
    // Monocart can also support all coverage reports, so there is no need to set up reports here.
    coverageReporters: ['none'],

    reporters: [
        // If custom reporters are specified, the default Jest reporter will be overridden. If you wish to keep it, 'default' must be passed as a reporters name:
        'default',

        // Monocart custom reporter to generate coverage reports. 
        ['jest-monocart-coverage', {
            name: 'My Unit Coverage Report',
            reports: [
                ['v8'],
                ['console-summary'],
                ['lcovonly']
            ],
            outputDir: './coverage-reports/unit'
        }]
    ]
    
};
export default config;

Check monocart coverage reports for more coverage options.

The Execution Order of Hooks

  • For Jest: custom reporter onEnd -> globalTeardown
  • For Playwright: globalTeardown -> coverage onEnd -> custom reporter onEnd

Common issues

  • Resolve full path of the file with option sourcePath (issue #5)
const path = require("path")

// MCR coverage options
{

    sourcePath: (filePath, info)=> {
        if (!filePath.includes('/') && info.distFile) {
            return `${path.dirname(info.distFile)}/${filePath}`;
        }
        return filePath;
    }
  
}

jest-monocart-coverage's People

Contributors

aghassi avatar cenfun avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

aghassi

jest-monocart-coverage's Issues

Bug with v8 Paths, but not sure what is the root cause

I followed the example provided in the README, but the issue I'm seeing with my system is that the v8 data strips out the sourcePath from the file. This does not happen if the jest config does not have coverageProvider: 'v8'. The thing is, I'm not sure why this is happening. I'm opening this issue more to discuss. I have not made a way to publicly reproduce because this is on our internal monorepo with Bazel.

Basically, the lcov file generate is missing path/to/file.ts with that option on. It just returns file.ts.

I have some theories, but nothing concrete. Any ideas?

Monocart report will not include all files

I found a strange issue, if I commented out the jest coverage reports, like this

//coverageReporters: ['none']

Then the console will output 2 coverage results, I believe the first one is from monocart jest repot, the 2nd one is from jest, and the first one does not include all files

If I set disable the coverageReporters field, then I will see only 1 coverage result, which does not include all files

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.