cypress: Network requests slower in Cypress than outside of Cypress

Current behaviour:

I’m trying to test my Nuxt app with Cypress, but find the tests to run very slowly because of how long it takes to download the JS bundles built by Nuxt. In development mode, bundles can get very large - upwards of 10mb. If I visit my site in Chrome, the network request for these bundles is very quick, <100ms. However, in my Cypress tests it takes almost 2 seconds just to download the bundle for each test case.

Desired behaviour:

Network speeds to be more comparable to those outside of Cypress.

Test code to reproduce

Run yarn test:e2e:dev in the example repository I’ve created.

This is a vanilla initial Nuxt app with nothing added apart from importing the large library zxcvbn in order to add a bit of arbitrary bulk to the bundle to bring it slightly closer to the size of a real app. Then compare the network requests during the test with those when you just visit localhost:3000 separately in Chrome.

For example, comparing the time for default~app.js:

  • In Cypress test: 1.1mb takes 324ms
  • In Chrome: 2.8mb takes 75ms

In each case, the vast majority of that time is spent in ‘Content Download’. The request is about 10x slower in Cypress than it normally is in Chrome. I realise the request goes through a proxy with Cypress, but is it expected to cause this much extra overhead? (I’m not quite sure why the the file is two different sizes - perhaps to do with the proxy?)

Versions

Cypress: 4.11.0 OS: OS X 10.15.5 Browser: Chrome 84.0.4147.105


Thanks in advance for any insight you can provide!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 14
  • Comments: 18 (4 by maintainers)

Most upvoted comments

We are also experiencing slow network requests with bigger bundles (20…25 MB). The modifyObstructiveCode=false did not help in our case.

I measured with https://test-page-speed.cypress.io/index1000.html. The results are:

setup duration
Locally, Chrome 86 1363 ms
Cypress 5.5.0, Chrome 86, inside cy.visit() 8241 ms
Cypress 5.5.0, Chrome 86 6188 ms
Locally, Firefox 81 1232 ms
Cypress 5.5.0, Firefox 81, inside cy.visit() 8194 ms
Cypress 5.5.0, Firefox 81 6087 ms
Cypress 5.5.0, Electron 85, inside cy.visit() 7149 ms

System Windows 10 2004

My colleagues measurements are around 3.3 seconds vs. 7.3 seconds in Cypress.

Setting modifyObstructiveCode to false does help a decent amount - it cuts the network request time in half which adds up to a lot over our entire test suite.

Other than that, I guess the best thing I can do at the moment is to try and keep the bundles being loaded as small as possible on our end.

Thanks for taking the time to look into this.