Question

I am using mocha test my nodejs code. I would like to get a coverage report. I found the JSCover I am trying to run. But I am getting

ReferenceError: _$jscoverage is not defined

I am executing:

   java -jar ../tools/jscover/JSCover-all.jar --no-instrument=node_modules -fs api/ api-coverage

test:
    @NODE_ENV=test ./node_modules/.bin/mocha \
        --require expect.js \
        --reporter $(REPORTER) \
        --timeout 2000 \
        --growl \
        $(TESTS)
    COVERAGE_ENABLED=1 $(MAKE) test REPORTER=html-file-cov

Any help?

Was it helpful?

Solution 2

I can't help you with JSCover, but I highly recommend using the fully-Javascript-based istanbul instead. Details here: Code coverage with Mocha

OTHER TIPS

JSCover uses a global variable called _$jscoverage. Normally a specific mode of JSCover pre-defines it at the global scope (usually the browser). When you run it with mocha - the latter doesn't defines this variable, thus you have to do that by yourself - for example, the first line of the file "expect.js" you mention in the question may be:

global._$jscoverage = {};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top