src/index.js
function patchHttpClient() {
  const _ClientRequest = http.ClientRequest;

  function patchedHttpClient(options, done) {
    if (http.OutgoingMessage) http.OutgoingMessage.call(this);

    const hostname = getHostname(options);

    // Ignore localhost requests
    if (hostname.indexOf('127.0.0.1') === -1 && hostname.indexOf('localhost') === -1) {
      if (hostnames[hostname]) {
        hostnames[hostname]++;
      } else {
        hostnames[hostname] = 1;
      }

      testRequests.push(getHref(options));
    }

    _ClientRequest.call(this, options, done);
  }

  if (http.ClientRequest) {
    inherits(patchedHttpClient, _ClientRequest);
  } else {
    inherits(patchedHttpClient, EventEmitter);
  }

  http.ClientRequest = patchedHttpClient;

  http.request = function(options, done) {
    return new http.ClientRequest(options, done);
  };
}
function patchHttpClient() {
  const _ClientRequest = http.ClientRequest;

  function patchedHttpClient(options, done) {
    if (http.OutgoingMessage) http.OutgoingMessage.call(this);

    const hostname = getHostname(options);

    // Ignore localhost requests
    if (hostname.indexOf('127.0.0.1') === -1 && hostname.indexOf('localhost') === -1) {
      if (hostnames[hostname]) {
        hostnames[hostname]++;
      } else {
        hostnames[hostname] = 1;
      }

      testRequests.push(getHref(options));
    }

    _ClientRequest.call(this, options, done);
  }

  if (http.ClientRequest) {
    inherits(patchedHttpClient, _ClientRequest);
  } else {
    inherits(patchedHttpClient, EventEmitter);
  }

  http.ClientRequest = patchedHttpClient;

  http.request = function(options, done) {
    return new http.ClientRequest(options, done);
  };
}
function patchHttpClient ( ) { const _ClientRequest = http . ClientRequest ; function patchedHttpClient ( options , done ) { if ( http . OutgoingMessage ) http . OutgoingMessage . call ( this ) ; const hostname = getHostname ( options ) ; // Ignore localhost requests if ( hostname . indexOf ( '127.0.0.1' ) === - 1 && hostname . indexOf ( 'localhost' ) === - 1 ) { if ( hostnames [ hostname ] ) { hostnames [ hostname ] ++ ; } else { hostnames [ hostname ] = 1 ; } testRequests . push ( getHref ( options ) ) ; } _ClientRequest . call ( this , options , done ) ; } if ( http . ClientRequest ) { inherits ( patchedHttpClient , _ClientRequest ) ; } else { inherits ( patchedHttpClient , EventEmitter ) ; } http . ClientRequest = patchedHttpClient ; http . request = function ( options , done ) { return new http . ClientRequest ( options , done ) ; } ; }
Patch Node's HTTP client to record external HTTP calls.
- All hostnames are stored in `hostname` with their count for the whole
test suite.
- Full request URLs are stores in `testRequests` and used to display
recorded requests for individual tests.
- Requests to localhost are ignored.
Patch Node s HTTP client to record external HTTP calls . - All hostnames are stored in hostname with their count for the whole test suite . - Full request URLs are stores in testRequests and used to display recorded requests for individual tests . - Requests to localhost are ignored .