Search code examples
angularkarma-coverage

karma-coverage: TypeError: Cannot read property 'split' of undefined


I am trying to support lcov reporter with karma-coverage. I modified my karma config like this:

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

    },

I keep getting the error:

ERROR [coverage]: TypeError: Cannot read property 'split' of undefined
    at HtmlReport.writeDetailPage ({path}\node_modules\istanbul\lib\report\html.js:413:33)

I am getting the required reports, but this error is failing my build. Is there a way to resolve this issue?


Solution

  • I was able to resolve this issue by using a different package. karma-remap-istanbul.

    Changes in Karma.conf.js

    remapIstanbulReporter: {
          remapOptions: {}, //additional remap options 
          reports: {
            'text-summary': null, // to display summary results on console
            json: 'coverage/coverage.json',
            lcovonly: 'coverage/lcov.info',
            html: 'coverage/html/',
          }
        },
        reporters: [  'mocha', 'coverage', 'karma-remap-istanbul'],
    

    Changes in webpack test configuration. I added the loader sourcemap-istanbul-instrumenter-loader instead of istanbul-intrumenter-loader supported by karma-remap-coverage

    {
              enforce: 'post',
              test: /\.(js|ts)$/,
              loader: 'sourcemap-istanbul-instrumenter-loader',
              include: helpers.root('src'),
              exclude: [
                /\.(e2e|spec)\.ts$/,
                /node_modules/
              ]
            }
    

    I was able to generate lcov report smoothly.

    Hope this helps others facing the same issue.