Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure mocha to find all test files recursively?

How can I configure mocha to find all test files in my project directory and not only the test files at the test folder in the root directory?

currently, I'm using npm scripts in package.json:

"test": "mocha"

and running using the following command:

npm run test
like image 979
Yair Nevet Avatar asked Mar 26 '18 17:03

Yair Nevet


2 Answers

To find all test files in your src directory, say, then you should be able to use a pattern like this:

mocha "src/**/*.test.js"

...and make sure your test files have a .test.js file extension so they differ from your other .js files.

(Note the double quotes around the pattern)

like image 101
Steve Holgado Avatar answered Oct 26 '22 23:10

Steve Holgado


this works for me, finding all test files in all directories except the node_modules

mocha \"./{,!(node_modules)/**/}*.test.js\"

for clarification, this glop expression says:

Take all files which end with .test.js in the current directory - which is the root - or in any subdirectory of the current directory, regardless of depth, except for ones that exists in ./node_modules folder.

like image 32
Fawzi Avatar answered Oct 27 '22 00:10

Fawzi