1
votes

I followed this guide to get coverage report integrated in WebStorm.

https://www.jetbrains.com/help/webstorm/mocha.html

When I click "Run Mocha test with coverage" the coverage window shows up after running the test. But I don't see any coverage reported. It is not even showing 0%, it is not showing any numbers at all in the Statistics column.

Any help will be appreciated.

Some more background:

  • WebStorm 2017.2.3
  • I'm referring Mocha v3.2.0 in package.json
  • The code is written in ES2015.
  • The mocha Run configuration uses these environment variables

BABEL_ENV=test and these extra mocha options: --compilers js:babel-core/register

Thanks in advance

Further information: when I run with coverage in WebStorm I see this command being output to the console:

/Users/nikolaschou/.nvm/versions/node/v8.1.2/bin/node /Users/nikolaschou/Dev/dsg/bifrostshop/node_modules/nyc/bin/nyc.js --reporter=lcovonly --extension=.ts --extension=.js --exclude=test/unitmocha//.spec. --exclude=test/unitmocha//.test. --report-dir=/private/var/folders/q7/kn0zjzks5dz0q2bx0kpg2yhw0000gn/T/mocha-intellij-coverage- /Users/nikolaschou/Dev/dsg/bifrostshop/node_modules/mocha/bin/_mocha --compilers js:babel-core/register --ui bdd --reporter "/Applications/WebStorm 2.app/Contents/plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js" --recursive /Users/nikolaschou/Dev/dsg/bifrostshop/test/unitmocha

2
what module do you use for collecting coverage - istanbul or nyc? Can you collect coverage for your tests when running in cmd line?lena
@lena I added more information to my question and as far as I can see, I use nycNikola Schou
I have a similar issue. In my case there is already an .nycrc file (to support command-line execution) with ` "include": [ "src/" ] ` When I run coverage through WebStorm, I get no coverage (like Nikola). When I delete (or rename) .nycrc, I get coverage on the test directory only.Daniel Steinberg
I have nyc installed and it works fine without this hack. The only thing I'm not seeing WebStorm do is highlight the lines red or green in the code being covered. I run my test from a mocha configuration, not command-line.PositiveGuy

2 Answers

1
votes

Add a file called .nycrc in the project root with these contents:

{ "exclude": [] }

This overrides nyc default config and win is restored.

1
votes

In my case I had this problem because mocha did not exit properly. As the coverage reports seem to be generated on program exit, they are never generated.

Mocha 4 especially has changed behaviour from Mocha 3 as it does "no longer automatically kill itself via process.exit() when it thinks it should be done running".

However you can force that old behaviour with the --exit option. The better option is probably to examine what keeps your program from terminating and perform a clean shut down. (Maybe with some help of wtfnode for example)

Readings: