Open tracker1 opened 9 years ago
The parser demo http://esprima.org/demo/parse.html seems to be able to parse it fine.. not sure where the error is coming from...
I'm just trying istanbul, and have encountered a similar error.
It appears to come from istanbul/lib/hook.js
line 53 (within transformFn()
), where when a 'transformer' is invoked it throws the TypeError.
However, I've no idea what is going on there!
Istanbul appears to run fine, despite the errors.
Istanbul doesn't yet support arrow functions even in the harmony branch
Closing as this is currently unsupported. For anyone else coming across this issue, here is the scripts section of my package.json, which is now showing coverage properly, and generating reports... I'm using babel-node
(installed via babel
) with isparta
which wraps istanbul
.
modules:
npm install --save-dev rimraf babel eslint isparta
package.json
...
"config": {
"MOCHA_OPTS": "--recursive test/unit/",
"ISPARTA_OPTS": "--report html",
"COVERAGE_OPTS": "--statements 100 --functions 100 --branches 100 --lines 100"
},
"scripts": {
"clean": "rimraf ./dist",
"build": "babel ./src --experimental --source-maps-inline -d ./dist",
"lint": "npm run lint-src && npm run lint-test",
"lint-src": "eslint src",
"lint-test": "eslint test --global describe,it,beforeEach,afterEach --rule no-unused-expressions:false ",
"unit": "babel-node -r node_modules/.bin/_mocha $npm_package_config_MOCHA_OPTS",
"coverage": "babel-node -r node_modules/.bin/isparta cover $npm_package_config_ISPARTA_OPTS node_modules/.bin/_mocha -- $npm_package_config_MOCHA_OPTS",
"coverage-check": "node node_modules/isparta/node_modules/istanbul/lib/cli check-coverage $npm_package_config_COVERAGE_OPTS",
"show-report": "node test/open-coverage-report",
"test": "npm run lint && npm run coverage && (npm run coverage-check || node scripts/open-coverage-report)"
},
...
Not sure why you closed this. It is still an issue, right?
Still an issue, using https://github.com/ambitioninc/babel-istanbul/commit/b335b104bc6461dae34a086a8e62a610c98cba20 for now.
I have a similar problem. I compile ES6 source files with traceur and apply istanbul to the one concatenated result file (which should be plain ES5) through karma. When enabling code coverage, the tests fail, while they succeed otherwise. So I have either success or coverage :-(
"coverage": "babel-node -r node_modules/.bin/isparta cover $npm_package_config_ISPARTA_OPTS node_modules/.bin/_mocha -- $npm_package_config_MOCHA_OPTS",
@tracker1, as far as i know npm is searching inside node_modules
, so you can omit node_modules/.bin/
from npm scripts
it still a problem. I have es6 one-liner, and istanbul shows that only 3 of 4 lines are covered. its awkward
@iamstarkov, what you are seeing seems to be correct since you are exporting a function that is not called. But I agree that the autogenerated code should be hidden and the coverage should be more like 1/2
I called that exported function in my tests, so it not an issue
anyway I had to switch to isparta to get proper es6 support
ok, does it work better with generating proper coverage reports that do not include babel-generated lines? I am using gulp-jsx-coverage which works very well but shows a coverage that is too high.
for my current projects it is working better than istanbul
I created a fork where I implemented ignoring the skipped lines. It's a very simple change but I am not sure how this can be turned into a setting. Just modify the file lib/object-utils.js and change the two functions computeSimpleTotals and computeBranchTotals to this:
function computeSimpleTotals(fileCoverage, property, mapProperty) {
var stats = fileCoverage[property],
map = mapProperty ? fileCoverage[mapProperty] : null,
ret = { total: 0, covered: 0, skipped: 0 };
Object.keys(stats).forEach(function (key) {
var covered = !!stats[key],
skipped = map && map[key].skip;
ret.total += 1;
if (covered && !skipped) {
ret.covered += 1;
}
if (skipped) {
ret.skipped += 1;
}
});
ret.total -= ret.skipped;
ret.pct = percent(ret.covered, ret.total);
return ret;
}
function computeBranchTotals(fileCoverage) {
var stats = fileCoverage.b,
branchMap = fileCoverage.branchMap,
ret = { total: 0, covered: 0, skipped: 0 };
Object.keys(stats).forEach(function (key) {
var branches = stats[key],
map = branchMap[key],
covered,
skipped,
i;
for (i = 0; i < branches.length; i += 1) {
covered = branches[i] > 0;
skipped = map.locations && map.locations[i] && map.locations[i].skip;
if (covered && !skipped) {
ret.covered += 1;
}
if (skipped) {
ret.skipped += 1;
}
}
ret.total += branches.length;
});
ret.total -= ret.skipped;
ret.pct = percent(ret.covered, ret.total);
return ret;
}
Get the fork here: https://github.com/technicallyfeasible/istanbul.
It's basically counting lines as covered only if they are not skipped and removes all skipped lines from the total as well.
I'm still seeing these issues w/ node 8.3. It seems that the esprima dependency needs to be updated. 2.7 doesn't even support EC6.
Failed to parse file: /test.js Transformation error; return original code { Error: Line 177: Unexpected token => at constructError (/Users/danw/.nvm/versions/node/v8.3.0/lib/node_modules/istanbul/node_modules/esprima/esprima.js:2407:21) at createError (/Users/danw/.nvm/versions/node/v8.3.0/lib/node_modules/istanbul/node_modules/esprima/esprima.js:2426:17) at unexpectedTokenError (/Users/danw/.nvm/versions/node/v8.3.0/lib/node_modules/istanbul/node_modules/esprima/esprima.js:2500:13) at throwUnexpectedToken (/Users/danw/.nvm/versions/node/v8.3.0/lib/node_modules/istanbul/node_modules/esprima/esprima.js:2505:15)
Relates to #66 - I am using:
"istanbul": "git://github.com/gotwarlost/istanbul.git#harmony"
Running the following:
iojs --es_staging --harmony_arrow_functions node_modules/istanbul/lib/cli cover node_modules/mocha/bin/_mocha -- -R spec --recursive ./test/unit/
Testing against this script
I'm seeing the following output...