nyc: Cannot read property 'start' of undefined
Reproduction Steps
- Create an
index.js
file which uses babel-register, destructuring and a binary expression:
require('babel-register')
const {x} = 'hi' || true
- Run
nyc
with html reporter andava
:
./node_modules/.bin/nyc --reporter html ./node_modules/.bin/ava ./index.js
Error
/Users/jamuferguson/dev/web/node_modules/nyc/node_modules/istanbul/lib/report/html.js:276
startCol = meta.start.column;
^
TypeError: Cannot read property 'start' of undefined
at /Users/jamuferguson/dev/web/node_modules/nyc/node_modules/istanbul/lib/report/html.js:276:32
at Array.forEach (native)
at annotateBranches (/Users/jamuferguson/dev/web/node_modules/nyc/node_modules/istanbul/lib/report/html.js:255:30)
at HtmlReport.Report.mix.writeDetailPage (/Users/jamuferguson/dev/web/node_modules/nyc/node_modules/istanbul/lib/report/html.js:426:9)
at /Users/jamuferguson/dev/web/node_modules/nyc/node_modules/istanbul/lib/report/html.js:489:26
at SyncFileWriter.extend.writeFile (/Users/jamuferguson/dev/web/node_modules/nyc/node_modules/istanbul/lib/util/file-writer.js:57:9)
at FileWriter.extend.writeFile (/Users/jamuferguson/dev/web/node_modules/nyc/node_modules/istanbul/lib/util/file-writer.js:147:23)
at /Users/jamuferguson/dev/web/node_modules/nyc/node_modules/istanbul/lib/report/html.js:488:24
at Array.forEach (native)
at HtmlReport.Report.mix.writeFiles (/Users/jamuferguson/dev/web/node_modules/nyc/node_modules/istanbul/lib/report/html.js:482:23)
You can also try this out in my repo here which is hooked up with this problem: https://github.com/xjamundx/nyc-broke
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 4
- Comments: 27 (13 by maintainers)
I spoke too soon. The HTML report is crashing because there are no statements in the coverage data:
Here I changed the
feedback.js
file tovar { a } = true && {}
.If I run this with Node 6 and disable
babel-register
I get this data:babel-register
emits ES5 code, coverage for which is mapped back to the original source through source maps. It looks like we’re able to map thetrue && {}
branch but not the fullvar { a } =
statement.I don’t think we can do much about the source mapping, though perhaps we can check whether the report contains statements for all branches. The HTML report won’t be entirely accurate but at least it won’t crash. @bcoe?
@bcoe no. The problem here is that the branch map refers to statements that have been removed from the coverage because they could not be mapped to the original source.
I’m proposing we remove branches that refer to missing statements. It makes the reports less accurate, which can’t be helped, but at least it won’t crash.