Skip to content

Fix flaky embed tests: identity loading outlives jsdom teardown - #6

Merged
lsegal merged 3 commits into
mainfrom
fix/issue-5-embed-test-teardown
Oct 3, 2026
Merged

lsegal merged 3 commits into
mainfrom
fix/issue-5-embed-test-teardown

Conversation

@lsegal

@lsegal lsegal commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the flaky app/src/embed.test.ts failure where identity loading started by App outlived the jsdom environment and threw ReferenceError: localStorage is not defined after teardown (example run).

Root cause

App starts loadIdentity (IndexedDB → localStorage) in an effect. The embed tests waited only one setTimeout(0) tick, and one mounted root was never unmounted, so identity loading could still be running when Vitest tore down jsdom. The effect also didn't check whether it had been unmounted until after LocalProject.open, so a late identity result still opened a project, and a late failure became an unhandled rejection.

Changes

  • app/src/App.tsx: the identity-loading effect ignores the result (or a rejection) of loadIdentity once the component has unmounted, and no longer opens a LocalProject after unmount.
  • app/src/embed.test.ts:
    • wraps loadIdentity to track in-flight loads, and afterEach waits for them to settle before the test ends;
    • unmounts the second mounted root, which was previously leaked;
    • adds a regression test: identity loading that rejects after unmount does not open a project and does not produce an unhandled rejection. This test fails without the App.tsx change.

Tests

  • vitest run src/embed.test.ts ran 20 times in a row: 20/20 passed with no unhandled errors.
  • pnpm run lint and pnpm run test passed (13 files, 42 tests).

Changelog

None added: the project has no changelog.

UI

Not applicable. This doesn't change any UI.

Closes #5

Agents: claude-code (claude-opus-5-5)

@lsegal
lsegal marked this pull request as ready for review October 3, 2026 21:25
@lsegal
lsegal merged commit f0572a6 into main Oct 3, 2026
1 check passed
@lsegal
lsegal deleted the fix/issue-5-embed-test-teardown branch October 3, 2026 21:31
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.

Fix flaky embed.test.ts: identity loading outlives jsdom teardown

1 participant