testjavascript / nodejs-integration-tests-best-practices

✅ Beyond the basics of Node.js testing. Including a super-comprehensive best practices list and an example app (March 2024)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Approach API URL, not a JS object. Use Axios, not Supertest

goldbergyoni opened this issue · comments

Approaching URL (with Axios for example) and not relating to 'app' object with supertest is better because:

  • Not coupled to Express
  • Much more popular
  • Allows approaching remote servers as well (e.g. staging, production)

@goldbergyoni
I know this is not critical, but why axios?
I found here a list of alternatives.

More info:

Maybe we should use node-fetch because it's more specific to node?

Axios has x10 more GitHub stars which tells much better about the community trust and popularity. npm downloads is misleading - You may reach to the top based on one person's decision.

Consequently, Axios eco-system is much bigger: If you search in GitHub for "axios" you'll get 26000 lib which has 'axios' in their title, some of them are plugins. Only 1500 are returned for node-fetch.

Practically, search for a circuit breaker or cache plugins - Axios has plugins with almost 1000 stars, the others plugins have much less

https://github.com/jonbern/fetch-retry#readme
https://github.com/softonic/axios-retry