Reputation: 8433
I have a load of tests, and some of them have "(slow)" in the name:
Some of them are slower than the tests marked (slow), but are relied on by other tests and so cannot be skipped. I would just like to skip the ones with (slow) in the name—is that possible?
I'm using Mocha.
Upvotes: 9
Views: 3943
Reputation: 7037
mocha --opts mocha.opts --grep "^(?!.*SomeExpression)"
I couldn't add parenthesis to the expression - bash / mocha fails. I suggest you to remove the parenthesis and put a tag like @performance in the descriptions and execute mocha with a grep expression like previous one.
Upvotes: 0
Reputation: 151391
It looks to me like you are doing it for a page you are loading in a browser to run Mocha. To do this in the browser you can pass these parameters in the URL of the page:
grep
which approximately corresponds to the --grep
option on the command line. This narrows the tests run to those that match the expression passed to grep
. However, there is currently (even as of 2.0.1) no way to get Mocha to interpret this parameter as a regular expression. It is always interpreted as a string. That's why I said "approximately corresponds". --grep
on the command line is a regular expression but the grep
parameter passed in a URL is a string.
invert
which correspond to the --invert
option on the command line. This will invert the match performed by grep
and thus selects the tests that grep
does not match.
So if you open you page by appending the following string ?grep=(slow)&invert=1
it will run the tests that do not have the string "(slow)"
in them.
Upvotes: 6
Reputation: 37137
Grep accepts a regex pattern, you can do it like this:
mocha --grep '^(?!.*\\b\(slow\)\\b)'
Upvotes: 4
Reputation: 1622
You can do this with a combination of two command line switches. Here is the relevant part of the documentation:
-g, --grep <pattern> only run tests matching <pattern>
-i, --invert inverts --grep matches
Upvotes: 6