Monkey-patch nock, add Node v8 to test matrix

This commit is contained in:
Rob Wu
2017-07-13 18:58:29 +02:00
parent f016bd71f5
commit 70400ab166
2 changed files with 23 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ node_js:
- 4
- 6
- 7
- 8
script:
- npm run lint
- npm run test

View File

@@ -1,4 +1,26 @@
var nock = require('nock');
if (parseInt(process.versions.node, 10) >= 8) {
// See DEP0066 at https://nodejs.org/api/deprecations.html.
// _headers and _headerNames have been removed from Node v8, which causes
// nock <= 9.0.13 to fail. The snippet below monkey-patches the library, see
// https://github.com/node-nock/nock/pull/929/commits/f6369d0edd2a172024124f
// for the equivalent logic without proxies.
Object.defineProperty(require('http').ClientRequest.prototype, '_headers', {
get: function() {
var request = this;
// eslint-disable-next-line no-undef
return new Proxy(request.getHeaders(), {
set: function(target, property, value) {
request.setHeader(property, value);
return true;
},
});
},
set: function() {
// Ignore.
},
});
}
nock.enableNetConnect('127.0.0.1');