sadabnepal / supertest-ts-mocha-api-test

Boilerplate API test framework using Mocha, SuperTest, TypeScript and ReportPortal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

API Test Automation framework

Boilerplate API test framework using Mocha, SuperTest and TypeScript.

Pre-requisite:

NodeJs VSCode

Getting Started:

Clone Repository

git https://github.com/sadabnepal/supertest-ts-mocha-api-test.git
cd supertest-ts-mocha-api-test

Install the dependencies

npm install

Setup user token

- Open the URL 'https://gorest.co.in/'
- Login or Sign
- Click on Login user drop down --> Access Token
- Create .env file and add actual token, refer .env.example file

Run tests

npm test
npm run test:rp [ to capture test results in report portal ]

Report Path:

path: <PROJECT_FOLDER>/report/index.html

Docker Run:

Setup docker in your local machine to run test in dockerize environment

docker build -t node-api-image . [ you can given any name of your choice ]
docker run node-api-image:latest [ to run test inside docker ]

Run in Github Actions

Currently test is setup to execute in github action on push event. You need to create github secrete for GO_RES_USER_TOKEN with value generated in Setup user token step.

Github Permission to update report: Go to Repository -> Settings -> Actions -> General
Scroll to bottom of the page and look for 'Workflow permissions' section
Check 'Read and write permission' and click on save

Report Portal Integration

  • Setup: run below two command to spin up report portal instance locally with docker (read more https://reportportal.io/installation)
  • Login: Open http://localhost:8080/ and login with time user superadmin and password erebus
  • Generate API key:
    • Click on bottom left of logged in user --> click on Profile
    • Click on API KEYS --> Generate API Key --> copy the generated key
    • Create .env file in root project folder. Refer .env.example file
    • Paste your API key into .env file as REPORT_PORTAL_KEY=<your api key>
  • Enter REPORT_PORTAL_PROJECT=<project_assignment> into .env. Value can be found on PROJECT ASSIGNMENT tab of user profile
  • Other details are updated in reportPortal.js file

docker_run

Features:

- Supertest library
- Mocha framework to organize tests
- Mochawesome report integration with logs
- Custom types for better code intellisense
- Service as enum for better input control
- Schema validation
- Multi environment support 
- Docker and Github integration
- Enhanced import statements
- Request and response report logger
- Lint for better code quality
- Husky for auto lint check before code commit
- Manage secretes using dotenv library
- Runtime dynamic test data generation using faker js library
- AI powered Report Portal integration

Tech stacks:

SuperTest TypeScript Mocha ChaiJS GithubActions Docker ESlint Husky

Folder Structure:

├───.github
├───.husky
├───.vscode
├───src
|     ├───data
|     ├───env
|     ├───helper
|     ├───schema
|     ├───services
|     ├───static
|     ├───test
|     └───types
├───.env.example
├───.eslintrc.js
├───.gitignore
├───.mocharc.js
├───Dockerfile
├───package-lock.json
├───package.json
├───README.md
└───tsconfig.json

Sample Report

SampleReport

About

Boilerplate API test framework using Mocha, SuperTest, TypeScript and ReportPortal


Languages

Language:HTML 98.1%Language:TypeScript 1.3%Language:JavaScript 0.5%Language:Dockerfile 0.0%