Auto-run tests in Node.js
Want to run Node.js tests every time a file changes? Add this to your ~/.bash_profile
:
alias automocha="supervisor -q -n exit -x mocha -- -b"
And of course, install mocha and supervisor to your global context:
$ npm install -g supervisor mocha
Now just run automocha
to invoke mocha
every time a file changes.
Bonus: add it to your package.json
Don't want to have these on the global context? That's fair, just merge these definitions into your package.json:
"scripts": {
"autotest": "./node_modules/.bin/supervisor -q -n exit -x ./node_modules/.bin/mocha -- -b"
},
"devDependencies": {
"mocha": "~1.10.0",
"supervisor": "~0.5.2"
}
Then run it:
$ npm run autotest
Written by Rico Sta. Cruz
Related protips
3 Responses
Why not use Karma instead.
over 1 year ago
·
because Karma is for the clientside
over 1 year ago
·
Your package.json could be written as:
"scripts": {
"autotest": "supervisor -q -n exit -x mocha -- -b"
},
"devDependencies": {
"mocha": "~1.10.0",
"supervisor": "~0.5.2"
}
and would behave the same because npm is super clever
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Nodejs
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#