3

Git pre-commit hook that fails if "it.only" used (Jest/Jasmine)

 2 years ago
source link: https://blog.jakubholy.net/2015/03/27/git-pre-commit-hook-that-fails-if-it-only-used-jestjasmine/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Git pre-commit hook that fails if "it.only" used (Jest/Jasmine)

March 27, 2015

One of the annoying things with Jest is that while it enables you to run only a single test by using it.only, it does not report this in any noticeable way. Thus you can end up in the same situation as we did, not running many tests without knowing it. (Oh yeah, if we only did review the code properly ...).

This git pre-commit hook will fail when you introduce it.only into the code:

#!/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>&2ADDED_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 1fi


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK