Skip to content

test: simplify fake timer handling in will-display tests - #1538

Merged
fadi-george merged 4 commits into
mainfrom
fadi/sw-will-display-test-cleanup
Oct 28, 2026
Merged

fadi-george merged 4 commits into
mainfrom
fadi/sw-will-display-test-cleanup

Conversation

@fadi-george

Copy link
Copy Markdown
Contributor

Description

1 Line Summary

Simplify fake timer handling in the will-display service worker tests and add a no try/catch rule for tests to AGENTS.md.

Details

Follow-up to #1537. The two will-display tests faked every timer and used try/finally, plus a +10 advance to let the notification show.

  • Fake only setTimeout/clearTimeout, as TESTS.md requires for tests that touch IndexedDB.
  • Restore timers in an afterEach instead of try/finally.
  • flush() now uses setImmediate instead of setTimeout(0), so it also works while setTimeout is faked.
  • The never-responds test steps exactly T - 1 (not shown) and +1 (shown), with a flush() after each. The +10 only gave queued async work more rounds and did not represent real time.
  • The overlap test flushes after the responses and before advancing, so B's IndexedDB work finishes before the 1500ms DB guard timeout could fire and wedge the DB for later tests.
  • AGENTS.md: tests should not use try/catch or try/finally.

Test-only change, no SDK behavior changes.

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

  • vp test run: 64 files, 612 tests pass. ServiceWorker.test.ts passed 3 runs in a row.
  • vp check: no errors, no new warnings.
  • Mutation checks: the never-responds test fails when the timeout is 1ms early or 1ms late, and when the timeout is removed. The previous version still passed with the timeout up to 3ms early. The overlap test fails against the original single-slot implementation from fix: show push notifications when no visible page answers the will-display check #1537.
  • Build skipped since only test and docs files changed.

Checklist

  • All the automated tests pass or I explained why that is not possible
  • I have personally tested this on my machine or explained why that is not possible
  • I have included test coverage for these changes or explained why they are not needed

Programming Checklist
Interfaces:

  • Don't use default export
  • New interfaces are in model files

Functions:

  • Don't use default export
  • All function signatures have return types
  • Helpers should not access any data but rather be given the data to operate on.

Typescript:

  • No Typescript warnings
  • Avoid silencing null/undefined warnings with the exclamation point

Other:

  • Iteration: refrain from using elem of array syntax. Prefer forEach or use map
  • Avoid using global OneSignal accessor for context if possible. Instead, we can pass it to function/constructor so that we don't call OneSignal.context

Screenshots

Info

Not needed, test-only change.

Checklist

  • I have included screenshots/recordings of the intended results or explained why they are not needed

Related Tickets

Follow-up to #1537


🤖 Generated with Claude Code

Fake only setTimeout/clearTimeout as TESTS.md requires for IndexedDB
tests, restore timers in afterEach instead of try/finally, and make
flush() use setImmediate so it works while setTimeout is faked. The
never-responds test now steps exactly T-1 and +1 with no extra advance.

Also note in AGENTS.md that tests should not use try/catch or
try/finally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread AGENTS.md Outdated
fadi-george and others added 3 commits October 28, 2026 10:54
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fadi-george
fadi-george merged commit ab8f024 into main Oct 28, 2026
1 check passed
@fadi-george
fadi-george deleted the fadi/sw-will-display-test-cleanup branch October 28, 2026 17:57
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