node.js - Tell Mocha to use CoffeeScript files by default -
i'm trying set testing in mocha application i'm writing using zappa.js. far i've been following this tutorial, , converting need js coffeescript.
however i'm little stuck trying run tests. have makefile, looks this:
reporter = dot test: @node_env=test ./node_modules/.bin/mocha \ --reporter $(reporter) \ .phony: test
and i've set package.json file run tests so:
{ "scripts": { "test": "make test" } }
the issue i'm finding that, because i'm trying write mocha tests using coffeescript well, mocha not pick of tests in "test/" folder when run "npm test". know fact can tell mocha run .coffee files using following in terminal (which works):
mocha --compilers coffee:coffee-script
what want know how go telling mocha use coffeescript files default?
ok managed find way solve own question, thought i'd share in case else need this.
note: coffeescript 1.7+ --require coffee-script needs changed --require coffee-script/register
the solution instead create cakefile opposed makefile, looks this:
#cakefile {exec} = require "child_process" reporter = "min" task "test", "run tests", -> exec "node_env=test ./node_modules/.bin/mocha --compilers coffee:coffee-script --reporter #{reporter} --require coffee-script --require test/test_helper.coffee --colors ", (err, output) -> throw err if err console.log output
and change package.json this:
#package.json { "scripts": { "test": "cake test" } }
finally had install coffeescript project using:
npm install coffee-script
and create file test/test_helper.coffee, contains global declarations tests.
Comments
Post a Comment