meteormocha.jscode-coverageistanbulcodacy

Meteor-coverage seems to show executed statements as not covered


I'm using the meteor-coverage package (version 1.1.4) with mocha (version 2.4.5_6) and meteor version 1.4.4.1 on Ubuntu 14.04 LTS. I have been able to produce very pretty test coverage reports, but it seems that for the client-side tests something is amiss. In order to send the coverage data to localhost:3000/coverage I have created a function called sendCoverage() which I import in my .tests.js files:

export const sendCoverage = function sendCoverage() {
    Meteor.sendCoverage(function(stats,err) {console.log(stats,err);});
};

I call this function after a block of mocha tests:

after (function () {
    sendCoverage();
});

Now, this produces test coverage reports in my localhost:3000/coverage page, but it seems as though it does not display the coverage properly. For example, I see that some statements are executed, but are highlighted in red and flagged as not covered. For example:

coverage example

It seems as though the statements get executed 11 and 12 times, respectively. However, they are not flagged as being covered and in my reports the percentage of statement coverage reflects this.

Does anyone know what I may be doing wrong and/or have experience with client-side code coverage and the meteor-coverage package?

Thanks!

Post-solution edit

It seems I've got it working now. The percentages on Codacy match the percentages in my html report. Looking at the html report more closely, it seems the coverage numbers were correct after all. It was simply the drill down that was showing odd behavior. So, the conclusion is that it worked after all, but it took Codacy's second opinion to confirm this to me. My new approach will be to create lcov coverage reports with spacejam (see Ser's answer below) and export these to an external service like Codacy, Codecov or SonarQube.

Thanks Serut for the input!


Solution

  • I am the author of meteor-coverage. Glad to see that the package runs well on your app!

    First, I don't think the way your are collecting coverage and saving reports is optimized: don't create an utils with a function to save the coverage. You can save the coverage on each file just by using (assuming Meteor.sendCoverage always exists on test).

    after (function () {
        Meteor.sendCoverage(()=>{});
    });
    

    On the other hand, you should not write any code in your test file in order to save coverage. The test runner can do that for you like what I added on the spacejam fork. You can try to export the html and the lcov report using serut/spacejam.

    I think the lcov format is more reliable than the html report. If I look at some coverage report of the client side code from meteor-coverage, everything looks coherent. Try to send the lcov file to an Code Quality platform like Sonar, Codecov or Codacy. I hope it will fix the line problem, which may be related to istanbul and its html report generation.