Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'text' of undefined #602

Open
arusakov opened this issue Apr 22, 2016 · 13 comments
Open

Cannot read property 'text' of undefined #602

arusakov opened this issue Apr 22, 2016 · 13 comments

Comments

@arusakov
Copy link

arusakov commented Apr 22, 2016

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",
@viktordavidovich
Copy link

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.

@arusakov
Copy link
Author

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

@BerkeleyTrue
Copy link

I'm also running into this issue.

I'm using nyc@6.6.1 and ava@0.15.2, though.

@levity
Copy link

levity commented Sep 14, 2016

Also see #660

@FDIM
Copy link

FDIM commented Apr 6, 2017

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

@evanjmg
Copy link

evanjmg commented Apr 25, 2017

+1

@realnikunj
Copy link

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!

@OscarChavarro
Copy link

+1

@icfantv
Copy link

icfantv commented Jan 8, 2018

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",

@benedictchen
Copy link

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

@saulve
Copy link

saulve commented Mar 5, 2019

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',
]

@vijayaayilneni
Copy link

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

@skyboyer
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests