Skip to content

fix(tests): guard localStorage access against Node.js 22 built-in stub#822

Draft
Just-Insane wants to merge 1 commit into
SableClient:devfrom
Just-Insane:fix/debuglogger-test-init
Draft

fix(tests): guard localStorage access against Node.js 22 built-in stub#822
Just-Insane wants to merge 1 commit into
SableClient:devfrom
Just-Insane:fix/debuglogger-test-init

Conversation

@Just-Insane
Copy link
Copy Markdown
Contributor

Description

Node.js 22 ships a built-in localStorage stub that throws when accessed in a non-browser environment. The debug logger initialisation code accessed localStorage at module load time, causing the test suite to fail under Node 22 before any test ran.

Adds a guard so localStorage is only accessed when window.localStorage is available (i.e. in a real browser context).

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code

- debugLogger: wrap constructor localStorage.getItem in try/catch
- settings: wrap getSettings/setSettings in try/catch
- test/setup.ts: install in-memory localStorage polyfill before jsdom
  initialises so module-level singleton access resolves correctly

All 60 test files (570 tests) now pass on Node.js 22.
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.

1 participant