istanbul icon indicating copy to clipboard operation
istanbul copied to clipboard

Cannot read property 'text' of undefined

Open arusakov opened this issue 8 years ago • 13 comments

In coverage reporter (html)

Trace:

TypeError: Cannot read property 'text' of undefined
    at /Users/arusakov/myproject/node_modules/istanbul/lib/report/html.js:210:45
    at Array.forEach (native)
    at annotateStatements (/Users/arusakov/myproject/node_modules/istanbul/lib/report/html.js:193:33)
    at HtmlReport.Report.mix.writeDetailPage (/Users/arusakov/myproject/node_modules/istanbul/lib/report/html.js:428:9)
    at /Users/arusakov/myproject/node_modules/istanbul/lib/report/html.js:489:26
    at SyncFileWriter.extend.writeFile (/Users/arusakov/myproject/node_modules/istanbul/lib/util/file-writer.js:57:9)
    at FileWriter.extend.writeFile (/Users/arusakov/myproject/node_modules/istanbul/lib/util/file-writer.js:147:23)
    at /Users/arusakov/myproject/node_modules/istanbul/lib/report/html.js:488:24
    at Array.forEach (native)
    at HtmlReport.Report.mix.writeFiles (/Users/arusakov/myproject/node_modules/istanbul/lib/report/html.js:482:23)
    at /Users/arusakov/myproject/node_modules/istanbul/lib/report/html.js:484:22
    at Array.forEach (native)
    at HtmlReport.Report.mix.writeFiles (/Users/arusakov/myproject/node_modules/istanbul/lib/report/html.js:482:23)
    at HtmlReport.Report.mix.writeReport (/Users/arusakov/myproject/node_modules/istanbul/lib/report/html.js:566:14)
    at writeReport (/Users/arusakov/myproject/node_modules/karma-coverage/lib/reporter.js:62:16)
    at /Users/arusakov/myproject/node_modules/karma-coverage/lib/reporter.js:290:11

Related npm modules:

    "isparta-loader": "2.0.0",
    "istanbul": "0.4.3",
    "jasmine-core": "2.4.1",
    "karma": "0.13.22",
    "karma-coverage": "0.5.4",
    "karma-jasmine": "0.3.8",
    "karma-junit-reporter": "0.4.2",
    "karma-phantomjs-launcher": "1.0.0",
    "karma-sourcemap-loader": "0.3.7",
    "karma-webpack": "1.7.0",
    "phantomjs-prebuilt": "2.1.7",

arusakov avatar Apr 22 '16 14:04 arusakov

I had absolutely the same issue before, but I don't actually know how I fixed it. Just removed all node_modules and re-install again.

viktordavidovich avatar Apr 26 '16 00:04 viktordavidovich

@viktordavidovich Reinstalling doesn't fix error in my case :(

arusakov avatar Apr 26 '16 07:04 arusakov

I'm also running into this issue.

I'm using [email protected] and [email protected], though.

BerkeleyTrue avatar Jul 04 '16 22:07 BerkeleyTrue

Also see #660

levity avatar Sep 14 '16 04:09 levity

Due to this error html report is not generated for some files in my case, but only when running subset of unit tests

FDIM avatar Apr 06 '17 08:04 FDIM

+1

evanjmg avatar Apr 25 '17 15:04 evanjmg

I am running into the same issue. I am running manual tests on instrumented JS code and have done setup to export coverage objects into json file. However, "istanbul report" does not seem to work and gives the same error as mentioned by @arusakov Any help appreciated!

realnikunj avatar Jun 09 '17 09:06 realnikunj

+1

OscarChavarro avatar Jul 12 '17 16:07 OscarChavarro

I spent the better part of the morning at work getting this to work. Here's what we did:

  1. Install the babel-plugin-istanbul module and configured exactly per recommendations. I.e., added env: { test: { plugins: ['istanbul'] }} to our .babelrc file and removed 'coverage' from preprocessors for our ES6 files. Note that I don't love this as it moves testing config from the karma file into babel, but it worked so I wasn't about to screw it up.
  2. Install the karma-coverage-istanbul-reporter module and configure per recommendations and our existing setup. I.e., I removed our coverageReporter property replacing with coverageIstanbulReporter and tweaking the props so they match the expected configuration schema.

New schema looks like this (extraneous bits removed):

webpackConfig.module.rules.push({
  test: /\.es6/,
  enforce: 'post',
  exclude: /(test|node_modules)\//,
  use: { loader: 'istanbul-instrumenter-loader', options: { esModules: true } }
})

const overrideConf = {
  reporters: ['coverage-istanbul', 'mocha', 'junit'],
  coverageIstanbulReporter: {
    dir: '../coverage',
    fixWebpackSourcePaths: true,
    reports: ['cobertura', 'lcov', 'text', 'text-summary'],
    skipFilesWithNoCoverage: true
  },
  mochaReporter: {
    ignoreSkipped: true
  },
  autoWatch: false,
  preprocessors: {
    './testImporter.karma.es6': ['webpack', 'sourcemap']
  },
  webpack: webpackConfig
}

And the relevant portions of package.json (again, extraneous bits removed):

"babel-plugin-istanbul": "^4.1.5",
"istanbul": "^0.4.5",
"istanbul-instrumenter-loader": "^3.0.0",
"karma-coverage": "^1.1.1",
"karma-coverage-istanbul-reporter": "^1.3.3",

icfantv avatar Jan 08 '18 19:01 icfantv

@gotwarlost Come on guys? Let's get this fixed issue fixed and merged already.

benedictchen avatar Jun 29 '18 19:06 benedictchen

As mentioned by @icfantv I managed to get rid of this issue by using karma-coverage-istanbul-reporter

I added these two to my karma config

coverageIstanbulReporter: {
            dir: 'coverageReport/html/client',
            reports: ['html', 'text-summary'],
            fixWebpackSourcePaths: true
},
reporters: [
           'progress',
           'coverage-istanbul',
]

saulve avatar Mar 05 '19 17:03 saulve

@saulve- can you please provide complete karma config file, bcz I am not able to generate coverage report in VSTS.

vijayaayilneni avatar May 29 '19 18:05 vijayaayilneni

I've downgraded babel-plugin-istanbul from 6.1.0 to 6.0.0 and it does not crash to me any more.

It did not crash before - with 6.1.0 - before my recent changes to the main code, so it looks to me sometimes babel-plugin-istanbul can generate broken coverage data. However, I'm not sure how to reproduce this on smaller codebase.

So I cannot say if it's babel-plugin-istanbul's fault or not, but consider version change as a possible work around.

skyboyer avatar Dec 11 '23 11:12 skyboyer