[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(pool): throw if user's tests use `process.send()` (#8125)

authored by

Ari Perkkiö and committed by
GitHub
(Jun 9, 2025, 9:06 AM +0200) dfe81a67 c69be1fc

+52 -2
+12
test/cli/test/forks-channel.test.ts
··· 1 + import { expect, test } from 'vitest' 2 + import { runVitest } from '../../test-utils' 3 + 4 + test.each(['forks', 'vmForks'] as const)('test case\'s process.send() calls are handled', async (pool) => { 5 + const { stderr } = await runVitest({ 6 + root: './fixtures/forks-channel', 7 + pool, 8 + }) 9 + 10 + expect(stderr).toContain('⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯') 11 + expect(stderr).toContain('Error: [vitest-pool]: Unexpected call to process.send(). Make sure your test cases are not interfering with process\'s channel.') 12 + })
+9
test/cli/fixtures/forks-channel/process-send.test.ts
··· 1 + import { test } from "vitest"; 2 + 3 + test("calls IPC channel", () => { 4 + if (!process.send) { 5 + throw new Error("Expected test case to run inside child_process") 6 + } 7 + 8 + process.send({ "not serialized": "with v8 serializer" }) 9 + })
+1
test/cli/fixtures/forks-channel/vitest.config.ts
··· 1 + export default {}
+15 -1
packages/vitest/src/node/pools/forks.ts
··· 30 30 const rpc = createBirpc<RunnerRPC, RuntimeRPC>(createMethodsRPC(project, { cacheFs: true, collect }), { 31 31 eventNames: ['onCancel'], 32 32 serialize: v8.serialize, 33 - deserialize: v => v8.deserialize(Buffer.from(v)), 33 + deserialize: (v) => { 34 + try { 35 + return v8.deserialize(Buffer.from(v)) 36 + } 37 + catch (error) { 38 + let stringified = '' 39 + 40 + try { 41 + stringified = `\nReceived value: ${JSON.stringify(v)}` 42 + } 43 + catch {} 44 + 45 + throw new Error(`[vitest-pool]: Unexpected call to process.send(). Make sure your test cases are not interfering with process's channel.${stringified}`, { cause: error }) 46 + } 47 + }, 34 48 post(v) { 35 49 emitter.emit(events.message, v) 36 50 },
+15 -1
packages/vitest/src/node/pools/vmForks.ts
··· 35 35 { 36 36 eventNames: ['onCancel'], 37 37 serialize: v8.serialize, 38 - deserialize: v => v8.deserialize(Buffer.from(v)), 38 + deserialize: (v) => { 39 + try { 40 + return v8.deserialize(Buffer.from(v)) 41 + } 42 + catch (error) { 43 + let stringified = '' 44 + 45 + try { 46 + stringified = `\nReceived value: ${JSON.stringify(v)}` 47 + } 48 + catch {} 49 + 50 + throw new Error(`[vitest-pool]: Unexpected call to process.send(). Make sure your test cases are not interfering with process's channel.${stringified}`, { cause: error }) 51 + } 52 + }, 39 53 post(v) { 40 54 emitter.emit(events.message, v) 41 55 },