From f493527dc4c540c2835292badcdc1d5bdf25a187 Mon Sep 17 00:00:00 2001 From: spalger Date: Mon, 14 May 2018 12:16:03 -0700 Subject: [PATCH] [eslint] fix no-unused-vars violations --- .eslintrc | 2 +- test/integration/yaml_suite/run.js | 5 +-- test/mocks/writable_stream.js | 16 ++++----- test/unit/browser_builds/angular.js | 7 ---- test/unit/browser_builds/generic.js | 1 - test/unit/browser_builds/jquery.js | 1 - test/unit/buffer_flush_tests.js | 2 +- test/unit/coverage.js | 2 +- test/unit/generic_logger_tests.js | 24 ++++++------- test/unit/specs/abstract_logger.js | 2 -- test/unit/specs/client_action.js | 46 ++++++++++++------------ test/unit/specs/connection_abstract.js | 6 ++-- test/unit/specs/console_logger.js | 2 +- test/unit/specs/file_logger.js | 2 +- test/unit/specs/host.js | 1 - test/unit/specs/http_connector.js | 20 +++++------ test/unit/specs/log.js | 20 +++++++---- test/unit/specs/stdio_logger.js | 1 - test/unit/specs/stream_logger.js | 2 +- test/unit/specs/tracer_logger.js | 1 - test/unit/specs/transport.js | 15 +++++--- test/unit/specs/transport_with_server.js | 32 +++++------------ 22 files changed, 93 insertions(+), 117 deletions(-) diff --git a/.eslintrc b/.eslintrc index c6b0c225c..78c7e38af 100644 --- a/.eslintrc +++ b/.eslintrc @@ -29,7 +29,7 @@ rules: no-undef: warn no-underscore-dangle: off no-unused-expressions: error - no-unused-vars: warn + no-unused-vars: error no-use-before-define: off object-shorthand: off one-var: off diff --git a/test/integration/yaml_suite/run.js b/test/integration/yaml_suite/run.js index 64184700c..518cfa039 100644 --- a/test/integration/yaml_suite/run.js +++ b/test/integration/yaml_suite/run.js @@ -1,13 +1,10 @@ module.exports = function (branch) { var path = require('path'); - var jsYaml = require('js-yaml'); var YamlFile = require('./yaml_file'); var root = require('find-root')(__dirname); var rootReq = function (loc) { return require(path.join(root, loc)); }; var _ = require('lodash'); var utils = rootReq('src/lib/utils'); - var gruntUtils = rootReq('grunt/utils'); - var es = rootReq('src/elasticsearch'); var clientManager = require('./client_manager'); var port = parseInt(process.env.ES_PORT || 9200, 10); @@ -33,7 +30,7 @@ module.exports = function (branch) { return clientManager.get().clearEs(); }); - var files = _.map(require('./yaml_tests_' + utils.snakeCase(branch) + '.json'), function (docs, filename) { + _.map(require('./yaml_tests_' + utils.snakeCase(branch) + '.json'), function (docs, filename) { return new YamlFile(filename, docs); }); diff --git a/test/mocks/writable_stream.js b/test/mocks/writable_stream.js index 1907b233c..0fe6faf98 100644 --- a/test/mocks/writable_stream.js +++ b/test/mocks/writable_stream.js @@ -13,19 +13,19 @@ if (Writable) { MockWritableStream = module.exports = function (opts) { Writable.call(this, opts); - this._write = function (chunk, encoding, cb) {}; + this._write = function () {}; }; util.inherits(MockWritableStream, Writable); } else { // Node < 0.10 did not provide a usefull stream abstract var Stream = require('stream').Stream; - module.exports = MockWritableStream = function (opts) { + module.exports = MockWritableStream = function () { Stream.call(this); this.writable = true; }; util.inherits(MockWritableStream, Stream); - MockWritableStream.prototype.write = function (data) { + MockWritableStream.prototype.write = function () { if (!this.writable) { this.emit('error', new Error('stream not writable')); return false; @@ -41,15 +41,15 @@ if (Writable) { } }; - MockWritableStream.prototype.end = function (data, encoding, cb) { - if (typeof(data) === 'function') { - cb = data; - } else if (typeof(encoding) === 'function') { - cb = encoding; + MockWritableStream.prototype.end = function (data, encoding) { + if (typeof data === 'function') { + // no callback support + } else if (typeof encoding === 'function') { this.write(data); } else if (arguments.length > 0) { this.write(data, encoding); } + this.writable = false; }; diff --git a/test/unit/browser_builds/angular.js b/test/unit/browser_builds/angular.js index aa021498b..d6aa07db0 100644 --- a/test/unit/browser_builds/angular.js +++ b/test/unit/browser_builds/angular.js @@ -2,18 +2,14 @@ var _ = require('lodash'); var expect = require('expect.js'); var Promise = require('bluebird'); -var sinon = require('sinon'); describe('Angular esFactory', function () { before(function () { require('../../../src/elasticsearch.angular.js'); }); - var uuid = (function () { var i = 0; return function () { return ++i; }; }()); var esFactory; - var $http; var $rootScope; - var $httpBackend; function bootstrap(env) { beforeEach(function () { @@ -37,10 +33,8 @@ describe('Angular esFactory', function () { }); beforeEach(angular.mock.inject(function ($injector) { - $http = $injector.get('$http'); esFactory = $injector.get('esFactory'); $rootScope = $injector.get('$rootScope'); - $httpBackend = $injector.get('$httpBackend'); })); } @@ -70,7 +64,6 @@ describe('Angular esFactory', function () { it('returns an error created by calling a method incorrectly', function () { var client = esFactory({ hosts: null }); - var err; var prom = client.get().then(function () { throw new Error('expected request to fail'); diff --git a/test/unit/browser_builds/generic.js b/test/unit/browser_builds/generic.js index e523fe7c9..8af355ab1 100644 --- a/test/unit/browser_builds/generic.js +++ b/test/unit/browser_builds/generic.js @@ -1,5 +1,4 @@ var expect = require('expect.js'); -var Transport = require('../../../src/lib/transport'); describe('elasticsearch namespace', function () { var es = window.elasticsearch; diff --git a/test/unit/browser_builds/jquery.js b/test/unit/browser_builds/jquery.js index 11e04ad63..8edd6ae99 100644 --- a/test/unit/browser_builds/jquery.js +++ b/test/unit/browser_builds/jquery.js @@ -1,6 +1,5 @@ /* global $ */ var expect = require('expect.js'); -var Transport = require('../../../src/lib/transport'); describe('jQuery.es namespace', function () { it('is defined on the global jQuery', function () { diff --git a/test/unit/buffer_flush_tests.js b/test/unit/buffer_flush_tests.js index 4d61a7ed8..1149b415b 100644 --- a/test/unit/buffer_flush_tests.js +++ b/test/unit/buffer_flush_tests.js @@ -48,7 +48,7 @@ module.exports = function (makeLogger) { once.call(process, event, handler); }); - var logger = makeLogger(); + makeLogger(); expect(function () { // call the event handler diff --git a/test/unit/coverage.js b/test/unit/coverage.js index a59557d9d..c64cbd6bf 100644 --- a/test/unit/coverage.js +++ b/test/unit/coverage.js @@ -1,4 +1,4 @@ -var blanket = require('blanket')({ +require('blanket')({ pattern: require('path').join(__dirname, '../../src') }); diff --git a/test/unit/generic_logger_tests.js b/test/unit/generic_logger_tests.js index 42f788ceb..7dc2aed02 100644 --- a/test/unit/generic_logger_tests.js +++ b/test/unit/generic_logger_tests.js @@ -1,7 +1,5 @@ var expect = require('expect.js'); var Log = require('../../src/lib/log'); -var LoggerAbstract = require('../../src/lib/logger'); -var TracerLogger = require('../../src/lib/loggers/tracer'); var now = new Date('2013-03-01T00:00:00Z'); var sinon = require('sinon'); @@ -24,7 +22,7 @@ module.exports = function (makeLogger) { }); it('listens for the loggers\' "closing" event', function () { - var logger = makeLogger(parent); + makeLogger(parent); expect(parent.listenerCount('closing')).to.eql(1); }); }); @@ -38,7 +36,7 @@ module.exports = function (makeLogger) { }); it('listens to just error when log is explicitly error', function () { - var logger = makeLogger(parent, 'error'); + makeLogger(parent, 'error'); expect(parent.listenerCount('error')).to.eql(1); expect(parent.listenerCount('warning')).to.eql(0); expect(parent.listenerCount('info')).to.eql(0); @@ -47,7 +45,7 @@ module.exports = function (makeLogger) { }); it('listens for all the events when level is "trace"', function () { - var logger = makeLogger(parent, 'trace'); + makeLogger(parent, 'trace'); expect(parent.listenerCount('error')).to.eql(1); expect(parent.listenerCount('warning')).to.eql(1); expect(parent.listenerCount('info')).to.eql(1); @@ -56,7 +54,7 @@ module.exports = function (makeLogger) { }); it('listens for specific events when level is an array', function () { - var logger = makeLogger(parent, ['error', 'trace']); + makeLogger(parent, ['error', 'trace']); expect(parent.listenerCount('error')).to.eql(1); expect(parent.listenerCount('warning')).to.eql(0); expect(parent.listenerCount('info')).to.eql(0); @@ -87,7 +85,7 @@ module.exports = function (makeLogger) { }); it('emits events because something is listening', function () { - var logger = makeLogger(parent, 'trace'); + makeLogger(parent, 'trace'); stub(parent, 'emit'); parent.error(new Error('error message')); @@ -142,7 +140,7 @@ module.exports = function (makeLogger) { describe('#onError', function () { it('uses the Error name when it is not just "Error"', function () { var logger = makeLogger(); - stub(logger, 'write', function (label, msg) { + stub(logger, 'write', function (label) { expect(label).to.eql('TypeError'); }); @@ -152,7 +150,7 @@ module.exports = function (makeLogger) { it('uses "ERROR" when the error name is "Error"', function () { var logger = makeLogger(); - stub(logger, 'write', function (label, msg) { + stub(logger, 'write', function (label) { expect(label).to.eql('ERROR'); }); @@ -164,7 +162,7 @@ module.exports = function (makeLogger) { describe('#onWarning', function () { it('uses the "WARNING" label', function () { var logger = makeLogger(); - stub(logger, 'write', function (label, msg) { + stub(logger, 'write', function (label) { expect(label).to.eql('WARNING'); }); logger.onWarning('message'); @@ -185,7 +183,7 @@ module.exports = function (makeLogger) { describe('#onInfo', function () { it('uses the "INFO" label', function () { var logger = makeLogger(); - stub(logger, 'write', function (label, msg) { + stub(logger, 'write', function (label) { expect(label).to.eql('INFO'); }); logger.onInfo('message'); @@ -206,7 +204,7 @@ module.exports = function (makeLogger) { describe('#onDebug', function () { it('uses the "DEBUG" label', function () { var logger = makeLogger(); - stub(logger, 'write', function (label, msg) { + stub(logger, 'write', function (label) { expect(label).to.eql('DEBUG'); }); logger.onDebug('message'); @@ -227,7 +225,7 @@ module.exports = function (makeLogger) { describe('#onTrace', function () { it('uses the "TRACE" label', function () { var logger = makeLogger(); - stub(logger, 'write', function (label, msg) { + stub(logger, 'write', function (label) { expect(label).to.eql('TRACE'); }); logger.onTrace(Log.normalizeTraceArgs('GET', 'http://place/thing?me=true', '{}', '{"ok": true}', 200)); diff --git a/test/unit/specs/abstract_logger.js b/test/unit/specs/abstract_logger.js index 577c0fc9f..16b4dda71 100644 --- a/test/unit/specs/abstract_logger.js +++ b/test/unit/specs/abstract_logger.js @@ -1,11 +1,9 @@ describe('Logger Abstract', function () { var expect = require('expect.js'); - var sinon = require('sinon'); var Log = require('../../../src/lib/log'); var LoggerAbstract = require('../../../src/lib/logger'); var parentLog; - var stub = require('../../utils/auto_release_stub').make(); function makeLogger(parent, levels) { return new LoggerAbstract(parent || parentLog, { diff --git a/test/unit/specs/client_action.js b/test/unit/specs/client_action.js index 1b755ee16..417d86f7f 100644 --- a/test/unit/specs/client_action.js +++ b/test/unit/specs/client_action.js @@ -92,7 +92,7 @@ describe('Client Action runner', function () { describe('clientAction::proxy', function () { it('proxies to the passed function', function () { - var action = makeClientActionProxy(function (params, cb) { + var action = makeClientActionProxy(function () { throw new Error('proxy function called'); }); @@ -110,7 +110,7 @@ describe('Client Action runner', function () { }); }); - action({}, function (err, params) { + action({}, function () { expect(client.transport.request).to.be.a('function'); done(); }); @@ -126,7 +126,7 @@ describe('Client Action runner', function () { }); it('supports a param transformation function', function () { - var action = makeClientActionProxy(function (params, cb) { + var action = makeClientActionProxy(function (params) { expect(params).to.have.property('transformed'); }, { transform: function (params) { @@ -139,7 +139,7 @@ describe('Client Action runner', function () { it('returns the proxied function\'s return value', function () { var football = {}; - var action = makeClientActionProxy(function (params, cb) { + var action = makeClientActionProxy(function () { return football; }); @@ -186,7 +186,7 @@ describe('Client Action runner', function () { it('rejects date values', function (done) { action({ one: new Date() - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -196,7 +196,7 @@ describe('Client Action runner', function () { action({ one: ['one'], two: [1304] - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -205,7 +205,7 @@ describe('Client Action runner', function () { it('rejects object', function (done) { action({ one: { but: 'duration' } - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -242,7 +242,7 @@ describe('Client Action runner', function () { it('it rejects regexp', function (done) { action({ one: /regexp!/g - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -253,7 +253,7 @@ describe('Client Action runner', function () { one: { pasta: 'sauce' } - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -302,7 +302,7 @@ describe('Client Action runner', function () { it('it rejects things not in the list', function (done) { action({ one: 'not an opt' - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -417,7 +417,7 @@ describe('Client Action runner', function () { it('rejects dates', function (done) { action({ one: new Date() - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -426,7 +426,7 @@ describe('Client Action runner', function () { it('rejects objects', function (done) { action({ one: {} - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -435,7 +435,7 @@ describe('Client Action runner', function () { it('rejects arrays', function (done) { action({ one: [] - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -444,7 +444,7 @@ describe('Client Action runner', function () { it('rejects regexp', function (done) { action({ one: /pasta/g - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -488,7 +488,7 @@ describe('Client Action runner', function () { it('rejects dates', function (done) { action({ one: new Date() - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -497,7 +497,7 @@ describe('Client Action runner', function () { it('rejects objects', function (done) { action({ one: {} - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -506,7 +506,7 @@ describe('Client Action runner', function () { it('rejects arrays', function (done) { action({ one: [] - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -515,7 +515,7 @@ describe('Client Action runner', function () { it('rejects regexp', function (done) { action({ one: /pasta/g - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -559,7 +559,7 @@ describe('Client Action runner', function () { it('rejects objects', function (done) { action({ one: {} - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -568,7 +568,7 @@ describe('Client Action runner', function () { it('rejects arrays', function (done) { action({ one: [] - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -577,7 +577,7 @@ describe('Client Action runner', function () { it('rejects regexp', function (done) { action({ one: /pasta/g - }, function (err, params) { + }, function (err) { expect(err).to.be.a(TypeError); done(); }); @@ -732,7 +732,7 @@ describe('Client Action runner', function () { it('rejects a url if it required params that are not present', function (done) { action(params({ type: ['type1', 'type2'] - }), function (err, resp) { + }), function (err) { expect(err).to.be.a(TypeError); params.check(); done(); @@ -845,7 +845,7 @@ describe('Client Action runner', function () { it('enforces required params', function (done) { action(params({ b: '3w' - }), function (err, resp) { + }), function (err) { expect(err).to.be.a(TypeError); params.check(); done(); diff --git a/test/unit/specs/connection_abstract.js b/test/unit/specs/connection_abstract.js index f9b67ff33..f1c3f2753 100644 --- a/test/unit/specs/connection_abstract.js +++ b/test/unit/specs/connection_abstract.js @@ -17,11 +17,13 @@ describe('Connection Abstract', function () { it('requires a valid host', function () { expect(function () { - var conn = new ConnectionAbstract(); + // eslint-disable-next-line no-new + new ConnectionAbstract(); }).to.throwError(TypeError); expect(function () { - var conn = new ConnectionAbstract({}); + // eslint-disable-next-line no-new + new ConnectionAbstract({}); }).to.throwError(TypeError); }); diff --git a/test/unit/specs/console_logger.js b/test/unit/specs/console_logger.js index f7bacbeb0..e912664ef 100644 --- a/test/unit/specs/console_logger.js +++ b/test/unit/specs/console_logger.js @@ -20,7 +20,7 @@ function makeLogger(parent, levels) { return new ConsoleLogger(parent, config); } -var stub = require('../../utils/auto_release_stub').make(); +require('../../utils/auto_release_stub').make(); describe('Console Logger', function () { diff --git a/test/unit/specs/file_logger.js b/test/unit/specs/file_logger.js index 89162a0dc..cfe27ac17 100644 --- a/test/unit/specs/file_logger.js +++ b/test/unit/specs/file_logger.js @@ -79,7 +79,7 @@ describe('File Logger', function () { once.call(process, event, handler); }); - var logger = makeLogger(); + makeLogger(); expect(function () { // call the event handler diff --git a/test/unit/specs/host.js b/test/unit/specs/host.js index 74589bbef..8429cb998 100644 --- a/test/unit/specs/host.js +++ b/test/unit/specs/host.js @@ -1,5 +1,4 @@ var Host = require('../../../src/lib/host'); -var _ = require('lodash'); var expect = require('expect.js'); var url = require('url'); var expectSubObject = require('../../utils/expect_sub_object'); diff --git a/test/unit/specs/http_connector.js b/test/unit/specs/http_connector.js index e1d73fdff..22064e125 100644 --- a/test/unit/specs/http_connector.js +++ b/test/unit/specs/http_connector.js @@ -3,15 +3,12 @@ describe('Http Connector', function () { var _ = require('lodash'); var expect = require('expect.js'); var nock = require('nock'); - var sinon = require('sinon'); - var util = require('util'); var parseUrl = require('url').parse; var http = require('http'); var https = require('https'); var AgentKeepAlive = require('agentkeepalive'); var Host = require('../../../src/lib/host'); - var errors = require('../../../src/lib/errors'); var HttpConnection = require('../../../src/lib/connectors/http'); var ConnectionAbstract = require('../../../src/lib/connection'); @@ -62,7 +59,8 @@ describe('Http Connector', function () { it('expects the host to have a protocol of http or https', function () { expect(function () { - var con = new HttpConnection(new Host('thrifty://es.com/stuff')); + // eslint-disable-next-line no-new + new HttpConnection(new Host('thrifty://es.com/stuff')); }).to.throwError(/invalid protocol/i); }); @@ -254,7 +252,7 @@ describe('Http Connector', function () { stub(con.log, 'error'); stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody()); - con.request({}, function (err, resp, status) { + con.request({}, function () { expect(con.log.error.callCount).to.eql(0); done(); }); @@ -264,7 +262,7 @@ describe('Http Connector', function () { var con = new HttpConnection(new Host('https://google.com')); stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody(new Error('no more message :('))); - con.request({}, function (err, resp, status) { + con.request({}, function (err) { expect(err).to.be.an(Error); expect(err.message).to.eql('no more message :('); done(); @@ -275,7 +273,7 @@ describe('Http Connector', function () { var con = new HttpConnection(new Host('https://google.com')); stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody()); - con.request({}, function (err, resp, status) { + con.request({}, function (err, resp) { expect(resp).to.be(undefined); done(); }); @@ -414,7 +412,7 @@ describe('Http Connector', function () { stub(http.ClientRequest.prototype, 'setNoDelay'); var server = nock('http://localhost').get('/').reply(200); - con.request({}, function (err, resp, status) { + con.request({}, function () { expect(http.ClientRequest.prototype.setNoDelay.callCount).to.eql(1); expect(http.ClientRequest.prototype.setNoDelay.lastCall.args[0]).to.eql(true); server.done(); @@ -433,7 +431,7 @@ describe('Http Connector', function () { con.request({ body: body - }, function (err, resp, status) { + }, function () { expect(http.ClientRequest.prototype.setHeader.args.find((arg) => arg[0] === 'Content-Length')).to.eql(['Content-Length', 14]); server.done(); done(); @@ -452,7 +450,7 @@ describe('Http Connector', function () { .once() .reply(200, respBody); - con.request({}, function (err, resp, status) { + con.request({}, function (err, resp) { expect(resp).to.be(respBody); server.done(); done(); @@ -468,7 +466,7 @@ describe('Http Connector', function () { .once() .reply(200, respBody); - con.request({}, function (err, resp, status) { + con.request({}, function (err, resp) { expect(resp).to.be(respBody); server.done(); done(); diff --git a/test/unit/specs/log.js b/test/unit/specs/log.js index 6cccfde42..c6000a5f9 100644 --- a/test/unit/specs/log.js +++ b/test/unit/specs/log.js @@ -134,7 +134,7 @@ describe('Log class', function () { log = new Log({ log: [ { - type: function (log, config) { + type: function (log) { log.on('error', _.noop); log.on('warning', _.noop); log.on('info', _.noop); @@ -237,22 +237,28 @@ describe('Log class', function () { it('rejects numbers and other truthy data-types', function () { expect(function () { - var log = new Log({ log: 1515 }); + // eslint-disable-next-line no-new + new Log({ log: 1515 }); }).to.throwError(/invalid logging output config/i); expect(function () { - var log = new Log({ log: /regexp/ }); + // eslint-disable-next-line no-new + new Log({ log: /regexp/ }); }).to.throwError(/invalid logging output config/i); expect(function () { - var log = new Log({ log: new Date() }); + // eslint-disable-next-line no-new + new Log({ log: new Date() }); }).to.throwError(/invalid logging output config/i); expect(function () { - var log = new Log({ log: [1515] }); + // eslint-disable-next-line no-new + new Log({ log: [1515] }); }).to.throwError(/invalid logging output config/i); expect(function () { - var log = new Log({ log: [/regexp/] }); + // eslint-disable-next-line no-new + new Log({ log: [/regexp/] }); }).to.throwError(/invalid logging output config/i); expect(function () { - var log = new Log({ log: [new Date()] }); + // eslint-disable-next-line no-new + new Log({ log: [new Date()] }); }).to.throwError(/invalid logging output config/i); }); }); diff --git a/test/unit/specs/stdio_logger.js b/test/unit/specs/stdio_logger.js index 6e4d5c833..2ba49e4e1 100644 --- a/test/unit/specs/stdio_logger.js +++ b/test/unit/specs/stdio_logger.js @@ -31,7 +31,6 @@ describe('Stdio Logger', function () { var now = '2013-01-01T00:00:00Z'; var nowDate = new Date(now); var nowTime = nowDate.getTime(); - var clock; beforeEach(function () { stub.autoRelease(sinon.useFakeTimers(nowTime)); diff --git a/test/unit/specs/stream_logger.js b/test/unit/specs/stream_logger.js index 03fb2ceeb..734ef91e5 100644 --- a/test/unit/specs/stream_logger.js +++ b/test/unit/specs/stream_logger.js @@ -78,7 +78,7 @@ describe('Stream Logger', function () { once.call(process, event, handler); }); - var logger = makeLogger(); + makeLogger(); expect(function () { // call the event handler diff --git a/test/unit/specs/tracer_logger.js b/test/unit/specs/tracer_logger.js index d78269c11..28042670d 100644 --- a/test/unit/specs/tracer_logger.js +++ b/test/unit/specs/tracer_logger.js @@ -2,7 +2,6 @@ describe('Tracer Logger', function () { var Log = require('../../../src/lib/log'); var TracerLogger = require('../../../src/lib/loggers/tracer'); - var sinon = require('sinon'); var expect = require('expect.js'); var parentLog; diff --git a/test/unit/specs/transport.js b/test/unit/specs/transport.js index 0166e36d5..13798679e 100644 --- a/test/unit/specs/transport.js +++ b/test/unit/specs/transport.js @@ -59,7 +59,8 @@ describe('Transport Class', function () { it('Throws an error when connectionPool config is set wrong', function () { expect(function () { - var trans = new Transport({ + // eslint-disable-next-line no-new + new Transport({ connectionPool: 'pasta' }); }).to.throwError(/invalid connectionpool/i); @@ -166,7 +167,8 @@ describe('Transport Class', function () { describe('host config', function () { it('rejects non-strings/objects', function () { expect(function () { - var trans = new Transport({ + // eslint-disable-next-line no-new + new Transport({ host: [ 'localhost', 9393 @@ -175,7 +177,8 @@ describe('Transport Class', function () { }).to.throwError(TypeError); expect(function () { - var trans = new Transport({ + // eslint-disable-next-line no-new + new Transport({ host: [ [9292] ] @@ -287,7 +290,8 @@ describe('Transport Class', function () { it('calls _.shuffle be default', function () { stub(Transport.connectionPools.main.prototype, 'setHosts'); stub(_, 'shuffle'); - var trans = new Transport({ + // eslint-disable-next-line no-new + new Transport({ hosts: 'localhost' }); @@ -296,7 +300,8 @@ describe('Transport Class', function () { it('skips the call to _.shuffle when false', function () { stub(Transport.connectionPools.main.prototype, 'setHosts'); stub(_, 'shuffle'); - var trans = new Transport({ + // eslint-disable-next-line no-new + new Transport({ hosts: 'localhost', randomizeHosts: false }); diff --git a/test/unit/specs/transport_with_server.js b/test/unit/specs/transport_with_server.js index 1f55a7599..1a61ab72e 100644 --- a/test/unit/specs/transport_with_server.js +++ b/test/unit/specs/transport_with_server.js @@ -1,6 +1,5 @@ var Transport = require('../../../src/lib/transport'); var ConnectionPool = require('../../../src/lib/connection_pool'); -var Host = require('../../../src/lib/host'); var errors = require('../../../src/lib/errors'); var expect = require('expect.js'); @@ -10,21 +9,6 @@ var through2 = require('through2'); var _ = require('lodash'); var stub = require('../../utils/auto_release_stub').make(); -/** - * Allows the tests call #request() without it doing anything past trying to select - * a connection. - * @param {Transport} tran - the transport to neuter - */ -function shortCircuitRequest(tran, delay) { - stub(tran.connectionPool, 'select', function (cb) { - setTimeout(cb, delay); - }); -} - -function getConnection(transport, status) { - return transport.connectionPool.getConnections(status || 'alive', 1).pop(); -} - describe('Transport + Mock server', function () { describe('#request', function () { describe('server responds', function () { @@ -209,7 +193,7 @@ describe('Transport + Mock server', function () { trans.request({ path: '/', - }, function (err, body, status) { + }, function (err, body) { expect(err).to.be(undefined); expect(body).to.eql({ 'the answer': 42 @@ -228,7 +212,7 @@ describe('Transport + Mock server', function () { trans.request({ path: '/hottie-threads', - }, function (err, body, status) { + }, function (err, body) { expect(err).to.be(undefined); expect(body).to.match(/s?he said/g); done(); @@ -239,7 +223,7 @@ describe('Transport + Mock server', function () { describe('return value', function () { it('resolves the promise it with the response body', function (done) { - var serverMock = nock('http://esbox.1.com') + nock('http://esbox.1.com') .get('/') .reply(200, { good: 'day' @@ -266,7 +250,7 @@ describe('Transport + Mock server', function () { host: 'http://localhost:9200' }); - var server = nock('http://localhost:9200') + nock('http://localhost:9200') .get('/') .reply(200, { i: 'am here' @@ -286,7 +270,7 @@ describe('Transport + Mock server', function () { host: 'http://localhost:9200' }); - var server = nock('http://localhost:9200') + nock('http://localhost:9200') .get('/') .delay(1000) .reply(200, { @@ -295,7 +279,7 @@ describe('Transport + Mock server', function () { tran.request({ requestTimeout: 25 - }, function (err, resp, status) { + }, function (err) { expect(err).to.be.a(errors.RequestTimeout); done(); }); @@ -307,7 +291,7 @@ describe('Transport + Mock server', function () { var clock = sinon.useFakeTimers('setTimeout'); stub.autoRelease(clock); - var serverMock = nock('http://esbox.1.com') + nock('http://esbox.1.com') .get('/') .reply(200, function () { var str = through2(function (chunk, enc, cb) { @@ -338,7 +322,7 @@ describe('Transport + Mock server', function () { .then(function () { throw new Error('expected the request to fail'); }) - .catch(function (err) { + .catch(function () { expect(ConnectionPool.prototype._onConnectionDied.callCount).to.eql(1); expect(tran.sniff.callCount).to.eql(0); expect(_.size(clock.timers)).to.eql(1);