Istanbul: Usage with babel / tape?

Created on 10 May 2016  路  3Comments  路  Source: gotwarlost/istanbul

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?

Most helpful comment

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

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ouhouhsami picture ouhouhsami  路  16Comments

dankohn picture dankohn  路  25Comments

dcrockwell picture dcrockwell  路  37Comments

davglass picture davglass  路  49Comments

mbielski picture mbielski  路  37Comments