Search code examples
node.jsunit-testingmocha.jscode-coverageistanbul

Configuration for Istanbul and mocha Node js code coverage


I am new to Istanbul and mocha Framework.

for my Node.js project i am configuring mocha and Istanbul.

it works fine separately.

i don't have an idea how to integrate both and produce the coverage report.

I found some of the documentation or configuring in Package.json Script for Mac.

But i need to set up for windows machine.

i have spent enough time researching on my own but i didn't find any perfect doc for it,Can someone help with the proper documentation would be helpful.

Thanks in advance.


Solution

  • Scripts to be added in package.json for windows :

    "scripts": {
            "coverage": "istanbul cover ./node_modules/mocha/bin/_mocha test/*.js",
            "test": "mocha  test/*.js"
        }
    

    Command to run the Coverage with UnitTesting :

    npm run coverage
    

    Command to run only the Test Cases:

    npm run test