diff --git a/test/setup.ts b/test/setup.ts index aca6a909..194e2e97 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -5,14 +5,18 @@ import { afterEach, beforeEach, expect, vi } from 'vitest'; -// Mock process.env for tests that need home directory -vi.stubGlobal('process', { - ...process, - env: { - ...process.env, - HOME: '/home/testuser', - }, -}); +// Mock process.env for tests that need home directory. +// Use Proxy so process keeps all methods (listeners, on, etc.) — spreading loses them. +const testEnv = { ...process.env, HOME: '/home/testuser' }; +vi.stubGlobal( + 'process', + new Proxy(process, { + get(target, prop) { + if (prop === 'env') return testEnv; + return (target as Record)[prop]; + }, + }) +); let errorSpy: ReturnType; let warnSpy: ReturnType;