Version control checks

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

This lesson preview is part of the Pain Free Mocking with Jest course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to Pain Free Mocking with Jest, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course Pain Free Mocking with Jest
  • [00:00 - 00:10] Keeping tests running on commits is important to catch bugs early. The Husky 2 makes this easy by enabling Git hooks right from your packet.json file.

    [00:11 - 00:18] To get started, let's add Husky as a dependency to our project. Open your terminal and run this command.

    [00:19 - 00:37] We added Husky as a def dependency to our project. Next, we need to configure Husky by running some other commands.

    [00:38 - 03:06] Having run this command, open your packet.json file and in there we need to add some configurations for Husky. We added configuration for Husky, which accepts an object and in the hooks we added a pre-commit which will run our test. We can also add a pre-push which will run every time we push our local changes to the upstream branch. With pre-commit, it will run npm test every time we try to make a git commit. While helpful for quality, we don't want hooks slowing down developer workflow too much. As a tip, only include unit tests in the pre-commit hook since they run very fast and provide instant feedback. Other practices I've seen is to run lintas in the pre-commit hook and run unit tests in the pre-push hook. Let's open our code editor and make a few changes and see how Husky works. I added an assertion that I expect to fail. Expect true to be false, which definitely will fail. I will try to add this to git and make a commit. And we have a failing test which is expected true to be false. When we try to make our commit, the pre-commit hook run our test and if the test fails, the commit will not be successful. While helpful for quality, we don't want hooks slowing down developer workflow too much. As a tip, I advise only including unit tests in pre-commit hook since they run very fast and provide instant feedback. Other practices I've seen is to run lintas in the pre-commit hook and run unit tests in the pre-push hook. Developers have the flexibility to bypass the commit hooks for urgent changes using dash dash no-verify if needed as well. And as you can see, we were able to bypass the it-hook using dash dash no-verify. The CI pipeline that is continuous integration and handle running the lengthier integration and it-to-eat test so commits aren 't blocked or necessary.

    [03:07 - 03:22] In our next lesson, I'll demonstrate setting up a basic CI pipeline using GitHub actions. Combining local Husky hooks with a robust CI pipeline will ensure only stable high quality code, makes it into our repo and production environment.