I'm integrating tests into my Node server and am having some trouble with unit testing. When I run npm test
in my root directory, Mocha automatically runs all tests inside of my test
folder. However, the unit tests which are dispersed throughout the project do not run. How can I ensure that Mocha automatically runs them?
You could modify the npm test
command to find
your test files and run mocha
against them.
Assuming a directory structure like:
project/
src/
test/
main-tests.test.js
things/
test/
thing.test.js
more_things/
more-things.test.js
You would change your package.json
like this:
scripts: {
...
"test": "mocha $(find . -name '*.test.js')"
...
}
There are probably other ways to do this, like specifying the expected glob patterns of the locations of your test files.
Both of these methods require a plain pattern to the names of your test files.
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