Node.js – How to specify test directory for mocha

mocha.jsnode.jsunit testing

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

Best Answer

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.