mocha-phantom-coverage-reporter

PhantomJS LCOV reporter for Mocha

mocha-phantom-lcov-reporter

PhantomJS LCOV reporter for Mocha.

This reporter combine three Mocha reporter: Spec, HTMLCov and Mocha Lcov Reporter. It work with NodeJS and in browser with PhantomJS.

The output lcov file is fully compatible with Coveralls

For prepare your sources files for coverage you can read the "Usage" section of Mocha Lcov Reporter or "Mocha + JSCoverage" and "Istanbul" section of Coveralls node helper. If you are using CoffeeScript, I recommend CoffeeCoverage.

For NodeJS

mocha -R mocha-phantom-lcov-reporter

In browser

# Gruntfile.coffee 
grunt.loadNpmTasks('grunt-mocha')
 
grunt.initConfig
    mocha:
            all: 
                options:
                    mocha:
                        ignoreLeaks: false
 
                    urls: ['http://localhost:<%= connect.test.options.port %>/']
                    run: false
                    reporter: 'mocha-phantom-coverage-reporter'
                    timeout: 5000

This exemple is issue to generator-footguard a project generator for Yeoman. You can see the result on test-footguard

In your console you can see the spec reporter of Mocha and too files are created in coverage directory: coverage.lcov and coverage.html.

The file "coverage.html", it's the result of Mocha HTMLCov reporter. It's very helpful for debug coverage in local.

The file "coverage.lcov", it's file compatible with LCOV and Coveralls

For link your project with Coveralls, start to add node-coveralls dependency in your project.

$ npm install coveralls --save-dev

For send coverage result to Coveralls

cat ./coverage/coverage.lcov | ./node_modules/coveralls/bin/coveralls.js

Coveralls parse all files in lcov file for add source, maybe your sources are not linked correctly you can specify the folder like this:

cat ./coverage/coverage.lcov | ./node_modules/coveralls/bin/coveralls.js src

If you work with Grunt and CoffeeCcript, I recommend you grunt-coffeecov.

# Gruntfile.coffee 
grunt.loadNpmTasks('grunt-mocha')
grunt.loadNpmTasks('grunt-coffeecov')
grunt.loadNpmTasks('grunt-contrib-coffee')
 
grunt.initConfig
  connect:
    test:
      options:
        port: 3000
        hostname: '0.0.0.0'
 
  coffee:
    dist:
      expand: true
      cwd: 'src/coffee/'
      src: ['**/*.coffee']
      dest: '.tmp/js'
      ext: '.js'
 
  coffeecov:
    options:
      path: 'relative'
    dist:
      src: 'src/coffee/app'
      dest: '.tmp/js/app'
 
  mocha:
    all: 
      options:
        mocha:
          ignoreLeaks: false
 
        urls: ['http://localhost:3000/']
        run: false
        reporter: 'mocha-phantom-coverage-reporter'
        timeout: 10000
 
grunt.registerTask('test'[
  'coffee:dist'
  'coffeecov:dist'
  'connect:test'
  'mocha'
])