vendredi 1 mai 2015

How to use Istanbul for Mocha code-coverage of dynamically-loaded files?

I'm loading JS in my Mocha test at runtime using fs and vm.runInThisContext:

fs.readFile(path, {encoding: 'utf8'}, function(error, data){})
....
vm.runInThisContext( code );

but when I run istanbul like so

$ istanbul cover --hook-run-in-context node_modules/mocha/bin/_mocha -- --recursive -R spec
...
fake test
√ should pass

3 passing (28ms)

No coverage information was collected, exit without writing coverage information

Is there any documentation for how to use the --hook-run-in-context command to get code-coverage for these files? I'm wondering if perhaps there is an incompatibility between Mocha, Istanbul, and the most recent version of Node that I'm running.

(Windows 7 with Git Bash)

$ node -v && npm -v
v0.12.2
2.7.4

$ npm list -g mocha
C:\Users\212309975\AppData\Roaming\npm
└── mocha@2.2.4

Aucun commentaire:

Enregistrer un commentaire