Skip to content

test: share one awaited resetTestDb() helper across all DB tests - #28

Merged
tsenoner merged 1 commit into
mainfrom
fix/flaky-test-db-reset
Jun 23, 2026
Merged

test: share one awaited resetTestDb() helper across all DB tests#28
tsenoner merged 1 commit into
mainfrom
fix/flaky-test-db-reset

Conversation

@tsenoner

Copy link
Copy Markdown
Owner

Latent fix surfaced while reviewing #26/#27 (not specific to either).

The IndexedDB reset dance was hand-rolled in 21 test files in three diverging forms. ~10 used a fire-and-forget variant — _resetDbForTests() and indexedDB.deleteDatabase('daycipher') with neither awaited — exactly the race _resetDbForTests's own doc-comment warns "leaks state between tests." backup.test.ts also reset un-awaited mid-test, racing the following importAll.

Change

  • Add src/test/resetDb.ts exporting resetTestDb() — awaits the connection close, then awaits the delete.
  • Route every DB test through it (beforeEach(resetTestDb); await resetTestDb() where extra setup follows). One correct implementation; the racy variants and ~16 lines/file of duplicated boilerplate are gone.

Verification

typecheck ✓ · lint --max-warnings 0 ✓ · 290 tests ✓ · build ✓. Pure test-mechanism refactor — no app code touched, test count unchanged.

🤖 Generated with Claude Code

The IndexedDB reset dance was hand-rolled in 21 test files in three
diverging forms. ~10 used a fire-and-forget variant — `_resetDbForTests()`
and `indexedDB.deleteDatabase('daycipher')` with neither awaited — exactly
the race `_resetDbForTests`'s own doc-comment warns "leaks state between
tests." (backup.test.ts also had an un-awaited reset mid-test, racing the
following importAll.)

Add src/test/resetDb.ts exporting `resetTestDb()` — awaits the connection
close, then awaits the delete — and route every test through it
(`beforeEach(resetTestDb)`). One correct implementation; the racy variants
are gone and the duplicated boilerplate collapses to a single import.

typecheck ✓ · lint --max-warnings 0 ✓ · 290 tests ✓ · build ✓

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
daycipher Ready Ready Preview, Comment Jun 23, 2026 12:05pm

@tsenoner
tsenoner merged commit 67c1e68 into main Jun 23, 2026
3 checks passed
@tsenoner
tsenoner deleted the fix/flaky-test-db-reset branch June 23, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant