简体   繁体   English

CoffeeScript +摩卡咖啡+毯子,怎么办?

[英]CoffeeScript + Mocha + Blanket, how to?

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. 摩卡和毯子似乎可以很好地与已编译的Java脚本一起使用,但不能与原始的咖啡脚本一起使用。

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 对于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. 结果显示0% coverage 0 LOC ,仅此而已。

For Javascript 对于Javascript

However, if I compile those two coffeescript file into javascript, and run the following: 但是,如果我将这两个coffeescript文件编译为javascript,然后运行以下命令:

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. 因为我阅读了Blanket功能,发现Blanket可以与CoffeeScript一起很好地玩。 How to make that happen? 如何做到这一点?

From this post you need this in your package.json : 从这篇文章中,您需要在package.json

"blanket": {
    "loader": "./node-loaders/coffee-script"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM