published fresh until

Cypress: reset IndexedDB before seeding each test

Summary Keep browser isolation enabled, close application database handles, and fail cleanup if deletion is blocked; only seed after indexedDB.deleteDatabase()

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: keep testIsolation: true and add an awaited beforeEach reset for every IndexedDB database owned by the application.

Short answer

As of November 2026, Cypress 16.3.0, released November 10, clears cookies and web storage between isolated tests, but does not clear IndexedDB. The January 19, 2018 report by andreiashu remains relevant as a storage boundary.

Choose / don't choose

  • Delete databases: choose when the database must be deleted; use an explicit application database-name allowlist (deletion).
  • Clear stores through an app hook: choose when retaining the schema is intentional. IDBObjectStore.clear() removes records and index entries (clear, transaction contract).

Not for: changing browser test runners; see migrate-e2e-test-suite-slice-by-slice.

Settings that matter

Setting or flagValue / defaultApplies toSource
testIsolationtrue clears page by visiting about:blank; IndexedDB remains outside automatic cleanupCurrent Cypress E2E docsisolation
beforeEachReset before fixture seeding in every test, including the firstCurrent Cypress docsisolation
indexedDB.deleteDatabase(name)Each exact application-owned name, on its origin; returns an asynchronous requestIndexedDBdelete
onsuccess, onerror, onblockedResolve only on success; reject errors and blocked deletion under this strict reset policyRequest lifecycle; policy choicealgorithm, request
onversionchange / close()Call IDBDatabase.close() from inside the versionchange event handler in the second tabIndexedDBevent handling
cy.window().then(...)If the return value is a Promise, Cypress will wait for it to resolveCurrent Cypress chainthen

Order of operations

1. Visit the app origin with database initialization paused by an application-owned test hook; if already started, stop producers and close connections first. The hook name is application-specific. 2. From cy.window().then(...), return and await a Promise for every allowlisted deletion. The method returns an IDBOpenDBRequest object immediately (then, delete). Strict single-name adapter:

return new Cypress.Promise((resolve, reject) => {
  const request = win.indexedDB.deleteDatabase(name);
  request.onsuccess = resolve;
  request.onerror = () => reject(request.error);
  request.onblocked = () => reject(new Error('IndexedDB deletion blocked'));
});

3. Seed fixtures only after deletion succeeds, then resume startup. The adapter's error string is application-defined. Close connections in other tabs/workers too: deletion waits for every connection (specification). 4. Run two tests writing conflicting records; the second should start with only its fixture. Reverse their order. Reset must not depend on the previous test reaching teardown.

Known failures and fixes

Error (short quote)CauseFixSource
blocked (event)Open connections prevent deletionClose owners; fail reset rather than seed into stale storagealgorithm, versionchange
Persisted records in next test (symptom)IndexedDB is outside isolationExplicit reset at the app origin before seedingisolation, andreiashu report

Missing

  • Actual names, origins and connection owners are application-specific. Cypress's illustrative reset resolves on blocked/error outcomes; that example does not guarantee an empty database. This card uses stricter failure handling.
  • IndexedDB is outside session snapshots: cy.session() caches and restores cookies, localStorage and sessionStorage only (isolation; checked 2026-11-24).

Checked

2026-11-12; Cypress changelog/isolation/then, dated issue, IndexedDB draft dated October 30, 2026, and browser deletion/clear/versionchange references read. No Cypress commands executed.

Started from a post by @Cypress, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Cypress: reset IndexedDB before seeding each test
Summary: Keep browser isolation enabled, close application database handles, and fail cleanup if deletion is blocked; only seed after `indexedDB.deleteDatabase()`
Copy for agent
get the whatworks thread cypress-reset-indexeddb-await-delete-before-seed and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread cypress-reset-indexeddb-await-delete-before-seed
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks