I'm trying to use istanbul with https://github.com/wavded/babel-tape-runner but can't figure out the right command. I tried istanbul cover ./node_modules/.bin/babel-tape-runner -- test/**/* but it says "No coverage information was collected, exit without writing coverage information". Anyone knows how to get it working?
Check out https://github.com/istanbuljs/nyc
OK, I've managed to make this work, for both ES6 and JSX.
My package.json already used babel-tape-runner:
"scripts": {
"test": "babel-tape-runner static/__tests__/* | tap-diff",
Next, I installed the nyc and the babel plugin:
$ npm i --save-dev nyc babel-plugin-istanbul babel-register
I updated my .babelrc:
{
- "presets" : ["es2015", "react"]
+ "presets" : ["es2015", "react"],
+ "env": {
+ "test": {
+ "plugins": ["istanbul"]
+ }
+ }
}
and updated my package.json:
+ "nyc": {
+ "include": ["static"],
+ "extension": [
+ ".jsx"
+ ],
+ "require": [
+ "babel-register"
+ ],
+ "sourceMap": false,
+ "instrument": false
+ },
I could then run nyc to run my tests with coverage:
$ NODE_ENV=test ./node_modules/nyc/bin/nyc.js npm test
... test output here
All of 15 tests passed!
----------------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------------------|----------|----------|----------|----------|----------------|
All files | 74.11 | 57.41 | 70 | 73.33 | |
FooBar.jsx | 88.89 | 100 | 66.67 | 87.5 | 29 |
BarBarFoo.jsx | 77.27 | 72.73 | 80 | 77.27 |... 79,81,82,83 |
----------------------|----------|----------|----------|----------|----------------|
Finally, I could get a pretty HTML report:
$ ./node_modules/nyc/bin/nyc.js report --reporter=html
@florian-bd is https://github.com/istanbuljs / https://github.com/istanbuljs/nyc a separate project from istanbul? strange that there aren't any links in the readme/website pointing there
Most helpful comment
OK, I've managed to make this work, for both ES6 and JSX.
My package.json already used
babel-tape-runner:Next, I installed the nyc and the babel plugin:
I updated my .babelrc:
and updated my package.json:
I could then run nyc to run my tests with coverage:
Finally, I could get a pretty HTML report: