How to specify test directory for mocha?


Mocha tries to find test files under test by default, how do I specify another dir, e.g. server-test?

10/19/2015 1:08:44 PM

Accepted Answer

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/

8/6/2014 1:36:01 AM

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow