babel-plugin-istanbul
babel-plugin-istanbul copied to clipboard
All files are showing Unknown with plugin.
Also posted on StackOverflow
I'm trying to get nyc
ava
and babel
to all place nice together.
I've done this a bunch of times, I'm not sure what's going wrong now.
I was having an issue where async / await branches were showing as not covered, so this was working, I'm having trouble integrating the babel-plugin-istanbul
plugin for tests.
I have two files in the project, src/index.js
and src/test.js
.
{
"name": "example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "ava",
"coverage": "NODE_ENV=test nyc npm run test",
"report": "nyc report --reporter=html",
"report:open": "open ./coverage/index.html",
"cover": "npm run coverage && npm run report && npm run report:open"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-runtime": "^6.26.0",
"bluebird": "^3.5.0",
"lodash": "^4.17.4"
},
"devDependencies": {
"ava": "^0.22.0",
"babel-cli": "^6.26.0",
"babel-plugin-istanbul": "^4.1.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.0",
"babel-register": "^6.26.0",
"nyc": "^11.2.1",
"sinon": "^3.2.1",
"testdouble": "^3.2.4"
},
"babel": {
"presets": ["env"],
"plugins": ["transform-runtime"],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
},
"ava": {
"require": ["babel-register"],
"babel": "inherit"
},
"nyc": {
"sourceMap": false,
"instrument": false
}
}
Here's whats running:
> [email protected] coverage /Users/me/Desktop/example
> NODE_ENV=test nyc npm run test
> [email protected] test /Users/me/Desktop/example
> ava
11 passed
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | Unknown | Unknown | Unknown | Unknown | |
----------|----------|----------|----------|----------|----------------|
> [email protected] report /Users/me/Desktop/example
> nyc report --reporter=html
> [email protected] report:open /Users/em/Desktop/example
> open ./coverage/index.html
Why isn't src/index.js
showing in the coverage?
I have a lead. For some reason it works with [email protected]
and not the latest [email protected]
. What seems to be going on here?
I have same problem in [email protected] version.
I'm not sure the issue relates directly to babel-plugin-istanbul
as I'm not using but I am using a combo of [email protected]
, and [email protected]
and getting this same result
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | Unknown | Unknown | Unknown | Unknown | |
----------|----------|----------|----------|----------|----------------|
unless I roll back to [email protected]
and then coverage behaves as expected.
Just chucked this here in case it helps someone else
Same problem for me:
- "istanbul": "^0.4.5"
- "mocha": "^5.0.0"
- "nyc": "^11.4.1"
Test example:
var assert = require('chai').assert;
var request = require('request');
var id = 1;
describe('Job', function() {
it('Delete job', function(done) {
request.delete({
url: 'http://localhost:8080/jobs/' + id,
json: true
},
function(error, response, body) {
assert.equal(response.statusCode, 200);
assert.equal(body.itemsDeleted, 1);
done();
});
});
});
Running node server.js
in background, then runningnyc mocha test/*.js
and have:
Job
√ Delete job
1 passing (139ms)
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | Unknown | Unknown | Unknown | Unknown | |
----------|----------|----------|----------|----------|----------------|
Rolling back to [email protected]
didn't help.
Hmm.. i though that was a problem on my side 🤔 #meToo Ts-node (target: es7), nyc, mocha - everything fresh. Same 'Unknown' for all the rows, and both json and html reports are empty.
I also experience a similar situation. It works with nyc@10 but not with [email protected]
With [email protected], I got unknown for all files, one empty json and one non-empty that seems to contain some information in .nyc_output folder.
But, with nyc@10, I got this warning which seems to have been resolved in [email protected]: (node:56674) Warning: process.on(SIGPROF) is reserved while debugging https://github.com/istanbuljs/nyc/issues/587
"devDependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.1",
"babel-loader": "^7.1.2",
"babel-plugin-istanbul": "^4.1.5",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"commitizen": "^2.9.6",
"cross-env": "^5.1.3",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^4.17.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.8.0",
"fetch-mock": "^6.0.0",
"isomorphic-fetch": "^2.2.1",
"mocha": "^5.0.0",
"nyc": "10",
"sinon": "^4.3.0",
"webpack": "^3.11.0",
"webpack-dev-server": "^2.11.1"
},
+1
For me the problem was in the wrong source folder path in 'package.json'. I copy pasted it from tutorial without reading, and did not updated.
Still having this issue months after I created this ticket, and I just dug deeper into the issue, here are my findings.
I was receiving this issue in my HTML output for each file: https://github.com/istanbuljs/nyc/issues/239
And I was also receiving this in the newer version of nyc
+ babel-plugin-istanbul
.
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 0 | 0 | 0 | |
----------|----------|----------|----------|----------|-------------------|
I just learned several things the main one for now that I have confirmed is that:
⚠️ The
babel-plugin-istanbul
plugin needs to be the first babel plugin.
It seems I can get it working consistently by making this simple tweak to my settings.
This is what I am using, and it's working properly.
⚠️ Something to look out for is to ensure that while you're tinkering with settings, you don't inadvertently
ignore
orexclude
or notinclude
the very files you are trying to cover, best to leave all these fields innyc
as default while trying to get it to work, when you do then you can fiddle with these settings.
{
"scripts": {
"babel": "babel --copy-files src -d dist --ignore test.js",
"babel:watch": "npm run build --- --watch",
"prebuild": "rm -rf dist",
"build": "npm run babel",
"build:watch": "npm run babel:watch",
"coverage:file": "nyc npm run test:file",
"coverage:files": "nyc npm run test:files",
"lint": "npm run standard",
"lint:fix": "npm run standard:fix",
"pretest": "npm run standard",
"test": "npm run coverage:files",
"test:file": "NODE_ENV=test mocha --require babel-register",
"test:files": "npm run test:file -- src/**/test.js"
},
"babel": {
"env": {
"test": {
"plugins": [
"istanbul",
"rewire",
"transform-runtime"
]
}
},
"plugins": [
"transform-runtime"
],
"presets": [
[
"env",
{
"targets": {
"node": "4.0.0"
}
}
],
"stage-0"
]
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.2",
"babel-plugin-istanbul": "^4.1.5",
"babel-plugin-rewire": "^1.1.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"babel-template": "^6.26.0",
"babel-types": "^6.26.0",
"mocha": "^5.0.1",
"nyc": "11.6.0",
},
"nyc": {
"require": [
"babel-register"
],
"reporter": [
"json",
"lcov",
"html",
"text"
],
"check-coverage": true,
"per-file": false,
"lines": 100,
"statements": 100,
"functions": 100,
"branches": 100,
"sourceMap": false,
"instrument": false,
"all": true
},
}
I'm too having the same issue with nyc@11
.
When I roll back to nyc@10
it works.
Fixed for me with new version of nyc 12.0.2. Comrades, try to update, probably issue was resolved
@uka17 Indeed, not only is it resolved, it's even working better showing the proper coverage percentages due to the now-correct included/excluded list of files.
I tried updating to 12.0.2
and also the latest 13.1.0
but still the only way it will work for me is rolling back to 10.0.0
I am having data in out.json but index.html seems to show unknown%. my cypress folder is outside the src, into some for example
my source code: /project/feature/src my cypress: /project/feature-cypress/cypress. I am using nyc version 15.x
the coverage webpack is at feature-cypress level
This is my coverage webpack
module.exports = { module: { rules: [ { test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader', options: { esModules: true }, enforce: 'post', include: require('path').join(__dirname, '../src/app'), exclude: [ /\.(e2e|spec)\.ts$/, /node_modules/, /(ngfactory|ngstyle)\.js/ ] } ] } };
Also the is the coverage folder
![folder](https://user-images.githubusercontent.com/8687724/80966290-d8cbd480-8e31-11ea-8881-232a1c46c78c.png)