@@ -180,6 +180,7 @@ const createTestSuite = ({
180180 const mainProxyServerConnectionIds = [ ] ;
181181 const mainProxyServerConnectionsClosed = [ ] ;
182182 const mainProxyServerConnectionId2Stats = { } ;
183+ const mainProxyServerRequestsFinished = [ ] ;
183184
184185 let upstreamProxyHostname = '127.0.0.1' ;
185186
@@ -462,6 +463,10 @@ const createTestSuite = ({
462463 mainProxyServerConnectionId2Stats [ connectionId ] = stats ;
463464 } ) ;
464465
466+ mainProxyServer . on ( 'requestFinished' , ( { id, connectionId } ) => {
467+ mainProxyServerRequestsFinished . push ( { id, connectionId } ) ;
468+ } ) ;
469+
465470 return mainProxyServer . listen ( ) ;
466471 }
467472 } )
@@ -894,6 +899,19 @@ const createTestSuite = ({
894899 } ) ;
895900 }
896901
902+ if ( useMainProxy ) {
903+ _it ( 'should emit requestFinished event' , ( ) => {
904+ const opts = getRequestOpts ( '/hello-world' ) ;
905+ opts . method = 'GET' ;
906+ return requestPromised ( opts )
907+ . then ( ( response ) => {
908+ expect ( response . body ) . to . eql ( 'Hello world!' ) ;
909+ expect ( response . statusCode ) . to . eql ( 200 ) ;
910+ expect ( mainProxyServerRequestsFinished . length ) . to . be . above ( 0 ) ;
911+ } ) ;
912+ } ) ;
913+ }
914+
897915 if ( ! useSsl && mainProxyAuth && mainProxyAuth . username && mainProxyAuth . password ) {
898916 it ( 'handles GET request using puppeteer with invalid credentials' , async ( ) => {
899917 const phantomUrl = `${ useSsl ? 'https' : 'http' } ://${ LOCALHOST_TEST } :${ targetServerPort } /hello-world` ;
@@ -1259,6 +1277,7 @@ const createTestSuite = ({
12591277 expect ( mainProxyServer . getConnectionIds ( ) ) . to . be . deep . eql ( [ ] ) ;
12601278 }
12611279 expect ( mainProxyServerConnectionIds ) . to . be . deep . eql ( [ ] ) ;
1280+ mainProxyServerRequestsFinished . splice ( 0 , mainProxyServerRequestsFinished . length ) ;
12621281
12631282 const closedSomeConnectionsTwice = mainProxyServerConnectionsClosed
12641283 . reduce ( ( duplicateConnections , id , index ) => {
0 commit comments