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

ERROR [coverage]: [TypeError: Cannot call method 'split' of undefined] #123

Closed
jsdevel opened this issue Dec 16, 2014 · 32 comments
Closed

Comments

@jsdevel
Copy link

jsdevel commented Dec 16, 2014

I'm getting this error lately. Here is the full stack trace:

PhantomJS 1.9.8 (Linux): Executed 493 of 494 (skipped 1) SUCCESS (1.667 secs / 0.949 secs)

ERROR [coverage]: [TypeError: Cannot call method 'split' of undefined]
TypeError: Cannot call method 'split' of undefined
  at HtmlReport.Report.mix.writeDetailPage (/home/foo/projects/replatform/httpd/node_modules/istanbul/lib/report/html.js:379:31)
  at /home/foo/projects/replatform/httpd/node_modules/istanbul/lib/report/html.js:456:26
  at SyncFileWriter.extend.writeFile (/home/foo/projects/replatform/httpd/node_modules/istanbul/lib/util/file-writer.js:57:9)
  at FileWriter.extend.writeFile (/home/foo/projects/replatform/httpd/node_modules/istanbul/lib/util/file-writer.js:124:23)
  at /home/foo/projects/replatform/httpd/node_modules/istanbul/lib/report/html.js:455:24
  at Array.forEach (native)
  at HtmlReport.Report.mix.writeFiles (/home/foo/projects/replatform/httpd/node_modules/istanbul/lib/report/html.js:449:23)
  at /home/foo/projects/replatform/httpd/node_modules/istanbul/lib/report/html.js:451:22
  at Array.forEach (native)
  at HtmlReport.Report.mix.writeFiles (/home/foo/projects/replatform/httpd/node_modules/istanbul/lib/report/html.js:449:23)
  at HtmlReport.Report.mix.writeReport (/home/foo/projects/replatform/httpd/node_modules/istanbul/lib/report/html.js:533:14)
  at /home/foo/projects/replatform/httpd/node_modules/karma-coverage/lib/reporter.js:138:24
  at /home/foo/projects/replatform/httpd/node_modules/karma/lib/helper.js:87:7
  at Object.oncomplete (fs.js:107:15)


Here are my dependencies:

  "devDependencies": {
    "angular-cookies": "^1.3.5",
    "bootstrap": "^3.3.0",
    "brfs": "^1.2.0",
    "browser-sync": "^1.6.3",
    "browserify": "^6.2.0",
    "browserify-istanbul": "^0.1.2",
    "browserify-shim": "^3.8.0",
    "chai": "^1.9.2",
    "chalk": "^0.5.1",
    "console-shim2": "0.1.0",
    "csswring": "^1.3.1",
    "del": "^0.1.3",
    "event-stream": "^3.1.7",
    "exorcist": "^0.1.6",
    "fastclick": "^1.0.3",
    "glob": "^4.0.6",
    "gulp": "^3.8.9",
    "gulp-changed": "^1.0.0",
    "gulp-concat": "^2.4.1",
    "gulp-flatten": "0.0.4",
    "gulp-iconfont": "^0.2.1",
    "gulp-if": "^1.2.5",
    "gulp-insert": "^0.4.0",
    "gulp-jasmine": "^1.0.1",
    "gulp-jscs": "^1.2.1",
    "gulp-jshint": "^1.9.0",
    "gulp-karma": "0.0.4",
    "gulp-less": "^1.3.6",
    "gulp-load-plugins": "^0.7.1",
    "gulp-ng-annotate": "^0.3.3",
    "gulp-notify": "^2.0.0",
    "gulp-postcss": "^2.0.0",
    "gulp-rename": "^1.2.0",
    "gulp-replace": "^0.5.0",
    "gulp-sourcemaps": "^1.2.7",
    "gulp-uglify": "^1.0.1",
    "gulp-util": "^3.0.1",
    "istanbul": "0.2.6",
    "jshint-stylish": "^1.0.0",
    "karma": "~0.12.0",
    "karma-bro": "^0.9.0",
    "karma-chai": "^0.1.0",
    "karma-chrome-launcher": "~0.1.3",
    "karma-coverage": "~0.2.6",
    "karma-firefox-launcher": "~0.1",
    "karma-html2js-preprocessor": "~0.1",
    "karma-jasmine": "~0.2.0",
    "karma-junit-reporter": "^0.2.2",
    "karma-phantomjs-launcher": "~0.1.4",
    "karma-sinon": "^1.0.3",
    "karma-spec-reporter": "0.0.12",
    "merge-stream": "^0.1.6",
    "napa": "^1.0.2",
    "ng-storage": "^0.3.1",
    "path": "^0.4.9",
    "pretty-hrtime": "^0.2.2",
    "proxyquireify": "^1.1.0",
    "require-dir": "^0.1.0",
    "run-sequence": "^1.0.1",
    "sax": "^0.6.1",
    "sinon": "^1.10.3",
    "sinon-chai": "^2.6.0",
    "streamqueue": "^0.1.1",
    "vinyl-buffer": "^1.0.0",
    "vinyl-source-stream": "^1.0.0",
    "vinyl-transform": "0.0.1",
    "watchify": "^2.1.1"
  }

