Skip to content

test: [SDK-5338] stub _delayedInit in the consent tests so init does not outlive the environment - #1508

Merged
sherwinski merged 2 commits into
feat/identity-verificationfrom
sherwin/sdk-5338
Sep 22, 2026
Merged

sherwinski merged 2 commits into
feat/identity-verificationfrom
sherwin/sdk-5338

Conversation

@sherwinski

Copy link
Copy Markdown
Contributor

Description

1 Line Summary

Stub OneSignal._delayedInit in the "Consent Required" tests so an un-awaited init chain cannot outlive the test environment.

Details

CI run 35790346377 on #1505 failed with all 759 tests green and 1 unhandled rejection:

ReferenceError: document is not defined
 ❯ internalInit src/shared/helpers/init.ts:34:3
 ❯ __init src/onesignal/OneSignal.ts:195:7
 ❯ OneSignal._delayedInit src/onesignal/OneSignal.ts:198:86
 ❯ OneSignal.setConsentGiven src/onesignal/OneSignal.ts:229:44
This error originated in "src/onesignal/OneSignal.test.ts"

A second run on the same commit passed. The same error also failed run 35666490541 on sherwin/sdk-5229, so the flake predates the M3 stack.

Cause. The "Consent Required" block calls void OneSignal.setConsentGiven(true). OneSignal._pendingInit defaults to true, so the call starts _delayedInit() and the full init chain. The test does not await the chain. When Vitest tears down the DOM environment first, the chain reaches document.visibilityState with no document.

Fix. Stub _delayedInit in the block's beforeEach. The 2 tests check only the consent gate on login and logout, not init. A // @ts-expect-error marks the private member, the same pattern the file already uses.

Scope. Test-only. No SDK code changes. Run 35648657769 on sherwin/sdk-5230 failed the same way with localStorage is not defined from LoginManager.test.ts. That leak is noted on SDK-5338 and is not part of this PR.

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

  • vp check: 0 errors
  • npx tsc --noEmit: clean
  • vp test run: 67 files, 684 tests pass, 0 unhandled errors

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

SDK-5338


… the environment

The "Consent Required" block calls setConsentGiven(true) without an await.
_pendingInit defaults to true, so the call starts the full init chain. When
the environment tears down first, the chain reaches document.visibilityState
in init.ts and Vitest reports an unhandled rejection with all tests green.
@sherwinski
sherwinski merged commit d0760b8 into feat/identity-verification Sep 22, 2026
1 check passed
@sherwinski
sherwinski deleted the sherwin/sdk-5338 branch September 22, 2026 23:53
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