faux-jax icon indicating copy to clipboard operation
faux-jax copied to clipboard

Add bypass to node and xhr

Open ponelat opened this issue 9 years ago • 2 comments

This is an attempt at a bypass method which follows on https://github.com/algolia/faux-jax/issues/12 It adds it to node and xhr ( i couldn't manually test IE, so I left XDomainRequest).

Working with the XHR native, was a real gnarly one. I had initially hoped to put in the prototype chain, but I couldn't inherit from it. I tried running the xhr methods on a non-xhr instance and failed that too. I think an actual DOM element is made for XHR, but that's just a thought.

Nodejs was simple, but we don't get the whole request. Just the url, which mitm wants to create a socket on. This is the one I actually need. I was hoping for a uniform PR, to include to all other interface.

I'll check back here to cleanup the PR as needed, there might be some travis errors...

ponelat avatar Jul 25 '16 04:07 ponelat

I'll take a look at the fails, soon as I'm able.

PS: Forget to mention how this would work...

  • Introduced a new event pre-request, which will have a single arg
  • The arg will be the request, or a bare bones url ( from nodejs )
  • The arg will also have a .bypass method, which when called will set a flag on the request instance
  • Then req.send() is called, presence of req._bypass will...
    • ...use the real methods to create an ajax/http request
    • ... fire the request, and copy the results onto the fakeRequest instance ( in the case of nodejs, a full bypass occurs )

ponelat avatar Jul 25 '16 05:07 ponelat

The failed tests might just be a bad state in the browser testing stack. If you had them passing locally in a browser then we could move further.

Can you add some API documentation? Thanks

vvo avatar Jul 25 '16 08:07 vvo