Created
March 27, 2015 20:03
-
-
Save holyjak/53e9b514112e9dc1b2f5 to your computer and use it in GitHub Desktop.
Git pre-commit hook that fails for changes introducing Jest/Jasmine's exclusive tests using "it.only"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# 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 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?