fix: use vi.stubEnv for HOME instead of stubbing process

Stubbing process breaks vitest internals (process.listeners) in workers.
stubEnv only overrides the env var and leaves process intact.

Made-with: Cursor
This commit is contained in:
iliya 2026-03-03 01:22:36 +02:00
parent 6656c88546
commit 0144046c07

View file

@ -5,18 +5,9 @@
import { afterEach, beforeEach, expect, vi } from 'vitest';
// 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<string | symbol, unknown>)[prop];
},
})
);
// Mock HOME for tests that need a predictable home path. Use stubEnv so we never
// touch process itself — stubbing process breaks vitest (process.listeners etc).
vi.stubEnv('HOME', '/home/testuser');
let errorSpy: ReturnType<typeof vi.spyOn>;
let warnSpy: ReturnType<typeof vi.spyOn>;