Mocha Code Coverage Error - Failed to save lcovonly coverage

Hi Everyone - I’m new to this community but I was hoping to get some help with a code coverage issue :slight_smile:

I’m trying to generate and save an LCOV report file from a mocha test suite for my server in my (non-Typescript) Meteor app. To enable this, I’ve added the lmieulet:meteor-coverage meteor package, the instanbul babel plugin, and a .coverage.json file.

I’ve also written an npm script (named “test-cov”) which includes the necessary env variables to run the test with coverage.

However, when I run “npm run test-cov”, all the tests pass but I keep getting the following error about the coverage file not saving:

I’ve tried:

  • Switching between the absolute path for ‘output’ in coverage.json file and relative path (./.coverage)
  • Moving lmieulet:meteor-coverage package higher up in ./.meteor/packages folder
  • Adding TEST_BROWSER_DRIVER=chrome to the “test-cov” script and removing TEST_CLIENT=0 (even though we only have server tests anyway)

One complication may be that we also have a second testing suite (Jest), but I don’t believe that’s being invoked anywhere as a result of running “test-cov”

Does anyone have an idea of why this isn’t working? I’m at a loss about what to do, partly because the error message here is so brief…

here’s my npm script:

Here’s my babel config in package.json:

coverage.json:

config file built right after executing “npm run test-cov”:

It might be a directory permission issue

Yes, I had that thought too. But the permissions for the .coverage folder to write into are totally open:

And the permissions for the root folder containing the project itself are also pretty open (drwxr-xr-x)

Could still be a permissions issue since tests are run from a temporary directory with symlinks back to the source and other directories but I’m just guessing

We downgraded meteor-coverage back to 3.2.0 to make it work. Here is a working example repo: GitHub - leaonline/leaonline-teacher: Teacher dashboard application for the lea-online platforms

thanks for the suggestion - just tried it with 3.2.0 but it didn’t work. Another thought is that my meteor version is a bit old (1.11.1) - could that have something to do with it?

It may be permissions… but we’ve tried to make sure the folder permissions are pretty open and also have tried running as sudo and neither seem to work

Oh I didn’t know it’s that old. I think then you have also an older version of Meteor mocha?

It looks like I have 1.1.2 for meteortesting:mocha:

Can you try to upgrade to meteortesting:mocha@2.0?

Just changed the versions in .meteor/packages and .meteor/versions to 2.0.1 and unfortunately it’s still giving same error

For posterity’s sake: the problem was that nock was the coverage package’s ability to write the LCOV file once the testing was finished. If you’re using nock and experience a similar error, use nock.enableNetConnect() to fix