DEV Community

Cover image for Learn How to Test Serverless Applications
Pavan Belagatti
Pavan Belagatti

Posted on • Edited on

Learn How to Test Serverless Applications

Serverless has revolutionized the way applications are developed and deployed. With serverless architecture, developers can build and run applications without worrying about the underlying infrastructure. Node.js, a popular open-source platform, has become a go-to choice for building serverless applications due to its flexibility and scalability. Node.js helps developers build serverless applications quickly and efficiently. It offers an event-driven, non-blocking I/O model that makes it lightweight and ideal for microservices architecture. With Node.js, developers can build event-driven applications that can handle a large number of requests at once. It also offers a rich set of modules and libraries that make it easy to build complex serverless applications.

Today, we will see how to build an automated continuous integration pipeline to test our sample Node.js serverless application. Let's go!

Prerequisites

Tutorial

First, sign in to your Harness account. Harness is a continuous delivery platform.
signup Harness

Get started with creating your first pipeline
first pipeline

Authenticate with your GitHub account as your application code is present there.
add github

authenticate with GitHub

Select your application repository. The serverless application you forked above.
serverless application

Select 'Node.js' from the list and start configuring the pipeline. The right side in the below screenshot you see is a default yaml configuration of your pipeline.
default yaml

Once you continue, you will land on the pipeline studio which looks as below
build node app

Under the execution, click 'Build Node App' and you will see the default settings and commands.
Build Node App

The commands you see are below,

echo "Welcome to Harness CI"
node --version
npm install
npm run build --if-present
npm test
Enter fullscreen mode Exit fullscreen mode

You can modify and retain only the last three commands if you want.

Apply changes, save everything and run the pipeline.
run pipeline

You should see a successful pipeline execution.
successful pipeline

Switch to the console view and you should see what's happening in each stage.
console view

Your pipeline is all automated to run tests whenever any developer pushes code to the main branch.
You can verify this by going to the 'Triggers' tab from the pipeline studio.
Triggers tab

You can see push and pull triggers already configured for you.
push pull triggers

Let's push some code to the main branch.
As soon as you push the code, the build gets triggered and you can see the same below.
pipeline triggeredcode triggered CI

Congratulations! We have successfully configured a simple continuous integration pipeline for a sample Node.js serverless application.

If you like to learn a step-by-step CI/CD set-up, take a look at my complete CI/CD tutorial.

Top comments (0)