How to specify test directory for mocha?
Edit : This option is deprecated : https://mochajs.org/#mochaopts
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:
server-tests
If you wanted to run everything in that folder and subdirectories, put this into test/mocha.opts
server-tests
--recursive
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/
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.
Here's one way, if you have subfolders in your test folder e.g.
/test
/test/server-test
/test/other-test
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')