nyc: Cannot read property 'start' of undefined

Reproduction Steps

  1. Create an index.js file which uses babel-register, destructuring and a binary expression:
require('babel-register')
const {x} = 'hi' || true
  1. Run nyc with html reporter and ava:

./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)

Most upvoted comments

I spoke too soon. The HTML report is crashing because there are no statements in the coverage data:

{
    "/private/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T/tmp.wI9zPQGl/nyc-broke/public/js/feedback/feedback.js": {
        "path": "/private/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T/tmp.wI9zPQGl/nyc-broke/public/js/feedback/feedback.js",
        "s": {},
        "b": {
            "1": [1, 1]
        },
        "f": {},
        "fnMap": {},
        "statementMap": {},
        "branchMap": {
            "1": {
                "line": 1,
                "type": "binary-expr",
                "locations": [{
                    "start": {
                        "line": 1,
                        "column": 12
                    },
                    "end": {
                        "line": 1,
                        "column": 19
                    }
                }]
            }
        }
    }
}

Here I changed the feedback.js file to var { a } = true && {}.

If I run this with Node 6 and disable babel-register I get this data:

{
    "/private/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T/tmp.wI9zPQGl/nyc-broke/public/js/feedback/feedback.js": {
        "path": "/private/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T/tmp.wI9zPQGl/nyc-broke/public/js/feedback/feedback.js",
        "s": {
            "1": 1
        },
        "b": {
            "1": [1, 1]
        },
        "f": {},
        "fnMap": {},
        "statementMap": {
            "1": {
                "start": {
                    "line": 1,
                    "column": 0
                },
                "end": {
                    "line": 1,
                    "column": 22
                }
            }
        },
        "branchMap": {
            "1": {
                "line": 1,
                "type": "binary-expr",
                "locations": [{
                    "start": {
                        "line": 1,
                        "column": 12
                    },
                    "end": {
                        "line": 1,
                        "column": 16
                    }
                }, {
                    "start": {
                        "line": 1,
                        "column": 20
                    },
                    "end": {
                        "line": 1,
                        "column": 22
                    }
                }]
            }
        }
    }
}

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 the true && {} branch but not the full var { 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.