How to specify test directory for mocha?

后端 未结 14 1674
走了就别回头了
走了就别回头了 2020-12-04 05:59

Mocha tries to find test files under test by default, how do I specify another dir, e.g. server-test?

14条回答
  •  青春惊慌失措
    2020-12-04 06:19

    As @jeff-dickey suggested, in the root of your project, make a folder called test. In that folder, make a file called mocha.opts. Now where I try to improve on Jeff's answer, what worked for me was instead of specifying the name of just one test folder, I specified a pattern to find all tests to run in my project by adding this line:

    */tests/*.js --recursive in mocha.opts

    If you instead want to specify the exact folders to look for tests in, I did something like this:

    shared/tests/*.js --recursive
    server/tests/graph/*.js --recursive
    

    I hope this helps anyone who needed more than what the other answers provide

提交回复
热议问题