continuous-integrationtravis-cigithooksgit-husky

Why test in continuous integration if you can test on pre-commit and pre-push git hooks?


What is the point of using a Continuous Integration system to test your code if you already have a system like Husky running that allows you to test you code before pre-commit and pre-push?


Solution

  • Pre-commit and pre-push hooks are great for quick operations and tests. Sometimes you can even setup a hook in your IDE that will run quick unit tests every time you save a file. But usually you have multiple suites of tests and unlike unit tests functional, integration and performance tests often take longer time to run, which is not feasible for hooks.

    Also, you want to run your tests in the same environment where you build your deliverables, which is usually not your local machine.

    Another reason to use CI system is to run post-merge tests to verify that there are no issues introduced by multiple parallel merges.

    All-in-all, the more tests you run, the better and a CI system allows you to run both pre-merge tests usually triggered by some sort of pull request hook and post-merge tests. And all of that in a controlled reliable environment.