karma-runner / karma-runner/karma-coverage

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

Open
#241 1 comment 9 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
771
Forks
242
PR merge metrics
No merged PRs in 30d

Description

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:

``` javascript
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

PROJECTPATH













































```

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

Contributor guide

Open the contributing guide

Research direction

Start with the coverageReporter configuration in karma.conf.js and compare how the text/html reporters handle source paths with the lcovonly and cobertura reporters shown in the issue. Trace the plugin's reporter and source-map handling, then verify that both reports reference original source files rather than transpiled output.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, javascript, webpack
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.