kapilsethi / poc-api-testing-with-node-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

What's in this repository

How to use this repository:

Prerequisite:

  • Need to have
  • node.js (version "^v17.8.0")
  • Rancher desktop (can be downloaded from rancher website)
  • docker (if on mac run brew install docker)
  • docker compose (if on mac run brew install docker-compose)

installed on the local machine

Setup:

  • Run 'npm install' command

API key:

Setting up environment variables:

  • Rename '.env.example' file to '.env'
  • Update API_KEY value in '.env' file

Using linting utility:

  • Run 'npm run lint' command to run eslint

Starting wiremock:

  • run npm run start:mock:server to start the wiremock (should be able to see wiremock test data on wiremock mappping page url) OR
  • Download wiremock standalone JAR from here
  • start the wiremock in standalone mode using 'java -jar wiremock-standalone-<version>.jar --port 9000'

Stopping wiremock:

  • run npm run stop:mock:server to stop the wiremock

Running tests:

  • Run 'npm run test:mock' command to run all the tests against mock
  • Run 'npm run test:prod' command to run all the tests against prod
  • Run npm run generate:report command to open html report of the test execution results

Test execution report:

  • Test execution report can be found in './mochawesome-report'

Features:

  • Test framework:

    • Jest
  • Reporting framework:

    • Jest html reporters
  • HTTP client:

  • CI:

    • Travis CI
  • Mock:

    • Wiremock docker image
  • Linting Utility:

    • ESLint (extends typescript recommened rules. Details can be found here)
  • Pre-Commit hook:

    • pre-commit npm package to run linting utility before commit

Example API:

Troubleshooting:

Error: If getting error.code: ECONNREFUSED error when running tests against mock then

  • update the base url with ip instead of localhost in test-data.json file

"baseUrl": "http://<ip-of-the-machine>:9000/",


for more details refer to following stackoverflow pages

Have a feedback?

If you have any feedback or question, please email me at kapil.sethi9+github@gmail.com

About


Languages

Language:TypeScript 97.5%Language:JavaScript 2.5%