I've been struggling with this lately (probably due to my lack of experience with node.js), but eventually I got it working.
It's even set up in BitBucket CI, in such a way that the tests are automatically performed when I make a PR. Unfortunately the repository is private, or I would send you a link.
Anyway, in package.json, I got this:
{
"name": "MyProject",
...
"directories": {
"test": "test"
},
"scripts": {
"test": "mocha -u bdd test"
}
With the proper dependencies of course. -u bdd
is just to set the user interface/api style.
The test
subfolder of the project contains a bunch of JavaScript files named test-whatever.js
each with a describe
of a test suite. When I run npm test
, this config will scrape the directory and run the tests in each of the files.
I can't find where I found this solution, though. There is a similar question, but this answer isn't in there. Also Mocha's website suggests that test
is actually a list of files, so maybe Mocha is just smart at finding files when you specify a part of the file name, a directory name, or a mask with wildcards.