@@ -27,32 +27,12 @@ function createStubChild(pid = 1234) {
2727 Object . defineProperty ( child , "killed" , { value : false , configurable : true , writable : true } ) ;
2828 Object . defineProperty ( child , "exitCode" , { value : null , configurable : true , writable : true } ) ;
2929 Object . defineProperty ( child , "signalCode" , { value : null , configurable : true , writable : true } ) ;
30- let emittedClose = false ;
31- let emittedExit = false ;
32- let closedStreams = 0 ;
33- const maybeEmitCloseAfterStreamShutdown = ( ) => {
34- if ( emittedClose || ! emittedExit || closedStreams < 2 ) {
35- return ;
36- }
37- emittedClose = true ;
38- child . emit ( "close" , child . exitCode , child . signalCode ) ;
39- } ;
40- child . stdout . on ( "close" , ( ) => {
41- closedStreams += 1 ;
42- maybeEmitCloseAfterStreamShutdown ( ) ;
43- } ) ;
44- child . stderr . on ( "close" , ( ) => {
45- closedStreams += 1 ;
46- maybeEmitCloseAfterStreamShutdown ( ) ;
47- } ) ;
4830 const killMock = vi . fn ( ( ) => true ) ;
4931 child . kill = killMock as ChildProcess [ "kill" ] ;
5032 const emitClose = ( code : number | null , signal : NodeJS . Signals | null = null ) => {
51- emittedClose = true ;
5233 child . emit ( "close" , code , signal ) ;
5334 } ;
5435 const emitExit = ( code : number | null , signal : NodeJS . Signals | null = null ) => {
55- emittedExit = true ;
5636 child . exitCode = code ;
5737 child . signalCode = signal ;
5838 child . emit ( "exit" , code , signal ) ;
@@ -197,7 +177,7 @@ describe("createChildAdapter", () => {
197177 vi . useFakeTimers ( ) ;
198178 setPlatform ( "win32" ) ;
199179
200- const { adapter, emitExit } = await ( async ( ) => {
180+ const { adapter, emitExit, child } = await ( async ( ) => {
201181 const stub = createStubChild ( 8642 ) ;
202182 spawnWithFallbackMock . mockResolvedValue ( {
203183 child : stub . child ,
@@ -216,6 +196,8 @@ describe("createChildAdapter", () => {
216196 } ) ;
217197
218198 emitExit ( 0 , null ) ;
199+ child . stdout ?. emit ( "end" ) ;
200+ child . stderr ?. emit ( "end" ) ;
219201 await vi . advanceTimersByTimeAsync ( 300 ) ;
220202
221203 expect ( settled ) . toHaveBeenCalledWith ( { code : 0 , signal : null } ) ;
0 commit comments