{"id":13394235,"url":"https://github.com/Netflix/pollyjs","last_synced_at":"2025-03-13T20:31:23.269Z","repository":{"id":38876552,"uuid":"135633158","full_name":"Netflix/pollyjs","owner":"Netflix","description":"Record, Replay, and Stub HTTP Interactions.","archived":false,"fork":false,"pushed_at":"2023-10-08T03:50:51.000Z","size":4851,"stargazers_count":10214,"open_issues_count":53,"forks_count":353,"subscribers_count":375,"default_branch":"master","last_synced_at":"2024-10-29T22:51:29.450Z","etag":null,"topics":["browser","javascript","netflix","nodejs","record","replay","testing"],"latest_commit_sha":null,"homepage":"https://netflix.github.io/pollyjs","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Netflix.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-05-31T20:39:44.000Z","updated_at":"2024-10-29T21:41:53.000Z","dependencies_parsed_at":"2024-02-04T15:11:06.677Z","dependency_job_id":"598d9b72-2fe6-4f54-adf4-2b4187be1ac2","html_url":"https://github.com/Netflix/pollyjs","commit_stats":{"total_commits":358,"total_committers":36,"mean_commits":9.944444444444445,"dds":0.3044692737430168,"last_synced_commit":"2d7f0f33d9f552e78f0dfe81179751b4692357be"},"previous_names":[],"tags_count":154,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Netflix%2Fpollyjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Netflix%2Fpollyjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Netflix%2Fpollyjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Netflix%2Fpollyjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Netflix","download_url":"https://codeload.github.com/Netflix/pollyjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237565984,"owners_count":19330881,"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":["browser","javascript","netflix","nodejs","record","replay","testing"],"created_at":"2024-07-30T17:01:13.387Z","updated_at":"2025-03-13T20:31:22.585Z","avatar_url":"https://github.com/Netflix.png","language":"JavaScript","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"Polly.JS\" width=\"400px\" src=\"https://netflix.github.io/pollyjs/assets/images/wordmark-logo-alt.png\" /\u003e\n\u003c/p\u003e\n\u003ch2 align=\"center\"\u003eRecord, Replay, and Stub HTTP Interactions\u003c/h2\u003e\n\n[![Build Status](https://travis-ci.com/Netflix/pollyjs.svg?branch=master)](https://travis-ci.com/Netflix/pollyjs)\n[![license](https://img.shields.io/github/license/Netflix/pollyjs.svg)](http://www.apache.org/licenses/LICENSE-2.0)\n\nPolly.JS is a standalone, framework-agnostic JavaScript library that enables recording, replaying, and stubbing of HTTP interactions. By tapping into multiple request APIs across both Node \u0026 the browser, Polly.JS is able to mock requests and responses with little to no configuration while giving you the ability to take full control of each request with a simple, powerful, and intuitive API.\n\n\u003e Interested in contributing or just seeing Polly in action? Head over to [CONTRIBUTING.md](CONTRIBUTING.md) to learn how to spin up the project!\n\n## Why Polly?\n\nKeeping fixtures and factories in parity with your APIs can be a time consuming process.\nPolly alleviates this process by recording and maintaining actual server responses while also staying flexible.\n\n- Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.\n- Use Polly's client-side server to modify or intercept requests and responses to simulate different application states (e.g. loading, error, etc.).\n\n## Features\n\n- 🚀 Node \u0026 Browser Support\n- ⚡️️ Simple, Powerful, \u0026 Intuitive API\n- 💎 First Class Mocha \u0026 QUnit Test Helpers\n- 🔥 Intercept, Pass-Through, and Attach Events\n- 📼 Record to Disk or Local Storage\n- ⏱ Slow Down or Speed Up Time\n\n## Getting Started\n\nCheck out the [Quick Start](https://netflix.github.io/pollyjs/#/quick-start) documentation to get started.\n\n## Usage\n\nLet's take a look at what an example test case would look like using Polly.\n\n```js\nimport { Polly } from '@pollyjs/core';\nimport XHRAdapter from '@pollyjs/adapter-xhr';\nimport FetchAdapter from '@pollyjs/adapter-fetch';\nimport RESTPersister from '@pollyjs/persister-rest';\n\n/*\n  Register the adapters and persisters we want to use. This way all future\n  polly instances can access them by name.\n*/\nPolly.register(XHRAdapter);\nPolly.register(FetchAdapter);\nPolly.register(RESTPersister);\n\ndescribe('Netflix Homepage', function () {\n  it('should be able to sign in', async function () {\n    /*\n      Create a new polly instance.\n\n      Connect Polly to both fetch and XHR browser APIs. By default, it will\n      record any requests that it hasn't yet seen while replaying ones it\n      has already recorded.\n    */\n    const polly = new Polly('Sign In', {\n      adapters: ['xhr', 'fetch'],\n      persister: 'rest'\n    });\n    const { server } = polly;\n\n    /* Intercept all Google Analytic requests and respond with a 200 */\n    server\n      .get('/google-analytics/*path')\n      .intercept((req, res) =\u003e res.sendStatus(200));\n\n    /* Pass-through all GET requests to /coverage */\n    server.get('/coverage').passthrough();\n\n    /* start: pseudo test code */\n    await visit('/login');\n    await fillIn('email', 'polly@netflix.com');\n    await fillIn('password', '@pollyjs');\n    await submit();\n    /* end: pseudo test code */\n\n    expect(location.pathname).to.equal('/browse');\n\n    /*\n      Calling `stop` will persist requests as well as disconnect from any\n      connected browser APIs (e.g. fetch or XHR).\n    */\n    await polly.stop();\n  });\n});\n```\n\nThe above test case would generate the following [HAR](http://www.softwareishard.com/blog/har-12-spec/)\nfile which Polly will use to replay the sign-in response when the test is rerun:\n\n```json\n{\n  \"log\": {\n    \"_recordingName\": \"Sign In\",\n    \"browser\": {\n      \"name\": \"Chrome\",\n      \"version\": \"67.0\"\n    },\n    \"creator\": {\n      \"name\": \"Polly.JS\",\n      \"version\": \"0.5.0\",\n      \"comment\": \"persister:rest\"\n    },\n    \"entries\": [\n      {\n        \"_id\": \"06f06e6d125cbb80896c41786f9a696a\",\n        \"_order\": 0,\n        \"cache\": {},\n        \"request\": {\n          \"bodySize\": 51,\n          \"cookies\": [],\n          \"headers\": [\n            {\n              \"name\": \"content-type\",\n              \"value\": \"application/json; charset=utf-8\"\n            }\n          ],\n          \"headersSize\": 97,\n          \"httpVersion\": \"HTTP/1.1\",\n          \"method\": \"POST\",\n          \"postData\": {\n            \"mimeType\": \"application/json; charset=utf-8\",\n            \"text\": \"{\\\"email\\\":\\\"polly@netflix.com\\\",\\\"password\\\":\\\"@pollyjs\\\"}\"\n          },\n          \"queryString\": [],\n          \"url\": \"https://netflix.com/api/v1/login\"\n        },\n        \"response\": {\n          \"bodySize\": 0,\n          \"content\": {\n            \"mimeType\": \"text/plain; charset=utf-8\",\n            \"size\": 0\n          },\n          \"cookies\": [],\n          \"headers\": [],\n          \"headersSize\": 0,\n          \"httpVersion\": \"HTTP/1.1\",\n          \"redirectURL\": \"\",\n          \"status\": 200,\n          \"statusText\": \"OK\"\n        },\n        \"startedDateTime\": \"2018-06-29T17:31:55.348Z\",\n        \"time\": 11,\n        \"timings\": {\n          \"blocked\": -1,\n          \"connect\": -1,\n          \"dns\": -1,\n          \"receive\": 0,\n          \"send\": 0,\n          \"ssl\": -1,\n          \"wait\": 11\n        }\n      }\n    ],\n    \"pages\": [],\n    \"version\": \"1.2\"\n  }\n}\n```\n\n## Prior Art\n\nThe \"Client Server\" API of Polly is heavily influenced by the very popular mock server library [pretender](https://github.com/pretenderjs/pretender). Pretender supports XHR and Fetch stubbing and is a great lightweight alternative to Polly if your project does not require persisting capabilities or Node adapters.\n\nThank you to all contributors especially the maintainers: [trek](https://github.com/trek), [stefanpenner](https://github.com/stefanpenner), and [xg-wang](https://github.com/xg-wang).\n\n## Contributors\n\n[//]: contributor-faces\n\n\u003ca href=\"https://github.com/offirgolan\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/575938?v=4\" title=\"offirgolan\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/jasonmit\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/3108309?v=4\" title=\"jasonmit\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/cibernox\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/265339?v=4\" title=\"cibernox\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/DenrizSusam\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/39295979?v=4\" title=\"DenrizSusam\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/dustinsoftware\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/942358?v=4\" title=\"dustinsoftware\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/silverchen\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/6683103?v=4\" title=\"silverchen\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/tombh\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/160835?v=4\" title=\"tombh\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/zkwentz\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/4832?v=4\" title=\"zkwentz\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/agraves\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/46964?v=4\" title=\"agraves\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/brandon-leapyear\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/27799541?v=4\" title=\"brandon-leapyear\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/swashcap\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1858316?v=4\" title=\"swashcap\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/justsml\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/397632?v=4\" title=\"justsml\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/DanielRuf\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/827205?v=4\" title=\"DanielRuf\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/dciccale\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/539546?v=4\" title=\"dciccale\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/ericclemmons\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/15182?v=4\" title=\"ericclemmons\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/jamesgeorge007\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/25279263?v=4\" title=\"jamesgeorge007\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/woodenconsulting\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/4163029?v=4\" title=\"woodenconsulting\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/feinoujc\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1733707?v=4\" title=\"feinoujc\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/josex2r\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/3719730?v=4\" title=\"josex2r\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/jomaxx\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/2747424?v=4\" title=\"jomaxx\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/karlhorky\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1935696?v=4\" title=\"karlhorky\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/kennethlarsen\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1408595?v=4\" title=\"kennethlarsen\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/poteto\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1390709?v=4\" title=\"poteto\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/fastfrwrd\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/231133?v=4\" title=\"fastfrwrd\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/rwd\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/218337?v=4\" title=\"rwd\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/rmachielse\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/2470404?v=4\" title=\"rmachielse\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/ROpdebee\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/15186467?v=4\" title=\"ROpdebee\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/gribnoysup\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/5036933?v=4\" title=\"gribnoysup\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/shriyash\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/4494915?v=4\" title=\"shriyash\" width=\"80\" height=\"80\"\u003e\u003c/a\u003e\n\n[//]: contributor-faces\n\n## License\n\nCopyright (c) 2018 Netflix, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","funding_links":[],"categories":["JavaScript","*.js","browser","Packages","🧪 Testing"],"sub_categories":["Node","☸️ Kubernetes"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNetflix%2Fpollyjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNetflix%2Fpollyjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNetflix%2Fpollyjs/lists"}