gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 788 forks source link

riot tag based coverage report incorrectness #571

Open inancgumus opened 8 years ago

inancgumus commented 8 years ago

You can see the difference in below screenshots.

How is it possible that LCOV reporting gets its data from unprocessed src/hello.tag file while HTML reporting gets its data from processed src/hello.tag file? What is the difference? I've read their source codes but I couldn't find anything there.

Reproduce:

Example project:

git clone https://github.com/vitogit/tdd-mocha-chai-riot

Karma Config (updated):

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['mocha','chai','riot'],
    plugins: [
      'karma-mocha',
      'karma-mocha-reporter',
      'karma-phantomjs-launcher',
      'karma-chai',
      'karma-riot',
      'karma-coverage'
    ],
    files: [
      'node_modules/chai/chai.js',
      'src/**/*.tag',
      'test/**/*.js'
    ],
    preprocessors: {
      '**/*.tag': ['riot', 'coverage']
    },
    coverageReporter: {
      dir: 'coverage/',
      reporters: [
        // works correctly
        { type: 'html', subdir: 'report-html' },

        // does not work correctly -- gets its input from unprocessed riot tag file
        { type: 'lcovonly', subdir: '.', file: 'lcov.info' }
      ]
    },
    browsers: ['PhantomJS'],
    reporters: ['mocha', 'coverage'],
    failOnEmptyTestSuite: false,
    autoWatch: true
  })
}

How to run?

npm i && npm i karma-coverage --save-dev
karma start
cat coverage/lcov.info

You can also see html based coverage reports inside coverage directory's html coverage reports.

LCOV is incorrect:

screen shot 2016-03-14 at 15 10 26

HTML is correct:

screen shot 2016-03-14 at 15 11 51
inancgumus commented 8 years ago

By the way, actually, what I really wonder is why html coverage output is true while lcov coverage output is not?

weblogixx commented 8 years ago

I have the same problem. Lcov-Reporter shows incorrect line numbers, which makes me guess it really works on the already transpiled files (in this case react, but I do not think that this matters).

Output for text, html and cobertura seem to be fine... The main problem is that I cannot get other plugins to work in SonarQube, so I have to use lcov...

Is there any news on this problem?

inancgumus commented 8 years ago

@weblogixx Karma made everything complex. So, I've switched to more basic approach: Run mocha and istanbul directly from CLI through npm run. This way, what happens is clear and LCOV also works correctly, because I don't need to deal with karma plugins etc. I'm directly dealing with the core components directly.

weblogixx commented 8 years ago

@deeperx Thank you for your answer. This is interesting, it seems to be more like a karma coverage reporter problem then? Unfortunately, I am not able to change my setup from karma to pure mocha (I know it technically is possible, I already did it in one or two projects I am currently working on, but I have some projects that really depend on karma :().

inancgumus commented 8 years ago

Yes, it seems like that. It made so mad that I'd completely reconfigured to pure CLI based tools :)

Inanc Gumus

21 Tem 2016 tarihinde 08:23 saatinde, Chris notifications@github.com şunları yazdı:

@deeperx Thank you for your answer. This is interesting, it seems to be more like a karma coverage reporter problem then? Unfortunately, I am not able to change my setup from karma to pure mocha (I know it technically is possible, I already did it in one or two projects I am currently working on, but I have some projects that really depend on karma :()�.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.