File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
packages/vitest/src/runtime Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -23,12 +23,30 @@ function withSafeTimers(fn: () => void) {
2323 }
2424}
2525
26+ const promises = new Set < Promise < unknown > > ( )
27+
28+ export const rpcDone = ( ) => {
29+ if ( ! promises . size )
30+ return
31+ const awaitable = Array . from ( promises )
32+ return Promise . all ( awaitable )
33+ }
34+
2635export const rpc = ( ) => {
2736 const { rpc } = getWorkerState ( )
2837 return new Proxy ( rpc , {
2938 get ( target , p , handler ) {
3039 const sendCall = Reflect . get ( target , p , handler )
31- const safeSendCall = ( ...args : any [ ] ) => withSafeTimers ( ( ) => sendCall ( ...args ) )
40+ const safeSendCall = ( ...args : any [ ] ) => withSafeTimers ( async ( ) => {
41+ const result = sendCall ( ...args )
42+ promises . add ( result )
43+ try {
44+ return await result
45+ }
46+ finally {
47+ promises . delete ( result )
48+ }
49+ } )
3250 safeSendCall . asEvent = sendCall . asEvent
3351 return safeSendCall
3452 } ,
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { getWorkerState } from '../utils/global'
1111import type { MockMap } from '../types/mocker'
1212import type { VitestExecutor } from './execute'
1313import { createVitestExecutor } from './execute'
14- import { rpc } from './rpc'
14+ import { rpc , rpcDone } from './rpc'
1515
1616let _viteNode : {
1717 run : ( files : string [ ] , config : ResolvedConfig , executor : VitestExecutor ) => Promise < void >
@@ -109,5 +109,6 @@ function init(ctx: WorkerContext) {
109109export async function run ( ctx : WorkerContext ) {
110110 init ( ctx )
111111 const { run, executor } = await startViteNode ( ctx )
112- return run ( ctx . files , ctx . config , executor )
112+ await run ( ctx . files , ctx . config , executor )
113+ await rpcDone ( )
113114}
You can’t perform that action at this time.
0 commit comments