-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Elevating React Web Development with Gatsby
A Git hook is a method that fires on common Git commands. We can use this method to invoke custom scripts when we commit or push our code. It is common practice to use these hooks to run checks against your repository to ensure that the code that is being added does not break application functionality. One valuable check we could add is to run our applications unit tests before we push our code, and if they fail, we can stop the push. By implementing this feature, it's unlikely that the code being pushed will break any functionality we test for.
Let's implement this functionality now by creating a Git hook that is triggered by a git push. This will ensure our unit tests pass before allowing the push command to run. We will be using the husky package to do this as it is easy to set up and maintain:
npm install husky --save-dev
postinstall script in your package.json file with the following...