Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to unblock Node 8 #929

Merged
merged 6 commits into from
Jul 12, 2017
Merged

Updates to unblock Node 8 #929

merged 6 commits into from
Jul 12, 2017

Conversation

martinkuba
Copy link
Contributor

We are currently blocked from full support of Node 8 due to nock. This is my attempt to get nock working on Node 8. If someone can review and give me pointers, I am willing to finish this up.

There is one browserify test failing on Node 7 and 8, but it seems to have been there before this change.

@coveralls
Copy link

coveralls commented Jun 5, 2017

Coverage Status

Coverage decreased (-0.6%) to 92.089% when pulling 5db4fa0 on martinkuba:node8 into 17d7c25 on node-nock:master.

@coveralls
Copy link

coveralls commented Jun 5, 2017

Coverage Status

Coverage decreased (-0.9%) to 91.823% when pulling aac5c34 on martinkuba:node8 into 17d7c25 on node-nock:master.

@@ -52,7 +56,8 @@ function setRequestHeaders(req, options, interceptor) {
// We mock request headers if these were specified.
if (interceptor.reqheaders) {
_.forOwn(interceptor.reqheaders, function(val, key) {
setHeader(req, key, val);
if (!_.isFunction(val))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is val if it's a function and is it OK that we're not setting it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val can be the matching function from reqheaders. During the matching phase, headers specified in reqheaders are copied to the client request object - now using the setHeader() function. setHeader() checks for valid characters in the header value, so it errors when the value is a function.

I am actually not sure why the headers are copied from the interceptor to the request object, since I thought reqheaders are used only for matching. In any case, setting the function as a header value seems unintended, and taking it out did not break any tests.

@ianwsperber
Copy link
Contributor

Hi @martinkuba! Thanks so much for your contribution. I've been on vacation for the past month and a half an the other maintainers no longer appear to be working on the project. Have you had success running this code in your own projects?

@martinkuba
Copy link
Contributor Author

@ianwsperber Yes, we have been running our tests on my fork since I created this PR, and have not had any issues. We run our tests on all major versions of Node back to 0.8 (in https://github.com/newrelic/node-newrelic).

@ianwsperber
Copy link
Contributor

ianwsperber commented Jul 12, 2017

Great. This has been an open issue for a long time so I'm going to move ahead with merging your PR. Thanks a ton for taking the time to get it in @martinkuba . Should have a patch up on NPM within a couple hours.

@ianwsperber ianwsperber merged commit 35c76e3 into nock:master Jul 12, 2017
@ianwsperber
Copy link
Contributor

@martinkuba unfortunately tests are failing on master ATM, those need to be fixed before I can go ahead with release. Will create issue to track.

@ianwsperber
Copy link
Contributor

#947

@martinkuba
Copy link
Contributor Author

@ianwsperber Thanks for merging this. I wanted to reply to your other question, but did not get to it in time. I will follow up and look at the failing test as well.

@martinkuba
Copy link
Contributor Author

Opened #948 to fix the failing test.

};

module.request = function(options, callback) {
// debug('request options:', options);
return newRequest(proto, overriddenRequest.bind(module), options, callback);
};

if (semver.satisfies(process.version, '>=8')) {
Copy link

@andrasq andrasq Jul 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be tested once in a shared include file, not on every request.
The dependency could be avoided by writing it as if (parseInt(process.version.slice(1) >= 8)

}
};

// in Node 8, res.end() does not call res.write() directly
if (semver.satisfies(process.version, '>=8')) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above re testing the condition only once

@@ -34,8 +34,12 @@ function setHeader(request, name, value) {
request._headerNames = request._headerNames || {};
request._removedHeader = request._removedHeader || {};

request._headers[key] = value;
request._headerNames[key] = name;
if (request.setHeader) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even node v4 has a setHeader method on req, but v7 could still set directly.
Could just reuse the is-node-v8 condition computed above.

kevinoid added a commit to kevinoid/appveyor-status that referenced this pull request Jun 29, 2018
9.0.14 includes nock/nock#929 which fixes nock/nock#922 and
nock/nock#925 which prevented nock from working on Node 8 and later.
Now test everything on all supported Node versions.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
@lock
Copy link

lock bot commented Sep 13, 2018

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!

@lock lock bot locked as resolved and limited conversation to collaborators Sep 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants