Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run mocha tests by using a regex for matching on file names?

I am trying to run multiple js tests using mocha. I want to match on filenames using a regex, but according to the documentation you can only use a regex to match on describe blocks. All of my spec files are named *.spec.js, so I would assume I would be able to run just those files easily. Is there a way/plugin that I can match on the filenames that end in .spec.js?

like image 792
jhamm Avatar asked Oct 28 '25 10:10

jhamm


1 Answers

You can pass a glob expression to mocha like this:

mocha *.spec.js

If you do not specify a glob it defaults to mocha test/*.js.

The regexp you are refering to is the "grep" option which works on test names.

like image 66
mantoni Avatar answered Oct 30 '25 00:10

mantoni