11const _ = require ( 'lodash' )
22const express = require ( 'express' )
3- const http = require ( 'http' )
4- const https = require ( 'https' )
53const path = require ( 'path' )
64const debug = require ( 'debug' ) ( 'cypress:server:network-error-handling-spec' )
75const Promise = require ( 'bluebird' )
@@ -12,7 +10,6 @@ const chrome = require('@packages/server/lib/browsers/chrome')
1210const systemTests = require ( '../lib/system-tests' ) . default
1311const random = require ( '@packages/server/lib/util/random' )
1412const Fixtures = require ( '../lib/fixtures' )
15- let mitmProxy = require ( 'http-mitm-proxy' )
1613
1714const PORT = 13370
1815const PROXY_PORT = 13371
@@ -348,19 +345,19 @@ describe('e2e network error handling', function () {
348345 } )
349346
350347 context ( 'Cypress' , ( ) => {
348+ let debugProxy
349+
351350 beforeEach ( ( ) => {
352351 delete process . env . HTTP_PROXY
353352 delete process . env . HTTPS_PROXY
354353
355- return delete process . env . NO_PROXY
354+ delete process . env . NO_PROXY
356355 } )
357356
358- afterEach ( function ( ) {
359- if ( this . debugProxy ) {
360- return this . debugProxy . stop ( )
361- . then ( ( ) => {
362- this . debugProxy = null
363- } )
357+ afterEach ( async function ( ) {
358+ if ( debugProxy ) {
359+ await debugProxy . stop ( )
360+ debugProxy = null
364361 }
365362 } )
366363
@@ -415,11 +412,11 @@ describe('e2e network error handling', function () {
415412 return true
416413 } )
417414
418- this . debugProxy = new DebugProxy ( {
415+ debugProxy = new DebugProxy ( {
419416 onConnect,
420417 } )
421418
422- return this . debugProxy
419+ return debugProxy
423420 . start ( PROXY_PORT )
424421 . then ( ( ) => {
425422 process . env . HTTP_PROXY = `http://localhost:${ PROXY_PORT } `
@@ -465,9 +462,9 @@ describe('e2e network error handling', function () {
465462 } )
466463
467464 it ( 'behind a proxy' , function ( ) {
468- this . debugProxy = new DebugProxy ( )
465+ debugProxy = new DebugProxy ( )
469466
470- return this . debugProxy
467+ return debugProxy
471468 . start ( PROXY_PORT )
472469 . then ( ( ) => {
473470 process . env . HTTP_PROXY = `http://localhost:${ PROXY_PORT } `
@@ -485,27 +482,22 @@ describe('e2e network error handling', function () {
485482 } )
486483 } )
487484
488- it ( 'behind a proxy with transfer-encoding: chunked' , function ( ) {
489- mitmProxy = mitmProxy ( )
490-
491- mitmProxy . onRequest ( ( ctx , callback ) => {
492- return callback ( )
493- } )
494-
495- mitmProxy . listen ( {
496- host : '127.0.0.1' ,
497- port : PROXY_PORT ,
498- keepAlive : true ,
499- httpAgent : http . globalAgent ,
500- httpsAgent : https . globalAgent ,
501- forceSNI : false ,
502- forceChunkedRequest : true ,
485+ it ( 'behind a proxy with transfer-encoding: chunked' , async function ( ) {
486+ debugProxy = new DebugProxy ( {
487+ onRequest : ( reqUrl , req , res ) => {
488+ expect ( req . headers ) . to . have . property ( 'content-length' )
489+ // delete content-length to force te: chunked
490+ delete req . headers [ 'content-length' ]
491+ debugProxy . _onRequest ( reqUrl , req , res )
492+ } ,
503493 } )
504494
505495 process . env . HTTP_PROXY = `http://localhost:${ PROXY_PORT } `
506496 process . env . NO_PROXY = ''
507497
508- return systemTests . exec ( this , {
498+ await debugProxy . start ( PROXY_PORT )
499+
500+ await systemTests . exec ( this , {
509501 spec : 'network_error_304_handling_spec.js' ,
510502 video : false ,
511503 config : {
0 commit comments