With a mocha, how can I run all tests that * don't * have (slow) in the name?

I have a ton of tests, and some of them have "(slow)" in the name:

enter image description here

Some of them are slower than the tests marked (slow), but other tests rely on them and therefore cannot be skipped. I just wanted to skip those with a (slow) in the title, is this possible?

I am using mocha.

+6
source share
3 answers

It seems to me that you are doing this for the page that you load in your browser to launch Mocha. To do this, in the browser, you can pass these parameters to the URL of the page:

  • grep , which roughly matches the --grep option on the command line. This narrows down the tests executed for those that match the expression passed in grep . However, at present (even as of version 2.0.1) there is no way to force Mocha to interpret this parameter as a regular expression. It is always interpreted as a string. That’s why I said β€œroughly matches.” --grep on the command line is a regular expression, but the grep parameter passed in the url is a string.

  • invert that match the --invert option on the command line. This inverts the match executed with grep and thus selects those tests that do not match grep .

So, if you open the page by adding the following line ?grep=(slow)&invert=1 , it will run tests that do not have the line "(slow)" .

+3
source

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

+4
source

Grep accepts a regex pattern, you can do it like this:

 mocha --grep '^(?!.*\\b\(slow\)\\b)' 
+1
source

Source: https://habr.com/ru/post/978131/


All Articles