{"id":27351982,"url":"https://github.com/scaleleap/jest-polly","last_synced_at":"2025-04-12T20:54:16.240Z","repository":{"id":37032713,"uuid":"238439892","full_name":"ScaleLeap/jest-polly","owner":"ScaleLeap","description":"Integrate Jest with PollyJS for a smooth HTTP recording and playback experience for your integration tests.","archived":false,"fork":false,"pushed_at":"2025-04-07T02:23:54.000Z","size":2734,"stargazers_count":10,"open_issues_count":11,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T20:53:59.900Z","etag":null,"topics":["http","jest","pollyjs","recording","snapshot"],"latest_commit_sha":null,"homepage":"https://npm.im/@scaleleap/jest-polly","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ScaleLeap.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2020-02-05T12:00:41.000Z","updated_at":"2025-04-01T17:00:58.000Z","dependencies_parsed_at":"2022-09-10T09:11:43.898Z","dependency_job_id":"1297d907-1e6a-4712-8d68-c76c49d7ce17","html_url":"https://github.com/ScaleLeap/jest-polly","commit_stats":{"total_commits":517,"total_committers":8,"mean_commits":64.625,"dds":0.5996131528046422,"last_synced_commit":"1c21638eb0dcba01622399cbdcc6506bad861ea2"},"previous_names":[],"tags_count":132,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScaleLeap%2Fjest-polly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScaleLeap%2Fjest-polly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScaleLeap%2Fjest-polly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScaleLeap%2Fjest-polly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ScaleLeap","download_url":"https://codeload.github.com/ScaleLeap/jest-polly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631716,"owners_count":21136560,"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":["http","jest","pollyjs","recording","snapshot"],"created_at":"2025-04-12T20:54:15.621Z","updated_at":"2025-04-12T20:54:16.233Z","avatar_url":"https://github.com/ScaleLeap.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @scaleleap/jest-polly\n\n![logo](https://raw.githubusercontent.com/ScaleLeap/jest-polly/master/docs/assets/logo.png)\n\n\u003e Smoothest Jest integration with PollyJS.\n\n* * *\n\nIntegrate [Jest](https://github.com/facebook/jest) with [PollyJS](https://github.com/Netflix/pollyjs/)\nfor a smooth HTTP recording and playback experience for your integration tests.\n\n## List of features\n\n* Sane default [configuration](./src/config.ts#L16)\n* Secret Sanitization\n* TypeScript support\n\n## Environment Variables\n\n### [Polly Mode](https://netflix.github.io/pollyjs/#/configuration?id=mode)\n\nCan be set via `POLLY_MODE` environment variable.\n\nMode can be one of the following:\n\n* `replay`: Replay responses from recordings.\n* `record`: Force Polly to record all requests. This will overwrite recordings that already exist.\n* `passthrough`: Passes all requests through directly to the server without recording or replaying.\n\n**Default**: `replay`\n\nUsage:\n\n```sh\nPOLLY_MODE=record npm t\n```\n\n### [Record if Missing](https://netflix.github.io/pollyjs/#/configuration?id=recordifmissing)\n\nIf a request's recording is not found, pass-through to the server and record the response.\n\nCan be set via `POLLY_RECORD_IF_MISSING` environment variable.\n\n**Default**: `false` if running in CI environment or `true` otherwise.\n\nUsage:\n\n```sh\nPOLLY_RECORD_IF_MISSING=true npm t\n```\n\n## Secret Sanitization\n\nSometimes requests and/or responses may contain secret data, such as API keys, or oAuth tokens.\n\nTo automatically sanitize the recordings, you may add a list of secrets to the config to be replaced.\n\nSee \"Change PollyJS default config\" section for details.\n\n```ts\n// use a Record-style config, where keys are secrets,\n// and values are what they will be replaced with\njestPollyConfigService.config = {\n  secrets: {\n    'somepassword': 'x',\n    'my-api-key': 'x',\n  }\n}\n\n// or simply use an array, and everything will be replaced with `x` by default:\njestPollyConfigService.config = {\n  secrets: [process.env.MY_SECRET_VALYE]\n}\n```\n\n## Code Demo\n\n### Use in all tests\n\nIn your `package.json`\n\n```json\n{\n  \"jest\": {\n    \"setupFilesAfterEnv\": [\"@scaleleap/jest-polly\"]\n  }\n}\n```\n\nOr in `jest.config.js`\n\n```js\nmodule.exports = {\n  setupFilesAfterEnv: ['@scaleleap/jest-polly'],\n};\n```\n\n### Use in a single test\n\nIn `my.test.js`\n\n```ts\nimport '@scaleleap/jest-polly';\nimport fetch from 'node-fetch';\n\ntest('is ok', async () =\u003e {\n  const response = await fetch('https://httpstat.us/200');\n  expect(response.ok).toBe(true);\n});\n```\n\n### Using the Polly instance\n\nUse the [`polly` instance](https://netflix.github.io/pollyjs/#/api) to change default behavior.\n\n```ts\nimport { jestPollyContext } from '@scaleleap/jest-polly';\nimport fetch from 'node-fetch';\n\njestPollyContext\n  .polly\n  .server\n  .any('https://httpstat.us/500')\n  .intercept((req, res) =\u003e res.sendStatus(500));\n\ntest('is not ok', async () =\u003e {\n  const response = await fetch('https://httpstat.us/500');\n  expect(response.ok).not.toBe(true);\n});\n```\n\n### Change PollyJS default config\n\nIf you want to change the [default config](./src/config.ts#L16), use the following setter.\n\n**Note**: the config will be **merged** with the default config, and **not** overwritten.\n\n```ts\nimport { jestPollyConfigService } from '@scaleleap/jest-polly';\n\njestPollyConfigService.config = {\n  matchRequestsBy: {\n    order: false\n  }\n}\n```\n\n## Download \u0026 Installation\n\n```sh\nnpm i -D @scaleleap/jest-polly\n```\n\n## Contributing\n\nKeep it simple. Keep it minimal. Don't put every single feature just because you can.\n\n## Authors or Acknowledgments\n\n* Authored by Roman Filippov ([Scale Leap](https://www.scaleleap.com))\n* Inspired by [`@spotify/polly-jest-presets`](https://github.com/spotify/polly-jest-presets),\n  but the project wasn't well maintained\n* Inspired by [`@jomaxx/jest-polly`](https://github.com/jomaxx/jest-polly), but wasn't using `setup-polly-jest`\n\n## License\n\nThis project is licensed under the MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscaleleap%2Fjest-polly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscaleleap%2Fjest-polly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscaleleap%2Fjest-polly/lists"}