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.
According to it, tests are run synchronously. This only shows that ordered code is run in order. That doesn't happen by accident.
Run a Single Test File Using the mocha cli, you can easily specify an exact or wildcarded pattern that you want to run. This is accomplished with the grep option when running the mocha command. The spec must have some describe or it that matches the grep pattern, as in: describe('api', _ => { // ... })
Retrying Mocha. Mocha. js provides a this. retries() function that allows you specify the number of times a failed test can be retried. For each retry, Mocha reruns the beforeEach() and afterEach() hooks but not the before() and after() hooks.
Mocha does not run individual tests in parallel. If you only have one test file, you'll be penalized for using parallel mode.
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.
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
Grep accepts a regex pattern, you can do it like this:
mocha --grep '^(?!.*\\b\(slow\)\\b)'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With