Comfy-Org / Comfy-Org/ComfyUI_frontend

test: revisit stubGlobal sessionStorage approach in persistToSession resilience test

Open
#13,106 1 comment 1 reaction 1 assignee Claimed by @christian-byrne View on GitHub
area:testing
Dominant language
TypeScript
Stars
2k
Forks
699
Avg merge
1d 7h
Merged PRs (30d)
490

Description

## Background

In PR #11726, the `persistToSession resilience` test in `src/platform/workspace/stores/useWorkspaceAuth.test.ts` was updated to replace the original `vi.spyOn(sessionStorage, 'setItem')` with a full `vi.stubGlobal('sessionStorage', throwingSessionStorage)` object swap.

The swap was necessary because happy-dom's Storage prototype method spies were flaky in this specific test context — spy calls on the prototype were occasionally not captured on the instance, making `setItem` throw non-deterministically.

A comment was added in the code to document this rationale.

## Follow-up

Once the test suite is more stable (e.g. after a happy-dom upgrade, a switch to jsdom, or other environment changes that resolve prototype-spy reliability), revisit this test and assess whether:

1. `vi.spyOn(globalThis.sessionStorage, 'setItem').mockImplementation(() => { throw new Error('QuotaExceededError') })` is now reliable.
2. The `vi.stubGlobal` object swap can be reverted to the simpler spy approach to reduce test weight.

## Affected file

- `src/platform/workspace/stores/useWorkspaceAuth.test.ts` — `describe('persistToSession resilience')` block

## Acceptance criteria

- The test still asserts that `workspaceToken` is updated in-memory even when `sessionStorage.setItem` throws.
- The test still asserts the console warning is emitted.
- The implementation uses `vi.spyOn` instead of the heavier `vi.stubGlobal` object replacement (if the environment supports it reliably).

## References

- PR: https://github.com/Comfy-Org/ComfyUI_frontend/pull/11726
- Comment: https://github.com/Comfy-Org/ComfyUI_frontend/pull/11726#discussion_r3176260788
- Requested by: @christian-byrne

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.