@@ -90,7 +90,9 @@ function generateReadableStream(length = 1024 * 1024, chunkSize = 10 * 1024, sle
9090
9191 yield chunk ;
9292
93- await setTimeoutAsync ( sleep ) ;
93+ if ( sleep ) {
94+ await setTimeoutAsync ( sleep ) ;
95+ }
9496 }
9597 } ( ) ) ;
9698}
@@ -733,21 +735,19 @@ describe('supports http with nodejs', function () {
733735 } ) ;
734736 } ) ;
735737
736- it ( 'should pass errors for a failed stream' , function ( done ) {
738+ it ( 'should pass errors for a failed stream' , async function ( ) {
739+ server = await startHTTPServer ( ) ;
740+
737741 var notExitPath = path . join ( __dirname , 'does_not_exist' ) ;
738742
739- server = http . createServer ( function ( req , res ) {
740- req . pipe ( res ) ;
741- } ) . listen ( 4444 , function ( ) {
742- axios . post ( 'http://localhost:4444/' ,
743+ try {
744+ await axios . post ( LOCAL_SERVER_URL ,
743745 fs . createReadStream ( notExitPath )
744- ) . then ( function ( res ) {
745- assert . fail ( 'expected ENOENT error' ) ;
746- } ) . catch ( function ( err ) {
747- assert . equal ( err . message , `ENOENT: no such file or directory, open \'${ notExitPath } \'` ) ;
748- done ( ) ;
749- } ) . catch ( done ) ;
750- } ) ;
746+ ) ;
747+ assert . fail ( 'expected ENOENT error' ) ;
748+ } catch ( err ) {
749+ assert . equal ( err . message , `ENOENT: no such file or directory, open \'${ notExitPath } \'` ) ;
750+ }
751751 } ) ;
752752
753753 it ( 'should destroy the response stream with an error on request stream destroying' , async function ( ) {
@@ -761,10 +761,19 @@ describe('supports http with nodejs', function () {
761761
762762 const { data} = await axios . post ( LOCAL_SERVER_URL , stream , { responseType : 'stream' } ) ;
763763
764+ let streamError ;
765+
766+ data . on ( 'error' , function ( err ) {
767+ streamError = err ;
768+ } ) ;
769+
764770 try {
765771 await pipelineAsync ( data , devNull ( ) ) ;
766- } catch ( err ) {
767- assert . strictEqual ( err . code , 'ERR_STREAM_PREMATURE_CLOSE' ) ;
772+ assert . fail ( 'stream was not aborted' ) ;
773+ } catch ( e ) {
774+ console . log ( `pipeline error: ${ e } ` ) ;
775+ } finally {
776+ assert . strictEqual ( streamError && streamError . code , 'ERR_CANCELED' ) ;
768777 }
769778 } ) ;
770779 } ) ;
@@ -1873,11 +1882,11 @@ describe('supports http with nodejs', function () {
18731882 try {
18741883 await pipelineAsync ( data , devNull ( ) ) ;
18751884 assert . fail ( 'stream was not aborted' ) ;
1876- } catch ( err ) {
1877- assert . ok ( err . code === axios . AxiosError . ERR_CANCELED || err . code === 'ERR_STREAM_PREMATURE_CLOSE' ) ;
1885+ } catch ( e ) {
1886+ console . log ( `pipeline error: ${ e } ` ) ;
1887+ } finally {
1888+ assert . strictEqual ( streamError && streamError . code , 'ERR_CANCELED' ) ;
18781889 }
1879-
1880- assert . strictEqual ( streamError && streamError . code , 'ERR_CANCELED' ) ;
18811890 } ) ;
18821891 } )
18831892} ) ;
0 commit comments