karma-runner / karma-coverage

A Karma plugin. Generate code coverage.
MIT License
769 stars 247 forks source link

TypeError: cannot read property 'split' of undefined #278

Open akankshagaur opened 7 years ago

akankshagaur commented 7 years ago

Hi,

version: 1.1.1

I am using Karma-coverage to generate lcov report with in-memory report like this:

coverageReporter: {
       dir: 'reports/',
       reporters: [
          { type: 'in-memory' },
          { type: 'lcov', subdir: 'report-lcov' },
       ]
    },

I am getting the error:

TypeError: Cannot read property 'split' of undefined
    at HtmlReport.writeDetailPage ({path}\node_modules\istanbul\lib\report\html.js:412:28)

I tried modifying the html.js to see the result. coverage is sending undefined value to istanbul in the end. My reports are generating properly, but this error fails my build. Is there a fix to it?

chiefie commented 7 years ago

I am having this same issue too.

I'm using fountainjs to generate webapp, using Angular 1 with bower dependencies and injection, configured it to do coverage, ran the test and it passed the test and when generating the report, it failed with this error. However, the output gets generated.

franckXu commented 7 years ago

maybe this answer will help you ,istanbul-instrumenter-loader / html reports fail w/ v1 #32

tommck commented 7 years ago

no updates?

tommck commented 7 years ago

I've been trying to figure out this problem for a couple of days myself. Please let me know if you figure anything out

sgen commented 7 years ago

Ive been doing some debugging and I suspect the root cause is config.files is being passed to istanbul despite config.preProcessors patterns being set to instrument only some files.

This is the config for the project Im working on:

  config.set({
    frameworks: ["browserify", "jasmine"],
    files: [
       "helpers.js",
       "helpers.test.js",
    ],
    preprocessors: {
      'helpers.js': ['coverage', 'browserify'],
      'helpers.test.js': ['browserify']
    },
    reporters: ["progress", 'coverage'],
    browsers: ["Chrome"],
    client: {
      captureConsole: true,
    },
    logLevel: config.LOG_DEBUG,
    browserify: {
      debug: true,
      transform: ['browserify-istanbul']
    }
  });
};

Despite the preProcessor being set to only instrument helpers.js both helpers.js and helpers.test.js are being reported on.

The failure results from coverage report for helpers.test.js not containing the .code property, causing istanbul to check its file store for the contents of helpers.test.js via karma's MemoryStore here. Apparently MemoryStore does not contain the source code thus causing the value of code to be undefined here.

I am not well versed in the internals of karma or karma-coverage but I will keep looking later today.

tommck commented 7 years ago

I think you're on the right track. I really wish someone could solve this. I haven't had any luck.

sgen commented 7 years ago

I haven't made much progress. Ive tracked the bug to here the result parameter contains the invalid coverage property. However I cannot find the source of it. The only place I can find Karma.complete() being called is here however this only occurs on an error and no arguments are passed.

If someone knows where this event is being emitted from let me know.

michaelBenin commented 7 years ago

I believe there's a PR for this here: https://github.com/gotwarlost/istanbul/pull/816

jileeshs commented 6 years ago

Looks like Istanbul is not being maintained. I saw a sad comment on one of the PRs related to this issue, according to last comment on this https://github.com/gotwarlost/istanbul/pull/816#ref-commit-4a5e92c @gotwarlost is not active.

michaelBenin commented 6 years ago

@jileeshs https://github.com/istanbuljs/istanbuljs

jileeshs commented 6 years ago

Thank you @michaelBenin