8 ms·
Polly.js – Record, replay, and stub HTTP interactions
- swiezy2 8y agoInteresting but would be more useful with support for streaming
- zwentz 8y agoOn the roadmap, depending on your definition of "streaming" (e.g. buffer streams, websockets).
- isuckatcoding 8y agoUnrelated but There are so many things called Polly that it gets confusing
- youdontknowtho 8y agoYeah. I was going to bring up the library for .net that provides policy based retries.
- deleted 8y ago[deleted]
- Osiris 8y agoI've used mitmproxy + proxychains to do this. How is Polly different?
- jonknee 8y agohttps://netflix.github.io/pollyjs/#/README https://netflix.github.io/pollyjs/#/README Why Polly? Keeping fixtures and factories in parity with your APIs can be a time consuming process. Polly alleviates this by recording and maintaining actual server responses without foregoing flexibility. * Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests. * Use Polly's client-side server to modify or intercept requests and responses to simulate different application states (e.g. loading, error, etc.).
- curun1r 8y agoNot sure that tells me how it's different from replay or the other half dozen npm modules that do the same thing. It'd be nice for them to contrast their tool with existing ecosystem options considering some of them are pretty well established.
- jasonmit 8y agoCan you share which libraries you know that achieve the same thing? I'm happy to go through and respond to the differences.
- curun1r 8y agoI only have experience with replay, but an npm search turns up: replay, replayer, http-record, talkback, sepia, mitm-record, fetch-vcr, tape-nock, jest-playback, eight-track, axios-vcr, replayer, node-vcr, mocha-vcr, mockyeah, yakbak, nine-track, dkastner-replay, node-nock At which point I stopped looking...recording http requests isn't exactly new territory.
- simplify 8y agoI've personally used node-replay with great success. It has minimal configuration https://github.com/assaf/node-replay https://github.com/assaf/node-replay
- ikeboy 8y agoSo is this basically selenium in javascript with some neat features?
- gleenn 8y agoSounds more like the VCR gem from Ruby land.
- zwentz 8y agoYes exactly, that's the idea anyway. Has a few nice features on top such as controlling the network latency and expiring recordings (useful when working on a project supported by a big team).
- tootie 8y agoThis isn't selenium. More like wiremock.
- mygo 8y agoI know this is slightly different, but I wish more people knew about Chrome / Safari / Firefox’s “network” console tab. Great for debugging. Can look at all requests, headers, responses, timespans, etc. Some will even let you copy a given network request as a cURL command, capturing all headers, body, query strings, etc.
- dudul 8y agoAnd out of curiosity, what makes you think that people don't know about it? I've never met a web dev who didn't know about it in the past few years.
- thijsvandien 8y agoNew people are introduced to web development every day. Assuming some things are just common knowledge is not very beginner friendly. https://xkcd.com/1053/ https://xkcd.com/1053/
- burger_moon 8y agoI would love to hear from people involved in projects like this, what kind of work/ how much, was done to get it ready for and approved to be open sourced by the company. Especially at large corps like Netflix I'm sure there's a lot of hoops to jump through.
- staticassertion 8y agoNetflix seems to also have a really strong culture around this though, so I wouldn't be surprised if it's a lot less hoopy than you'd imagine.
- error54 8y agoNot to shamelessly plug but if you're in the Bay Area on June 28, we're giving a talk that's a bit about performance, a bit about Netflix engineering culture: https://jstalks2018.splashthat.com/ https://jstalks2018.splashthat.com/.
- MaxLeiter 8y agoIf I’m a student can I sign up to attend?
- wesleytodd 8y agoSure! (at least I don't see why you wouldn't be able to)
- koopa184 8y agoExactly. They had engineers dedicated to creating an open source latency/fault tolerance library called Hystrix. Not too surprising they’re dedicating resources to other projects, too.
- captain_perl 8y agoI'm sure the first project took some time to setup, but Netflix has released dozens of projects since. So very low hoops.
- john838 8y agoHow does it hook into the browser APIs? I can't seem to find it. By what black magic would it know how to hook into my puppeteer instance? Or I'm I not understand this?
- gnufied 8y agoAlso check out https://github.com/code-mancers/interceptor https://github.com/code-mancers/interceptor which as well uses browser APIs to enable users to mock http responses via a chrome extension.
- deleted 8y ago[deleted]
- bicubic 8y agoRelated to that, is there anything that allows to completely save the state of a modern website with all of the fetch requests and websocket related stuff it fired off? I just want an ability to save and reopen exactly what I'm looking at. There are some cool websites which will eventually go down and I want to preserve an interactive snapshot of them.
- coderdude 8y agoIt seems like you're describing a single page web app. I don't think anyone could answer this without knowing more about what you mean and what you would want to accomplish. Sounds neat, though.
- Mandatum 8y agoThis won't work for WebSockets, really websites that use WebSockets require some interaction to generate the transmitted message which is often dependent on the servers response. Private websites, or websites that require a login are hard - but it can be done. Would suggest HTTrack.
- reymus 8y agoBut it's not impossible to have some tool that records all of those interactions to reproduce later. A smart enough tool could record everything since you open the site until you click save. It would not reproduce the functionality that is backend dependent, but iy sure can replicate the dom, etc. Am I missing something?
- Mandatum 8y agoYeah - but there's a LOT of variables that come into play for something like that. It'd likely be easier to either record it with something like BugReplay.com or video.
- huntie 8y agoI haven't used it so I'm not sure that it does everything you want, but take a look at https://webrecorder.io/ https://webrecorder.io/
- textmode 8y agoAlternate URL (no Javascript required): https://github.com/Netflix/pollyjs https://github.com/Netflix/pollyjs
- tills13 8y agoa little ironic, no?
- yawz 8y agoI love the name! "Polly" repeats everything... and wants biscuit every now and then :).
- invisible 8y agoThis seems like it will be especially useful with apollo-client for graphQL requests.
- incadenza 8y agoso this will make the actual http request the first time, then keep a recording? I’m not entirely clear how this works from the docs.
- nitinreddy88 8y agoThere is already famous Policy package for .NET with same name https://github.com/App-vNext/Polly https://github.com/App-vNext/Polly
- stephen 8y agoLooks well done (it uses unicode art, so it must be amazing) but I have a fundamental distrust/dislike of record/replay frameworks...just seems like you're papering over an inherently bad testing approach. E.g. sure, when replays work, they're great, but: a) you have to do a manual recording to create them the first time (which means manually setting up test data in production that is just-right for your test case) b) you have to manually re-record when they fail (and again means you have manually go back and restore the test data in production that is just-right for your test case...and odds are you weren't the one who originally recorded this test, so good luck guessing exactly what that was). In both cases, you've accepted that you can't easily setup specific, isolated test data in your upstream system, and are really just doing "slightly faster manual testing". So, IMO, you should focus on solving the core issue: the uncontrollable upstream system. Or, if you can't, decouple all of your automated tests from it fully, and just accept that cross-system tests against a datasource you can't control is not a fun/good way to write more than a handful of tests (e.g. ~5 smoke tests are fine, but ~100s of record/replay tests for minute boundary cases sounds terrible).
- drb91 8y agoHow is this distinct from other http stubbing libraries?
- jasonmit 8y agoPolly records as well as exposes a stubbing API. So it's quite different from what I've seen of the others.
- drb91 8y agoAhh. Well, there’s quite a history of recording as well as stubbing: see ruby’s VCR.
- aspencer8111 8y agoCame here say the exact same thing: "Hey, look! Its VCR for JS. Yay!"
- biznickman 8y agoSo VCR gem for javascript. Great! Personally I stopped using VCR gem a while back as it blocks edge cases. However for larger projects where things can get unwieldily this makes a lot of sense. Local test suites should never hit external APIs so it's much better to have mocks/stubs than to have no tests at all. However on smaller projects I've found that just clicking through to make sure things work and then letting my error reporting system catch bugs to be much more effective :) It's a hard line to walk and I surely haven't perfected it. I'll give it a shot on a future project!
- sidcool 8y agoWhat would a use case of this library look like?
- jorisd 8y agoThis is very cool, solving some issues I no doubt many people have when writing tests against a (fast-)moving target. I'll definitely give it a try in my next project. I looked through the codebase, and noticed that this uses a custom data format to persist HTTP requests and responses in local storage. I'm not sure if it's technically possible in all circumstances, but I think it might be valuable to have requests and responses be stored as HAR 1.2 [1] when possible, so that the trace can be used by other tools [2] to aid in debugging, verifying and analyzing behaviour as well as perhaps automated creation of load/performance tests. [1] - http://www.softwareishard.com/blog/har-12-spec/ http://www.softwareishard.com/blog/har-12-spec/ [2] - e.g. https://toolbox.googleapps.com/apps/har_analyzer/ https://toolbox.googleapps.com/apps/har_analyzer/
- vaidik 8y agoI used to use nock which would work very well in node environments. But this works in the browser as well. So I guess this can be fairly helpful while writing tests post development. If you are doing TDD, then recording/replaying doesn't fit anywhere in the development cycle. I like the API of this library and the browser support that was missing in nock. So thanks Netflix! Although it would have been nice to see nock add this support. Which is what I wonder - why not just contribute to existing libraries.
- pimterry 8y agoIf you're looking for Nock but not just node, try Mockttp: https://github.com/pimterry/mockttp https://github.com/pimterry/mockttp. It lets you create & configure mock HTTP servers for JS testing, but with one API that works out of the box in Node and in browsers. This avoids the record/replay model too, so you can still take the TDD approach and define your API behaviour in the test itself. (Disclaimer: I'm the author of Mockttp)
- vaidik 8y agoAlso, what's up with the in-your-face hiring pitch right in the documentation? https://netflix.github.io/pollyjs/#/README?id=we39re-hiring https://netflix.github.io/pollyjs/#/README?id=we39re-hiring
- anchpop 8y agoI assume that devs read the documentation, and they want to hire devs, and it's their tool, so they put their hiring pitch in their documentation for their tool to try and hire devs
- bookofgreg 8y agoI personally replace all stubbed HTTP interactions between my services with contracts with good success. https://docs.pact.io/getting-started https://docs.pact.io/getting-started
- xab9 8y agoI did something similar, but as an interim proxy (can record, replay, there are modifier hooks, can slow down requests). You have to point towards a backend api and on the frontend you use the proxy url instead of the original. But it's mostly for debugging, so the scope is much more limited.
- ascendantlogic 8y agoI'm curious what the application could be for load testing? Tools like locust and gatling are nice but are still synthetic. I'd love to capture X minutes of traffic, then dupe it Y times and replay it as a more accurate representation of traffic patterns for load testing. Is that a thing?
- jmckenz 8y agonot had a chance to properly try yet, but https://goreplay.org/ https://goreplay.org/ does exactly what you are asking. Alternatively, in the container world, tools such as Istio (https://istio.io/ https://istio.io/) allow traffic shadowing - you can duplicate traffic and route it somewhere else
- ksejka 8y agois it a port of https://github.com/App-vNext/Polly https://github.com/App-vNext/Polly ?
- badrelmers 8y agoWhy another tshark/tcpdump? all this can be done with a simple script with few lines. Today we need javascript recorders, traffic recorders are a kid game and using a certificate to touch https is a dangerous way (but every project there is doing same). Tshark and sslkeylogfile is the only safe way... but I like this project I don't know why! I feel something.