Skip to content

Instantly share code, notes, and snippets.

@KleaTech
Last active March 31, 2023 14:28
Show Gist options
  • Save KleaTech/91123138faeaf0fefbf24a0eaa21df8c to your computer and use it in GitHub Desktop.
Save KleaTech/91123138faeaf0fefbf24a0eaa21df8c to your computer and use it in GitHub Desktop.
Run only tests that has .only or all of them if there's no .only
grep --exclude-dir=node_modules -rl . -e 'test.only\|it.only\|describe.only' --null | tr '\n' ' ' | xargs -0 npx jest | grep . || npx jest
clear && grep --exclude-dir=node_modules -rl . -e 'test.only\|it.only\|describe.only' --null | tr '\n' ' ' | xargs -0 npx jest --coverage=false
@einSelbst
Copy link

einSelbst commented Jan 31, 2023

Nice, it even works with --watch. Unfortunately it removes the colours from the output in iterm2 on mac.

Edit: If I ctrl-c once instead of stopping it it re-runs it but with coloured output. Great.

@KleaTech
Copy link
Author

That's weird. I'm using M1 Macbook Pro with default terminal, colors and ctrl-c works as expected. Maybe it's related to the ending | grep . || npx jest. That's a workaround because xterm should run once even with empty input, but it does not run on my machine. Maybe you can try with just
grep --exclude-dir=node_modules -rl . -e 'test.only\|it.only\|describe.only' --null | tr '\n' ' ' | xargs -0 npx jest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment