@@ -154,6 +154,7 @@ const createTestSuite = ({
154
154
const mainProxyServerConnectionIds = [ ] ;
155
155
const mainProxyServerConnectionsClosed = [ ] ;
156
156
const mainProxyServerConnectionId2Stats = { } ;
157
+ const mainProxyServerRequestsFinished = [ ] ;
157
158
158
159
let upstreamProxyHostname = '127.0.0.1' ;
159
160
@@ -419,6 +420,10 @@ const createTestSuite = ({
419
420
mainProxyServerConnectionId2Stats [ connectionId ] = stats ;
420
421
} ) ;
421
422
423
+ mainProxyServer . on ( 'requestFinished' , ( { id, connectionId } ) => {
424
+ mainProxyServerRequestsFinished . push ( { id, connectionId } ) ;
425
+ } ) ;
426
+
422
427
return mainProxyServer . listen ( ) ;
423
428
}
424
429
} )
@@ -832,6 +837,19 @@ const createTestSuite = ({
832
837
} ) ;
833
838
}
834
839
840
+ if ( useMainProxy ) {
841
+ _it ( 'should emit requestFinished event' , ( ) => {
842
+ const opts = getRequestOpts ( '/hello-world' ) ;
843
+ opts . method = 'GET' ;
844
+ return requestPromised ( opts )
845
+ . then ( ( response ) => {
846
+ expect ( response . body ) . to . eql ( 'Hello world!' ) ;
847
+ expect ( response . statusCode ) . to . eql ( 200 ) ;
848
+ expect ( mainProxyServerRequestsFinished . length ) . to . be . above ( 0 ) ;
849
+ } ) ;
850
+ } ) ;
851
+ }
852
+
835
853
if ( ! useSsl && mainProxyAuth && mainProxyAuth . username && mainProxyAuth . password ) {
836
854
it ( 'handles GET request using puppeteer with invalid credentials' , async ( ) => {
837
855
const phantomUrl = `${ useSsl ? 'https' : 'http' } ://${ LOCALHOST_TEST } :${ targetServerPort } /hello-world` ;
@@ -1178,6 +1196,7 @@ const createTestSuite = ({
1178
1196
expect ( mainProxyServer . getConnectionIds ( ) ) . to . be . deep . eql ( [ ] ) ;
1179
1197
}
1180
1198
expect ( mainProxyServerConnectionIds ) . to . be . deep . eql ( [ ] ) ;
1199
+ mainProxyServerRequestsFinished . splice ( 0 , mainProxyServerRequestsFinished . length ) ;
1181
1200
1182
1201
const closedSomeConnectionsTwice = mainProxyServerConnectionsClosed
1183
1202
. reduce ( ( duplicateConnections , id , index ) => {
0 commit comments