{"id":24530607,"url":"https://github.com/crisvp/axios-vcr2","last_synced_at":"2025-03-15T18:42:03.797Z","repository":{"id":58745381,"uuid":"533412992","full_name":"crisvp/axios-vcr2","owner":"crisvp","description":"Record and play back Axios HTTP interactions","archived":false,"fork":false,"pushed_at":"2023-03-06T14:15:11.000Z","size":373,"stargazers_count":0,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-07T17:59:18.670Z","etag":null,"topics":["axios","qa","test","testing","vcr"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/axios-vcr2","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crisvp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-06T16:35:56.000Z","updated_at":"2022-09-07T14:56:34.000Z","dependencies_parsed_at":"2023-02-12T23:31:10.191Z","dependency_job_id":null,"html_url":"https://github.com/crisvp/axios-vcr2","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crisvp%2Faxios-vcr2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crisvp%2Faxios-vcr2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crisvp%2Faxios-vcr2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crisvp%2Faxios-vcr2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crisvp","download_url":"https://codeload.github.com/crisvp/axios-vcr2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243776406,"owners_count":20346350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["axios","qa","test","testing","vcr"],"created_at":"2025-01-22T08:16:54.395Z","updated_at":"2025-03-15T18:42:03.777Z","avatar_url":"https://github.com/crisvp.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# axios-vcr2\n\n[![Contributors][contributors-shield]][contributors-url]\n[![Forks][forks-shield]][forks-url]\n[![Stargazers][stars-shield]][stars-url]\n[![Issues][issues-shield]][issues-url]\n[![MIT License][license-shield]][license-url]\n\n[![Tests][gh-build-shield]][gh-build-url]\n[![NPM][npm-shield]][npm-url]\n\n[![LinkedIn][linkedin-shield]][linkedin-url]\n\n## About The Project\n\nThis is a library intended to mock HTTP responses in node - specifically [jest](https://github.com/facebook/jest) or similar testing frameworks.\n\nIt is intended to be easy to use: mount a cassette, record a session, and play it back on subsequent requests, recording only exactly what you want and need without hooking into the global node libraries.\n\nIf you are looking for something more powerful, try [nock](https://github.com/nock/nock) instead.\n\nThis is primarily a TypeScript rewrite of [axios-vcr](https://github.com/nettofarah/axios-vcr), addressing some small bugs and adding the ability to use custom Axios instances.\n\n## Getting Started\n\n### Prerequisites\n\nYou will need a package manager of your choice, and you will probably want to use this in some testing framework.\nThere is no dependency on any specific framework - you can use this package in any node environment.\n\n* yarn\n\n  ```sh\n  npm install yarn@latest -g\n  ```\n\n* axios\n\n  ```sh  \n  yarn add axios@latest\n  ```\n\n### Installation\n\n* axios-vcr2\n\n  ```sh\n  yarn add -D axios-vcr2\n  ```\n\n## Usage\n\n### Basic usage\n\n```TypeScript\n  import axios from \"axios\";\n  import { mountCassette, ejectCassette } from \"axios-vcr2\";\n\n  mountCassette(\"myCassettes.json\");\n  // Record the request the first time this line runs\n  // Next time you run this file, the request will be played back.\n  axios.get(\"http://www.example.com/\");\n\n  // After ejecting the cassette, requests will not be recorded.\n  ejectCassette(\"myCassettes.json\");\n  \n  axios.get(\"http://www.example.com/\"); // \u003c- not recorded/played back\n```\n\n### Advanced usage\n\nIt is possible to use custom axios instances, use more than one cassette, and/or to specify custom matchers.\n\n```TypeScript\n  import axios, { AxiosRequestConfig } from \"axios\";\n  import { mountCassette, ejectCassette } from \"axios-vcr2\";\n\n  const myAxios = axios.create();\n\n  // This matcher looks at the method and URL. This is very similar to\n  // the `defaultMatcher` included with this package.\n  function exampleMatcher(requestConfig: AxiosRequestConfig): string {\n    const { baseURL, method } = config;\n    const url = config.baseURL ? new URL(url, config.baseURL).toString() : config.url;\n\n    // This can be any string. It will be used as the cassette id, to match subsequent\n    // requests. The matchers included with this package use md5 to hash a processed object.\n    // Return 'null' not to save the request in this file.\n    //\n    // This matcher only returns IDs for URLs matching example.com\n    return url.includes(\"example.com\") ? `${method}:${url}` : null;\n  }\n\n  // This matcher only returns IDs for URLs matching askjeeves.com\n  function jeevesMatcher(requestConfig: AxiosRequestConfig): string {\n    const { baseURL, method } = config;\n    const url = config.baseURL ? new URL(url, config.baseURL).toString() : config.url;\n    return url.includes(\"askjeeves.com\") ? `${method}:${url}` : null;\n  }\n\n  mountCassette(\"example.com.json\", myAxios, exampleMatcher);\n  mountCassette(\"askjeeves.com.json\", myAxios, jeevesMatcher);\n\n  // Two files will be created; example.com.json containing 2 requests to example.com,\n  // and askjeeves.com.json containing 1 request to askjeeves.com\n  myAxios.get(\"http://www.example.com/\");\n  myAxios.post(\"http://www.example.com/\", { a: 1 }); \n  myAxios.get(\"http://www.askjeeves.com/\");\n```\n\n## Development\n\n### testing\n\n```sh\nyarn test\n```\n\n### Debugging\n\nThis package uses [debug](https://github.com/debug-js/debug). To enable debugging, set the environment variable\n`DEBUG` to `axios-vcr2:*`:\n\n```sh\nDEBUG=\"axios-vcr2:*\" yarn test\n```\n\n### Contributing\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n## Contact\n\nCris van Pelt - cris@melkfl.es\n\nProject Link: [https://github.com/crisvp/axios-vcr2](https://github.com/crisvp/axios-vcr2)\n\n\u003c!-- MARKDOWN LINKS \u0026 IMAGES --\u003e\n\u003c!-- https://www.markdownguide.org/basic-syntax/#reference-style-links --\u003e\n[contributors-shield]: https://img.shields.io/github/contributors/crisvp/axios-vcr2.svg?style=for-the-badge\n[contributors-url]: https://github.com/crisvp/axios-vcr2/graphs/contributors\n[forks-shield]: https://img.shields.io/github/forks/crisvp/axios-vcr2.svg?style=for-the-badge\n[forks-url]: https://github.com/crisvp/axios-vcr2/network/members\n[stars-shield]: https://img.shields.io/github/stars/crisvp/axios-vcr2.svg?style=for-the-badge\n[stars-url]: https://github.com/crisvp/axios-vcr2/stargazers\n[issues-shield]: https://img.shields.io/github/issues/crisvp/axios-vcr2.svg?style=for-the-badge\n[issues-url]: https://github.com/crisvp/axios-vcr2/issues\n[license-shield]: https://img.shields.io/github/license/crisvp/axios-vcr2.svg?style=for-the-badge\n[license-url]: https://github.com/crisvp/axios-vcr2/blob/master/LICENSE\n[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge\u0026logo=linkedin\u0026colorB=555\n[linkedin-url]: https://linkedin.com/in/crisvanpelt\n[npm-shield]: https://img.shields.io/npm/dw/axios-vcr2\n[npm-url]: https://www.npmjs.com/package/axios-vcr2\n[gh-build-shield]: https://img.shields.io/github/checks-status/crisvp/axios-vcr2/main\n[gh-build-url]: https://github.com/crisvp/axios-vcr2/actions/workflows/run-tests.yml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrisvp%2Faxios-vcr2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrisvp%2Faxios-vcr2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrisvp%2Faxios-vcr2/lists"}