Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/vitest/src/node/pools/forks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ function createChildProcessChannel(project: TestProject, collect = false) {
const rpc = createBirpc<RunnerRPC, RuntimeRPC>(createMethodsRPC(project, { cacheFs: true, collect }), {
eventNames: ['onCancel'],
serialize: v8.serialize,
deserialize: v => v8.deserialize(Buffer.from(v)),
deserialize: (v) => {
try {
return v8.deserialize(Buffer.from(v))
}
catch (error) {
let stringified = ''

try {
stringified = `\nReceived value: ${JSON.stringify(v)}`
}
catch {}

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 })
}
},
post(v) {
emitter.emit(events.message, v)
},
Expand Down
16 changes: 15 additions & 1 deletion packages/vitest/src/node/pools/vmForks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,21 @@ function createChildProcessChannel(project: TestProject, collect: boolean) {
{
eventNames: ['onCancel'],
serialize: v8.serialize,
deserialize: v => v8.deserialize(Buffer.from(v)),
deserialize: (v) => {
try {
return v8.deserialize(Buffer.from(v))
}
catch (error) {
let stringified = ''

try {
stringified = `\nReceived value: ${JSON.stringify(v)}`
}
catch {}

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 })
}
},
post(v) {
emitter.emit(events.message, v)
},
Expand Down
9 changes: 9 additions & 0 deletions test/cli/fixtures/forks-channel/process-send.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test } from "vitest";

test("calls IPC channel", () => {
if (!process.send) {
throw new Error("Expected test case to run inside child_process")
}

process.send({ "not serialized": "with v8 serializer" })
})
1 change: 1 addition & 0 deletions test/cli/fixtures/forks-channel/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {}
12 changes: 12 additions & 0 deletions test/cli/test/forks-channel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect, test } from 'vitest'
import { runVitest } from '../../test-utils'

test.each(['forks', 'vmForks'] as const)('test case\'s process.send() calls are handled', async (pool) => {
const { stderr } = await runVitest({
root: './fixtures/forks-channel',
pool,
})

expect(stderr).toContain('⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯')
expect(stderr).toContain('Error: [vitest-pool]: Unexpected call to process.send(). Make sure your test cases are not interfering with process\'s channel.')
})