cypress icon indicating copy to clipboard operation
cypress copied to clipboard

refactor: begin to use axios for cloud api requests

Open cacieprins opened this issue 3 weeks ago • 0 comments

  • Closes

Additional details

As a first step in removing @cypress/request, this shifts the API call to create an instance to Axios.

  • Because of how we modify dependencies in situ for v8 snapshots, Axios needed to be patched. This patch forces Axios into server-mode.
  • Logging is handled as an Axios middleware
  • Error transforms are handled as an Axios middleware. To aid with DRY, this function is defined in such a way as to be used with older API request definitions.
  • createInstance is moved to its own file and isolated from the statefulness of the main api/index.ts file
  • Type definitions are introduced for the request initiator, to aid with typescript migrations
  • retries are handled with the asyncRetry util. axios-retry was considered, but the additional package size and complications regarding overriding behavior for POSTs made it untimely.
  • Additional tests were introduced for the middleware. The existing integration tests suffice for this refactor. More closely unit testing this module in isolation is rather difficult with the test harness in @packages/server, but should be considered a TODO if we migrate to vitest.

Note: while this request is a POST, and POSTs are not typically retry-able, this endpoint is now idempotent. Retries are enabled in order to improve resiliency to network splits, etc.

Steps to test

How has the user experience changed?

PR Tasks

cacieprins avatar Feb 06 '25 20:02 cacieprins