How to specify test directory for mocha?

后端 未结 14 1665
走了就别回头了
走了就别回头了 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:29

    Don't use the -g or --grep option, that pattern operates on the name of the test inside of it(), not the filesystem. The current documentation is misleading and/or outright wrong concerning this. To limit the entire command to a portion of the filesystem, you can pass a pattern as the last argument (its not a flag).

    For example, this command will set your reporter to spec but will only test js files immediately inside of the server-test directory:

    mocha --reporter spec server-test/*.js
    

    This command will do the same as above, plus it will only run the test cases where the it() string/definition of a test begins with "Fnord:":

    mocha --reporter spec --grep "Fnord:" server-test/*.js
    

提交回复
热议问题