gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 787 forks source link

Unable to render report when mock-fs is used #726

Closed simeg closed 7 years ago

simeg commented 7 years ago

I have a test file that uses mock-fs which is a package that mocks a filesystem for testing with Node. I wanted to use Codecov with my repo but I could not. Everything was showing OK, I could see that stats being generated on my local machine as well as on Jenkins. But it did not generate any files.

This is what I did to resolve it (where I set NODE_ENV === 'test' on Jenkins): var fsMock = process.env.NODE_ENV === 'test' ? function() {} : require('mock-fs');

The drawback is that now a file is actually created on the Jenkins machine after every run, but I can live with that.

My question is: What could be causing this?

simeg commented 7 years ago

Ok, this problem was me not reading the documentation properly.

When you are done with the mock-fs package you should restore it using .restore(), I did this in my tear down method. Now it's working perfectly.