@@ -18,6 +18,7 @@ import {
1818import { log } from '../log'
1919import { createVitestRpc } from './rpc'
2020import { resolve } from 'pathe'
21+ import { parse , stringify } from 'flatted'
2122
2223export type WsConnectionMetadata = Omit < ResolvedMeta , 'process' > & {
2324 ws : WebSocket
@@ -83,6 +84,21 @@ export function onWsConnection(
8384 const { api, handlers } = createVitestRpc ( {
8485 on : ( listener ) => ws . on ( 'message' , listener ) ,
8586 send : ( message ) => ws . send ( message ) ,
87+ serialize :
88+ pkg . runtime !== 'node'
89+ ? ( e ) =>
90+ stringify ( e , ( _ , v ) => {
91+ if ( v instanceof Error ) {
92+ return {
93+ name : v . name ,
94+ message : v . message ,
95+ stack : v . stack ,
96+ }
97+ }
98+ return v
99+ } )
100+ : undefined ,
101+ deserialize : pkg . runtime !== 'node' ? parse : undefined ,
86102 } )
87103 ws . once ( 'close' , ( ) => {
88104 log . verbose ?.( '[API]' , 'Vitest WebSocket connection closed, cannot call RPC anymore.' )
@@ -153,6 +169,7 @@ export function onWsConnection(
153169 env : getConfig ( pkg . folder ) . env || undefined ,
154170 configFile : pkg . configFile ,
155171 cwd : pkg . cwd ,
172+ runtime : pkg . runtime ,
156173 arguments : pkg . arguments ,
157174 workspaceFile : pkg . workspaceFile ,
158175 id : pkg . id ,
0 commit comments