How to specify test directory for mocha?

Use this:

mocha server-test

Or if you have subdirectories use this:

mocha "server-test/**/*.js"

Note the use of double quotes. If you omit them you may not be able to run tests in subdirectories.

Edit : This option is deprecated :

If you want to do it by still just running mocha on the command line, but wanted to run the tests in a folder ./server-tests instead of ./test, create a file at ./test/mocha.opts with just this in the file:


If you wanted to run everything in that folder and subdirectories, put this into test/mocha.opts


mocha.opts are the arguments passed in via the command line, so making the first line just the directory you want to change the tests too will redirect from ./test/

Here's one way, if you have subfolders in your test folder e.g.


Then in linux you can use the find command to list all *.js files recursively and pass it to mocha:

mocha $(find test -name '*.js')