I'm having some issues while running istanbul with mocha and the babel compiler..
all my tests are runnning just fine, but after all the tests done it shows me this message:
No coverage information was collected, exit without writing coverage information
And it is not producing any coverage report..
The command that Im running is:
NODE_ENV=test istanbul cover _mocha -- --require babel-core/register --recursive
the project is hosted in github: https://github.com/weslleyaraujo/react-flux-puzzle/tree/feat/unit-tests-24
any ideas what it could be?
Using Babel 6.x, let's say we have file
test/pad.spec.js
:Install a bunch of crap:
Create a
.babelrc
:Run the tests:
UPDATE: I've had success using
nyc
(which consumesistanbul
) instead ofistanbul
/babel-istanbul
. This is somewhat less complicated. To try it:Install stuff (you can remove
babel-istanbul
andbabel-cli
):Create
.babelrc
as above.Execute this:
...which should give you similar results. By default, it puts coverage info into
.nyc-output/
, and prints a nice text summary in the console.Note: You can remove
node_modules/.bin/
from any of these commands when placing the command inpackage.json
'sscripts
field.As of now 17.4.2016 this coverage reporting stuff is still a bit messy and with my React-project that has .jsx files and a helper file the coverage reporting script looks like this:
So it wouldn't be too easy the current version 0.4.3 of Istanbul doesn't work with Babel so you have to use the experimental alpha-version:
And then you need
.istanbul.yml
-file so that Istanbul recognizes the .jsx-files with these lines:And now it should work. Also as a small bonus if you want to add coverage reporting with Travis and Coveralls you should:
npm i coveralls --save-dev
add this to your
.travis.yml
:And now you can put that cool badge to your README. Neato!
Solution A: Using nyc and babel-plugin-istanbul
Setup
(don't forget:@next
fornyc
)Add an env to
babel
config:nyc
config:PS:
include
field needs to be specified in.nycrc
of inpackage.json
, if specified in command line, coverage will not worksRunning the tests:
Solution B: No extra packages : Only the basic ones
Work has been done recently on istanbul (1.0.0-alpha.2) to support Babel generated code with sourcemaps (see #212 and this for an example).
There are 2 ways:
B1. Tests that exports (previously) transpiled code
This is done in 2 steps: Firstly, build your source with babel (e.g. from ./src to ./out) and write your tests against transpiled source (
export foo from "./out/foo";
).Then you will be able to run the tests using istanbul 1.0.0-alpha.2 :
Now if you want code coverage to follow the original code you've written (not the transpiled one), make sure to build with babel source-maps options set to both :
PS: If needed you can also do :
B2. Tests that directly exports original code
In this case you write your tests against original source (
export foo from "./src/foo";
), and with no further step, you directly run istanbul 1.0.0-alpha.2 using babel-node against cli.js :PS: If needed you can also do :