In my Jasmine-Node spec_helper I have require("../app/test") and it pulls in that test file just fine. But if I try require("../app/*"), I get Error: Cannot find module '../app/*'.
Is there a way to pull in all the files/sub-dirs of a directory like this?
There are a few ways to accomplish what you want, the easiest probably being to create an
index.jsin your./appdirectory. Thisindex.jswould in turn reference all the modules inside that directory, and export them:If you want to do it dynamically, you will have to write some code:
For more info on how node loads modules, here’s the relevant docs and about folders as modules in particular.
Unfortunately, Jed’s answer here is wrong.