Using Jest for Snapshot testing your React Components

When it comes to testing React components there are plenty of school of thoughts around it. I have been using Airbnb’s Enzyme.js for a while and felt uncomfortable in updating the test specs with ever-changing UI. Then I came across something interesting called Snapshot Testing using Jest. It was also compelling to know that Jest snapshot testing was developed along with the React Developers to make the component testing easier. I do not want to get into a war of words which is better and this post is not intended for it. And the snapshot testing will not replace your unit test, you will still continue to write your unit tests for the business logic. So what Jest does? It creates a serializable react dom tree which can be saved and checked-in along with your code. In later time if you component changes, you can immediately verify whether the change is an intended one or by a mistake. If it is an intended change, you will update the snapshot and check-in the new version otherwise discards the change. Alright, enough theory! Let’s get into some action. I am going to use one the react starter kit library that I have

Continue reading »

How to Dockerize NodeJS web app – part 1

Many teams, companies and companies had a struggle in containerizing their NodeJS web apps. There were many reasons behind it. There are multiple ways to dockerize a NodeJS and we will the some of the efficient ways that worked for me and are running successfully in production. When we were trying to create a docker image for our Node JS based application, we chose to use the official Node docker image (~700MB). On top of that we need to add the node modules, business logic, etc and so on. The final image size was staggering (~1.2GB). It was not what we wanted. Secondly, the average build time to do NPM install and run a grunt task totally took 15 minutes for every build. I am not even talking about the pain of configuring this for different CI/CD pipelines and environments. The initial docker file was looking something like this: #Initial Docker File FROM node:6.10.1-alpine ENV APP_ENV $APP_ENV ENV BINPATH /usr/bin COPY wkhtmltox/bin/wkhtmltopdf /usr/local/bin/ RUN mkdir -p /usr/src/app WORKDIR /usr/src/app/ # Install app dependencies COPY package.json /usr/src/app/ #COPY start.sh /usr/src/app/ RUN npm install –production RUN npm install -g grunt-cli@1.2.0 # Bundle app source COPY . /usr/src/app # Install pm2 so we

Continue reading »