VCR: Record ajax request to later playback
Record XMLHttpRequest calls and saves them using localStorage or files if using Nodejs. It's a js implementation of myronmarston's VCR but for javasccript without any dependencies
$ npm install vcr
VCRconfigurechookInto = windowXMLHttpRequest;ccassetteLibraryDir = "recorder"; // default: 'cassettes'chost = ""; // will prepend req url;
The only required config it's wich object to intercept, for now only works with XMLHttpRequest to catch ajax requests.
hookInto: object to intercept cassetteLibraryDir: when using nodejs defines where to store cassettes host: usefull when running within node and want to cache request to save, destroy, update, etc.
I try to make it as similar to original VCR as possible. Using Gerbil it's something like this:
scenario"Ajax interception"VCRconfigurechookInto = windowXMLHttpRequest;;VCRuseCassette'test'XMLHttpRequest = vXMLHttpRequest;varvar ajax = ;ajaxopen'GET' 'test.html';ifajaxreadyState === 4gassertEqual"Hello World!\n" ajaxresponseText;;ajaxsendnull;// Record First RequestmakeRequest;// Wait for it...gsetTimeout makeRequest; 100;;;
If you are using nodejs .json files will be created as cassetes to reproduce afterwards. In the other hand if you are running it in a browser localStorage will be used to persist the recordings.
Pablo Dejuan for the idea.