cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.43k stars 3.14k forks source link

Slow starting cypress tests #27226

Open lmiller1990 opened 1 year ago

lmiller1990 commented 1 year ago

Discussed in https://github.com/cypress-io/cypress/discussions/26901

Originally posted by **RobbeCl** June 1, 2023 When running Cypress locally, everything runs blazingly fast, but in CI/CD the startup time takes around 4 minutes (consistently between chrome/firefox/electron headless). We are using the docker image [cypress/browsers:node18.12.0-chrome107](https://hub.docker.com/layers/cypress/browsers/node18.12.0-chrome107/images/sha256-50959d1166a52276536e5535d1671692b83c097921685fe6a17f020d0b0f6ccf?context=explore). We are also using a strong AWS machine (t3a.2xlarge) so processing should be a problem I think. Besides that we are using an [esbuild preprocessor](https://github.com/bahmutov/cypress-esbuild-preprocessor). Some logging info: It hangs around 4 minutes and then prints "Run Starting" (with all the browser infromation + test suites). After it launches the browser (after 4 minutes) everyting runs fast and smooth. It just the startup-time which is slow. Behaviour is the same on e2e tests as component tests. Could it be the esbuild preprocessing step which takes a long tome or is it something browser-related?
jrnail23 commented 3 months ago

@lmiller, I had a very similar issue, so let me start by asking, are you by chance using pnpm? I am, and it turns out that the thing causing my Cypress startup to hang was Cypress checking git for the latest changes to my test files. That check was taking 4 minutes, and it was because in CircleCI, I was caching my pnpm store in my project workspace without gitignoring it. So when that git check was happening, it was inspecting LOTS more files than it thought it would need to. After adding .pnpm-store to .gitignore, the startup delay was completely fixed. My next step after that, FWIW, was to pull my .pnpm-store into the my project's parent dir, so git wouldn't try to track it at all.

RobbeCl commented 3 months ago

That was it!! Amazing thanks @jrnail23 . How did you found out that was the problem?

jrnail23 commented 3 months ago

@RobbeCl mostly grinding through lots of verbose cypress logs (DEBUG=cypress-verbose:* and DEBUG=cypress:*). I ran through the debug timings and among the innocuous +32ms and +1s values, a couple of +4m timings started showing up. From the +4m entries I was able to rule out issues with Firefox loading, then I started seeing stuff involving git, and I dug into the Cypress source code. Not gonna lie, that was a tough one to figure out though. I had lots of other extraneous factors to rule out leading up to that point.

AlexGuironnetRTE commented 3 months ago

Hello! We're having a kind-of-similar problem with cypress open hanging for a while at startup (see https://github.com/cypress-io/cypress/issues/29171). We're not using pnpm so it's probably not related, but you mentioned that at some point the issue occurred on your colleague's computer and not on yours. That's the case for our problem too. Have you been able to figure out what caused this difference by any chance?