In this article, we talk about a basic example using Nodejs, Express, Docker, Jest and Sonarqube.

Using the wikipedia explanation “SonarQube is an open source platform developed by SonarSource for continuous code quality inspection, to perform automatic reviews with static code analysis to detect bugs, code odors and security vulnerabilities in over 20 languages. programming.”

For this tutorial, we’ll need:

  • Node/npm
  • Docker

With node and docker installed, let’s start the project

Starting the project

Creating project folder and browsing

mkdir NodeSonarExample

cd ./NodeSonarExample

Starting the project

npm init -y

Installing dependencies

In this session, we will install the dependencies and development dependencies for the project.

  1. Express which allows http requests, widely used in MVC and Restfull applications.
  2. Jest is used to perform unit testing.

npm install — save express jest

  1. sonarqube-scanner is necessary to scan JS code very simply, without needing to install any specific tool or (Java) runtime.
  2. jest-sonar-reporter is a custom results processor for Jest. The processor converts Jest’s output into Sonar’s generic test data format.
  3. supertest we can test http requests for express routes

npm install -D sonarqube-scanner jest-sonar-reporter supertest

Docker Image SonarQube

Let’s start sonarqube by creating the docker-compose.sonar.yml file.

version:  '3'
services:
    sonarqube:
        container_name:  sonarqube
        image:  sonarqube:latest
        ports:
            -  "9000:9000"
            -  "9092:9092"

and execute the file with the command:

docker-compose -f docker-compose.sonar.yml up -d

With sonarqube running, navigate to sonarqube address and authenticate using the default account

login: admin

password: admin

Authenticated, you will notice that there is no project pipeline created as shown in the image below

Simple project example

In this session, I will show the project structure, and all the code involved

#node #sonarqube #jest #nodejs #docker

How to Evaluation Nodejs Code with Jest, SonarQube and Docker
58.70 GEEK