Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Git pre-commit hook that fails for changes introducing Jest/Jasmine's exclusive tests using "it.only"
# A git pre-commit hook that verifies that the change does not introduce
# the use of a Jest/Jasmine exclusive test via 'it.only(..)', which would
# prevent most other tests from being run without any clear indication thereof
# Redirect output to stderr.
exec 1>&2
ADDED_IT_ONLY=$(git diff -U0 --cached -S"(\W|^)it\.only\s+?\(" --pickaxe-regex | egrep "(^\+.*it.only)|\+{3}")
if [ -n "$ADDED_IT_ONLY" ]; then
echo "PRE-COMIT CHECK FAILED: You have added calls to it.only(..) thus preventing other tests from running, please fix: $ADDED_IT_ONLY"
exit 1

This comment has been minimized.

Copy link

commented Oct 15, 2015

Thanks a lot for that simple and elegant solution! I adapted it to my needs. Just out of curiosity the regex you are using doesn't "+?" behave the same way as "*" would have?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.