From 9d65e1c3ededcf3f266ddab0a509a47432dc7ddc Mon Sep 17 00:00:00 2001 From: Salakar Date: Fri, 7 Feb 2020 00:31:08 +0000 Subject: [PATCH] tests: fix buffer test (failed due to new parser) & remove unused node feature checks (< 4) --- index.js | 12 ------------ lib/commands.js | 28 ++++++---------------------- test/pubsub.spec.js | 2 ++ 3 files changed, 8 insertions(+), 34 deletions(-) diff --git a/index.js b/index.js index 402b9b1e47..b1f265262c 100644 --- a/index.js +++ b/index.js @@ -20,11 +20,6 @@ var SUBSCRIBE_COMMANDS = { punsubscribe: true }; -// Newer Node.js versions > 0.10 return the EventEmitter right away and using .EventEmitter was deprecated -if (typeof EventEmitter !== 'function') { - EventEmitter = EventEmitter.EventEmitter; -} - function noop () {} function handle_detect_buffers_reply (reply, command, buffer_args) { @@ -153,7 +148,6 @@ function RedisClient (options, stream) { this.server_info = {}; this.auth_pass = options.auth_pass || options.password; this.selected_db = options.db; // Save the selected db here, used when reconnecting - this.old_state = null; this.fire_strings = true; // Determine if strings or buffers should be written to the stream this.pipeline = false; this.sub_commands_left = 0; @@ -175,12 +169,6 @@ function RedisClient (options, stream) { 'If you want to keep on listening to this event please listen to the stream drain event directly.' ); } else if ((event === 'message_buffer' || event === 'pmessage_buffer' || event === 'messageBuffer' || event === 'pmessageBuffer') && !this.buffers && !this.message_buffers) { - if (this.reply_parser.name !== 'javascript') { - return this.warn( - 'You attached the "' + event + '" listener without the returnBuffers option set to true.\n' + - 'Please use the JavaScript parser or set the returnBuffers option to true to return buffers.' - ); - } this.reply_parser.optionReturnBuffers = true; this.message_buffers = true; this.handle_reply = handle_detect_buffers_reply; diff --git a/lib/commands.js b/lib/commands.js index 6275ec8bf6..a3b5189698 100644 --- a/lib/commands.js +++ b/lib/commands.js @@ -4,18 +4,6 @@ var commands = require('redis-commands'); var Multi = require('./multi'); var RedisClient = require('../').RedisClient; var Command = require('./command'); -// Feature detect if a function may change it's name -var changeFunctionName = (function () { - var fn = function abc () {}; - try { - Object.defineProperty(fn, 'name', { - value: 'foobar' - }); - return true; - } catch (e) { - return false; - } -}()); var addCommand = function (command) { // Some rare Redis commands use special characters in their command name @@ -61,11 +49,9 @@ var addCommand = function (command) { if (commandName !== command) { RedisClient.prototype[commandName.toUpperCase()] = RedisClient.prototype[commandName] = RedisClient.prototype[command]; } - if (changeFunctionName) { - Object.defineProperty(RedisClient.prototype[command], 'name', { - value: commandName - }); - } + Object.defineProperty(RedisClient.prototype[command], 'name', { + value: commandName + }); } // Do not override existing functions @@ -108,11 +94,9 @@ var addCommand = function (command) { if (commandName !== command) { Multi.prototype[commandName.toUpperCase()] = Multi.prototype[commandName] = Multi.prototype[command]; } - if (changeFunctionName) { - Object.defineProperty(Multi.prototype[command], 'name', { - value: commandName - }); - } + Object.defineProperty(Multi.prototype[command], 'name', { + value: commandName + }); } }; diff --git a/test/pubsub.spec.js b/test/pubsub.spec.js index c017cdb36f..da2561459f 100644 --- a/test/pubsub.spec.js +++ b/test/pubsub.spec.js @@ -524,6 +524,8 @@ describe('publish/subscribe', function () { assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect()); sub.quit(end); }); + // Either message_buffers or buffers has to be true, but not both at the same time + assert.notStrictEqual(sub.message_buffers, sub.buffers); }); var batch = sub.batch(); batch.psubscribe('*');