node.jsnodeunit

How to get nodeunit to detect and run tests included in subfolders?


I have the following folder structure to my nodeunit tests for a particular project:

/tests
/tests/basic-test.js
/tests/models/
/tests/models/model1-tests.js
/tests/models/model2-tests.js

My question is - how do I get nodeunit to automatically execute ALL of the tests in the tests folder, including the sub-directories contained within?

If I execute nodeunit tests it only executes basic-test.js and skips everything in the sub-folders by default.


Solution

  • Use make based magic (or shell based magic).

    test: 
        nodeunit $(shell find ./tests -name \*.js)
    

    Here your passing the result of running find ./tests -name \*.js to nodeunit which should run all javascript tests recursively