Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular: How to force run unit tests when running Git push?

I have seen Angular projects in which the unit tests are run every time a build is executed and also when running the git push command. If any tests fail during either command, the process does not execute until all your unit tests pass or unless you bypass. I would like to have this kind of set up for my project as best practice. Please help :)

like image 973
B Snow Avatar asked Sep 18 '18 18:09

B Snow


2 Answers

To run builds, unit tests, etc before a commit or a push you can use a tool like Husky.

like image 80
Ruben Vermeulen Avatar answered Nov 13 '22 13:11

Ruben Vermeulen


Git provides a methodology to hook it's events using .git/hooks

you can add a folder to your project called .git/hooks and within that folder add a subfolder called pre-commit and within that you may place scripts that are to be ran. This being whatever your test command is.

For example test.sh would contain: ng test

More documentation about hooking git events can be found here: https://git-scm.com/docs/githooks

Let me know if you have any questions, I would be happy to revise my answer!

like image 3
Danoweb Avatar answered Nov 13 '22 15:11

Danoweb