fix: preserve process methods in test setup to avoid vitest worker crash

Stub process with Proxy instead of spread — spreading loses inherited
methods (listeners, on, etc.), causing process.listeners is not a function
and ERR_IPC_CHANNEL_CLOSED in CI on Windows.

Made-with: Cursor
This commit is contained in:
iliya 2026-03-03 01:21:23 +02:00
parent 1100d8fa3d
commit 4d471ef7be

View file

@ -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<string | symbol, unknown>)[prop];
},
})
);
let errorSpy: ReturnType<typeof vi.spyOn>;
let warnSpy: ReturnType<typeof vi.spyOn>;