プログラミング + アカデミック + 何か面白いこと

  1. Programming
  2. 61 view

[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

coffee-coverage

Reference

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

Programming recent post

  1. Install sbt 1.0.0 and run sample template

  2. [Machine Learning]Created docker image includ…

  3. [Node.js]How to write batch script with Node.…

  4. [Play][Scala]Develop Request Driven Batch Usi…

  5. [OpenCV][Ruby]Auto check web page design corr…

関連記事

PAGE TOP