cypress: Cypress Run - Do not relaunch browser in between each spec file
In our current project we have around 40 spec files with tests for different components or pages. The Cypress pipeline on our CI takes around 12-13 min. Instead of just throwing more server resources at it and paralyze the runs we looked into how we could improve the runtime by doing some optimizations.
We noticed that for every spec file it reloads the Cypress runner, this takes up some time which might not be necessary.
Our current solution is to create a index_spec.js that dynamically imports all other spec files in that folder. This cuts the runtime down with around 4-5 minutes, but this doesn’t work well with plugins like cypress-plugin-snapshots as they use the spec files path to generate the path to store the snapshots.
Would it be possible to have the run command support a way to bundle specs?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 32
- Comments: 16 (5 by maintainers)
+100 to this feature. I have 100s of tests split up logically into spec files, which is useful to a) avoid a single, massive spec file and b) to allow me to run a single spec at a time if needed. But when running all the tests (definitely in CI, but also locally sometimes) I don’t need the browser to restart after each spec, and it adds a ton of time.
My tests are relatively simple - parallelism and user sessions would be overkill, or not applicable. I just need a way to run multiple spec files without killing the browser between each one!
@jennifer-shehane Has the team evaluated the option that instead of killing the browser completely, we could add a new tab to it then close the previous tab? I figure that at least we could save the time and resources that the browser needs when it initialize the first time.
I’m with @mcintyret on this one - I’ve got about a dozen spec files (expected to grow rapidly), each testing a specific page in our app, and if I execute
cypress runthe majority of the test run is spent waiting for the browser to tear down or spin up. With our Jasmine/Karma tests, the browser remains open between the specs, meaning those are lightning fast to execute. This isn’t about state like some of the other comments, each spec goes to a different page, it’s just simply the time taken to relaunch browser.@renelux - How are you combining/importing diff spec file into index_spec.js file ?
@sagar-ag05 We’re working on a session API that should help with this use case. https://github.com/cypress-io/cypress/issues/8301
He is just doing something like
Making 1 spec file that imports the others, so Cypress only launches once (for the 1 spec file).
Not sure this is ideal, but it answers the question you are asking (what did the user do). Most likely you’ll want a different
specPatternfor development (so you don’t need to run every single spec in open mode, which would make iterating on specs slow).