I am working on developing a REST API using ExpressJS, NodeJS, Mongoose and Mocha.
The thing is that I have an app.coffee file, thats responsible for setting up Expr
There might be a more straightforward way, but I went to Grunt for automating my functional tests. There's an express and mocha plugin to reach your goal. My gruntfile:
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
express: {
options: {}
, test: {
options: {
script: './app.js'
}
}
}
, simplemocha: {
options: {
globals: ['should']
, timeout: 8000
, ignoreLeaks: false
, ui: 'bdd'
, reporter: 'tap'
}
, all: { src: ['tests/*.test.js'] }
}
})
grunt.loadNpmTasks('grunt-express-server')
grunt.loadNpmTasks('grunt-simple-mocha')
grunt.registerTask('default', ['express:test', 'simplemocha', 'express:test:stop'])
}
bonus: add 'grunt' as a git pre-commit hook. This way you cannot commit without passing all the tests