1

I just setup my project with mocha, coffeescript and blanket. Mocha and blanket seems to play well with the compiled Javascript, but not the original coffeescript.

This is my code to be tested:

class App
    @add: (a, b) ->
        a + b

    @pow: (exp, base) ->
        if exp == 0
            return 1
        product = 1
        for i in [1..exp]
            product *= base
        product

module.exports = App

Here's my test code:

App = require '../src/app'
assert = require 'assert'

describe 'App', () ->
    describe 'add', () ->
        it 'should return sum of two numbers', () ->
            assert.equal( App.add( 2, 3 ), 5 )

    describe 'pow', () ->
        it 'should return the correct result', () ->
            assert.equal( App.pow( 2, 3 ), 9 )

For CoffeeScript

I ran mocha as the following:

mocha --compilers coffee:coffee-script --require blanket --reporter html-cov > coverage.html

The result shows 0% coverage 0 LOC and nothing else.

For Javascript

However, if I compile those two coffeescript file into javascript, and run the following:

mocha --require blanket --reporter html-cov > coverage.html

The report displays nicely.

So, am I doing something wrong? Because I read the Blanket features and found that Blanket should play well with CoffeeScript. How to make that happen?

Peter Ren
  • 177
  • 7

1 Answers1

2

From this post you need this in your package.json:

"blanket": {
    "loader": "./node-loaders/coffee-script"
}
AsTeR
  • 7,247
  • 14
  • 60
  • 99
Vidya
  • 29,932
  • 7
  • 42
  • 70
  • I read your answer and added this option, it's working. However, there are two problems: 1. The result is attached with the coffee-script loader itself. 2. The resulting code is Javascript, not CoffeeScript. I know that Blanket implements a javascript syntax analyzer, not CoffeeScript, but it should be possible to figure out the line number using source maps, right? – Peter Ren Nov 13 '13 at 16:30
  • As much as I love CoffeeScript, it is a bit immature in terms of debugging. [Source maps](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) should certainly help you. – Vidya Nov 13 '13 at 22:22
  • 2
    Note this need to be in the config: {} section of your package.json – startswithaj Mar 20 '14 at 02:05
  • 3
    Hopefully this saves the next person some trouble, it appears a "pattern" param is necessary along with "loader" or else you'll receive an error: "Error: Bad file instrument indicator. Must be a string, regex, function, or array." – Elliot Chong Jun 26 '14 at 00:34