karma-coverage icon indicating copy to clipboard operation
karma-coverage copied to clipboard

Reporters lcovonly and cobertura collect information for transpiled files instead of original ones

Open weblogixx opened this issue 9 years ago • 1 comments

Hi all,

I currently use karma-coverage on a bigger webpack based project. The html reporter works just fine and shows the coverage information on the original source. However, the lcov and cobertura reporters report on the babel-transpiled items instead of this. There was already an issue about this problem at https://github.com/gotwarlost/istanbul/issues/571.

The problems author moved away from karma, which made lcov work correctly. Therefore I think that it might have to do with the karma-coverage plugin.

I am currently using https://github.com/weblogixx/react-webpack-template as a base (just adding lcovonly into the karma.conf.js coverage section).

Adjusted part of karma.conf.js:

    coverageReporter: {
      dir: 'coverage/',
      watermarks: {
        statements: [ 70, 80 ],
        functions: [ 70, 80 ],
        branches: [ 70, 80 ],
        lines: [ 70, 80 ]
      },
      reporters: [
        { type: 'text' },
        {
          type: 'html',
          subdir: 'html'
        },
        {
          type: 'cobertura',
          subdir: 'cobertura'
        },
        {
          type: 'lcovonly',
          subdir: 'lcov'
        }
      ]
    }

Output of lcovonly (example, paths stripped for better readability):

TN:
SF:PROJECTPATH/src/components/Main.js
FN:7,(anonymous_1)
FN:7,defineProperties
FN:7,(anonymous_3)
FN:21,_interopRequireDefault
FN:23,_classCallCheck
FN:25,_possibleConstructorReturn
FN:27,_inherits
FN:32,(anonymous_8)
FN:35,AppComponent
FN:43,render
FNF:10
FNH:10
FNDA:1,(anonymous_1)
FNDA:1,defineProperties
FNDA:1,(anonymous_3)
FNDA:3,_interopRequireDefault
FNDA:2,_classCallCheck
FNDA:2,_possibleConstructorReturn
FNDA:1,_inherits
FNDA:1,(anonymous_8)
FNDA:2,AppComponent
FNDA:2,render

and the following one for cobertura:

<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="3412"  lines-covered="3412"  line-rate="1"  branches-valid="3865"  branches-covered="3814"  branch-rate="0.9868000000000001"  timestamp="1469031357031" complexity="0" version="0.1">
<sources>
    <source>PROJECTPATH</source>
</sources>
        <class name="Main.js"  filename="src/components/Main.js"  line-rate="1"  branch-rate="1" >
        <methods>
            <method name="(anonymous_1)"  hits="1"  signature="()V" >
                <lines><line number="7"  hits="1" /></lines>
            </method>
            <method name="defineProperties"  hits="1"  signature="()V" >
                <lines><line number="7"  hits="1" /></lines>
            </method>
            <method name="(anonymous_3)"  hits="1"  signature="()V" >
                <lines><line number="7"  hits="1" /></lines>
            </method>
            <method name="_interopRequireDefault"  hits="3"  signature="()V" >
                <lines><line number="21"  hits="3" /></lines>
            </method>
            <method name="_classCallCheck"  hits="2"  signature="()V" >
                <lines><line number="23"  hits="2" /></lines>
            </method>
            <method name="_possibleConstructorReturn"  hits="2"  signature="()V" >
                <lines><line number="25"  hits="2" /></lines>
            </method>
            <method name="_inherits"  hits="1"  signature="()V" >
                <lines><line number="27"  hits="1" /></lines>
            </method>
            <method name="(anonymous_8)"  hits="1"  signature="()V" >
                <lines><line number="32"  hits="1" /></lines>
            </method>
            <method name="AppComponent"  hits="2"  signature="()V" >
                <lines><line number="35"  hits="2" /></lines>
            </method>
            <method name="render"  hits="2"  signature="()V" >
                <lines><line number="43"  hits="2" /></lines>
            </method>
        </methods>
        <lines>
            <line number="0"  hits="3"  branch="false" />
            <line number="1"  hits="1"  branch="false" />
            <line number="2"  hits="1"  branch="false" />
            <line number="4"  hits="1"  branch="false" />
            <line number="5"  hits="1"  branch="false" />
            <line number="6"  hits="1"  branch="false" />
            <line number="10"  hits="2"  branch="false" />
        </lines>
        </class>
    </classes>

The text and html reporters get the correct values, so I can see the coverage in the generated reports correctly.

weblogixx avatar Jul 21 '16 05:07 weblogixx

still valid for me 6 years from the originally reported the issue, @weblogixx have you found any solution?

danbilokha avatar Mar 09 '22 14:03 danbilokha