Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

mochaをcoffee scriptで使う

mochaをcoffee scriptを経由して使う事ができます。
こういうaltJSてclassとかあるし、どうやるのか前から気になっては居たのですが……なるほどなぁ

実際のところ

スクリプト

test/test.coffee
chai = require 'chai'
chai.should()

{Task,TaskList, List} = require '../javascript/map.coffee'

describe 'Task instance', ->
    task1 = task2 = null
    it 'should have a name', ->
        task1 = new Task 'feed the cat'
        task1.name.should.equal 'feed the cat'
    it 'should be initially incomplete', ->
        task1.status.should.equal 'incomplete'
    it 'should be able to be completed', ->
        task1.complete().should.be.true
        task1.status.should.equal 'complete'
javascript/map.coffee
class Task
  constructor: (@name) ->
    @status = 'incomplete'

  complete: ->
    @status = 'complete'
    true


root = exports ? window
root.Task = Task

テスト実行

$ mocha --compilers coffee:coffee-script/register

registerとやらないと、言う事聞いてくれないので注意。

    • compilers

CoffeeScript is no longer supported out of the box. CS and similar transpilers may be used by mapping the file extensions (for use with --watch) and the module name. For example --compilers coffee:coffee-script with CoffeeScript 1.6- or --compilers coffee:coffee-script/register with CoffeeScript 1.7+.

追記

他のaltJSについても調べてみました
shuzo-kino.hateblo.jp