The Holy Java

Building the right thing, building it right, fast

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

Posted by Jakub Holý on 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:


4 Responses to “Git pre-commit hook that fails if “it.only” used (Jest/Jasmine)”

  1. xpj said

    We are failing build when somebody left in tests ddescribe and iit 🙂 (we use karma with jasmine). This kind of Git pre-commit hook we are using for forcing prefix of commit messages with Jira Task ID.

    • Hello xpj, thank you for sharing your experience! Can you share your solution for failing build when ddescribe/iit is left in code?

      • xpj said

        We are using maven and we have script next to pom.xml. In pom.xml we configured exec-maven-plugin to run this shell script in the test phase. If this script returns exit code different from 1, build fails.

        Script is simple, just few greps 🙂 But it works really good, only with one exception – multiline comment, but we have some rule, that even multiline comment should be same as single line (/* */ vs. //)

      • xpj said

        Correcting one thing – if script returns exit code different from 0, it fails build…

Sorry, the comment form is closed at this time.

%d bloggers like this: