Dycey
Dycey

Reputation: 4685

How do I exclude files from a jest cli command?

Is there a jest equivalent, or a way of doing it in bash, to the git regex approach for including files that match one regex (all files in the /tests folder), but then exclude any that match a second (any test files that include API in the name)? e.g.

git ls-files -- 'tests' ':!:*API*'

I would like to do it as single line command because I want to be able to run all the tests in the /tests directory, but in two mutually exclusive sets using a single yarn test script from my package.json file.


EDIT: Expanding on Brenda J. Butler's answer:

yarn jest `find tests -type f ! -name \*API\* | grep -v .DS_`
  1. Realising that jest can take either a regex OR a file list,
  2. using backticks to do a bash substitution, and
  3. additionally, as this is on MacOS, using a grep -v to also pull out the .DS_Store from the file list.

Upvotes: 0

Views: 813

Answers (1)

Brenda J. Butler
Brenda J. Butler

Reputation: 1485

bash:

# finding files under tests whose names don't contain API
$ find tests -type f ! -name \*API\*

# finding files under tests whose names contain API
$ find tests -type f -name \*API\*

Upvotes: 1

Related Questions