From 263bec4e03dfbd6b4d5ec521246de295dd870eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Bly=C5=BE=C4=97?= Date: Wed, 14 Mar 2018 05:59:37 +0200 Subject: [PATCH] Make unit tests pass in node 8 (#643) * make tests not crash in node 8 * upgrade nock This makes tests pass in node 8, as well as node 6 --- package.json | 2 +- src/lib/utils.js | 5 ++++- test/unit/specs/http_connector.js | 7 +++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 92b3182b4..f5624c488 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "mocha-lcov-reporter": "0.0.1", "mocha-screencast-reporter": "~0.1.4", "moment": "^2.13.0", - "nock": "~0.28.3", + "nock": "^9.2.3", "null-loader": "^0.1.1", "open": "0.0.5", "optimist": "~0.6.0", diff --git a/src/lib/utils.js b/src/lib/utils.js index 20cd9edbb..4ae5feb54 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -71,7 +71,10 @@ _.each([ _['isArrayOf' + type + 's'] = function (arr) { // quick shallow check of arrays - return _.isArray(arr) && _.every(arr.slice(0, 10), check); + return _.isArray(arr) && _.every(arr.slice(0, 10), function (item) { + + return check(item); + }); }; }); diff --git a/test/unit/specs/http_connector.js b/test/unit/specs/http_connector.js index 74d070063..ac5ff8db2 100644 --- a/test/unit/specs/http_connector.js +++ b/test/unit/specs/http_connector.js @@ -434,7 +434,7 @@ describe('Http Connector', function () { con.request({ body: body }, function (err, resp, status) { - expect(http.ClientRequest.prototype.setHeader.lastCall.args).to.eql(['Content-Length', 14]); + expect(http.ClientRequest.prototype.setHeader.args.find((arg) => arg[0] === 'Content-Length')).to.eql(['Content-Length', 14]); server.done(); done(); }); @@ -444,7 +444,10 @@ describe('Http Connector', function () { var con = new HttpConnection(new Host()); var respBody = 'i should not be encoded'; var server = nock('http://localhost:9200') - .matchHeader('accept-encoding', undefined) + .matchHeader('accept-encoding', function (v) { + + return v === undefined; + }) .get('/') .once() .reply(200, respBody);