1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

chore - remove standard and use individual config

Standard is not as up to date and still uses a old eslint version.
Instead, use the airbnb default with a couple of modifications.

All required changes are included.
This commit is contained in:
Ruben Bridgewater
2017-11-28 21:38:21 -02:00
parent 0206ecbf51
commit 2b4ab10305
97 changed files with 888 additions and 673 deletions

View File

@@ -5,6 +5,7 @@ const path = require('path')
const config = require('./lib/config')
const RedisProcess = require('./lib/redis-process')
const StunnelProcess = require('./lib/stunnel-process')
let rp
let stunnelProcess
@@ -16,7 +17,7 @@ process.on('unhandledRejection', (err, promise) => {
})
})
function startRedis (conf, done, port) {
function startRedis(conf, done, port) {
RedisProcess.start((err, _rp) => {
rp = _rp
return done(err)
@@ -37,7 +38,7 @@ if (!process.env.REDIS_TESTS_STARTED) {
})
}
function arrayHelper (results) {
function arrayHelper(results) {
if (results instanceof Array) {
assert.strictEqual(results.length, 1, 'The array length may only be one element')
return results[0]
@@ -45,7 +46,7 @@ function arrayHelper (results) {
return results
}
function toString (res) {
function toString(res) {
// If options are passed to return either strings or buffers...
if (Buffer.isBuffer(res)) {
return res.toString()
@@ -55,40 +56,40 @@ function toString (res) {
}
// Stringify all values as well
if (typeof res === 'object' && res !== null) {
Object.keys(res).map((key) => (res[key] = toString(res[key])))
Object.keys(res).forEach((key) => { res[key] = toString(res[key]) })
}
return res
}
module.exports = {
redisProcess () {
redisProcess() {
return rp
},
stopRedis (done) {
stopRedis(done) {
rp.stop(done)
},
startRedis,
stopStunnel (done) {
stopStunnel(done) {
if (stunnelProcess) {
StunnelProcess.stop(stunnelProcess, done)
} else {
done()
}
},
startStunnel (done) {
startStunnel(done) {
StunnelProcess.start((err, _stunnelProcess) => {
stunnelProcess = _stunnelProcess
return done(err)
}, path.resolve(__dirname, './conf'))
},
isNumber (expected) {
isNumber(expected) {
return function (results) {
results = arrayHelper(results)
assert.strictEqual(results, expected, `${expected} !== ${results}`)
assert.strictEqual(typeof results, 'number', `expected a number, got ${typeof results}`)
}
},
isString (str) {
isString(str) {
str = `${str}` // Make sure it's a string
return function (results) {
results = arrayHelper(results)
@@ -96,50 +97,51 @@ module.exports = {
assert.strictEqual(results, str, `${str} does not match ${results}`)
}
},
isNull () {
isNull() {
return function (results) {
results = arrayHelper(results)
assert.strictEqual(results, null, `${results} is not null`)
}
},
isUndefined () {
isUndefined() {
return function (results) {
results = arrayHelper(results)
assert.strictEqual(results, undefined, `${results} is not undefined`)
}
},
isError (regex) {
isError(regex) {
return function (err, res) {
assert.strictEqual(res, undefined, 'There should be an error, no result!')
assert(err instanceof Error, 'err is not instance of \'Error\', but an error is expected here.')
if (regex) assert(regex.test(err.message))
}
},
isDeepEqual (args) {
isDeepEqual(args) {
return function (res) {
res = toString(res)
assert.deepStrictEqual(res, args)
}
},
match (pattern) {
match(pattern) {
return function (results) {
results = arrayHelper(results)
assert(pattern.test(results), `expected string '${results}' to match ${pattern.toString()}`)
}
},
fail (err) {
fail(err) {
err = err instanceof Error
? err
: new Error('This should not be reachable')
throw err
},
serverVersionAtLeast (connection, desiredVersion) {
// Wait until a connection has established (otherwise a timeout is going to be triggered at some point)
serverVersionAtLeast(connection, desiredVersion) {
// Wait until a connection has established (otherwise a timeout is going to
// be triggered at some point)
if (Object.keys(connection.serverInfo).length === 0) {
throw new Error('Version check not possible as the client is not yet ready or did not expose the version')
}
// Return true if the server version >= desiredVersion
const version = connection.serverInfo.server.version
const { version } = connection.serverInfo.server
for (let i = 0; i < 3; i++) {
if (version[i] > desiredVersion[i]) {
return true
@@ -151,7 +153,7 @@ module.exports = {
}
return true
},
allTests (opts, cb) {
allTests(opts, cb) {
if (!cb) {
cb = opts
opts = {}
@@ -167,11 +169,9 @@ module.exports = {
}]
options.forEach((options) => {
let strOptions = ''
let key
for (key in options) {
if (options.hasOwnProperty(key)) {
strOptions += `${key}: ${options[key]}; `
}
const keys = Object.keys(options)
for (let i = 0; i < keys.length; i++) {
strOptions += `${keys[i]}: ${options[keys[i]]}; `
}
describe(`using options: ${strOptions}`, () => {
protocols.forEach((ip, i) => {
@@ -183,12 +183,12 @@ module.exports = {
})
})
},
removeMochaListener () {
removeMochaListener() {
const mochaListener = process.listeners('uncaughtException').pop()
process.removeListener('uncaughtException', mochaListener)
return mochaListener
},
callFuncAfter (func, max) {
callFuncAfter(func, max) {
let i = 0
return function () {
i++
@@ -199,7 +199,7 @@ module.exports = {
return false
}
},
killConnection (client) {
killConnection(client) {
// Change the connection option to a non existing one and destroy the stream
client._connectionOptions = {
port: 65535,