flickr / yakbak

Record and playback HTTP responses
MIT License
1.06k stars 84 forks source link

prefer fs.exists over trying require.resolve #52

Closed jdivock-stripe closed 3 years ago

jdivock-stripe commented 4 years ago

👋 I'm putting this PR up after experiencing a "fun" issues with using yakbak along with jest. Long story short I have a suite of functional tests that spin up a yakbak server and point to it for all api calls during test execution. This initially worked out great, but starting with jest24 all requires are held inside of a jest-haste-map which caches both hits and misses. The result of this was any fixtures written by yakbak would be written and cached as a miss, then continually reported as a miss even after the call to the api was made and a fixture was written.

I get around this by replacing the try block that was previously used to detect if a fixture existed by a simple fs.existsSync(file) call. This way no miss is recorded to the jest cache and the fixture and record logic is still preserved. Happy to adjust this logic or take a different approach if you see any issues. Thanks!

yahoocla commented 4 years ago

Thank you for submitting this pull request, however I do not see a valid CLA on file for you. Before we can merge this request please visit https://yahoocla.herokuapp.com/ and agree to the terms. Thanks! :smile: