File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -575,6 +575,8 @@ export class ProcessPromise extends Promise<ProcessOutput> {
575
575
}
576
576
577
577
if ( last ) yield last
578
+
579
+ if ( ( await this . exitCode ) !== 0 ) throw this . _output
578
580
}
579
581
580
582
// Stream-like API
Original file line number Diff line number Diff line change @@ -817,6 +817,32 @@ describe('core', () => {
817
817
assert . equal ( chunks [ 0 ] , 'Chunk1' , 'First chunk should be "Chunk1"' )
818
818
assert . equal ( chunks [ 3 ] , 'Chunk4' , 'Second chunk should be "Chunk4"' )
819
819
} )
820
+
821
+ it ( 'should process all output before handling a non-zero exit code' , async ( ) => {
822
+ const process = $ `sleep 0.1; echo foo; sleep 0.1; echo bar; sleep 0.1; exit 1;`
823
+
824
+ const chunks = [ ]
825
+
826
+ let errorCaught = null
827
+ try {
828
+ for await ( const chunk of process ) {
829
+ chunks . push ( chunk )
830
+ }
831
+ } catch ( err ) {
832
+ errorCaught = err
833
+ }
834
+
835
+ assert . equal ( chunks . length , 2 , 'Should have received 2 chunks' )
836
+ assert . equal ( chunks [ 0 ] , 'foo' , 'First chunk should be "foo"' )
837
+ assert . equal ( chunks [ 1 ] , 'bar' , 'Second chunk should be "bar"' )
838
+
839
+ assert . ok ( errorCaught , 'An error should have been caught' )
840
+ assert . equal (
841
+ errorCaught . exitCode ,
842
+ 1 ,
843
+ 'The process exit code should be 1'
844
+ )
845
+ } )
820
846
} )
821
847
822
848
test ( 'quiet() mode is working' , async ( ) => {
You can’t perform that action at this time.
0 commit comments