Organizing mocha tests in subdirectories
I got tired of having all my mocha tests in one massive directory. I wanted to organize them a bit better.
Before, I would simply run this command
Pretty straight-forward. That won’t hit your subfolders though. Say your structure was like this:
|
|
The above mocha
command would run only two tests! Not cool. This was discussed in the mocha project here: https://github.com/mochajs/mocha/issues/106
TJH and others pointed out you can just pass the files to mocha as a group. Here’s the command:
|
|
This command finds all js
files anywhere in the test
directory. They can be deep in subfolders. Yay!
Now, I don’t want to type that every time. We can take advantage of NPM’s package.js
file and add a script entry for tests.
|
|
Here it is in context
Now to run my tests, I can simply type