Skip to content

Update pharos-toast-close event test to use fake times so it is less flaky - #1489

Merged
brentswisher merged 1 commit into
developfrom
hotfix/toast-close-test-flaky
Nov 5, 2026
Merged

brentswisher merged 1 commit into
developfrom
hotfix/toast-close-test-flaky

Conversation

@brentswisher

@brentswisher brentswisher commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

This change: (check at least one)

  • Adds a new feature
  • Fixes a bug
  • Improves maintainability
  • Improves documentation
  • Is a release activity

Is this a breaking change? (check one)

  • Yes
  • No

Is the: (complete all)

  • Title of this pull request clear, concise, and indicative of the issue number it addresses, if any?
  • Test suite(s) passing?
  • Code coverage maximal?
  • Changeset added?

What does this change address?
The pharos-toast > fires a custom event pharos-toast-close after closing test fails intermittently in Firefox on GitHub Actions with AssertionError: expected '' to be 'toast'. It caused 5 of the 7 recent "Verify changes" failures, and passes when the tests are re-run.

How does this change work?

  • After focusout, the toast waits 6000ms (TOAST_LIFE) before closing, and close() waits another 500ms before firing pharos-toast-close. So the event can't fire until 6500ms at the earliest.
  • The old test waited in real time with vi.waitFor(..., { timeout: 7000 }), which left only 500ms of slack. In passing CI runs this test took 6508–6862ms. When a runner was busy, Firefox's timers ran late enough to miss the limit.
  • The test now uses vi.useFakeTimers() and vi.advanceTimersByTimeAsync(6500), so the result no longer depends on how fast the runner is. vi.useRealTimers() runs in a finally block so fake timers can't leak into other tests.

Verification

  • I couldn't reproduce the original flake locally, but I temporarily advanced the clock to 6400ms. It then failed in all three browsers with the same assertion error CI shows.

Additional context

  • The toast test file now runs about 6.5s faster per browser, which is a nice added bonus.

@brentswisher brentswisher self-assigned this Nov 4, 2026
@changeset-bot

changeset-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8c66ec7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
packages/pharos/lib/index.js 56.4 KB (0%)

@brentswisher brentswisher changed the title test(toast): use fake timers for pharos-toast-close event test Update pharos-toast-close event test to use fake times so it is less flaky Nov 5, 2026
@brentswisher
brentswisher marked this pull request as ready for review November 5, 2026 00:34
@brentswisher
brentswisher requested a review from a team as a code owner November 5, 2026 00:34
@brentswisher
brentswisher requested review from daneah, jialin-he and satya-achanta-venkata and removed request for a team November 5, 2026 00:34
The close event fires at least 6500ms after focusout (6000ms toast life
plus a 500ms dispatch delay), but the test waited only 7000ms in real
time. Passing CI runs took 6508-6862ms, and slow Firefox timers on
GitHub runners regularly went past the limit.

Advance a fake clock instead, so the result no longer depends on how
fast the runner is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@brentswisher
brentswisher force-pushed the hotfix/toast-close-test-flaky branch from e77d0d6 to 8c66ec7 Compare November 5, 2026 12:56
@brentswisher
brentswisher enabled auto-merge (squash) November 5, 2026 12:56
@brentswisher
brentswisher merged commit 5c6ab09 into develop Nov 5, 2026
9 of 11 checks passed
@brentswisher
brentswisher deleted the hotfix/toast-close-test-flaky branch November 5, 2026 12:59
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.

2 participants