jeffrifwald / babel-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
144 stars 23 forks source link

Support tests written in ES6+ ? #20

Closed hax closed 8 years ago

hax commented 8 years ago

It seems that babel-istanbul require the tests written in ES5, or pre-compile the tests. And if pre-compile, the test files will be included in coverage...

Some details:

My script is like babel-istanbul cover _mocha -- test --ui tdd and error:

No coverage information was collected, exit without writing coverage information
/Users/hax/maps/test/ArrayMap.js:1
(function (exports, require, module, __filename, __dirname) { import assert from 'assert'
                                                              ^^^^^^

SyntaxError: Unexpected reserved word

So I precompile the tests via babel --out-dir es5-test test, run babel-istanbul cover _mocha -- es5-test --ui tdd, it's ok but es5-test also listed in the coverage which surprise me.

BTW, it seems babel-istanbul will throw if the test files contains inline sourcemaps.

jeffrifwald commented 8 years ago

The library istanbul ignores the test directory by default. If you don't want coverage on the test files, you need to tell istanbul to ignore the es5-test directory. It might look something like babel-istanbul cover --ignore=es5-test cover _mocha -- test --ui tdd, but I have not tested that out.

Alternatively, you could do what I do and just run all your tests with babel-node. That will compile everything on the fly and you no longer need another folder for compiled tests: babel-node node_modules/.bin/babel-istanbul cover _mocha -- test --ui tdd

I'm not sure about the inline sourcemaps. I would opt to not use inline sourcemaps for testing.

hax commented 8 years ago

Thank you @jmcriffey , babel-node node_modules/.bin/babel-istanbul cover _mocha -- test --ui tdd works for me.

BTW, I forgot to report babel-istanbul cover mocha -- test --ui tdd --compilers js:babel/register also generate the lcov, but it shows the compiled code with the locations of source...