riot / karma-riot

A Karma plugin. Compile and test HTML and JS in Riot tag files.
https://www.npmjs.com/package/karma-riot
MIT License
19 stars 9 forks source link

tag based coverage report #7

Open inancgumus opened 8 years ago

inancgumus commented 8 years ago

Can't generate valid coverage reports from compiled tag files. For example: With karma lcov reporting, compiled tag file's coverage is not correctly reported.

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'],
      'src/**/*.js': ['coverage']
    },
    coverageReporter: {
      dir: 'coverage/',
      reporters: [
        { type: 'html', subdir: 'report-html' },
        { type: 'text', subdir: '.', file: 'text.txt' },
        { type: 'text-summary', subdir: '.', file: 'text-summary.txt' },
        { 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
cognitom commented 8 years ago

Because of the sourcemap? At this point Riot doesn't provide its sourcemap.

inancgumus commented 8 years ago

@cognitom How can we add sourcemap support to Riot?

GianlucaGuarini commented 8 years ago

Isn't the whole discussion a waste of time? I mean if you want to get the coverage on the riot tags just export them using the compiler and run karma using the js output riot **/*.tag my-tags.js We will at some point implement sourcemaps, but since there is a compiler exporting the riot tags to pure javascript, sourcemaps are just a "nice to have" feature not a "must".

inancgumus commented 8 years ago

@GianlucaGuarini Simplicity and minimalism is one of the tenets of Riot as compared to React as I understand. So, adding turnaround solutions to make it work for to get a coverage report isn't making Riot simple, in constrast, making it hard to work with for/in proper testing environments which is a minimum needed stuff for every developer. I vote on it's a "must" not "nice to have". Thanks for the turnaround solution by the way.

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?

GianlucaGuarini commented 8 years ago

Probably we need just to update karma-riot to let it recognize the riot compiler output as part of the coverage code. I will check it asap