question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Network requests slower in Cypress than outside of Cypress

See original GitHub issue

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!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
dintiflacommented, Oct 29, 2020

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.

3reactions
axwalkercommented, Aug 18, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Network Requests - Cypress Documentation
Cypress helps you test the entire lifecycle of HTTP requests within your application ... views, etc) the tests are often much slower than...
Read more >
How We Improved Network Speed By 300% In Cypress 3.3.0
The problem: it was slow​​ It was so bad that they reported load times of 5.5 seconds in Cypress, compared to 300ms in...
Read more >
Best Practices - Cypress Documentation
Resetting tests is much slower than adding more assertions. It is common for tests in Cypress to issue 30+ commands. Because nearly every...
Read more >
Troubleshooting | Cypress Documentation
If you're having an issue during installation of Cypress, try removing the contents of the Cypress cache. This will clear out all installed...
Read more >
Retry-ability - Cypress Documentation
A core feature of Cypress that assists with testing dynamic web applications is retry-ability. Like a good transmission in a car, it usually...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found