Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test coverage with Karma, browserify and Coffeescript

I'm having troubles to add test code coverage, I'm using Karma and files added to Karma are already bundled with browserify, so in karma.conf.coffee it looks like that:

files: [
   { pattern:'bin/public/client/app.js', served:yes: included:yes }
   { pattern:'src/lib/vendor/angular-mocks/angular-mocks.js', served:yes: included:yes }
   { pattern:'bin/tests.js', served:yes: included:no }
]

And that works for running the test, but not coverage

I'm using karma-coverage npm package, and this:

preprocessors: 'bin/public/client/app.js':['coverage']

reporters: ['progress','coverage']

Actually does create coverage stat files, but those are completely wrong, because it reddens parts that browserify brought from node_modules (because I don't have tests to cover those)

Ideally I have to gather source maps that browserify generates, and run coverage against those, but browserify embeds source maps into .js files. Using karma-sourcemap-loader lets me see original coffeescript files of tests, when debugging (for some reason it works only in ChromeCanary, nevertheless it works)

I tried to do preprocessors: 'src/client/**/*.coffee':['coverage'], but that yields no stats at all saying 'No data to display'

Do you have any ideas?

upd:

I've figured by running browserify-istanbul transform right after coffeeify and that gave me nice diagram like this: enter image description here

Now, I need somehow to remove app.js from it, because really it doesn't matter and really confuses

upd:

Oh, instead of javascript I have to supply coffee files:

preprocessors : {
    'bin/tests.js': ['sourcemap']
    'src/client/**/*.coffee': ['coverage']
}
like image 556
iLemming Avatar asked Jul 24 '14 21:07

iLemming


1 Answers

Seems I answered my own question. Also it seems there's a bug in current version of karma-coverage - it throws an error when coverageReporter.type is html (which is by default html). I'm glad I've figured it out. It's always nice to see how much code covered by tests

like image 110
iLemming Avatar answered Oct 12 '22 00:10

iLemming