4

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!

4

1 回答 1

1

我是流星覆盖的作者。很高兴看到该软件包在您的应用程序上运行良好!

首先,我认为您收集覆盖率和保存报告的方式没有得到优化:不要创建具有保存覆盖率功能的实用程序。您可以通过使用来保存每个文件的覆盖率(假设 Meteor.sendCoverage在测试中始终存在)。

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

另一方面,您不应该在测试文件中编写任何代码以节省覆盖率。测试运行器可以像我在 spacejam fork 上添加的那样为你做这件事。您可以尝试使用serut/spacejamhtml导出和报告。lcov

我认为lcov格式比html报告更可靠。如果我查看来自 meteor-coverage 的客户端代码的一些覆盖率报告,一切看起来都是连贯的。尝试将 lcov 文件发送到 Sonar、Codecov 或 Codacy 等代码质量平台。我希望它能解决线路问题,这可能与 istanbul 及其 html 报告生成有关。

于 2017-06-03T18:45:14.890 回答