Skip to content Skip to sidebar Skip to footer

Karma And Coffescript And Code Coverage

I think something may be wrong with the Karma CoffeeScript code coverage preprocessor. Or I'm not sure what I'm doing wrong! So I come to you StackOverflow. Basically I'm trying to

Solution 1:

I'd look at the following:

https://github.com/karma-runner/karma-coverage/issues/75, see @zeno's comment in particular. There is a forked build that allows karma-coverage to parse standard coffee script. It does this by using a fork of Ibrik by HBOCodeLabs that switches out redux for standard coffeescript. To use you would add the following to your dev dependencies

karma-coverage": "git+https://github.com/kylewelsby/karma-coverage#fix-coffee-script-compiler"

That works for me!

Solution 2:

Karma code coverage is powered by brick project. brick compiles and instruments the coffeescript code. The compiler used by brick is not the standard coffeescript compiler, instead, brick uses a non 100% compatible compiler called coffeescript-redux

Our project is perfectly compiled by coffeescript 1.8 but has a lot of errors when compiled with redux

The ibrik project and the redux compilers have been relatively inactive in a while, thus we simply forgot our attempts to get the cover of our code. Maybe in a future, with the relaunch of coffeescript-redux, we can use again the karma-code-coverage plugin.

--------- UPDATE --------------

The ibrik project has been updated to use coffescript, but karma-coverage not yet. You can hack your package.json to get it working or wait to karma-coverage fix it, however I have two karma config files in my project, first to run without coverage (fast - 3 seconds) and second to coverage the javascript (little slower - 10 seconds)

Check karma-coverage.conf.coffee

wiredep = require('wiredep')
path = require('path')

module.exports = (config) ->
  config.set
    frameworks: ['jasmine']

    files: wiredep(devDependencies: true)['js'].map (file) ->
      path.relative(process.cwd(), file)
    .concat [
      '.tmp/common/app.js''.tmp/common/services/helpers/**/*.js''.tmp/common/**/*.js''.tmp/app/**/*.js''src/common/**/*.spec.coffee''src/app/**/*.spec.coffee''test/spec/**/*.coffee'
      # directives templates
      'src/common/directives/**/*.html''src/app/components/**/*.html''bower_components/angular-strap/src/**/*.tpl.html'
      # fixtures
      {
        pattern: 'test/fixtures/**/*.json'
        watched: true
        served: true
        included: false
      }
    ]

    exclude: []

    preprocessors:
      'src/app/components/**/*.html': 'ng-html2js''bower_components/angular-strap/src/**/*.tpl.html': 'ng-html2js''src/common/**/*.spec.coffee': 'coffee''src/app/**/*.spec.coffee': 'coffee''test/spec/**/*.coffee': 'coffee''.tmp/**/*.js': 'coverage'

    reporters: ['progress', 'html', 'coverage']

    ngHtml2JsPreprocessor:
      stripPrefix: 'src/'

    coverageReporter:
      type: 'html',
      dir: '.tmp/test/coverage/'

    htmlReporter:
      outputDir: '.tmp/test/html/'

    coffeePreprocessor:
      options:
        bare: true
        sourceMap: true
      transformPath: (path) ->
        returnpath.replace(/.js$/, '.coffee')

    port: 9876
    colors: true
    logLevel: config.LOG_INFO
    autoWatch: true
    browsers: ['PhantomJS']
    singleRun: false

Post a Comment for "Karma And Coffescript And Code Coverage"