I currently have my NodeJS source files in src
and test suites in test
, e.g.:
/src/bar/baz/foo.js
/test/bar/baz/foo.spec.js
This leads to awkward require statements like var foo = require('../../../src/bar/baz/foo')
. And it's hard to see at a glance which source files are missing tests. I would like to instead keep my test suites in the same directory as the relevant source files:
/src/bar/baz/foo.js
/src/bar/baz/foo.spec.js
But now running mocha --recursive src
causes errors as Mocha tries to run my source files as tests.
I've seen suggestions of using find
or gulp
to filter the file list but I find it surprising that this can't be done with plain Mocha. What's the recommended way of organising files this way?
Just pass the pattern of your test files to mocha, like:
mocha "src/**/*.spec.js"
This is going to run the .spec.js
files in all subdirectories of src
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With