Giter VIP home page Giter VIP logo

Comments (8)

austinbirch avatar austinbirch commented on July 21, 2024

I was just about to report what I think is the same issue.

nock version - 0.13.3
(https://github.com/mikeal/request) request version - 2.11.1
Node version - 0.8.8

I’ve posted the test code and the output below.

(function() {
  var request = require('request');

  var makeRequest = function(cb) {
    var options = {
      "uri": "http://www.google.com/"
    };

    request(options, function(err, res, body) {
      cb(err, res, body);
    });
  };

  // this outputs 'res.statusCode = 200', actually hitting the server
  makeRequest(function(err, res, body) {
    console.log('res.statusCode = ' + res.statusCode);

    // now, afterwards, try whilst using nock
    makeRequestWithNock();
  });

  var makeRequestWithNock = function() {
    var nock = require('nock');
    var scope = nock('http://www.google.com').get('/').reply(301);

    // with nock in place, this causes the error
    makeRequest(function(err, res, body) {
      console.log('res.statusCode = ' + res.statusCode);
    });
    // outputs 'false'
    console.log('scope.isDone() = ' + scope.isDone());
  };

})();

output:

res.statusCode = 200
scope.isDone() = false

/Users/austin/Development/nock-request/node_modules/request/main.js:517
    if (response.connection.listeners('error').indexOf(self._parserErrorHandle
                            ^
TypeError: Cannot call method 'listeners' of undefined
    at OverridenClientRequest.<anonymous> (/Users/austin/Development/nock-request/node_modules/request/main.js:517:29)
    at OverridenClientRequest.EventEmitter.emit (events.js:88:17)
    at end (/Users/austin/Development/nock-request/node_modules/nock/lib/request_overrider.js:206:11)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

from nock.

austinbirch avatar austinbirch commented on July 21, 2024

I’ve done a little digging, and I think I have located the breaking changes.
The last version of request available in npm that doesn’t throw this error is '2.9.203'

It seems that all of the commits causing this issue are included in this pull request:
request/request#293

When following is called, response.connection is undefined.

self.req = self.httpModule.request(self, function (response) { 

(request/request@07135d5#L0R510)

The error is thrown in request when they try to attach/check for listeners on response.connection.

I’m not really entirely sure what the best approach to fixing this is (I’m not very familiar with either project's internal code), but I thought it might make things a bit easier to figure out.

from nock.

pgte avatar pgte commented on July 21, 2024

Thanks for the report, I'll take a look.

from nock.

pgte avatar pgte commented on July 21, 2024

Released Nock v0.13.4

from nock.

austinbirch avatar austinbirch commented on July 21, 2024

Thank you.

from nock.

lock avatar lock commented on July 21, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!

from nock.

nockbot avatar nockbot commented on July 21, 2024

πŸŽ‰ This issue has been resolved in version 11.0.0-beta.20 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

from nock.

nockbot avatar nockbot commented on July 21, 2024

πŸŽ‰ This issue has been resolved in version 11.0.0 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

from nock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.