Over the weekend I started a node.js app and decided to give mocha a try. Despite all google I did and all github issues I read, I couldn’t find an easy way to run tests that are on subdirectories.
But why should it be easy? :P
Mocha advices you to use Makefiles to setup which tests it should run, IMHO this is over-engineering – maybe one day you will need it.
The solution I propose is quite easy, and I just needed to look at the mocha binary file and see the possible arguments it accepts.
The --recursive option does what we need. So, one just needs to run mocha using this option and mocha will find all files under the test directory.
In order to set this as a default argument, configure this on your test/mocha.opts file.
This also works when running npm test, as long as your package.json is configured properly: