Code Snippets

Pre-commit hook for behat tests

If you are working on small project and you’re using Behat tests, there will be times when you change code and as consequence of that, introduce a bug or break a feature. And more often than that, because we are humans and we forget to do things all the time, you will not run your functional ( in my case Behat ) tests, so bug will go live.

So in order to automate that i created a pre-commit hook that runs Behat test and then rejects commit if they fail.

#!/bin/sh


if behat --config=behat.yml | grep -q 'Failed\ scenarios\:'; then

    echo "\033[0;31mYou have failing Behat scenarios, therefore commit is rejected\033[0m"

    exit 1

fi

Git hooks are located in your .git directory and you can have your own bash code executed on every git event you choose, pre or post event.

Feel free to play with this little script and improve it as it pleases your needs.

P.S. If you want to skip this check then you can commit your code with

git commit --no-verify

 

​Read More
Code Snippets

Long-term caching with Webpack

I am going to show you simple way to cache public files. Using this configuration bellow, we are instructing our server and browser to cache the file for as long as possible.

​Read More
Code Snippets

Webpack Basics Explained

I am primarily a backend developer, but I love fiddling with Javascript. Yeah I know, that’s strange, but I don’t find annoying to sometimes write some CSS or some frontend logic in JS. But I had a problem. I haven’t had any chance to develop anything on fronted for couple of years. Before that I was writing all logic in JQuery, using simple pattern: When Event happens Do something.

​Read More