From 50b4009005a7adf1d3fa2af2739dac402ca7f9fc Mon Sep 17 00:00:00 2001 From: JinHyuk Kim Date: Wed, 6 Feb 2019 23:19:03 +0900 Subject: [PATCH] fix incorrect code for eslint rules (#1367) * fix code for eslint rules --- test/batch.spec.js | 68 +++++++++++++++++------------------ test/commands/select.spec.js | 4 +-- test/connection.spec.js | 2 +- test/lib/redis-process.js | 25 ++++++------- test/multi.spec.js | 70 ++++++++++++++++++------------------ test/node_redis.spec.js | 2 +- test/tls.spec.js | 12 +++---- 7 files changed, 92 insertions(+), 91 deletions(-) diff --git a/test/batch.spec.js b/test/batch.spec.js index 762b2f7049..df038e77e6 100644 --- a/test/batch.spec.js +++ b/test/batch.spec.js @@ -187,12 +187,12 @@ describe("The 'batch' method", function () { ['del', 'some set'], ['smembers', 'some set', undefined] // The explicit undefined is handled as a callback that is undefined ]) - .scard('some set') - .exec(function (err, replies) { - assert.strictEqual(4, replies[0].length); - assert.strictEqual(0, replies[2].length); - return done(); - }); + .scard('some set') + .exec(function (err, replies) { + assert.strictEqual(4, replies[0].length); + assert.strictEqual(0, replies[2].length); + return done(); + }); }); it('allows multiple operations to be performed using constructor with all kinds of syntax', function (done) { @@ -213,29 +213,29 @@ describe("The 'batch' method", function () { ['HMSET', 'batchhmset', ['batchbar', 'batchbaz']], ['hmset', 'batchhmset', ['batchbar', 'batchbaz'], helper.isString('OK')], ]) - .hmget(now, 123456789, 'otherTypes') - .hmget('key2', arr2, function noop () {}) - .hmget(['batchhmset2', 'some manner of key', 'batchbar3']) - .mget('batchfoo2', ['batchfoo3', 'batchfoo'], function (err, res) { - assert.strictEqual(res[0], 'batchbar2'); - assert.strictEqual(res[1], 'batchbar3'); - assert.strictEqual(res[2], null); - }) - .exec(function (err, replies) { - assert.equal(arr.length, 3); - assert.equal(arr2.length, 2); - assert.equal(arr3.length, 3); - assert.equal(arr4.length, 3); - assert.strictEqual(null, err); - assert.equal(replies[10][1], '555'); - assert.equal(replies[11][0], 'a type of value'); - assert.strictEqual(replies[12][0], null); - assert.equal(replies[12][1], 'test'); - assert.equal(replies[13][0], 'batchbar2'); - assert.equal(replies[13].length, 3); - assert.equal(replies.length, 14); - return done(); - }); + .hmget(now, 123456789, 'otherTypes') + .hmget('key2', arr2, function noop () {}) + .hmget(['batchhmset2', 'some manner of key', 'batchbar3']) + .mget('batchfoo2', ['batchfoo3', 'batchfoo'], function (err, res) { + assert.strictEqual(res[0], 'batchbar2'); + assert.strictEqual(res[1], 'batchbar3'); + assert.strictEqual(res[2], null); + }) + .exec(function (err, replies) { + assert.equal(arr.length, 3); + assert.equal(arr2.length, 2); + assert.equal(arr3.length, 3); + assert.equal(arr4.length, 3); + assert.strictEqual(null, err); + assert.equal(replies[10][1], '555'); + assert.equal(replies[11][0], 'a type of value'); + assert.strictEqual(replies[12][0], null); + assert.equal(replies[12][1], 'test'); + assert.equal(replies[13][0], 'batchbar2'); + assert.equal(replies[13].length, 3); + assert.equal(replies.length, 14); + return done(); + }); }); it('converts a non string key to a string', function (done) { @@ -316,11 +316,11 @@ describe("The 'batch' method", function () { ['mget', ['batchfoo', 'some', 'random value', 'keys']], ['incr', 'batchfoo'] ]) - .exec(function (err, replies) { - assert.strictEqual(replies.length, 2); - assert.strictEqual(replies[0].length, 4); - return done(); - }); + .exec(function (err, replies) { + assert.strictEqual(replies.length, 2); + assert.strictEqual(replies[0].length, 4); + return done(); + }); }); it('allows multiple operations to be performed on a hash', function (done) { diff --git a/test/commands/select.spec.js b/test/commands/select.spec.js index 1dff2025d9..66a66f389b 100644 --- a/test/commands/select.spec.js +++ b/test/commands/select.spec.js @@ -72,7 +72,7 @@ describe("The 'select' method", function () { assert.strictEqual(client.selected_db, undefined, 'default db should be undefined'); client.select(9999, function (err) { assert.equal(err.code, 'ERR'); - assert((err.message == 'ERR DB index is out of range' || err.message == 'ERR invalid DB index')); + assert((err.message === 'ERR DB index is out of range' || err.message === 'ERR invalid DB index')); done(); }); }); @@ -97,7 +97,7 @@ describe("The 'select' method", function () { client.on('error', function (err) { assert.strictEqual(err.command, 'SELECT'); - assert((err.message == 'ERR DB index is out of range' || err.message == 'ERR invalid DB index')); + assert((err.message === 'ERR DB index is out of range' || err.message === 'ERR invalid DB index')); done(); }); diff --git a/test/connection.spec.js b/test/connection.spec.js index f92dca1949..c33d1b8a83 100644 --- a/test/connection.spec.js +++ b/test/connection.spec.js @@ -376,7 +376,7 @@ describe('connection tests', function () { var add = process.platform !== 'win32' ? 15 : 200; var now = Date.now(); assert(now - time < connect_timeout + add, 'The real timeout time should be below ' + (connect_timeout + add) + 'ms but is: ' + (now - time)); - // Timers sometimes trigger early (e.g. 1ms to early) + // Timers sometimes trigger early (e.g. 1ms to early) assert(now - time >= connect_timeout - 5, 'The real timeout time should be above ' + connect_timeout + 'ms, but it is: ' + (now - time)); done(); }); diff --git a/test/lib/redis-process.js b/test/lib/redis-process.js index e98f7fbffc..c46fd8d70f 100644 --- a/test/lib/redis-process.js +++ b/test/lib/redis-process.js @@ -27,20 +27,21 @@ function waitForRedis (available, cb, port) { bluebird.join( tcpPortUsed.check(port, '127.0.0.1'), tcpPortUsed.check(port, '::1'), - function (ipV4, ipV6) { - if (ipV6 === available && ipV4 === available) { - if (fs.existsSync(socket) === available) { - clearInterval(id); - return cb(); + function (ipV4, ipV6) { + if (ipV6 === available && ipV4 === available) { + if (fs.existsSync(socket) === available) { + clearInterval(id); + return cb(); + } + // The same message applies for can't stop but we ignore that case + throw new Error('Port ' + port + ' is already in use. Tests can\'t start.\n'); } - // The same message applies for can't stop but we ignore that case - throw new Error('Port ' + port + ' is already in use. Tests can\'t start.\n'); + if (Date.now() - time > 6000) { + throw new Error('Redis could not start on port ' + (port || config.PORT) + '\n'); + } + running = false; } - if (Date.now() - time > 6000) { - throw new Error('Redis could not start on port ' + (port || config.PORT) + '\n'); - } - running = false; - }).catch(function (err) { + ).catch(function (err) { console.error('\x1b[31m' + err.stack + '\x1b[0m\n'); process.exit(1); }); diff --git a/test/multi.spec.js b/test/multi.spec.js index e654375dc8..33ffdbe16c 100644 --- a/test/multi.spec.js +++ b/test/multi.spec.js @@ -379,12 +379,12 @@ describe("The 'multi' method", function () { ['del', 'some set'], ['smembers', 'some set'] ]) - .scard('some set') - .exec(function (err, replies) { - assert.strictEqual(4, replies[0].length); - assert.strictEqual(0, replies[2].length); - return done(); - }); + .scard('some set') + .exec(function (err, replies) { + assert.strictEqual(4, replies[0].length); + assert.strictEqual(0, replies[2].length); + return done(); + }); }); it('allows multiple operations to be performed using constructor with all kinds of syntax', function (done) { @@ -406,30 +406,30 @@ describe("The 'multi' method", function () { ['HMSET', 'multihmset', ['multibar', 'multibaz'], undefined], // undefined is used as a explicit not set callback variable ['hmset', 'multihmset', ['multibar', 'multibaz'], helper.isString('OK')], ]) - .hmget(now, 123456789, 'otherTypes') - .hmget('key2', arr2, function noop () {}) - .hmget(['multihmset2', 'some manner of key', 'multibar3']) - .mget('multifoo2', ['multifoo3', 'multifoo'], function (err, res) { - assert(res[0], 'multifoo3'); - assert(res[1], 'multifoo'); - called = true; - }) - .exec(function (err, replies) { - assert(called); - assert.equal(arr.length, 3); - assert.equal(arr2.length, 2); - assert.equal(arr3.length, 3); - assert.equal(arr4.length, 3); - assert.strictEqual(null, err); - assert.equal(replies[10][1], '555'); - assert.equal(replies[11][0], 'a type of value'); - assert.strictEqual(replies[12][0], null); - assert.equal(replies[12][1], 'test'); - assert.equal(replies[13][0], 'multibar2'); - assert.equal(replies[13].length, 3); - assert.equal(replies.length, 14); - return done(); - }); + .hmget(now, 123456789, 'otherTypes') + .hmget('key2', arr2, function noop () {}) + .hmget(['multihmset2', 'some manner of key', 'multibar3']) + .mget('multifoo2', ['multifoo3', 'multifoo'], function (err, res) { + assert(res[0], 'multifoo3'); + assert(res[1], 'multifoo'); + called = true; + }) + .exec(function (err, replies) { + assert(called); + assert.equal(arr.length, 3); + assert.equal(arr2.length, 2); + assert.equal(arr3.length, 3); + assert.equal(arr4.length, 3); + assert.strictEqual(null, err); + assert.equal(replies[10][1], '555'); + assert.equal(replies[11][0], 'a type of value'); + assert.strictEqual(replies[12][0], null); + assert.equal(replies[12][1], 'test'); + assert.equal(replies[13][0], 'multibar2'); + assert.equal(replies[13].length, 3); + assert.equal(replies.length, 14); + return done(); + }); }); it('converts a non string key to a string', function (done) { @@ -505,11 +505,11 @@ describe("The 'multi' method", function () { ['mget', ['multifoo', 'some', 'random value', 'keys']], ['incr', 'multifoo'] ]) - .exec(function (err, replies) { - assert.strictEqual(replies.length, 2); - assert.strictEqual(replies[0].length, 4); - return done(); - }); + .exec(function (err, replies) { + assert.strictEqual(replies.length, 2); + assert.strictEqual(replies[0].length, 4); + return done(); + }); }); it('allows multiple operations to be performed on a hash', function (done) { diff --git a/test/node_redis.spec.js b/test/node_redis.spec.js index fe9a35c279..e553f8521e 100644 --- a/test/node_redis.spec.js +++ b/test/node_redis.spec.js @@ -122,7 +122,7 @@ describe('The node_redis client', function () { it('check if all new options replaced the old ones', function (done) { client.selected_db = 1; var client2 = client.duplicate({ - db: 2, + db: 2, no_ready_check: true }); assert(client.connected); diff --git a/test/tls.spec.js b/test/tls.spec.js index 3b0e18197a..e3c758285b 100644 --- a/test/tls.spec.js +++ b/test/tls.spec.js @@ -110,17 +110,17 @@ describe('TLS connection tests', function () { }); describe('using rediss as url protocol', function (done) { - var tls_connect = tls.connect + var tls_connect = tls.connect; beforeEach(function () { tls.connect = function (options) { - options = utils.clone(options) + options = utils.clone(options); options.ca = tls_options.ca; return tls_connect.call(tls, options); - } - }) + }; + }); afterEach(function () { tls.connect = tls_connect; - }) + }); it('connect with tls when rediss is used as the protocol', function (done) { if (skip) this.skip(); client = redis.createClient('rediss://localhost:' + tls_port); @@ -129,7 +129,7 @@ describe('TLS connection tests', function () { client.set('foo', 'bar'); client.get('foo', helper.isString('bar', done)); }); - }) + }); it('fails to connect because the cert is not correct', function (done) { if (skip) this.skip();