Skip to main content

Posts

Showing posts from 2018

Run MochaJS Tests Recursively

I've been doing a lot of NodeJS lately and one thing I always forget is how to run Mocha recursively. To run all test recursively update your package.json to include the following { "scripts" : { "test" : "mocha --recursive './{,!(web|node_modules)/**/}*.spec.js'" }, } to run the tests, run the following command from where package.json is stored npm test or yarn test The test entry in the package.json file will run MochaJS recursively on all directories except web and node_modules directories, and run the tests in any file that ends with the extension .spec.js Excluding the node_modules directory is a good idea because you don't need to run the tests of your installed packages and when you have a lot of packages installed it can slow down your test suite. If you're using windows you might need to use double quotes instead of single quotes. For example "test" : "mocha --recursive \" ./{,!(web