How to implement Istanbul Coverage with Selenium and Mocha
Getting istanbul
working
I had the same problem you had months ago. All zeroes in the reports. The problem has to do with the use of ESM modules. It appears that may be your issue too: I see sourceType: 'module'
in your babel config.
If so, you will need to uses @istanbuljs/esm-loader-hook
to get mocha to work with Istanbul when using modules.
Install @istanbuljs/esm-loader-hook
and then invoke mocha like this:
npx nyc mocha --experimental-loader=@istanbuljs/esm-loader-hook
You can see https://github.com/istanbuljs/nyc/issues/1343 for some troubleshooting steps.
A possibly better alternative: c8
If you still have trouble getting Istanbul to work, before you spend too much time trying to figure out why, I strongly recommend you try an alternative to istanbul/nyc that uses V8's native coverage facilities and just magically works: c8.
It is written by @bcoe, one of the maintainers of nyc/instanbul. When I had trouble with Istanbul, it took me 5 minutes to get c8 to work. It is compatible with Istanbul's reporters and you get the exact same reporting functionality out-of-the-box.