Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

test: give jsdom suites jsdom's localStorage on Node 25+

enesf67ddf7b8841
diff --git a/test/setup/jsdom-storage.ts b/test/setup/jsdom-storage.ts
new file mode 100644
index 000000000..e247cde95
--- /dev/null
+++ b/test/setup/jsdom-storage.ts
@@ -0,0 +1,24 @@
+// TEST-ONLY — give jsdom suites jsdom's Web Storage, not Node's.
+//
+// Node 25+ ships its own global `localStorage` / `sessionStorage` (Web Storage enabled by
+// default). Without `--localstorage-file` the getter answers `undefined` (and prints an
+// ExperimentalWarning). vitest's jsdom environment copies a window key onto the global only when
+// the global does NOT already have it (`getWindowKeys`: `if (k in global) return KEYS.includes(k)`),
+// and the storage keys are not in that list — so under Node 25+ every `// @vitest-environment
+// jsdom` suite saw Node's `undefined` instead of jsdom's working Storage, and
+// `localStorage.clear()` threw. On Node 22/24 (CI) the key is absent and jsdom's copy lands
+// normally, which is why it only failed on a newer local Node.
+//
+// Only acts in a jsdom environment (vitest sets `globalThis.jsdom` there). Node-environment
+// suites keep stubbing storage themselves, exactly as before.
+type JsdomGlobal = { jsdom?: { window: Window } }
+
+const dom = (globalThis as JsdomGlobal).jsdom
+if (dom) {
+ for (const key of ['localStorage', 'sessionStorage'] as const) {
+ const storage = dom.window[key]
+ if (globalThis[key] === storage) continue
+ // Configurable + writable so a suite can still `vi.stubGlobal` / redefine it.
+ Object.defineProperty(globalThis, key, { value: storage, configurable: true, writable: true })
+ }
+}
diff --git a/vitest.config.ts b/vitest.config.ts
index a037f0e8e..02dcb1257 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -42,7 +42,7 @@ export default defineConfig({
'test/setup/tmux-sandbox.ts',
'test/setup/tmp-sandbox.ts'
],
- setupFiles: ['test/setup/tmux-worker-env.ts', 'test/setup/tmp-worker-env.ts'],
+ setupFiles: ['test/setup/tmux-worker-env.ts', 'test/setup/tmp-worker-env.ts', 'test/setup/jsdom-storage.ts'],
// Issue #160: with the default (one worker per core), a 10-core Mac runs ~10 fs-heavy suites
// at once and transient fd exhaustion (EMFILE) turns into silent test flakiness — probes like
// `fs.existsSync` swallow the error and answer false, so whole files fail in ways that never