I've tried using the latest version of istanbul but that doesn't help any. Is there any more info I can provode to help troubleshoot this?

Here's my karma.conf.js file:

// Karma configuration
// Generated on Fri Oct 17 2014 15:46:09 GMT-0700 (PDT)

module.exports = function(config) {
  var options = {
    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',
    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['chai', 'sinon', 'jasmine', 'browserify'],
    // list of files / patterns to load in the browser
    files: [
      'node_modules/angular/angular.js',
      'node_modules/angular-mocks/angular-mocks.js',
      'src/test/chai-sinon-setup.js',
      'src/test/**/*.js'
    ],
    // list of files to exclude
    exclude: [
    ],
    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      'src/main/**/*.js': ['browserify', 'coverage'],
      'src/test/**/*.js': ['browserify']
    },
    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['spec', 'coverage'],
    coverageReporter: {
      reporters: [
        {type: 'html', dir: 'coverage/'},
        {type: 'cobertura'}
      ]
    },
    // web server port
    port: 9876,
    // enable / disable colors in the output (reporters and logs)
    colors: true,
    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,
    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,
    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: [
      //'Chrome'
      'PhantomJS'
    ],
    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: true,
    // Browserify config (all optional)
    browserify: {
      // extensions: ['.coffee'],
      // ignore: [],
      plugin: ['proxyquireify/plugin'],
      transform: ['brfs', 'browserify-istanbul'],
      debug: false
      // noParse: ['jquery'],
      //watch: true,
    },
    plugins: [
      // Karma will require() these plugins
      'karma-bro',
      'karma-chai',
      'karma-spec-reporter',
      'karma-sinon',
      'karma-chrome-launcher',
      'karma-phantomjs-launcher',
      'karma-firefox-launcher',
      'karma-jasmine',
      'karma-coverage'
    ]
  };

  if (process.env.KARMA_BROWSER_NO_ACTIVITY_TIMEOUT) {
    options.browserNoActivityTimeout =  process.env.KARMA_BROWSER_NO_ACTIVITY_TIMEOUT;
  }

  config.set(options);
};

@jramoyo
Copy link

jramoyo commented Dec 17, 2014

I'm getting the same error - it's broken starting 0.2.7.

@mtfranchetto
Copy link

Same error.

@osdio
Copy link

osdio commented Dec 27, 2014

I also meet the same error

@piecyk
Copy link
Contributor

piecyk commented Dec 27, 2014

The problem is that browserify transform Istanbul takes care the coverage report...
setting karma preprocessors for coverage has no effect on that.

fix: when using browserify dont create source code caching

@maksimr
Copy link
Contributor

maksimr commented Dec 27, 2014

Seems problem in this commit.

@jsdevel
Copy link
Author

jsdevel commented Dec 29, 2014

So locking the dependency for karma-coverage to 0.2.6 solved the issue for me after clearing node_modules and npm installing.

@nicdutil
Copy link

nicdutil commented Jan 6, 2015

