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 788 forks source link

Code coverage reports show coverage of transpiled code as opposed to the original ES6 code #405

Open catamphetamine opened 9 years ago

catamphetamine commented 9 years ago

I use it like this:

  "scripts": {
    "test": "mocha --compilers js:babel/register-without-polyfill --colors --bail --reporter spec test/",
    "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --compilers js:babel/register-without-polyfill --colors --reporter dot test/",
    "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --compilers js:babel/register-without-polyfill --colors --reporter spec test/",

And when I look at the code coverage reports they show coverage for the transpiled code. How can I generate coverage for the original ES6 code? I guess Babel should output some source maps. Or does istanbul support ES6 natively? (and what's the command)

iamstarkov commented 9 years ago

faced the same issue screen shot 2015-07-17 at 19 58 50

sivakumar-kailasam commented 9 years ago

Was facing the same issue and came across isparta. After a bit of meddling around I made it work for my repo https://github.com/sivakumar-kailasam/broccoli-leasot/commit/ff5f848b4104b131fcb47fc494d6455cf32182c4 . You can see it working at https://codeclimate.com/github/sivakumar-kailasam/broccoli-leasot/coverage/55b70ac20d7e0c07370386ad

justindalton commented 9 years ago

@sivakumar-kailasam I was able to get it working with isparta as well. The only problem I still have with it is that it won't cover .jsx files which istanbul is able to do.

madbence commented 9 years ago

@justincdalton My setup:

Relevant package.json entry:

{
  "cover": "babel-node node_modules/.bin/isparta cover --include '**/*.es6' node_modules/.bin/_mocha -- 'test/**/*.es6' --reporter dot"
}

Relevant .istanbul.yml entry:

instrumentation:
  root: src
  extensions:
    - .es6

I guess you can replace es6 with jsx and it Just Works™.