Socket
Book a DemoInstallSign in
Socket

axios-record-replay-adapter

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-record-replay-adapter

Sit back, relax, and enjoy automatic mocking for axios HTTP requests

1.1.1
latest
Source
npmnpm
Version published
Weekly downloads
2
-86.67%
Maintainers
1
Weekly downloads
 
Created
Source

axios-record-replay-adapter 🎥 🎬 🍿

npm version npm downloads styled with prettier build status

Sit back, relax, and enjoy automatic mocking for axios HTTP requests

Table of contents

Installation

yarn

yarn add axios
yarn add axios-record-replay-adapter --dev

npm

npm i axios --save
npm i axios-record-replay-adapter --save-dev

Setup

Ignore recordings directory

When running tests in watch mode, the recordings directory must be ignored to prevent recording files from triggering tests to re-run.

Jest

{
  "jest": {
    "watchPathIgnorePatterns": [
      "<rootDir>/recordings"
    ]
  }
}

Usage

With defaults

useAxiosRecordReplayAdapter()

With options

const customAxiosIntance = axios.create()
useAxiosRecordReplayAdapter({
  axiosInstance: customAxiosInstance
  recordingsDir: './tests/recordings'
})

Restore axios default adapter

axios-record-replay-adpater returns a function to restore the default axios adapter.

const restoreDefaultAdapater = useAxiosRecordReplay()
restoreDefaultAdapater()

Advanced usage

With buildRequest()

useAxiosRecordReplayAdapter({
  buildRequest(axiosRequestConfig) {
    return {
      path: new URL(axiosRequestConfig.url).pathname
    }
  }
})

With buildResponse()

useAxiosRecordReplayAdapter({
  buildResponse(axiosResponse) {
    return {
      data: axiosResponse.data
    }
  }
})

With buildFilenamePrefix()

NOTE: The result of buildRequest() gets passed to buildFilenamePrefix(request)

useAxiosRecordReplayAdapter({
  buildFilenamePrefix(requestFromBuildRequest) {
    return request.path.replace(/\//g, '-').slice(1)
  }
})

Contributing

  • Fork this repository to your own GitHub account and then clone it to your local device
  • Install the dependecies using yarn
  • Link the package to the global module directory: yarn link
  • Run yarn test --watch and start making your changes
  • You can use yarn link axios-record-replay-adapter to test your changes in a local project
  • Ensure any changes are documented in CHANGELOG.md

License

MIT © Brent Mealhouse

FAQs

Package last updated on 28 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.