Repository navigation
Conversation
A component that reads the session mounts the store of the client, which takes its storage listener off window one second after it was let go. A file that ended sooner left that timer behind, and when its process lived on, as while CI writes the coverage, it fired after jsdom was gone and failed the run on an unhandled error. The test setup now runs that cleanup at the end of each file.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Some components read the session through better-auth, which keeps a listener on
window. The library removes that listener one second after the last component lets go of it. If a test file ends sooner, the timer is still pending. When the process lives on for that second, as it does while CI writes coverage, the timer fires after Vitest has already removed jsdom.window.removeEventListenerno longer exists, and Vitest fails the whole run with an unhandled error even though every test passed.Fix
The test setup now runs the library's own cleanup for the session stores in an
afterAllhook. It runs whilewindowstill exists, so the late timer has nothing left to do.Changes
src/lib/testing/auth-stores.tswithsettleAuthStores(). It finds the mounted session stores of the real auth client and runs their nanostores cleanup right away. It does nothing when a file never loaded the client or replaced it with a mock.settleAuthStores()from a newafterAllhook insrc/lib/testing/setup.ts.tests/unit/lib/auth-stores.test.tsx. It checks two things: thestoragelistener is removed fromwindowat once after unmount, and nothing happens when no store is mounted.changelog/unreleased/Skyfay-auth-test-flake.md.