Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sadabnepal/graphql-supertest-api
GraphQL API Test framework using TypeScript supertest library and mocha framework
https://github.com/sadabnepal/graphql-supertest-api
graphql graphql-testing mocha supertest supertest-mocha-chai type-utility types typescript
Last synced: 9 days ago
JSON representation
GraphQL API Test framework using TypeScript supertest library and mocha framework
- Host: GitHub
- URL: https://github.com/sadabnepal/graphql-supertest-api
- Owner: sadabnepal
- Created: 2024-05-13T08:34:57.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-06-25T00:40:45.000Z (5 months ago)
- Last Synced: 2024-10-11T22:41:18.421Z (about 1 month ago)
- Topics: graphql, graphql-testing, mocha, supertest, supertest-mocha-chai, type-utility, types, typescript
- Language: HTML
- Homepage:
- Size: 612 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# GraphQL Test Automation framework
Boilerplate graphql test framework using Mocha, SuperTest and TypeScript.### Pre-requisite:
[![NodeJs](https://img.shields.io/badge/-NodeJS-white?logo=node.js)](https://nodejs.org/en/download/)
[![VSCode](https://img.shields.io/badge/-Visual%20Studio%20Code-%233178C6?logo=visual-studio-code)](https://code.visualstudio.com/download)### Getting Started
Clone Repository
```bash
git clone https://github.com/sadabnepal/graphql-supertest-api.git
cd graphql-supertest-api
```Install packages:
```bash
npm install
```Setup user token:
```bash
- 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=`, refer .env.example file
```Setup husky:
```bash
npm run prepare
```Run tests:
```bash
npm run test
```Lint & fix:
```bash
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](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository) 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 saveSample Report
![SampleReport](./assets/report.png)### 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](https://img.shields.io/badge/-GraphQL-E10098?logo=graphql&logoColor=white)](https://www.npmjs.com/package/supertest)
[![SuperTest](https://img.shields.io/badge/-SuperTest-07BA82?logoColor=white)](https://www.npmjs.com/package/supertest)
[![TypeScript](https://img.shields.io/badge/-TypeScript-%233178C6?logo=Typescript&logoColor=black)](https://www.typescriptlang.org/)
[![Mocha](https://img.shields.io/badge/-Mocha-%238D6748?logo=Mocha&logoColor=white)](https://mochajs.org/)
[![ChaiJS](https://img.shields.io/badge/-ChaiJS-FEDABD?logo=Chai&logoColor=black)](https://www.chaijs.com/)
[![GithubActions](https://img.shields.io/badge/github%20actions-%232671E5?logo=githubactions&logoColor=white)](https://github.com/features/actions)
[![ESlint](https://img.shields.io/badge/ESLint-4B3263?logo=eslint&logoColor=white)]([https://www.docker.com/](https://typescript-eslint.io/))
[![Husky](https://img.shields.io/badge/Husky-dbc1ac?logo=gitlab&logoColor=black)]([https://www.docker.com/](https://typicode.github.io/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
- [x] basics of GraphQL (query, mutation)
- [ ] advance topics (fragments, unions, aliases)
- [x] 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)