tprieboj
tprieboj

Reputation: 1703

Angular 7 e2e connect ETIMEDOUT, tunneling socket could not be established

I want to use e2e tests in my Angular project using protractor. Running ng e2e will cause a error

Error: connect ETIMEDOUT 216.58.201.112:443
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)

I followed this setup. First I set up Windows environment HTTP_PROXY variable.

enter image description here

Then I created src/proxy.conf.jsso it looks like this.

var HttpsProxyAgent = require('https-proxy-agent');

// https://angular.io/guide/build#proxying-to-a-backend-server
var proxyConfig = [{
  context: '/api',
  // target: 'http://your-remote-server.com:3000',
  target: 'http://172.24.61.70',
  secure: false
}];

function setupForCorporateProxy(proxyConfig) {
  var proxyServer = process.env.http_proxy || process.env.HTTP_PROXY;
  if (proxyServer) {
    var agent = new HttpsProxyAgent(proxyServer);
    console.log('Using corporate proxy server: ' + proxyServer);
    proxyConfig.forEach(function(entry) {
      entry.agent = agent;
    });
  }
  return proxyConfig;
}

module.exports = setupForCorporateProxy(proxyConfig);

Lastly I added serve to architect in angular.json.

"architect": {
    "e2e": {
      ...
    },
    "serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "my-portal:build",
        "proxyConfig": "src/proxy.conf.js"
      }
    },
    "lint": {
      ...
    }
  }

Now I am getting an error:

Error: tunneling socket could not be established, cause=getaddrinfo ENOTFOUND 8080 8080:80
at ClientRequest.onError (C:\projects\star-card-frontend\node_modules\tunnel-agent\index.js:177:17)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at Socket.socketErrorListener (_http_client.js:387:9)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

EDIT

For som reason tunnel-agent is receiving bad proxy options:

{  
   host:'8080',
   port:0,
   proxyAuth:null,
   headers:{  
      host:'chromedriver.storage.googleapis.com:443'
   }
}

Upvotes: 0

Views: 828

Answers (2)

tprieboj
tprieboj

Reputation: 1703

Ok, digging the node_modules revealed that parser in url.js used in tunnel.js parsed my HTTP_PROXY environment variable but it expected complete ulr with protocol. So adding protocol into HTTP_PROXY => http://172.24.72.10:8080 fixed the issue.

Upvotes: 1

Kacper
Kacper

Reputation: 1199

Try to set proxy in your protractor config. Set stg like that:

config = {
    capabilities: {
        proxy: {
            proxyType: 'system'
            httpProxy: process.env.http_proxy || process.env.HTTP_PROXY
        }
    }
}

Upvotes: 0

Related Questions