@@ -63,12 +63,12 @@ const countString = (str, substr, cb) => {
6363
6464describe ( "proxy" , function ( ) {
6565 this . timeout ( 30000 ) ;
66- let srvA = null ;
67- let srvB = null ;
68- let proxy = null ;
66+ let srvA : http . Server | null = null ;
67+ let srvB : http . Server | null = null ;
68+ let proxy : Proxy | null = null ;
6969 const testHashes = { } ;
7070 const testFiles = [ "1024.bin" ] ;
71- let wss = null ;
71+ let wss : WebSocket . Server | null = null ;
7272
7373 before ( ( done ) => {
7474 testFiles . forEach ( ( val ) => {
@@ -121,23 +121,23 @@ describe("proxy", function () {
121121 } ) ;
122122
123123 afterEach ( ( ) => {
124- proxy . close ( ) ;
124+ proxy ? .close ( ) ;
125125 proxy = null ;
126126 } ) ;
127127
128128 after ( ( ) => {
129- srvA . close ( ) ;
129+ srvA ? .close ( ) ;
130130 srvA = null ;
131- srvB . close ( ) ;
131+ srvB ? .close ( ) ;
132132 srvB = null ;
133- wss . close ( ) ;
133+ wss ? .close ( ) ;
134134 wss = null ;
135135 } ) ;
136136
137137 describe ( "ca server" , ( ) => {
138138 it ( "should generate a root CA file" , ( done ) => {
139139 fs . access ( `${ __dirname } /../.http-mitm-proxy/certs/ca.pem` , ( err ) => {
140- let rtv = null ;
140+ let rtv : string | boolean | null = null ;
141141 if ( err ) {
142142 rtv = `${ __dirname } /../.http-mitm-proxy/certs/ca.pem ${ err } ` ;
143143 } else {
@@ -305,13 +305,14 @@ describe("proxy", function () {
305305
306306 describe ( "host match" , ( ) => {
307307 it ( "proxy and modify AAA 5 times if hostA" , ( done ) => {
308+ assert . ok ( proxy ) ;
308309 proxy . onRequest ( ( ctx , callback ) => {
309310 const testHostNameA = `127.0.0.1:${ testPortA } ` ;
310311 if ( ctx . clientToProxyRequest . headers . host === testHostNameA ) {
311- const chunks = [ ] ;
312+ const chunks : Buffer [ ] = [ ] ;
312313 ctx . onResponseData ( ( ctx , chunk , callback ) => {
313314 chunks . push ( chunk ) ;
314- return callback ( null , null ) ;
315+ return callback ( null , undefined ) ;
315316 } ) ;
316317 ctx . onResponseEnd ( ( ctx , callback ) => {
317318 let body = Buffer . concat ( chunks ) . toString ( ) ;
@@ -364,6 +365,7 @@ describe("proxy", function () {
364365 } ) ;
365366
366367 it ( "should use chunked transfer encoding when global onResponseData is active" , ( done ) => {
368+ assert . ok ( proxy ) ;
367369 proxy . onResponseData ( ( ctx , chunk , callback ) => {
368370 callback ( null , chunk ) ;
369371 } ) ;
@@ -380,6 +382,7 @@ describe("proxy", function () {
380382 } ) ;
381383
382384 it ( "should use chunked transfer encoding when context onResponseData is active" , ( done ) => {
385+ assert . ok ( proxy ) ;
383386 proxy . onResponse ( ( ctx , callback ) => {
384387 ctx . onResponseData ( ( ctx , chunk , callback ) => {
385388 callback ( null , chunk ) ;
@@ -399,6 +402,7 @@ describe("proxy", function () {
399402 } ) ;
400403
401404 it ( "should use chunked transfer encoding when context ResponseFilter is active" , ( done ) => {
405+ assert . ok ( proxy ) ;
402406 proxy . onResponse ( ( ctx , callback ) => {
403407 ctx . addResponseFilter ( zlib . createGzip ( ) ) ;
404408 callback ( null ) ;
@@ -459,6 +463,7 @@ describe("proxy", function () {
459463 close : false ,
460464 } ;
461465
466+ assert . ok ( proxy ) ;
462467 proxy . onWebSocketConnection ( ( ctx , callback ) => {
463468 stats . connection = true ;
464469 return callback ( ) ;
0 commit comments