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:
parent
1100d8fa3d
commit
4d471ef7be
1 changed files with 12 additions and 8 deletions
|
|
@ -5,14 +5,18 @@
|
||||||
|
|
||||||
import { afterEach, beforeEach, expect, vi } from 'vitest';
|
import { afterEach, beforeEach, expect, vi } from 'vitest';
|
||||||
|
|
||||||
// Mock process.env for tests that need home directory
|
// Mock process.env for tests that need home directory.
|
||||||
vi.stubGlobal('process', {
|
// Use Proxy so process keeps all methods (listeners, on, etc.) — spreading loses them.
|
||||||
...process,
|
const testEnv = { ...process.env, HOME: '/home/testuser' };
|
||||||
env: {
|
vi.stubGlobal(
|
||||||
...process.env,
|
'process',
|
||||||
HOME: '/home/testuser',
|
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 errorSpy: ReturnType<typeof vi.spyOn>;
|
||||||
let warnSpy: ReturnType<typeof vi.spyOn>;
|
let warnSpy: ReturnType<typeof vi.spyOn>;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue