@@ -206,22 +206,28 @@ describe("startSshPortForward", () => {
206206 expect ( kill ) . toHaveBeenCalledWith ( "SIGTERM" ) ;
207207 } ) ;
208208
209- it ( "does not crash when stderr emits a stream error" , async ( ) => {
210- vi . useFakeTimers ( ) ;
211- spawnFakeSshListening ( ) ;
209+ it . each ( [ "active" , "teardown" ] as const ) (
210+ "does not crash when stderr errors while the tunnel is %s" ,
211+ async ( phase ) => {
212+ vi . useFakeTimers ( ) ;
213+ spawnFakeSshListening ( ) ;
212214
213- const tunnel = await startSshPortForward ( {
214- target : "me@example.com:2222" ,
215- localPortPreferred : 43210 ,
216- remotePort : 18789 ,
217- timeoutMs : 1000 ,
218- } ) ;
215+ const tunnel = await startSshPortForward ( {
216+ target : "me@example.com:2222" ,
217+ localPortPreferred : 43210 ,
218+ remotePort : 18789 ,
219+ timeoutMs : 1000 ,
220+ } ) ;
219221
220- const child = mocks . spawn . mock . results [ 0 ] ?. value as EventEmitter & {
221- stderr : EventEmitter ;
222- } ;
223- child . stderr . emit ( "error" , new Error ( "stderr EPIPE" ) ) ;
222+ const child = mocks . spawn . mock . results [ 0 ] ?. value as EventEmitter & {
223+ killed : boolean ;
224+ stderr : EventEmitter ;
225+ } ;
226+ const stopping = phase === "teardown" ? tunnel . stop ( ) : undefined ;
227+ expect ( child . killed ) . toBe ( phase === "teardown" ) ;
228+ expect ( ( ) => child . stderr . emit ( "error" , new Error ( "stderr EPIPE" ) ) ) . not . toThrow ( ) ;
224229
225- await expect ( tunnel . stop ( ) ) . resolves . toBeUndefined ( ) ;
226- } ) ;
230+ await expect ( stopping ?? tunnel . stop ( ) ) . resolves . toBeUndefined ( ) ;
231+ } ,
232+ ) ;
227233} ) ;
0 commit comments