{"action":"created","issue":{"url":"https://api.github.com/repos/Netflix/pollyjs/issues/116","repository_url":"https://api.github.com/repos/Netflix/pollyjs","labels_url":"https://api.github.com/repos/Netflix/pollyjs/issues/116/labels{/name}","comments_url":"https://api.github.com/repos/Netflix/pollyjs/issues/116/comments","events_url":"https://api.github.com/repos/Netflix/pollyjs/issues/116/events","html_url":"https://github.com/Netflix/pollyjs/issues/116","id":367145835,"node_id":"MDU6SXNzdWUzNjcxNDU4MzU=","number":116,"title":"[RFC] setupPolly method for jest","user":{"login":"gribnoysup","id":5036933,"node_id":"MDQ6VXNlcjUwMzY5MzM=","avatar_url":"https://avatars2.githubusercontent.com/u/5036933?v=4","gravatar_id":"","url":"https://api.github.com/users/gribnoysup","html_url":"https://github.com/gribnoysup","followers_url":"https://api.github.com/users/gribnoysup/followers","following_url":"https://api.github.com/users/gribnoysup/following{/other_user}","gists_url":"https://api.github.com/users/gribnoysup/gists{/gist_id}","starred_url":"https://api.github.com/users/gribnoysup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gribnoysup/subscriptions","organizations_url":"https://api.github.com/users/gribnoysup/orgs","repos_url":"https://api.github.com/users/gribnoysup/repos","events_url":"https://api.github.com/users/gribnoysup/events{/privacy}","received_events_url":"https://api.github.com/users/gribnoysup/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-10-05T10:11:36Z","updated_at":"2018-10-18T07:34:54Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Hi team! First of all, thanks a lot for this library, great work 👏\r\n\r\nThis issue is a proposal and request for comments on adding a `setupPolly` helper for jest environments. After having a discussion with @offirgolan in https://github.com/Netflix/pollyjs/pull/115#discussion_r222127410 I decided to investigate is it possible to make the same hook support with automated name generation for jest/jasmine environments as the one implemented for Mocha and QUnit in the core of this library.\r\n\r\nThere are two main differences that I spotted between those two mentioned above and jest/jasmine:\r\n\r\n* `this` is not commonly used in jest, so access to polly instance should be handled differently\r\n* there is no \"normal\" way to acces the current test name in hooks\r\n\r\nTrying to address those issues led me to the solution that can be considered hacky, so instead of going with the PR right away, I created `setup-polly-jest` library as a proof of concept (but it works and covered with tests)\r\n\r\nDuring my investigation I found out that you can get access to the full test name, but to do this, you'll need a return value from `{test,it}` call in the test suite.\r\n\r\nThe solution is to proxy `jasmine.Env.it` and `jasmine.Env.dit` methods to get the access to test case instance, get the full name and also hook into before and after hooks of the test case, overriding another jasmine method.\r\n\r\nTo address the `this` issue I decided on a little bit different approach, where `setupPolly` will return `context` with polly instance as a property (as a bonus, it will also have `clearPolly` method to disable polly at any moment in the test workflow)\r\n\r\nYou can find repository here: https://github.com/gribnoysup/setup-polly-jest and it is even published as `@gribnoysup/setup-polly-jest` so it should be easy for you to test how it works. Repo contains documentation, unit tests and an \"integration\" test suite that uses the library itself to setup polly in jest test environment\r\n\r\nIf you think that this approach is acceptable, I'll be glad to integrate this solution into `@pollyjs/core`package 👍"},"comment":{"url":"https://api.github.com/repos/Netflix/pollyjs/issues/comments/430905939","html_url":"https://github.com/Netflix/pollyjs/issues/116#issuecomment-430905939","issue_url":"https://api.github.com/repos/Netflix/pollyjs/issues/116","id":430905939,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMDkwNTkzOQ==","user":{"login":"gribnoysup","id":5036933,"node_id":"MDQ6VXNlcjUwMzY5MzM=","avatar_url":"https://avatars2.githubusercontent.com/u/5036933?v=4","gravatar_id":"","url":"https://api.github.com/users/gribnoysup","html_url":"https://github.com/gribnoysup","followers_url":"https://api.github.com/users/gribnoysup/followers","following_url":"https://api.github.com/users/gribnoysup/following{/other_user}","gists_url":"https://api.github.com/users/gribnoysup/gists{/gist_id}","starred_url":"https://api.github.com/users/gribnoysup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gribnoysup/subscriptions","organizations_url":"https://api.github.com/users/gribnoysup/orgs","repos_url":"https://api.github.com/users/gribnoysup/repos","events_url":"https://api.github.com/users/gribnoysup/events{/privacy}","received_events_url":"https://api.github.com/users/gribnoysup/received_events","type":"User","site_admin":false},"created_at":"2018-10-18T07:34:54Z","updated_at":"2018-10-18T07:34:54Z","author_association":"CONTRIBUTOR","body":"@offirgolan haha, no worries about the delay and thanks for the feedback 🙌I opened a work-in-progress PR for this feature, I think we can continue the discussion there 👍  "}}
{"actor":{"display_login":"gribnoysup"}}