Categories: Uncategorized

[Test][CoffeeScript]Measure coverage with Coffee Script Mocha Blanket

Overview

Measure C0 coverage of CoffeeScript by Mocha/Blanket.

Environment

  • OS: Ubuntu 12.04LTS
  • Node.js v0.10.26

Install Mochat/Blanekt/CoffeeScript

How to install node.js here.
$ vim package.json
{
  "name": "coveragesample",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "coffee-script":  "1.7.1",
    "chai":            "1.9.1",
    "mocha":           "1.20.1",
    "blanket":         "1.1.6"
  }
}
$ npm install

Test Target Code and Test Code

Test target code
module.exports = -> true
Test code
main   = require('../src/');
assert = require('chai').assert

describe 'testing', ->

  it 'is pretty nice with CoffeeScript', ->
    assert main() == true
Setting of Mocha
--compilers coffee:coffee-script/register
--reporter spec
Run test
$./node_modules/.bin/mocha

  testing
    ✓ is pretty nice with CoffeeScript

  1 passing (8ms)

Run coverage measuring

Add blanket setting to package.json
{
  "name": "coveragesample",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "coffee-script":  "1.7.1",
    "chai":           "1.9.1",
    "mocha":          "1.20.1",
    "blanket":        "1.1.6"
  },
  "config": {
    "blanket": {
      "pattern": "src",
      "loader": "./node-loaders/coffee-script",
      "data-cover-never": "node_modules"
    }
  }
}
Add option to mocha.opts
--compilers coffee:coffee-script/register
--reporter spec
--require blanket
Run coverage measuring
$ ./node_modules/.bin/mocha -R html-cov test > coverage.html

Reference

  • Mocha: http://visionmedia.github.io/mocha/#reporters
  • Blanket: https://github.com/alex-seville/blanket
zuqqhi2