Skip to content

GraphQL API Test framework using TypeScript supertest library and mocha framework

Notifications You must be signed in to change notification settings

sadabnepal/graphql-supertest-api

Repository files navigation

GraphQL Test Automation framework

Boilerplate graphql test framework using Mocha, SuperTest and TypeScript.

Pre-requisite:

NodeJs VSCode

Getting Started

Clone Repository

git clone https://github.com/sadabnepal/graphql-supertest-api.git
cd graphql-supertest-api

Install packages:

npm install

Setup user token:

- Open the URL 'https://gorest.co.in/'
- Login or Sign
- Click on Login user drop down --> Access Token --> Copy token
- Create .env file in root project folder
- paster actual token `GO_RES_USER_TOKEN=<your_token_goes_here>`, refer .env.example file

Setup husky:

npm run prepare

Run tests:

npm run test

Lint & fix:

npm run lint
npm run lint:fix

Github Actions :

Currently test is setup to execute in github action on push event. You need to create github secrete with name API_TOKEN and 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

Sample Report SampleReport

Features:

- Supertest library
- Mocha framework to organize tests
- Mochawesome report integration with logs
- Custom types for better code intellisense
- Github Action integration
- 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

Tech stacks:

GraphQL SuperTest TypeScript Mocha ChaiJS GithubActions ESlint Husky

learning references:

topic references
GraphQL https://graphql.org/learn
SuperTest https://github.com/ladjs/supertest#readme
Mocha https://ricostacruz.com/mocha/
Mocha config https://github.com/mochajs/mocha/tree/master/example/config
TS style guide https://google.github.io/styleguide/tsguide.html
ChaiJs https://www.chaijs.com
Mochawesome https://github.com/adamgruber/mochawesome
DotEnv https://www.npmjs.com/package/dotenv
Eslint https://eslint.org/docs/latest/use/getting-started
Husky https://typicode.github.io/husky/
VScode settings https://code.visualstudio.com/docs/getstarted/settings

GraphQL Topics to Explore

  • basics of GraphQL (query, mutation)
  • advance topics (fragments, unions, aliases)
  • filters using arguments, variables, directive
  • setting default variable
  • variables inside fragments
  • use of directive to build dynamic/reusable query
  • fields in query vs fields in mutation
  • inline fragments (unions)
  • meta fields (fetch type of field __typename)

About

GraphQL API Test framework using TypeScript supertest library and mocha framework

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published