Same here. Thanks @jsdevel !!!
Finally got coverage working with karma and browserify!

I just want to mention that I'm running karma on Linux (Ubuntu 14.04).
I'm trying to get all of this to work on windows, but karma-browserify /browserify
is giving me errors about finding my modules..

@tramck
Copy link

tramck commented Jan 21, 2015

+1 to this issue. @jsdevel 's solution worked for me.

@leonard84
Copy link

+1 downgrading to 0.2.6 worked like @jsdevel described

@jenswegar
Copy link

+1 for this issue @jsdevel downgrade fix worked for me as well

treyhunner added a commit to startersacademy/fullstack-project-01 that referenced this issue Feb 17, 2015
Notes:

- browserify-istanbul is used instead of a karma-coverage preprocessor
  because of this bug:
  karma-runner/karma-coverage#16 (comment)
- karma-coverage version pinned to 0.2.6 to workaround this bug:
  karma-runner/karma-coverage#123 (comment)
treyhunner added a commit to startersacademy/fullstack-project-01 that referenced this issue Feb 18, 2015
Notes:

- browserify-istanbul is used instead of a karma-coverage preprocessor
  because of this bug:
  karma-runner/karma-coverage#16 (comment)
- karma-coverage version pinned to 0.2.6 to workaround this bug:
  karma-runner/karma-coverage#123 (comment)
@neilrees
Copy link

+1 downgrading to 0.2.6 also worked here

@peter-mouland
Copy link

+1 downgrading

@SomeKittens
Copy link

Also ran into this issue. Downgrading worked.

@dsuckau
Copy link

dsuckau commented Mar 13, 2015

For me the same, downgrading to 0.2.6 worked

@jskrzypek
Copy link

+1 downgrading to 0.2.6, but any idea of when we will be able to upgrade and still have working coverage with browserify?

@jasonslyvia
Copy link

+1, downgrading worked.

@codepunkt
Copy link

+1 here, downgraded to 0.2.6.

Please investigate!

@jukkasi
Copy link

jukkasi commented Apr 17, 2015

+1

1 similar comment
@TYRONEMICHAEL
Copy link

+1

@akoval
Copy link

akoval commented Jun 9, 2015

