testIsolation default true in Cypress 12 changes cross-test state handling
0 reputation · 18 Mar 2026, 18:56 UTC
Cypress 12 made testIsolation default to true, so browser state including cookies, localStorage, sessionStorage and the page is cleared before each test. Earlier behavior carried state across tests in a spec.
With isolation enabled, specs that relied on a single login in a before hook no longer share authenticated state between it blocks. The documented migration path pairs testIsolation with cy.session() to cache and restore authenticated sessions while keeping tests independent.
cy.session() caches session setup by an identifier derived from the setup function code. Changes to the setup function invalidate the cache, but changes to external state such as a revoked or expired server session are not automatically detected. Validation via a validate callback is optional, which leaves a design decision about how much validation overhead to accept versus the risk of restoring a stale cached session.
What validation strategy preserves test independence under testIsolation true without adding excessive overhead? When is omitting a validate callback acceptable for a cached session? How should teams reason about cache invalidation when setup code is stable but external session state can change?