Released 10/23/2015
Summary:
- XHR handling has been rewritten to be much more flexible, extensible, and future-proof.
Breaking Changes:
- The object you receive after waiting on an XHR alias is now different.
Previously this was a
FakeXMLHttpRequest
object which came from Sinon.js. Now it is a specialXMLHttpRequest
object which comes from Cypress. You may need to rewrite some of your assertions but we've tried to keep the signatures as close as possible. - The XHR's URL property will now always return you a
Fully Qualified Domain Name
including the origin, port, host, etc. Previously the URL property represented whatever the XHR was opened with. We've worked around this difference by when checking whether an XHR should be stubbed, the origin is tested both as present and omitted.
Deprecations:
- Accessing
requestJSON
orresponseJSON
on XHR objects is deprecated, and will be removed in the next version. Accessing those properties will throw a warning which explains how to rewrite these. cy.respond
is temporarily deprecated because the semantics of how this works is completely different and will require more work (mentioned later on) before this can be re-enabled again.
Features:
- All XHR's (regardless of whether they are stubbed or not) are now logged in the Command Log. Stubbed XHR's display as "XHR Stub" vs vanilla "XHR".
- Stubbed XHR's will now show up in the
Network Tab
in Dev Tools. In other words they will really go out and you'll be able to inspect them just like regular XHRs. - Regular XHR's can now be aliased and waited on without actually being stubbed
by passing
{stub: false}
to thecy.route()
. - XHR's will continue to work correctly even after a test ends. In previous versions, due to replacing the entire XHR object, your application would not work correctly after a test ended. This prevented you from "navigating around" and working with your app after the tests end.
- Servers can now be disabled in the middle of a test. Previously once a server was started all XHR's would be stubbed.
- You can now disable the force sending of
404
to all XHR's which are not stubbed. This allows you to mix and match, enabling some requests to be stubbed and others to hit your server and respond normally. - The default XHR configuration can now be overwritten in a single area.
- Many new configuration options are available for controlling how XHR's are stubbed.
- XHR's now include an
Initiator
stack regardless of whether they're stubbed. TheInitiator
stack includes the stack which caused the XHR to be created and sent. - The
onConsole
information related to an XHR has been updated to make it easier to understand why a route was or was not stubbed, and its associated request and response headers. - Response headers on XHR stubs will now automatically set their
Content-Type
based on the stub response. Previously this would always set to theContent-Type
toapplication/json
. Now if you force a response to be text or html, theContent-Type
response header will be set appropriately. - You can now force other additional response headers to be sent on stubbed XHRs.
- XHR's now snapshot twice - when the request is made and when the response is returned.
- Removed sending
sinon
on everycy.visit()
. - The XHR object which is returned to you to via
cy.wait()
is now more consistent with other return values such ascy.request()
. It should be much easier to work withrequest body
,request headers
,response body
andresponse headers
.
Bugfixes:
- Routes no longer display as duplicated in between test runs when
cy.server()
is started prior to acy.visit()
and you cause a full page refresh, which caused all routes to be re-bound. - Any issues related to
requestJSON
orresponseJSON
being duplicated are now fixed. Fixes #65. - Fully Qualified XHR's which should be proxied are now correctly transparently rewritten to prevent CORS problems.
cy.route()
-onRequest
andonResponse
callbacks are now called withcy
as the context.- Filtering assets which should never be stubbed has been improved. Now
.jsx
templates pass-through correctly. - CORS Network Errors are now correctly caught.
Misc:
- All
ng
based commands now display in the Command Log. - The built in XHR response delay has been removed since now all requests really go over the HTTP stack, which inherently has its own delay. You can still optionally force responses to be delayed by a set amount.
Almost there:
- Support for the native
fetch
object. - Configuration to automatically force Cypress to wait for outstanding XHR's (like it does for other Page Events). This would mean when testing more traditional apps without XHR stubbing, commands would automatically wait until all outstanding XHR's complete. The internal retry loop needs to be rewritten to make this possible, but the XHR architecture is now there.