after suggested fix (#124):

ERROR [coverage]: [TypeError: Cannot set property 'covered' of undefined]
TypeError: Cannot set property 'covered' of undefined
at /node_modules/karma-coverage/node_modules/istanbul/lib/report/html.js:174:66
at Array.forEach (native)
at annotateLines (/node_modules/karma-coverage/node_modules/istanbul/lib/report/html.js:172:28)
at HtmlReport.Report.mix.writeDetailPage (/node_modules/karma-coverage/node_modules/istanbul/lib/report/html.js:406:9)
at /node_modules/karma-coverage/node_modules/istanbul/lib/report/html.js:472:26
at SyncFileWriter.extend.writeFile (/node_modules/karma-coverage/node_modules/istanbul/lib/util/file-writer.js:57:9)
at FileWriter.extend.writeFile (/node_modules/karma-coverage/node_modules/istanbul/lib/util/file-writer.js:147:23)
at /node_modules/karma-coverage/node_modules/istanbul/lib/report/html.js:471:24
at Array.forEach (native)
at HtmlReport.Report.mix.writeFiles (/node_modules/karma-coverage/node_modules/istanbul/lib/report/html.js:465:23)

@SomeKittens
Copy link

@akoval See my issue: #122 (comment)

@dignifiedquire
Copy link
Member

Should be fixed in 0.4.0

@Tin-Nguyen
Copy link

Hi @dignifiedquire ,

After upgraded the component to 0.4.0, I got the error
ERROR [coverage]: [TypeError: Cannot set property 'covered' of undefined]

Tried with 0.3.1, I got the error
ERROR [coverage]: [TypeError: Cannot call method 'split' of undefined]

I just got the issue when using the transform babelify for browserify

Is there anyone has resolved the issue yet? :((

@Tin-Nguyen
Copy link

I've just checked and realized that the component still be 0.3.1. I still got the error
ERROR [coverage]: [TypeError: Cannot set property 'covered' of undefined]

I have also checked the release of the component and cannot find out the version 0.4.0. The latest version now is 0.3.0.

@dignifiedquire
Copy link
Member

Are you sure you are running against the official npm registry, I get this:

❯ npm view karma-coverage@latest version
0.4.2

as well as https://www.npmjs.com/package/karma-coverage which shows the latest version being 0.4.2

@Tin-Nguyen
Copy link

Yes, sorry for my mistake. I did it. However, the issue still be there.

I tried to do with logLevel: config.LOG_DISABLE in karma.conf.js file. The workaround works for me. But I'm not sure this is a good way.

@dignifiedquire
Copy link
Member

Could you file a new issue please, and post the full log with logLevel: config.LOG_DEBUG please?

@Tin-Nguyen
Copy link

Chrome 43.0.2357 (Mac OS X 10.10.2): Executed 313 of 324 (skipped 11) SUCCESS (0.465 secs / 0.303 secs)

ERROR [coverage]: [TypeError: Cannot read property 'text' of undefined]
TypeError: Cannot read property 'text' of undefined
at removed/node_modules/istanbul/lib/report/html.js:283:53
at Array.forEach (native)
at annotateBranches (removed/node_modules/istanbul/lib/report/html.js:250:30)
at HtmlReport.Report.mix.writeDetailPage (removed/node_modules/istanbul/lib/report/html.js:421:9)
at removed/node_modules/istanbul/lib/report/html.js:484:26
at SyncFileWriter.extend.writeFile (removed/node_modules/istanbul/lib/util/file-writer.js:57:9)
at FileWriter.extend.writeFile (removed/node_modules/istanbul/lib/util/file-writer.js:147:23)
at removed/node_modules/istanbul/lib/report/html.js:483:24
at Array.forEach (native)
at HtmlReport.Report.mix.writeFiles (removed/node_modules/istanbul/lib/report/html.js:477:23)
at removed/node_modules/istanbul/lib/report/html.js:479:22
at Array.forEach (native)
at HtmlReport.Report.mix.writeFiles (removed/node_modules/istanbul/lib/report/html.js:477:23)
at HtmlReport.Report.mix.writeReport (removed/node_modules/istanbul/lib/report/html.js:561:14)
at writeReport (removed/node_modules/karma-coverage/lib/reporter.js:56:16)
at removed/node_modules/karma-coverage/lib/reporter.js:153:13
at removed/node_modules/karma/lib/helper.js:80:7
at Object.oncomplete (fs.js:108:15)

@peter-mouland
Copy link

hey @Tin-Nguyen this really does sounds like a new issue. Could you raise a separate issue which will also mean everyone on this list wont get emailed?

@Tin-Nguyen
Copy link

OK @peter-mouland , I have posted 1 new issue at #167

@johnnyreilly
Copy link

Hi,

I can see this has been closed as fixed but the issue still seems to exist.

28 07 2015 15:19:13.438:ERROR [coverage]: [TypeError: Cannot read property 'split' of undefined]
TypeError: Cannot read property 'split' of undefined
    at HtmlReport.Report.mix.writeDetailPage (E:\Source\PROJECT\node_modules\karma-coverage\node_modules\istanbul\lib\reort\html.js:407:30)
    at E:\Source\PROJECT\node_modules\karma-coverage\node_modules\istanbul\lib\report\html.js:484:26
    at SyncFileWriter.extend.writeFile (E:\Source\PROJECT\node_modules\karma-coverage\node_modules\istanbul\lib\util\fil-writer.js:57:9)
    at FileWriter.extend.writeFile (E:\Source\PROJECT\node_modules\karma-coverage\node_modules\istanbul\lib\util\file-writer.js:147:23)
    at E:\Source\PROJECT\node_modules\karma-coverage\node_modules\istanbul\lib\report\html.js:483:24
    at Array.forEach (native)
    at HtmlReport.Report.mix.writeFiles (E:\Source\PROJECT\node_modules\karma-coverage\node_modules\istanbul\lib\report\tml.js:477:23)
    at E:\Source\PROJECT\node_modules\karma-coverage\node_modules\istanbul\lib\report\html.js:479:22
    at Array.forEach (native)
    at HtmlReport.Report.mix.writeFiles (E:\Source\PROJECT\node_modules\karma-coverage\node_modules\istanbul\lib\report\tml.js:477:23)
    at HtmlReport.Report.mix.writeReport (E:\Source\PROJECT\node_modules\karma-coverage\node_modules\istanbul\lib\reporthtml.js:561:14)
    at writeReport (E:\Source\PROJECT\node_modules\karma-coverage\lib\reporter.js:62:16)
    at E:\Source\PROJECT\node_modules\karma-coverage\lib\reporter.js:286:11
    at FSReqWrap.oncomplete (fs.js:95:15)

These are my devDependencies:

  "devDependencies": {
    "babelify": "^6.1.2",
    "browserify": "^10.2.4",
    "browserify-istanbul": "^0.2.1",
    "gulp": "^3.9.0",
    "gulp-autoprefixer": "^2.3.1",
    "gulp-cached": "^1.1.0",
    "gulp-cssmin": "^0.1.7",
    "gulp-if": "^1.2.5",
    "gulp-less": "^3.0.3",
    "gulp-notify": "^2.2.0",
    "gulp-sourcemaps": "^1.5.2",
    "gulp-streamify": "0.0.5",
    "gulp-uglify": "^1.2.0",
    "gulp-util": "^3.0.6",
    "jasmine-core": "^2.3.4",
    "karma": "^0.13.2",
    "karma-browserify": "^4.2.1",
    "karma-coverage": "^0.4.2",
    "karma-jasmine": "^0.3.6",
    "karma-mocha-reporter": "^1.0.2",
    "karma-phantomjs-launcher": "^0.2.0",
    "karma-phantomjs-shim": "^1.0.0",
    "karma-teamcity-reporter": "^0.2.0",
    "phantomjs": "^1.9.17",
    "vinyl-source-stream": "^1.1.0",
    "watchify": "^3.2.3"
  },

And this is my config:

module.exports = function(config) {
  config.set({
    browsers: [ 'PhantomJS' ],

    files: [
      //'src/**/!(main).js',
      'src/dependencies.js',
      'test/**/*.tests.js'
    ],

    frameworks: [ 'jasmine', 'browserify', 'phantomjs-shim' ],

    logLevel: config.LOG_INFO, //config.LOG_DEBUG

    preprocessors: {
      'src/**/*.js': [ 'browserify', 'coverage' ],
      'test/**/*.tests.js': [ 'browserify' ]
    },

    // browserify configuration
    browserify: {
      debug: true,
      transform: [
        ['babelify', { sourceMaps: false, stage: 3 }],
        'browserify-istanbul'
      ]
    },

    coverageReporter: {
      reporters:[
        {type: 'html', dir:'coverage/'},
        //{type: 'teamcity'},
        {type: 'text'},
        {type: 'text-summary'}
      ],
    }
  });
};

I'm on Windows in case that's relevant... Locking the dependency for karma-coverage to 0.2.6 did not work for me unfortunately.

@twonder
Copy link

twonder commented Feb 1, 2017

I found this issue:
webpack-contrib/istanbul-instrumenter-loader#32 (comment)

Pinning to "instanbul-instrumenter-loader" : "0.2.0" fixed the issue for me.

metatoaster added a commit to metatoaster/calmjs.webpack that referenced this issue Dec 8, 2017
- As the code need to be applied _inside_ the webpack, the relevant
  loader must be used.
- Using a fork of the loader because it can generate html reports
  without dying in a fire like the official one.

  - karma-runner/karma-coverage#123
  - karma-runner/karma-coverage#278
metatoaster added a commit to metatoaster/calmjs.webpack that referenced this issue Dec 14, 2017
- As the code need to be applied _inside_ the webpack, the relevant
  loader must be used.
- Using a fork of the loader because it can generate html reports
  without dying in a fire like the official one.

  - karma-runner/karma-coverage#123
  - karma-runner/karma-coverage#278
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests