Reputation: 43
I have a problem with mocha, it does not understand my test hierarchy! I want my tests to be near their codebase, so I have some hierarchy like this in my project:
Level1
|_ level11
|_ level11.js
|_ level11.test.js
|_ level11111
|_ level11111.js
|_ level11111.test.js
|_ level12
|_ level12.js
|_ level12.test.js
|_ level121
|_ level121.js
|_ level121.test.js
Level2
|_ level2.js
|_ level2.test.js
I have tried everything! Using **/**.test.js
or —recursive
flag, non of them do what it should do!
Upvotes: 3
Views: 507
Reputation: 991
Linux to rescue! I had the same problem in a HUGE project that literally had no structure at all! Some developers had put tests in tests
folder and some other in nested layers and … (some tests were using mocha and some using jest! In the SAME project! :D)
you can use:
mocha $(find . -name '*.spec.js')
in your package.json
so:
"scripts": {
"test": "mocha $(find . -name '*.spec.js')"
},
Upvotes: 1
Reputation: 772
Configure your .mocharc.js
file to allow running recursive tests as below:
module.exports = {
"recursive": true,
"exit": true,
"timeout": "10000",
"ignore": ["test/Helpers/*.js", "test/Samples/*.js", "test/Helpers/**/"],
"reporter": "mochawesome",
"reporterOptions": {
"reportDir": "mocha"
}
};
Upvotes: 0
Reputation: 16294
You need to use recursive
with the extension
flag:
mocha --extension .test.js --recursive
Just read the documentation for --extension and --recursive for more.
Upvotes: 0