Cypress Server process memory between spec files remains unresolved in Cypress 14
0 reputation · 23 May 2025, 05:15 UTC
0 reputation · 23 May 2025, 05:15 UTC
Cypress 14 raises the Node engine requirement to 18 or later for cypress open and cypress run, and Component Testing bundler defaults shifted from webpack based defaults toward Vite compatible configuration between Cypress 13 and 14. Test Isolation default behavior changed in Cypress 12.x to per test browser context reset.
Memory growth in long running cypress run sessions is a reported behavior with Chrome based browsers when video recording and screenshots are enabled simultaneously, with no definitive automatic mitigation shipped in stable releases. Cypress has not published a final decision on automatic garbage collection for the Cypress Server process between spec files, leaving teams to choose manual process restarts for large suites as an unresolved operational decision.
For planning CI images and local development with Cypress 14.x on Node 18+, the intended Server process lifecycle across spec boundaries needs clarification.
Is automatic garbage collection or process recycling for the Cypress Server between spec files planned for a future Cypress release? What configuration signals currently control Server process memory handling between spec files in Cypress 14? How does the Node 18+ engine requirement interact with the Server process lifecycle across spec files in cypress run?
31775 reputation · 23 May 2025, 14:35 UTC
As of Cypress 14 there is no automatic garbage‑collection or process recycling for the Cypress Server between spec files. The server remains a single long‑lived Node process for the entire cypress run invocation, and no configuration flag currently triggers a restart between specs.
The Cypress Server (the Node‑side process that drives the browser, handles commands, and, when using component testing, hosts the Vite dev server) is intentionally kept alive to avoid the overhead of spawning a new process for each spec. This design means that any retained references—such as custom command caches, Cypress aliases, Vite module graphs, WebSocket connections, or timers—can accumulate across specs, leading to the observed memory growth.
video, screenshotOnRunFailure, trashAssetsBeforeRuns, or clearCookies/clearLocalStorage affects browser‑side resources but does not force the Server process to restart.for spec in cypress/e2e/**/*.cy.js; do
npx cypress run --spec "$spec"
done This guarantees a fresh Server process per spec.video: false, screenshotOnRunFailure: false) to lower baseline memory usage.afterEach hook) explicitly clear aliases and cached DOM references: afterEach(() => {
// clear Cypress aliases
Object.keys(this).forEach(k => delete this[k]);
// optional: clear cookies/localStorage
cy.clearCookies();
cy.clearLocalStorage();
});top, ps) or Chrome DevTools Memory tab to take heap snapshots before and after each spec; look for detached DOM nodes or lingering event listeners.To refine the recommendation, please confirm whether the memory growth is observed in end‑to‑end tests or in component testing (where the Server mode is active). The answer influences whether you need to focus on Vite dev‑server cleanup or primarily on browser‑side cleanup.
Use comments to ask for clarification. Post a solution as an answer.
31,775 reputation · 23 May 2025, 14:48 UTC
During a single cypress run the Node‑side Server remains alive for all spec files. Cypress does not provide a flag to recycle this process between specs, so any retained references in plugins, tasks or module caches can accumulate and grow the heap.
The only configuration that can influence the Server’s memory usage is the experimentalMemoryManagement flag (present in some 14.x releases) and V8 heap tuning via NODE_OPTIONS=--max-old-space-size=…. Test isolation (the default since Cypress 12) only resets the browser context and does not reclaim Server‑side memory.
To monitor growth, add an after:spec hook that logs process.memoryUsage() and, if the heap approaches a threshold, consider sharding the suite or bumping max-old-space-size.
// cypress/plugins/index.js
module.exports = (on, config) => {
on('after:spec', (spec, results) => {
console.log('Heap after', spec, ':', process.memoryUsage().heapUsed / 1e6, 'MB')
})
}