File tree 2 files changed +22
-3
lines changed
packages/vitest/src/runtime
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) {
23
23
}
24
24
}
25
25
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
+
26
35
export const rpc = ( ) => {
27
36
const { rpc } = getWorkerState ( )
28
37
return new Proxy ( rpc , {
29
38
get ( target , p , handler ) {
30
39
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
+ } )
32
50
safeSendCall . asEvent = sendCall . asEvent
33
51
return safeSendCall
34
52
} ,
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { getWorkerState } from '../utils/global'
11
11
import type { MockMap } from '../types/mocker'
12
12
import type { VitestExecutor } from './execute'
13
13
import { createVitestExecutor } from './execute'
14
- import { rpc } from './rpc'
14
+ import { rpc , rpcDone } from './rpc'
15
15
16
16
let _viteNode : {
17
17
run : ( files : string [ ] , config : ResolvedConfig , executor : VitestExecutor ) => Promise < void >
@@ -109,5 +109,6 @@ function init(ctx: WorkerContext) {
109
109
export async function run ( ctx : WorkerContext ) {
110
110
init ( ctx )
111
111
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 ( )
113
114
}
You can’t perform that action at this time.
0 commit comments