Best JavaScript code snippet using appium-xcuitest-driver
RedisClient.test.js
Source:RedisClient.test.js
1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3require("jest");4const Sinon = require("sinon");5const najs_facade_1 = require("najs-facade");6const constants_1 = require("../../lib/constants");7const RedisClient_1 = require("../../lib/redis/RedisClient");8const RedisPromise_1 = require("../../lib/redis/RedisPromise");9const najs_binding_1 = require("najs-binding");10const isPromise_1 = require("../../lib/private/isPromise");11const constants_2 = require("../../lib/constants");12const ConfigFacade_1 = require("../../lib/facades/global/ConfigFacade");13describe('RedisClient', function () {14 let redisClient;15 beforeAll(function () {16 redisClient = new RedisClient_1.RedisClient();17 });18 it('extends from Facade so it definitely a FacadeClass', function () {19 expect(redisClient).toBeInstanceOf(najs_facade_1.Facade);20 expect(redisClient.getClassName()).toEqual(constants_1.Najs.Redis.RedisClient);21 expect(najs_binding_1.ClassRegistry.has(constants_1.Najs.Redis.RedisClient)).toBe(true);22 });23 describe('constructor()', function () {24 it('calls createClient() with default and config get from ConfigFacade', function () {25 ConfigFacade_1.ConfigFacade.shouldReceive('get').withArgs(constants_2.ConfigurationKeys.Redis, {26 host: 'localhost',27 port: 637928 });29 const newRedisClient = new RedisClient_1.RedisClient();30 expect(newRedisClient.getCurrentClient()).toEqual('default');31 najs_facade_1.FacadeContainer.verifyAndRestoreAllFacades();32 });33 });34 describe('.createClient()', function () {35 it('creates new client and put into bucket if the name is not exists', function () {36 redisClient.createClient('test', {37 host: 'localhost',38 port: 637939 });40 expect(typeof redisClient['bucket']['test'] === 'object').toBe(true);41 });42 it('does not creates new client the name is exists', function () {43 redisClient.createClient('default', {44 host: 'localhost',45 port: 637946 });47 expect(redisClient.getCurrentClient()).toEqual('default');48 });49 it('always return created/existing client', function () {50 expect(redisClient.createClient('test', {51 host: 'localhost',52 port: 637953 }) === redisClient['bucket']['test']).toBe(true);54 expect(redisClient.getCurrentClient()).toEqual('default');55 });56 });57 describe('.useClient()', function () {58 it('sets currentBucket to the name if it exists', function () {59 expect(redisClient.useClient('test').getCurrentClient()).toEqual('test');60 expect(redisClient.useClient('default').getCurrentClient()).toEqual('default');61 });62 it('throws an Error if the name is not in bucket list', function () {63 try {64 redisClient.useClient('test-not-found');65 }66 catch (error) {67 expect(error.message).toEqual('RedisClient "test-not-found" is not found');68 return;69 }70 expect('should not reach this line').toEqual('hm');71 });72 });73 describe('.getClient()', function () {74 it('returns RedisPromise instance which wraps native RedisClient', function () {75 const redis = redisClient.getClient('test');76 expect(redis).toBeInstanceOf(RedisPromise_1.RedisPromise);77 expect(redis['redisClient'] === redisClient['bucket']['test']).toBe(true);78 });79 it('creates create instance once time and returns the cache in next time called', function () {80 expect(redisClient['redisPromiseBucket']['test']).not.toBeUndefined();81 expect(redisClient.getClient('test') === redisClient['redisPromiseBucket']['test']).toBe(true);82 });83 });84 describe('.getRedisClient()', function () {85 it('returns native redis client if name exists', function () {86 expect(redisClient.getRedisClient('test') === redisClient['bucket']['test']).toBe(true);87 });88 it('throws an Error if the name is not in bucket list', function () {89 try {90 redisClient.getRedisClient('test-not-found');91 }92 catch (error) {93 expect(error.message).toEqual('RedisClient "test-not-found" is not found');94 return;95 }96 expect('should not reach this line').toEqual('hm');97 });98 });99 describe('.getCurrentClient()', function () {100 it('simply returns currentBucket', function () { });101 });102 describe('.hasClient()', function () {103 it('simply returns true if there is client with name in bucket', function () {104 expect(redisClient.hasClient('default')).toBe(true);105 expect(redisClient.hasClient('test')).toBe(true);106 expect(redisClient.hasClient('test-not-found')).toBe(false);107 });108 });109 // -------------------------------------------------------------------------------------------------------------------110 function promisify_test_for(facadeMethod, redisMethod, args) {111 describe('.' + facadeMethod + '()', function () {112 it('returns a promise', function () {113 const promisifyStub = Sinon.stub(RedisPromise_1.RedisPromise, 'promisify');114 promisifyStub.callsFake(async function () { });115 expect(isPromise_1.isPromise(redisClient[facadeMethod](...args))).toBe(true);116 promisifyStub.restore();117 });118 it('calls RedisPromise.proxify(), passes method name and arguments', async function () {119 const promisifyStub = Sinon.stub(RedisPromise_1.RedisPromise, 'promisify');120 promisifyStub.callsFake(async function () {121 return true;122 });123 redisClient[facadeMethod](...args);124 expect(promisifyStub.calledWith(redisMethod)).toBe(true);125 expect(promisifyStub.lastCall.args[1]).toEqual(redisClient['bucket'][redisClient['currentBucket']]);126 expect(Array.from(promisifyStub.lastCall.args[2])).toEqual(args);127 promisifyStub.restore();128 });129 });130 }131 promisify_test_for('monitor', 'monitor', []);132 promisify_test_for('info', 'info', []);133 promisify_test_for('info', 'info', ['test']);134 promisify_test_for('ping', 'ping', []);135 promisify_test_for('ping', 'ping', ['test']);136 promisify_test_for('publish', 'publish', ['test', 'value']);137 promisify_test_for('client', 'client', []);138 promisify_test_for('client', 'client', ['test', 'value']);139 promisify_test_for('hmset', 'hmset', ['test']);140 promisify_test_for('hmset', 'hmset', ['test', '0', '1', '2']);141 promisify_test_for('hmset', 'hmset', ['test', 0, 1, 2]);142 promisify_test_for('subscribe', 'subscribe', ['channel']);143 promisify_test_for('subscribe', 'subscribe', [['channel', 'another-channel']]);144 promisify_test_for('unsubscribe', 'unsubscribe', ['channel']);145 promisify_test_for('unsubscribe', 'unsubscribe', [['channel', 'another-channel']]);146 promisify_test_for('psubscribe', 'psubscribe', ['channel']);147 promisify_test_for('psubscribe', 'psubscribe', [['channel', 'another-channel']]);148 promisify_test_for('punsubscribe', 'punsubscribe', ['channel']);149 promisify_test_for('punsubscribe', 'punsubscribe', [['channel', 'another-channel']]);150 promisify_test_for('auth', 'auth', ['password']);151 promisify_test_for('append', 'append', ['test', 'abc']);152 promisify_test_for('bgrewriteaof', 'bgrewriteaof', []);153 promisify_test_for('bgsave', 'bgsave', []);154 promisify_test_for('bitcount', 'bitcount', ['test']);155 promisify_test_for('bitcount', 'bitcount', ['test', 1, 2]);156 promisify_test_for('bitfield', 'bitfield', ['test', 1]);157 promisify_test_for('bitfield', 'bitfield', ['test', [1]]);158 promisify_test_for('bitfield', 'bitfield', ['test', ['test']]);159 promisify_test_for('bitop', 'bitop', ['test', 'a', 'b', 'c', 'd']);160 promisify_test_for('bitpos', 'bitpos', ['test', 1, 0, 2]);161 promisify_test_for('blpop', 'blpop', ['test', 'value']);162 promisify_test_for('brpop', 'brpop', ['test', 'value']);163 promisify_test_for('brpoplpush', 'brpoplpush', ['list', 'another-list', 10]);164 promisify_test_for('cluster', 'cluster', []);165 promisify_test_for('cluster', 'cluster', ['test', 'value']);166 promisify_test_for('command', 'command', []);167 promisify_test_for('config', 'config', []);168 promisify_test_for('config', 'config', ['test', 'value']);169 promisify_test_for('dbsize', 'dbsize', []);170 promisify_test_for('debug', 'debug', []);171 promisify_test_for('debug', 'debug', ['test', 'value']);172 promisify_test_for('decr', 'decr', ['test']);173 promisify_test_for('decrby', 'decrby', ['test', 1]);174 promisify_test_for('del', 'del', []);175 promisify_test_for('del', 'del', ['test', 'value']);176 promisify_test_for('discard', 'discard', []);177 promisify_test_for('dump', 'dump', ['test']);178 promisify_test_for('echo', 'echo', ['test']);179 promisify_test_for('eval', 'eval', []);180 promisify_test_for('eval', 'eval', ['test', 'value']);181 promisify_test_for('evalsha', 'evalsha', []);182 promisify_test_for('evalsha', 'evalsha', ['test', 'value']);183 promisify_test_for('exists', 'exists', []);184 promisify_test_for('exists', 'exists', ['test', 'value']);185 promisify_test_for('expire', 'expire', ['test', 12]);186 promisify_test_for('expireat', 'expireat', ['test', 1212121212]);187 promisify_test_for('flushall', 'flushall', []);188 promisify_test_for('flushdb', 'flushdb', []);189 promisify_test_for('geoadd', 'geoadd', []);190 promisify_test_for('geoadd', 'geoadd', ['test']);191 promisify_test_for('geoadd', 'geoadd', ['test', 'value']);192 promisify_test_for('geoadd', 'geoadd', ['test', 0]);193 promisify_test_for('geoadd', 'geoadd', ['test', 0, 1]);194 promisify_test_for('geoadd', 'geoadd', ['test', 0, 1, 2]);195 promisify_test_for('geohash', 'geohash', []);196 promisify_test_for('geohash', 'geohash', ['test']);197 promisify_test_for('geohash', 'geohash', ['test', 'value']);198 promisify_test_for('geohash', 'geohash', ['test', '0']);199 promisify_test_for('geohash', 'geohash', ['test', '0', '1']);200 promisify_test_for('geohash', 'geohash', ['test', '0', '1', '2']);201 promisify_test_for('geopos', 'geopos', []);202 promisify_test_for('geopos', 'geopos', ['test']);203 promisify_test_for('geopos', 'geopos', ['test', 'value']);204 promisify_test_for('geopos', 'geopos', ['test', '0']);205 promisify_test_for('geopos', 'geopos', ['test', '0', '1']);206 promisify_test_for('geopos', 'geopos', ['test', '0', '1', '2']);207 promisify_test_for('geodist', 'geodist', []);208 promisify_test_for('geodist', 'geodist', ['test']);209 promisify_test_for('geodist', 'geodist', ['test', 'value']);210 promisify_test_for('geodist', 'geodist', ['test', '0']);211 promisify_test_for('geodist', 'geodist', ['test', '0', '1']);212 promisify_test_for('geodist', 'geodist', ['test', '0', '1', '2']);213 promisify_test_for('georadius', 'georadius', []);214 promisify_test_for('georadius', 'georadius', ['test']);215 promisify_test_for('georadius', 'georadius', ['test', 'value']);216 promisify_test_for('georadius', 'georadius', ['test', 0]);217 promisify_test_for('georadius', 'georadius', ['test', 0, 1]);218 promisify_test_for('georadius', 'georadius', ['test', 0, 1, 2]);219 promisify_test_for('georadiusbymember', 'georadiusbymember', []);220 promisify_test_for('georadiusbymember', 'georadiusbymember', ['test']);221 promisify_test_for('georadiusbymember', 'georadiusbymember', ['test', 'value']);222 promisify_test_for('georadiusbymember', 'georadiusbymember', ['test', 0]);223 promisify_test_for('georadiusbymember', 'georadiusbymember', ['test', 0, 1]);224 promisify_test_for('georadiusbymember', 'georadiusbymember', ['test', 0, 1, 2]);225 promisify_test_for('get', 'get', ['test']);226 promisify_test_for('getbit', 'getbit', ['test', 7]);227 promisify_test_for('getrange', 'getrange', ['test', 0, 3]);228 promisify_test_for('getset', 'getset', ['test', 'value']);229 promisify_test_for('hdel', 'hdel', []);230 promisify_test_for('hdel', 'hdel', ['test']);231 promisify_test_for('hdel', 'hdel', ['test', 'value']);232 promisify_test_for('hdel', 'hdel', ['test', 0]);233 promisify_test_for('hdel', 'hdel', ['test', 0, 1]);234 promisify_test_for('hdel', 'hdel', ['test', 0, 1, 2]);235 promisify_test_for('hexists', 'hexists', ['test', 'value']);236 promisify_test_for('hget', 'hget', ['test', 'value']);237 promisify_test_for('hgetall', 'hgetall', ['test']);238 promisify_test_for('hincrby', 'hincrby', ['test', 'value', 3]);239 promisify_test_for('hincrbyfloat', 'hincrbyfloat', ['test', 'value', 3.0]);240 promisify_test_for('hkeys', 'hkeys', ['test']);241 promisify_test_for('hlen', 'hlen', ['test']);242 promisify_test_for('hmget', 'hmget', []);243 promisify_test_for('hmget', 'hmget', ['test']);244 promisify_test_for('hmget', 'hmget', ['test', 'value']);245 promisify_test_for('hmget', 'hmget', ['test', 0]);246 promisify_test_for('hmget', 'hmget', ['test', 0, 1]);247 promisify_test_for('hmget', 'hmget', ['test', 0, 1, 2]);248 promisify_test_for('hmget', 'hmget', ['test', 'value', 'value']);249 promisify_test_for('hset', 'hset', ['test', 'value', 'value']);250 promisify_test_for('hsetnx', 'hsetnx', ['test', 'value', 'value']);251 promisify_test_for('hstrlen', 'hstrlen', ['test', 'value']);252 promisify_test_for('hvals', 'hvals', ['test']);253 promisify_test_for('incr', 'incr', ['test']);254 promisify_test_for('incrby', 'incrby', ['test', 3]);255 promisify_test_for('incrbyfloat', 'incrbyfloat', ['test', 3.0]);256 promisify_test_for('keys', 'keys', ['test']);257 promisify_test_for('lastsave', 'lastsave', []);258 promisify_test_for('lindex', 'lindex', ['test', 1]);259 promisify_test_for('linsert', 'linsert', ['test', 'AFTER', 'test', 'value']);260 promisify_test_for('llen', 'llen', ['test']);261 promisify_test_for('lpop', 'lpop', ['test']);262 promisify_test_for('lpush', 'lpush', []);263 promisify_test_for('lpush', 'lpush', ['test']);264 promisify_test_for('lpush', 'lpush', ['test', 'value']);265 promisify_test_for('lpush', 'lpush', ['test', 0]);266 promisify_test_for('lpush', 'lpush', ['test', 0, 1]);267 promisify_test_for('lpush', 'lpush', ['test', 0, 1, 2]);268 promisify_test_for('lpush', 'lpush', ['test', 'value', 'value']);269 promisify_test_for('lpushx', 'lpushx', ['lpushx', 'value']);270 promisify_test_for('lrange', 'lrange', ['test', 0, 1]);271 promisify_test_for('lrem', 'lrem', ['test', 1, 'value']);272 promisify_test_for('lset', 'lset', ['test', 1, 'value']);273 promisify_test_for('ltrim', 'ltrim', ['test', 1, 2]);274 promisify_test_for('mget', 'mget', []);275 promisify_test_for('mget', 'mget', ['test', 'value']);276 promisify_test_for('migrate', 'migrate', []);277 promisify_test_for('migrate', 'migrate', ['test', 'value']);278 promisify_test_for('move', 'move', ['test', 1]);279 promisify_test_for('mset', 'mset', []);280 promisify_test_for('mset', 'mset', ['test', 'value']);281 promisify_test_for('msetnx', 'msetnx', []);282 promisify_test_for('msetnx', 'msetnx', ['test', 'value']);283 promisify_test_for('object', 'object', []);284 promisify_test_for('object', 'object', ['test', 'value']);285 promisify_test_for('persist', 'persist', ['test']);286 promisify_test_for('pexpire', 'pexpire', ['test', 1]);287 promisify_test_for('pexpireat', 'pexpireat', ['test', 1]);288 promisify_test_for('pfadd', 'pfadd', []);289 promisify_test_for('pfadd', 'pfadd', ['test']);290 promisify_test_for('pfadd', 'pfadd', ['test', 'value']);291 promisify_test_for('pfadd', 'pfadd', ['test', 0]);292 promisify_test_for('pfadd', 'pfadd', ['test', 0, 1]);293 promisify_test_for('pfadd', 'pfadd', ['test', 0, 1, 2]);294 promisify_test_for('pfadd', 'pfadd', ['test', 'value', 'value']);295 promisify_test_for('pfcount', 'pfcount', []);296 promisify_test_for('pfcount', 'pfcount', ['test', 'value']);297 promisify_test_for('pfmerge', 'pfmerge', []);298 promisify_test_for('pfmerge', 'pfmerge', ['test', 'value']);299 promisify_test_for('psetex', 'psetex', ['test', 1, 'value']);300 promisify_test_for('pubsub', 'pubsub', []);301 promisify_test_for('pubsub', 'pubsub', ['test', 'value']);302 promisify_test_for('pttl', 'pttl', ['test']);303 promisify_test_for('quit', 'quit', []);304 promisify_test_for('randomkey', 'randomkey', []);305 promisify_test_for('readonly', 'readonly', []);306 promisify_test_for('readwrite', 'readwrite', []);307 promisify_test_for('rename', 'rename', ['test', 'test-new']);308 promisify_test_for('renamenx', 'renamenx', ['test', 'test-new']);309 promisify_test_for('restore', 'restore', ['test', 1, 'value']);310 promisify_test_for('role', 'role', []);311 promisify_test_for('rpop', 'rpop', ['test']);312 promisify_test_for('rpoplpush', 'rpoplpush', ['test', 'value']);313 promisify_test_for('rpush', 'rpush', []);314 promisify_test_for('rpush', 'rpush', ['test']);315 promisify_test_for('rpush', 'rpush', ['test', 'value']);316 promisify_test_for('rpush', 'rpush', ['test', 0]);317 promisify_test_for('rpush', 'rpush', ['test', 0, 1]);318 promisify_test_for('rpush', 'rpush', ['test', 0, 1, 2]);319 promisify_test_for('rpush', 'rpush', ['test', 'value', 'value']);320 promisify_test_for('rpushx', 'rpushx', ['test', 'value']);321 promisify_test_for('sadd', 'sadd', []);322 promisify_test_for('sadd', 'sadd', ['test']);323 promisify_test_for('sadd', 'sadd', ['test', 'value']);324 promisify_test_for('sadd', 'sadd', ['test', 0]);325 promisify_test_for('sadd', 'sadd', ['test', 0, 1]);326 promisify_test_for('sadd', 'sadd', ['test', 0, 1, 2]);327 promisify_test_for('sadd', 'sadd', ['test', 'value', 'value']);328 promisify_test_for('save', 'save', []);329 promisify_test_for('scard', 'scard', ['test']);330 promisify_test_for('script', 'script', []);331 promisify_test_for('script', 'script', ['test', 'value']);332 promisify_test_for('sdiff', 'sdiff', []);333 promisify_test_for('sdiff', 'sdiff', ['test', 'value']);334 promisify_test_for('sdiffstore', 'sdiffstore', []);335 promisify_test_for('sdiffstore', 'sdiffstore', ['test']);336 promisify_test_for('sdiffstore', 'sdiffstore', ['test', 'value']);337 promisify_test_for('sdiffstore', 'sdiffstore', ['test', 0]);338 promisify_test_for('sdiffstore', 'sdiffstore', ['test', 0, 1]);339 promisify_test_for('sdiffstore', 'sdiffstore', ['test', 0, 1, 2]);340 promisify_test_for('sdiffstore', 'sdiffstore', ['test', 'value', 'value']);341 promisify_test_for('select', 'select', ['test']);342 promisify_test_for('select', 'select', [0]);343 promisify_test_for('set', 'set', ['test', 'value']);344 promisify_test_for('set', 'set', ['test', 'value', 'any']);345 promisify_test_for('set', 'set', ['test', 'value', 'any', 12]);346 promisify_test_for('set', 'set', ['test', 'value', 'any', 12, 'any']);347 promisify_test_for('setbit', 'setbit', ['test', 0, '1']);348 promisify_test_for('setex', 'setex', ['test', 12, 'value']);349 promisify_test_for('setnx', 'setnx', ['test', 'value']);350 promisify_test_for('setrange', 'setrange', ['test', 0, 'value']);351 promisify_test_for('shutdown', 'shutdown', []);352 promisify_test_for('shutdown', 'shutdown', ['test', 'value']);353 promisify_test_for('sinter', 'sinter', []);354 promisify_test_for('sinter', 'sinter', ['test']);355 promisify_test_for('sinter', 'sinter', ['test', 'value']);356 promisify_test_for('sinter', 'sinter', ['test', 0]);357 promisify_test_for('sinter', 'sinter', ['test', 0, 1]);358 promisify_test_for('sinter', 'sinter', ['test', 0, 1, 2]);359 promisify_test_for('sinter', 'sinter', ['test', 'value', 'value']);360 promisify_test_for('sinterstore', 'sinterstore', []);361 promisify_test_for('sinterstore', 'sinterstore', ['test', 'value']);362 promisify_test_for('sismember', 'sismember', ['test', 'member']);363 promisify_test_for('slaveof', 'slaveof', ['localhost', '6666']);364 promisify_test_for('slowlog', 'slowlog', []);365 promisify_test_for('slowlog', 'slowlog', ['test', 'value']);366 promisify_test_for('smembers', 'smembers', ['test']);367 promisify_test_for('smove', 'smove', ['source', 'destination', 'test']);368 promisify_test_for('sort', 'sort', []);369 promisify_test_for('sort', 'sort', ['test', 'value']);370 promisify_test_for('spop', 'spop', ['test']);371 promisify_test_for('spop', 'spop', ['test', 2]);372 promisify_test_for('srandmember', 'srandmember', ['test']);373 promisify_test_for('srandmember', 'srandmember', ['test', 2]);374 promisify_test_for('srem', 'srem', []);375 promisify_test_for('srem', 'srem', ['test']);376 promisify_test_for('srem', 'srem', ['test', 'value']);377 promisify_test_for('srem', 'srem', ['test', 0]);378 promisify_test_for('srem', 'srem', ['test', 0, 1]);379 promisify_test_for('srem', 'srem', ['test', 0, 1, 2]);380 promisify_test_for('srem', 'srem', ['test', 'value', 'value']);381 promisify_test_for('strlen', 'strlen', ['test']);382 promisify_test_for('sunion', 'sunion', []);383 promisify_test_for('sunion', 'sunion', ['test', 'value']);384 promisify_test_for('sunionstore', 'sunionstore', []);385 promisify_test_for('sunionstore', 'sunionstore', ['test', 'value']);386 promisify_test_for('sync', 'sync', []);387 promisify_test_for('time', 'time', []);388 promisify_test_for('ttl', 'ttl', ['test']);389 promisify_test_for('type', 'type', ['test']);390 promisify_test_for('unwatch', 'unwatch', []);391 promisify_test_for('wait', 'wait', [1, 10000]);392 promisify_test_for('watch', 'watch', []);393 promisify_test_for('watch', 'watch', ['test', 'value']);394 promisify_test_for('zadd', 'zadd', []);395 promisify_test_for('zadd', 'zadd', ['test']);396 promisify_test_for('zadd', 'zadd', ['test', 'value']);397 promisify_test_for('zadd', 'zadd', ['test', 0]);398 promisify_test_for('zadd', 'zadd', ['test', 0, 1]);399 promisify_test_for('zadd', 'zadd', ['test', 0, 1, 2]);400 promisify_test_for('zadd', 'zadd', ['test', 'value', 'value']);401 promisify_test_for('zcard', 'zcard', ['test']);402 promisify_test_for('zcount', 'zcount', ['test', 1, 3]);403 promisify_test_for('zcount', 'zcount', ['test', '1', '3']);404 promisify_test_for('zincrby', 'zincrby', ['test', 1, 'member']);405 promisify_test_for('zinterstore', 'zinterstore', []);406 promisify_test_for('zinterstore', 'zinterstore', ['test', 'value']);407 promisify_test_for('zlexcount', 'zlexcount', ['test', 'min', 'max']);408 promisify_test_for('zrange', 'zrange', ['test', 0, 1]);409 promisify_test_for('zrange', 'zrange', ['test', 0, 1, 'score']);410 promisify_test_for('zrevrangebylex', 'zrevrangebylex', ['test', 1, 2]);411 promisify_test_for('zrevrangebylex', 'zrevrangebylex', ['test', 1, 2, 'limit', 0, 1]);412 promisify_test_for('zrangebylex', 'zrangebylex', ['test', 1, 2]);413 promisify_test_for('zrangebylex', 'zrangebylex', ['test', 1, 2, 3, 4, 5]);414 promisify_test_for('zrangebyscore', 'zrangebyscore', ['test', 1, 2]);415 promisify_test_for('zrangebyscore', 'zrangebyscore', ['test', 'min', 'max']);416 promisify_test_for('zrangebyscore', 'zrangebyscore', ['test', 'min', 'max']);417 promisify_test_for('zrangebyscore', 'zrangebyscore', ['test', 'min', 'max', 'score']);418 promisify_test_for('zrangebyscore', 'zrangebyscore', ['test', 'min', 'max', 'limit', 1, 2]);419 promisify_test_for('zrangebyscore', 'zrangebyscore', ['test', 'min', 'max', 'limit', 1, 2, 3]);420 promisify_test_for('zrank', 'zrank', ['test', 'member']);421 promisify_test_for('zrem', 'zrem', []);422 promisify_test_for('zrem', 'zrem', ['test']);423 promisify_test_for('zrem', 'zrem', ['test', 'value']);424 promisify_test_for('zrem', 'zrem', ['test', 0]);425 promisify_test_for('zrem', 'zrem', ['test', 0, 1]);426 promisify_test_for('zrem', 'zrem', ['test', 0, 1, 2]);427 promisify_test_for('zrem', 'zrem', ['test', 'value', 'value']);428 promisify_test_for('zremrangebylex', 'zremrangebylex', ['test', 1, 2]);429 promisify_test_for('zremrangebyrank', 'zremrangebyrank', ['test', 1, 2]);430 promisify_test_for('zremrangebyscore', 'zremrangebyscore', ['test', 1, 2]);431 promisify_test_for('zremrangebyscore', 'zremrangebyscore', ['test', 'min', 'max']);432 promisify_test_for('zrevrange', 'zrevrange', ['test', 1, 2]);433 promisify_test_for('zrevrange', 'zrevrange', ['test', 1, 2, 'score']);434 promisify_test_for('zrevrangebyscore', 'zrevrangebyscore', ['test', 1, 2]);435 promisify_test_for('zrevrangebyscore', 'zrevrangebyscore', ['test', 1, 2, 'score']);436 promisify_test_for('zrevrangebyscore', 'zrevrangebyscore', ['test', 1, 2, 'limit', 0, 1]);437 promisify_test_for('zrevrangebyscore', 'zrevrangebyscore', ['test', 1, 2, 'score', 'limit', 0, 1]);438 promisify_test_for('zrevrank', 'zrevrank', ['test', 'member']);439 promisify_test_for('zscore', 'zscore', ['test', 'member']);440 promisify_test_for('zunionstore', 'zunionstore', []);441 promisify_test_for('zunionstore', 'zunionstore', ['test', 'value']);442 promisify_test_for('scan', 'scan', []);443 promisify_test_for('scan', 'scan', ['test', 'value']);444 promisify_test_for('sscan', 'sscan', []);445 promisify_test_for('sscan', 'sscan', ['test']);446 promisify_test_for('sscan', 'sscan', ['test', 'value']);447 promisify_test_for('sscan', 'sscan', ['test', 0]);448 promisify_test_for('sscan', 'sscan', ['test', 0, 1]);449 promisify_test_for('sscan', 'sscan', ['test', 0, 1, 2]);450 promisify_test_for('sscan', 'sscan', ['test', 'value', 'value']);451 promisify_test_for('hscan', 'hscan', []);452 promisify_test_for('hscan', 'hscan', ['test']);453 promisify_test_for('hscan', 'hscan', ['test', 'value']);454 promisify_test_for('hscan', 'hscan', ['test', 0]);455 promisify_test_for('hscan', 'hscan', ['test', 0, 1]);456 promisify_test_for('hscan', 'hscan', ['test', 0, 1, 2]);457 promisify_test_for('hscan', 'hscan', ['test', 'value', 'value']);458 promisify_test_for('zscan', 'zscan', []);459 promisify_test_for('zscan', 'zscan', ['test']);460 promisify_test_for('zscan', 'zscan', ['test', 'value']);461 promisify_test_for('zscan', 'zscan', ['test', 0]);462 promisify_test_for('zscan', 'zscan', ['test', 0, 1]);463 promisify_test_for('zscan', 'zscan', ['test', 0, 1, 2]);464 promisify_test_for('zscan', 'zscan', ['test', 'value', 'value']);...
RedisPromise.test.js
Source:RedisPromise.test.js
1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3require("jest");4const Sinon = require("sinon");5const Redis = require("redis");6const isPromise_1 = require("../../lib/private/isPromise");7const RedisPromise_1 = require("../../lib/redis/RedisPromise");8describe('RedisPromise', function () {9 const redisClient = Redis.createClient();10 const redisPromise = new RedisPromise_1.RedisPromise(redisClient);11 describe('static .promisify()', function () {12 it('simply calls RedisClient.prototype[method] with custom callback', function () {13 const redisStub = Sinon.stub(Redis.RedisClient.prototype, 'get');14 expect(isPromise_1.isPromise(RedisPromise_1.RedisPromise.promisify('get', redisClient, ['test']))).toBe(true);15 expect(redisStub.calledWith('test')).toBe(true);16 expect(typeof redisStub.lastCall.args[1] === 'function').toBe(true);17 expect(redisStub.lastCall.thisValue === redisClient).toBe(true);18 redisStub.restore();19 });20 it('calls Promise.resolve if there is no error', async function () {21 const result = await RedisPromise_1.RedisPromise.promisify('append', redisClient, ['test', 'a']);22 expect(result).toBeGreaterThan(0);23 });24 it('call Promise.reject if there is any error', async function () {25 const redisStub = Sinon.stub(Redis.RedisClient.prototype, 'get');26 try {27 redisStub.callsFake(function (key, done) {28 done(new Error(key));29 });30 await RedisPromise_1.RedisPromise.promisify('get', redisClient, ['test']);31 }32 catch (error) {33 expect(error.message).toEqual('test');34 redisStub.restore();35 return;36 }37 expect('should not reach this line').toEqual('hm');38 });39 });40 function promisify_test_for(facadeMethod, redisMethod, args) {41 describe('.' + facadeMethod + '()', function () {42 it('returns a promise', function () {43 const promisifyStub = Sinon.stub(RedisPromise_1.RedisPromise, 'promisify');44 promisifyStub.callsFake(async function () { });45 expect(isPromise_1.isPromise(redisPromise[facadeMethod](...args))).toBe(true);46 promisifyStub.restore();47 });48 it('calls RedisPromise.proxify(), passes method name and arguments', async function () {49 const promisifyStub = Sinon.stub(RedisPromise_1.RedisPromise, 'promisify');50 promisifyStub.callsFake(async function () {51 return true;52 });53 redisPromise[facadeMethod](...args);54 expect(promisifyStub.calledWith(redisMethod)).toBe(true);55 expect(promisifyStub.lastCall.args[1]).toEqual(redisClient);56 expect(Array.from(promisifyStub.lastCall.args[2])).toEqual(args);57 promisifyStub.restore();58 });59 });60 }61 promisify_test_for('monitor', 'monitor', []);62 promisify_test_for('info', 'info', []);63 promisify_test_for('info', 'info', ['test']);64 promisify_test_for('ping', 'ping', []);65 promisify_test_for('ping', 'ping', ['test']);66 promisify_test_for('publish', 'publish', ['test', 'value']);67 promisify_test_for('client', 'client', []);68 promisify_test_for('client', 'client', ['test', 'value']);69 promisify_test_for('hmset', 'hmset', ['test']);70 promisify_test_for('hmset', 'hmset', ['test', '0', '1', '2']);71 promisify_test_for('hmset', 'hmset', ['test', 0, 1, 2]);72 promisify_test_for('subscribe', 'subscribe', ['channel']);73 promisify_test_for('subscribe', 'subscribe', [['channel', 'another-channel']]);74 promisify_test_for('unsubscribe', 'unsubscribe', ['channel']);75 promisify_test_for('unsubscribe', 'unsubscribe', [['channel', 'another-channel']]);76 promisify_test_for('psubscribe', 'psubscribe', ['channel']);77 promisify_test_for('psubscribe', 'psubscribe', [['channel', 'another-channel']]);78 promisify_test_for('punsubscribe', 'punsubscribe', ['channel']);79 promisify_test_for('punsubscribe', 'punsubscribe', [['channel', 'another-channel']]);80 promisify_test_for('auth', 'auth', ['password']);81 promisify_test_for('append', 'append', ['test', 'abc']);82 promisify_test_for('bgrewriteaof', 'bgrewriteaof', []);83 promisify_test_for('bgsave', 'bgsave', []);84 promisify_test_for('bitcount', 'bitcount', ['test']);85 promisify_test_for('bitcount', 'bitcount', ['test', 1, 2]);86 promisify_test_for('bitfield', 'bitfield', ['test', 1]);87 promisify_test_for('bitfield', 'bitfield', ['test', [1]]);88 promisify_test_for('bitfield', 'bitfield', ['test', ['test']]);89 promisify_test_for('bitop', 'bitop', ['test', 'a', 'b', 'c', 'd']);90 promisify_test_for('bitpos', 'bitpos', ['test', 1, 0, 2]);91 promisify_test_for('blpop', 'blpop', ['test', 'value']);92 promisify_test_for('brpop', 'brpop', ['test', 'value']);93 promisify_test_for('brpoplpush', 'brpoplpush', ['list', 'another-list', 10]);94 promisify_test_for('cluster', 'cluster', []);95 promisify_test_for('cluster', 'cluster', ['test', 'value']);96 promisify_test_for('command', 'command', []);97 promisify_test_for('config', 'config', []);98 promisify_test_for('config', 'config', ['test', 'value']);99 promisify_test_for('dbsize', 'dbsize', []);100 promisify_test_for('debug', 'debug', []);101 promisify_test_for('debug', 'debug', ['test', 'value']);102 promisify_test_for('decr', 'decr', ['test']);103 promisify_test_for('decrby', 'decrby', ['test', 1]);104 promisify_test_for('del', 'del', []);105 promisify_test_for('del', 'del', ['test', 'value']);106 promisify_test_for('discard', 'discard', []);107 promisify_test_for('dump', 'dump', ['test']);108 promisify_test_for('echo', 'echo', ['test']);109 promisify_test_for('eval', 'eval', []);110 promisify_test_for('eval', 'eval', ['test', 'value']);111 promisify_test_for('evalsha', 'evalsha', []);112 promisify_test_for('evalsha', 'evalsha', ['test', 'value']);113 promisify_test_for('exists', 'exists', []);114 promisify_test_for('exists', 'exists', ['test', 'value']);115 promisify_test_for('expire', 'expire', ['test', 12]);116 promisify_test_for('expireat', 'expireat', ['test', 1212121212]);117 promisify_test_for('flushall', 'flushall', []);118 promisify_test_for('flushdb', 'flushdb', []);119 promisify_test_for('geoadd', 'geoadd', []);120 promisify_test_for('geoadd', 'geoadd', ['test']);121 promisify_test_for('geoadd', 'geoadd', ['test', 'value']);122 promisify_test_for('geoadd', 'geoadd', ['test', 0]);123 promisify_test_for('geoadd', 'geoadd', ['test', 0, 1]);124 promisify_test_for('geoadd', 'geoadd', ['test', 0, 1, 2]);125 promisify_test_for('geohash', 'geohash', []);126 promisify_test_for('geohash', 'geohash', ['test']);127 promisify_test_for('geohash', 'geohash', ['test', 'value']);128 promisify_test_for('geohash', 'geohash', ['test', '0']);129 promisify_test_for('geohash', 'geohash', ['test', '0', '1']);130 promisify_test_for('geohash', 'geohash', ['test', '0', '1', '2']);131 promisify_test_for('geopos', 'geopos', []);132 promisify_test_for('geopos', 'geopos', ['test']);133 promisify_test_for('geopos', 'geopos', ['test', 'value']);134 promisify_test_for('geopos', 'geopos', ['test', '0']);135 promisify_test_for('geopos', 'geopos', ['test', '0', '1']);136 promisify_test_for('geopos', 'geopos', ['test', '0', '1', '2']);137 promisify_test_for('geodist', 'geodist', []);138 promisify_test_for('geodist', 'geodist', ['test']);139 promisify_test_for('geodist', 'geodist', ['test', 'value']);140 promisify_test_for('geodist', 'geodist', ['test', '0']);141 promisify_test_for('geodist', 'geodist', ['test', '0', '1']);142 promisify_test_for('geodist', 'geodist', ['test', '0', '1', '2']);143 promisify_test_for('georadius', 'georadius', []);144 promisify_test_for('georadius', 'georadius', ['test']);145 promisify_test_for('georadius', 'georadius', ['test', 'value']);146 promisify_test_for('georadius', 'georadius', ['test', 0]);147 promisify_test_for('georadius', 'georadius', ['test', 0, 1]);148 promisify_test_for('georadius', 'georadius', ['test', 0, 1, 2]);149 promisify_test_for('georadiusbymember', 'georadiusbymember', []);150 promisify_test_for('georadiusbymember', 'georadiusbymember', ['test']);151 promisify_test_for('georadiusbymember', 'georadiusbymember', ['test', 'value']);152 promisify_test_for('georadiusbymember', 'georadiusbymember', ['test', 0]);153 promisify_test_for('georadiusbymember', 'georadiusbymember', ['test', 0, 1]);154 promisify_test_for('georadiusbymember', 'georadiusbymember', ['test', 0, 1, 2]);155 promisify_test_for('get', 'get', ['test']);156 promisify_test_for('getbit', 'getbit', ['test', 7]);157 promisify_test_for('getrange', 'getrange', ['test', 0, 3]);158 promisify_test_for('getset', 'getset', ['test', 'value']);159 promisify_test_for('hdel', 'hdel', []);160 promisify_test_for('hdel', 'hdel', ['test']);161 promisify_test_for('hdel', 'hdel', ['test', 'value']);162 promisify_test_for('hdel', 'hdel', ['test', 0]);163 promisify_test_for('hdel', 'hdel', ['test', 0, 1]);164 promisify_test_for('hdel', 'hdel', ['test', 0, 1, 2]);165 promisify_test_for('hexists', 'hexists', ['test', 'value']);166 promisify_test_for('hget', 'hget', ['test', 'value']);167 promisify_test_for('hgetall', 'hgetall', ['test']);168 promisify_test_for('hincrby', 'hincrby', ['test', 'value', 3]);169 promisify_test_for('hincrbyfloat', 'hincrbyfloat', ['test', 'value', 3.0]);170 promisify_test_for('hkeys', 'hkeys', ['test']);171 promisify_test_for('hlen', 'hlen', ['test']);172 promisify_test_for('hmget', 'hmget', []);173 promisify_test_for('hmget', 'hmget', ['test']);174 promisify_test_for('hmget', 'hmget', ['test', 'value']);175 promisify_test_for('hmget', 'hmget', ['test', 0]);176 promisify_test_for('hmget', 'hmget', ['test', 0, 1]);177 promisify_test_for('hmget', 'hmget', ['test', 0, 1, 2]);178 promisify_test_for('hmget', 'hmget', ['test', 'value', 'value']);179 promisify_test_for('hset', 'hset', ['test', 'value', 'value']);180 promisify_test_for('hsetnx', 'hsetnx', ['test', 'value', 'value']);181 promisify_test_for('hstrlen', 'hstrlen', ['test', 'value']);182 promisify_test_for('hvals', 'hvals', ['test']);183 promisify_test_for('incr', 'incr', ['test']);184 promisify_test_for('incrby', 'incrby', ['test', 3]);185 promisify_test_for('incrbyfloat', 'incrbyfloat', ['test', 3.0]);186 promisify_test_for('keys', 'keys', ['test']);187 promisify_test_for('lastsave', 'lastsave', []);188 promisify_test_for('lindex', 'lindex', ['test', 1]);189 promisify_test_for('linsert', 'linsert', ['test', 'AFTER', 'test', 'value']);190 promisify_test_for('llen', 'llen', ['test']);191 promisify_test_for('lpop', 'lpop', ['test']);192 promisify_test_for('lpush', 'lpush', []);193 promisify_test_for('lpush', 'lpush', ['test']);194 promisify_test_for('lpush', 'lpush', ['test', 'value']);195 promisify_test_for('lpush', 'lpush', ['test', 0]);196 promisify_test_for('lpush', 'lpush', ['test', 0, 1]);197 promisify_test_for('lpush', 'lpush', ['test', 0, 1, 2]);198 promisify_test_for('lpush', 'lpush', ['test', 'value', 'value']);199 promisify_test_for('lpushx', 'lpushx', ['lpushx', 'value']);200 promisify_test_for('lrange', 'lrange', ['test', 0, 1]);201 promisify_test_for('lrem', 'lrem', ['test', 1, 'value']);202 promisify_test_for('lset', 'lset', ['test', 1, 'value']);203 promisify_test_for('ltrim', 'ltrim', ['test', 1, 2]);204 promisify_test_for('mget', 'mget', []);205 promisify_test_for('mget', 'mget', ['test', 'value']);206 promisify_test_for('migrate', 'migrate', []);207 promisify_test_for('migrate', 'migrate', ['test', 'value']);208 promisify_test_for('move', 'move', ['test', 1]);209 promisify_test_for('mset', 'mset', []);210 promisify_test_for('mset', 'mset', ['test', 'value']);211 promisify_test_for('msetnx', 'msetnx', []);212 promisify_test_for('msetnx', 'msetnx', ['test', 'value']);213 promisify_test_for('object', 'object', []);214 promisify_test_for('object', 'object', ['test', 'value']);215 promisify_test_for('persist', 'persist', ['test']);216 promisify_test_for('pexpire', 'pexpire', ['test', 1]);217 promisify_test_for('pexpireat', 'pexpireat', ['test', 1]);218 promisify_test_for('pfadd', 'pfadd', []);219 promisify_test_for('pfadd', 'pfadd', ['test']);220 promisify_test_for('pfadd', 'pfadd', ['test', 'value']);221 promisify_test_for('pfadd', 'pfadd', ['test', 0]);222 promisify_test_for('pfadd', 'pfadd', ['test', 0, 1]);223 promisify_test_for('pfadd', 'pfadd', ['test', 0, 1, 2]);224 promisify_test_for('pfadd', 'pfadd', ['test', 'value', 'value']);225 promisify_test_for('pfcount', 'pfcount', []);226 promisify_test_for('pfcount', 'pfcount', ['test', 'value']);227 promisify_test_for('pfmerge', 'pfmerge', []);228 promisify_test_for('pfmerge', 'pfmerge', ['test', 'value']);229 promisify_test_for('psetex', 'psetex', ['test', 1, 'value']);230 promisify_test_for('pubsub', 'pubsub', []);231 promisify_test_for('pubsub', 'pubsub', ['test', 'value']);232 promisify_test_for('pttl', 'pttl', ['test']);233 promisify_test_for('quit', 'quit', []);234 promisify_test_for('randomkey', 'randomkey', []);235 promisify_test_for('readonly', 'readonly', []);236 promisify_test_for('readwrite', 'readwrite', []);237 promisify_test_for('rename', 'rename', ['test', 'test-new']);238 promisify_test_for('renamenx', 'renamenx', ['test', 'test-new']);239 promisify_test_for('restore', 'restore', ['test', 1, 'value']);240 promisify_test_for('role', 'role', []);241 promisify_test_for('rpop', 'rpop', ['test']);242 promisify_test_for('rpoplpush', 'rpoplpush', ['test', 'value']);243 promisify_test_for('rpush', 'rpush', []);244 promisify_test_for('rpush', 'rpush', ['test']);245 promisify_test_for('rpush', 'rpush', ['test', 'value']);246 promisify_test_for('rpush', 'rpush', ['test', 0]);247 promisify_test_for('rpush', 'rpush', ['test', 0, 1]);248 promisify_test_for('rpush', 'rpush', ['test', 0, 1, 2]);249 promisify_test_for('rpush', 'rpush', ['test', 'value', 'value']);250 promisify_test_for('rpushx', 'rpushx', ['test', 'value']);251 promisify_test_for('sadd', 'sadd', []);252 promisify_test_for('sadd', 'sadd', ['test']);253 promisify_test_for('sadd', 'sadd', ['test', 'value']);254 promisify_test_for('sadd', 'sadd', ['test', 0]);255 promisify_test_for('sadd', 'sadd', ['test', 0, 1]);256 promisify_test_for('sadd', 'sadd', ['test', 0, 1, 2]);257 promisify_test_for('sadd', 'sadd', ['test', 'value', 'value']);258 promisify_test_for('save', 'save', []);259 promisify_test_for('scard', 'scard', ['test']);260 promisify_test_for('script', 'script', []);261 promisify_test_for('script', 'script', ['test', 'value']);262 promisify_test_for('sdiff', 'sdiff', []);263 promisify_test_for('sdiff', 'sdiff', ['test', 'value']);264 promisify_test_for('sdiffstore', 'sdiffstore', []);265 promisify_test_for('sdiffstore', 'sdiffstore', ['test']);266 promisify_test_for('sdiffstore', 'sdiffstore', ['test', 'value']);267 promisify_test_for('sdiffstore', 'sdiffstore', ['test', 0]);268 promisify_test_for('sdiffstore', 'sdiffstore', ['test', 0, 1]);269 promisify_test_for('sdiffstore', 'sdiffstore', ['test', 0, 1, 2]);270 promisify_test_for('sdiffstore', 'sdiffstore', ['test', 'value', 'value']);271 promisify_test_for('select', 'select', ['test']);272 promisify_test_for('select', 'select', [0]);273 promisify_test_for('set', 'set', ['test', 'value']);274 promisify_test_for('set', 'set', ['test', 'value', 'any']);275 promisify_test_for('set', 'set', ['test', 'value', 'any', 12]);276 promisify_test_for('set', 'set', ['test', 'value', 'any', 12, 'any']);277 promisify_test_for('setbit', 'setbit', ['test', 0, '1']);278 promisify_test_for('setex', 'setex', ['test', 12, 'value']);279 promisify_test_for('setnx', 'setnx', ['test', 'value']);280 promisify_test_for('setrange', 'setrange', ['test', 0, 'value']);281 promisify_test_for('shutdown', 'shutdown', []);282 promisify_test_for('shutdown', 'shutdown', ['test', 'value']);283 promisify_test_for('sinter', 'sinter', []);284 promisify_test_for('sinter', 'sinter', ['test']);285 promisify_test_for('sinter', 'sinter', ['test', 'value']);286 promisify_test_for('sinter', 'sinter', ['test', 0]);287 promisify_test_for('sinter', 'sinter', ['test', 0, 1]);288 promisify_test_for('sinter', 'sinter', ['test', 0, 1, 2]);289 promisify_test_for('sinter', 'sinter', ['test', 'value', 'value']);290 promisify_test_for('sinterstore', 'sinterstore', []);291 promisify_test_for('sinterstore', 'sinterstore', ['test', 'value']);292 promisify_test_for('sismember', 'sismember', ['test', 'member']);293 promisify_test_for('slaveof', 'slaveof', ['localhost', '6666']);294 promisify_test_for('slowlog', 'slowlog', []);295 promisify_test_for('slowlog', 'slowlog', ['test', 'value']);296 promisify_test_for('smembers', 'smembers', ['test']);297 promisify_test_for('smove', 'smove', ['source', 'destination', 'test']);298 promisify_test_for('sort', 'sort', []);299 promisify_test_for('sort', 'sort', ['test', 'value']);300 promisify_test_for('spop', 'spop', ['test']);301 promisify_test_for('spop', 'spop', ['test', 2]);302 promisify_test_for('srandmember', 'srandmember', ['test']);303 promisify_test_for('srandmember', 'srandmember', ['test', 2]);304 promisify_test_for('srem', 'srem', []);305 promisify_test_for('srem', 'srem', ['test']);306 promisify_test_for('srem', 'srem', ['test', 'value']);307 promisify_test_for('srem', 'srem', ['test', 0]);308 promisify_test_for('srem', 'srem', ['test', 0, 1]);309 promisify_test_for('srem', 'srem', ['test', 0, 1, 2]);310 promisify_test_for('srem', 'srem', ['test', 'value', 'value']);311 promisify_test_for('strlen', 'strlen', ['test']);312 promisify_test_for('sunion', 'sunion', []);313 promisify_test_for('sunion', 'sunion', ['test', 'value']);314 promisify_test_for('sunionstore', 'sunionstore', []);315 promisify_test_for('sunionstore', 'sunionstore', ['test', 'value']);316 promisify_test_for('sync', 'sync', []);317 promisify_test_for('time', 'time', []);318 promisify_test_for('ttl', 'ttl', ['test']);319 promisify_test_for('type', 'type', ['test']);320 promisify_test_for('unwatch', 'unwatch', []);321 promisify_test_for('wait', 'wait', [1, 10000]);322 promisify_test_for('watch', 'watch', []);323 promisify_test_for('watch', 'watch', ['test', 'value']);324 promisify_test_for('zadd', 'zadd', []);325 promisify_test_for('zadd', 'zadd', ['test']);326 promisify_test_for('zadd', 'zadd', ['test', 'value']);327 promisify_test_for('zadd', 'zadd', ['test', 0]);328 promisify_test_for('zadd', 'zadd', ['test', 0, 1]);329 promisify_test_for('zadd', 'zadd', ['test', 0, 1, 2]);330 promisify_test_for('zadd', 'zadd', ['test', 'value', 'value']);331 promisify_test_for('zcard', 'zcard', ['test']);332 promisify_test_for('zcount', 'zcount', ['test', 1, 3]);333 promisify_test_for('zcount', 'zcount', ['test', '1', '3']);334 promisify_test_for('zincrby', 'zincrby', ['test', 1, 'member']);335 promisify_test_for('zinterstore', 'zinterstore', []);336 promisify_test_for('zinterstore', 'zinterstore', ['test', 'value']);337 promisify_test_for('zlexcount', 'zlexcount', ['test', 'min', 'max']);338 promisify_test_for('zrange', 'zrange', ['test', 0, 1]);339 promisify_test_for('zrange', 'zrange', ['test', 0, 1, 'score']);340 promisify_test_for('zrevrangebylex', 'zrevrangebylex', ['test', 1, 2]);341 promisify_test_for('zrevrangebylex', 'zrevrangebylex', ['test', 1, 2, 'limit', 0, 1]);342 promisify_test_for('zrangebylex', 'zrangebylex', ['test', 1, 2]);343 promisify_test_for('zrangebylex', 'zrangebylex', ['test', 1, 2, 3, 4, 5]);344 promisify_test_for('zrangebyscore', 'zrangebyscore', ['test', 1, 2]);345 promisify_test_for('zrangebyscore', 'zrangebyscore', ['test', 'min', 'max']);346 promisify_test_for('zrangebyscore', 'zrangebyscore', ['test', 'min', 'max']);347 promisify_test_for('zrangebyscore', 'zrangebyscore', ['test', 'min', 'max', 'score']);348 promisify_test_for('zrangebyscore', 'zrangebyscore', ['test', 'min', 'max', 'limit', 1, 2]);349 promisify_test_for('zrangebyscore', 'zrangebyscore', ['test', 'min', 'max', 'limit', 1, 2, 3]);350 promisify_test_for('zrank', 'zrank', ['test', 'member']);351 promisify_test_for('zrem', 'zrem', []);352 promisify_test_for('zrem', 'zrem', ['test']);353 promisify_test_for('zrem', 'zrem', ['test', 'value']);354 promisify_test_for('zrem', 'zrem', ['test', 0]);355 promisify_test_for('zrem', 'zrem', ['test', 0, 1]);356 promisify_test_for('zrem', 'zrem', ['test', 0, 1, 2]);357 promisify_test_for('zrem', 'zrem', ['test', 'value', 'value']);358 promisify_test_for('zremrangebylex', 'zremrangebylex', ['test', 1, 2]);359 promisify_test_for('zremrangebyrank', 'zremrangebyrank', ['test', 1, 2]);360 promisify_test_for('zremrangebyscore', 'zremrangebyscore', ['test', 1, 2]);361 promisify_test_for('zremrangebyscore', 'zremrangebyscore', ['test', 'min', 'max']);362 promisify_test_for('zrevrange', 'zrevrange', ['test', 1, 2]);363 promisify_test_for('zrevrange', 'zrevrange', ['test', 1, 2, 'score']);364 promisify_test_for('zrevrangebyscore', 'zrevrangebyscore', ['test', 1, 2]);365 promisify_test_for('zrevrangebyscore', 'zrevrangebyscore', ['test', 1, 2, 'score']);366 promisify_test_for('zrevrangebyscore', 'zrevrangebyscore', ['test', 1, 2, 'limit', 0, 1]);367 promisify_test_for('zrevrangebyscore', 'zrevrangebyscore', ['test', 1, 2, 'score', 'limit', 0, 1]);368 promisify_test_for('zrevrank', 'zrevrank', ['test', 'member']);369 promisify_test_for('zscore', 'zscore', ['test', 'member']);370 promisify_test_for('zunionstore', 'zunionstore', []);371 promisify_test_for('zunionstore', 'zunionstore', ['test', 'value']);372 promisify_test_for('scan', 'scan', []);373 promisify_test_for('scan', 'scan', ['test', 'value']);374 promisify_test_for('sscan', 'sscan', []);375 promisify_test_for('sscan', 'sscan', ['test']);376 promisify_test_for('sscan', 'sscan', ['test', 'value']);377 promisify_test_for('sscan', 'sscan', ['test', 0]);378 promisify_test_for('sscan', 'sscan', ['test', 0, 1]);379 promisify_test_for('sscan', 'sscan', ['test', 0, 1, 2]);380 promisify_test_for('sscan', 'sscan', ['test', 'value', 'value']);381 promisify_test_for('hscan', 'hscan', []);382 promisify_test_for('hscan', 'hscan', ['test']);383 promisify_test_for('hscan', 'hscan', ['test', 'value']);384 promisify_test_for('hscan', 'hscan', ['test', 0]);385 promisify_test_for('hscan', 'hscan', ['test', 0, 1]);386 promisify_test_for('hscan', 'hscan', ['test', 0, 1, 2]);387 promisify_test_for('hscan', 'hscan', ['test', 'value', 'value']);388 promisify_test_for('zscan', 'zscan', []);389 promisify_test_for('zscan', 'zscan', ['test']);390 promisify_test_for('zscan', 'zscan', ['test', 'value']);391 promisify_test_for('zscan', 'zscan', ['test', 0]);392 promisify_test_for('zscan', 'zscan', ['test', 0, 1]);393 promisify_test_for('zscan', 'zscan', ['test', 0, 1, 2]);394 promisify_test_for('zscan', 'zscan', ['test', 'value', 'value']);...
webext.js
Source:webext.js
1/*******************************************************************************23 uBlock Origin - a browser extension to block requests.4 Copyright (C) 2019-present Raymond Hill56 This program is free software: you can redistribute it and/or modify7 it under the terms of the GNU General Public License as published by8 the Free Software Foundation, either version 3 of the License, or9 (at your option) any later version.1011 This program is distributed in the hope that it will be useful,12 but WITHOUT ANY WARRANTY; without even the implied warranty of13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14 GNU General Public License for more details.1516 You should have received a copy of the GNU General Public License17 along with this program. If not, see {http://www.gnu.org/licenses/}.1819 Home: https://github.com/gorhill/uBlock20*/2122'use strict';2324// `webext` is a promisified api of `chrome`. Entries are added as25// the promisification of uBO progress.2627const webext = (( ) => { // jshint ignore:line28// >>>>> start of private scope2930const promisifyNoFail = function(thisArg, fnName, outFn = r => r) {31 const fn = thisArg[fnName];32 return function() {33 return new Promise(resolve => {34 fn.call(thisArg, ...arguments, function() {35 if ( chrome.runtime.lastError instanceof Object ) {36 void chrome.runtime.lastError.message;37 }38 resolve(outFn(...arguments));39 });40 });41 };42};4344const promisify = function(thisArg, fnName) {45 const fn = thisArg[fnName];46 return function() {47 return new Promise((resolve, reject) => {48 fn.call(thisArg, ...arguments, function() {49 const lastError = chrome.runtime.lastError;50 if ( lastError instanceof Object ) {51 return reject(lastError.message);52 }53 resolve(...arguments);54 });55 });56 };57};5859const webext = {60 // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/browserAction61 browserAction: {62 setBadgeBackgroundColor: promisifyNoFail(chrome.browserAction, 'setBadgeBackgroundColor'),63 setBadgeText: promisifyNoFail(chrome.browserAction, 'setBadgeText'),64 setIcon: promisifyNoFail(chrome.browserAction, 'setIcon'),65 setTitle: promisifyNoFail(chrome.browserAction, 'setTitle'),66 },67 // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus68 menus: {69 create: function() {70 return chrome.contextMenus.create(...arguments, ( ) => {71 void chrome.runtime.lastError;72 });73 },74 onClicked: chrome.contextMenus.onClicked,75 remove: promisifyNoFail(chrome.contextMenus, 'remove'),76 },77 // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/privacy78 privacy: {79 },80 // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage81 storage: {82 // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/local83 local: {84 clear: promisify(chrome.storage.local, 'clear'),85 get: promisify(chrome.storage.local, 'get'),86 getBytesInUse: promisify(chrome.storage.local, 'getBytesInUse'),87 remove: promisify(chrome.storage.local, 'remove'),88 set: promisify(chrome.storage.local, 'set'),89 },90 },91 // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs92 tabs: {93 get: promisifyNoFail(chrome.tabs, 'get', tab => tab instanceof Object ? tab : null),94 executeScript: promisifyNoFail(chrome.tabs, 'executeScript'),95 insertCSS: promisifyNoFail(chrome.tabs, 'insertCSS'),96 removeCSS: promisifyNoFail(chrome.tabs, 'removeCSS'),97 query: promisifyNoFail(chrome.tabs, 'query', tabs => Array.isArray(tabs) ? tabs : []),98 reload: promisifyNoFail(chrome.tabs, 'reload'),99 remove: promisifyNoFail(chrome.tabs, 'remove'),100 update: promisifyNoFail(chrome.tabs, 'update', tab => tab instanceof Object ? tab : null),101 },102 // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webNavigation103 webNavigation: {104 getFrame: promisify(chrome.webNavigation, 'getFrame'),105 getAllFrames: promisify(chrome.webNavigation, 'getAllFrames'),106 },107 // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/windows108 windows: {109 get: promisifyNoFail(chrome.windows, 'get', win => win instanceof Object ? win : null),110 create: promisifyNoFail(chrome.windows, 'create', win => win instanceof Object ? win : null),111 update: promisifyNoFail(chrome.windows, 'update', win => win instanceof Object ? win : null),112 },113};114115// browser.privacy entries116{117 const settings = [118 // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/privacy/network119 [ 'network', 'networkPredictionEnabled' ],120 [ 'network', 'webRTCIPHandlingPolicy' ],121 // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/privacy/websites122 [ 'websites', 'hyperlinkAuditingEnabled' ],123 ];124 for ( const [ category, setting ] of settings ) {125 let categoryEntry = webext.privacy[category];126 if ( categoryEntry instanceof Object === false ) {127 categoryEntry = webext.privacy[category] = {};128 }129 const settingEntry = categoryEntry[setting] = {};130 const thisArg = chrome.privacy[category][setting];131 settingEntry.clear = promisifyNoFail(thisArg, 'clear');132 settingEntry.get = promisifyNoFail(thisArg, 'get');133 settingEntry.set = promisifyNoFail(thisArg, 'set');134 }135}136137// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/managed138if ( chrome.storage.managed instanceof Object ) {139 webext.storage.managed = {140 get: promisify(chrome.storage.managed, 'get'),141 };142}143144// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/sync145if ( chrome.storage.sync instanceof Object ) {146 webext.storage.sync = {147 QUOTA_BYTES: chrome.storage.sync.QUOTA_BYTES,148 QUOTA_BYTES_PER_ITEM: chrome.storage.sync.QUOTA_BYTES_PER_ITEM,149 MAX_ITEMS: chrome.storage.sync.MAX_ITEMS,150 MAX_WRITE_OPERATIONS_PER_HOUR: chrome.storage.sync.MAX_WRITE_OPERATIONS_PER_HOUR,151 MAX_WRITE_OPERATIONS_PER_MINUTE: chrome.storage.sync.MAX_WRITE_OPERATIONS_PER_MINUTE,152153 clear: promisify(chrome.storage.sync, 'clear'),154 get: promisify(chrome.storage.sync, 'get'),155 getBytesInUse: promisify(chrome.storage.sync, 'getBytesInUse'),156 remove: promisify(chrome.storage.sync, 'remove'),157 set: promisify(chrome.storage.sync, 'set'),158 };159}160161// https://bugs.chromium.org/p/chromium/issues/detail?id=608854162if ( chrome.tabs.removeCSS instanceof Function ) {163 webext.tabs.removeCSS = promisifyNoFail(chrome.tabs, 'removeCSS');164}165166return webext;167168// <<<<< end of private scope
...
promises.js
Source:promises.js
1"use strict";2var __spreadArray = (this && this.__spreadArray) || function (to, from) {3 for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)4 to[j] = from[i];5 return to;6};7Object.defineProperty(exports, "__esModule", { value: true });8exports.FileHandle = void 0;9function promisify(vol, fn, getResult) {10 if (getResult === void 0) { getResult = function (input) { return input; }; }11 return function () {12 var args = [];13 for (var _i = 0; _i < arguments.length; _i++) {14 args[_i] = arguments[_i];15 }16 return new Promise(function (resolve, reject) {17 vol[fn].bind(vol).apply(void 0, __spreadArray(__spreadArray([], args), [function (error, result) {18 if (error)19 return reject(error);20 return resolve(getResult(result));21 }]));22 });23 };24}25var FileHandle = /** @class */ (function () {26 function FileHandle(vol, fd) {27 this.vol = vol;28 this.fd = fd;29 }30 FileHandle.prototype.appendFile = function (data, options) {31 return promisify(this.vol, 'appendFile')(this.fd, data, options);32 };33 FileHandle.prototype.chmod = function (mode) {34 return promisify(this.vol, 'fchmod')(this.fd, mode);35 };36 FileHandle.prototype.chown = function (uid, gid) {37 return promisify(this.vol, 'fchown')(this.fd, uid, gid);38 };39 FileHandle.prototype.close = function () {40 return promisify(this.vol, 'close')(this.fd);41 };42 FileHandle.prototype.datasync = function () {43 return promisify(this.vol, 'fdatasync')(this.fd);44 };45 FileHandle.prototype.read = function (buffer, offset, length, position) {46 return promisify(this.vol, 'read', function (bytesRead) { return ({ bytesRead: bytesRead, buffer: buffer }); })(this.fd, buffer, offset, length, position);47 };48 FileHandle.prototype.readFile = function (options) {49 return promisify(this.vol, 'readFile')(this.fd, options);50 };51 FileHandle.prototype.stat = function (options) {52 return promisify(this.vol, 'fstat')(this.fd, options);53 };54 FileHandle.prototype.sync = function () {55 return promisify(this.vol, 'fsync')(this.fd);56 };57 FileHandle.prototype.truncate = function (len) {58 return promisify(this.vol, 'ftruncate')(this.fd, len);59 };60 FileHandle.prototype.utimes = function (atime, mtime) {61 return promisify(this.vol, 'futimes')(this.fd, atime, mtime);62 };63 FileHandle.prototype.write = function (buffer, offset, length, position) {64 return promisify(this.vol, 'write', function (bytesWritten) { return ({ bytesWritten: bytesWritten, buffer: buffer }); })(this.fd, buffer, offset, length, position);65 };66 FileHandle.prototype.writeFile = function (data, options) {67 return promisify(this.vol, 'writeFile')(this.fd, data, options);68 };69 return FileHandle;70}());71exports.FileHandle = FileHandle;72function createPromisesApi(vol) {73 if (typeof Promise === 'undefined')74 return null;75 return {76 FileHandle: FileHandle,77 access: function (path, mode) {78 return promisify(vol, 'access')(path, mode);79 },80 appendFile: function (path, data, options) {81 return promisify(vol, 'appendFile')(path instanceof FileHandle ? path.fd : path, data, options);82 },83 chmod: function (path, mode) {84 return promisify(vol, 'chmod')(path, mode);85 },86 chown: function (path, uid, gid) {87 return promisify(vol, 'chown')(path, uid, gid);88 },89 copyFile: function (src, dest, flags) {90 return promisify(vol, 'copyFile')(src, dest, flags);91 },92 lchmod: function (path, mode) {93 return promisify(vol, 'lchmod')(path, mode);94 },95 lchown: function (path, uid, gid) {96 return promisify(vol, 'lchown')(path, uid, gid);97 },98 link: function (existingPath, newPath) {99 return promisify(vol, 'link')(existingPath, newPath);100 },101 lstat: function (path, options) {102 return promisify(vol, 'lstat')(path, options);103 },104 mkdir: function (path, options) {105 return promisify(vol, 'mkdir')(path, options);106 },107 mkdtemp: function (prefix, options) {108 return promisify(vol, 'mkdtemp')(prefix, options);109 },110 open: function (path, flags, mode) {111 return promisify(vol, 'open', function (fd) { return new FileHandle(vol, fd); })(path, flags, mode);112 },113 readdir: function (path, options) {114 return promisify(vol, 'readdir')(path, options);115 },116 readFile: function (id, options) {117 return promisify(vol, 'readFile')(id instanceof FileHandle ? id.fd : id, options);118 },119 readlink: function (path, options) {120 return promisify(vol, 'readlink')(path, options);121 },122 realpath: function (path, options) {123 return promisify(vol, 'realpath')(path, options);124 },125 rename: function (oldPath, newPath) {126 return promisify(vol, 'rename')(oldPath, newPath);127 },128 rmdir: function (path) {129 return promisify(vol, 'rmdir')(path);130 },131 stat: function (path, options) {132 return promisify(vol, 'stat')(path, options);133 },134 symlink: function (target, path, type) {135 return promisify(vol, 'symlink')(target, path, type);136 },137 truncate: function (path, len) {138 return promisify(vol, 'truncate')(path, len);139 },140 unlink: function (path) {141 return promisify(vol, 'unlink')(path);142 },143 utimes: function (path, atime, mtime) {144 return promisify(vol, 'utimes')(path, atime, mtime);145 },146 writeFile: function (id, data, options) {147 return promisify(vol, 'writeFile')(id instanceof FileHandle ? id.fd : id, data, options);148 },149 };150}...
awsFunctions.js
Source:awsFunctions.js
1const { promisify } = require('util');2const AWS = require('aws-sdk');3const getRegion = require('../util/getRegion');4const apiVersion = 'latest';5const region = getRegion();6const lambda = new AWS.Lambda({ apiVersion, region });7const api = new AWS.APIGateway({ apiVersion, region });8const ec2 = new AWS.EC2({ apiVersion, region });9const sts = new AWS.STS({ apiVersion, region });10const sqs = new AWS.SQS({ apiVersion, region });11const iam = new AWS.IAM({ apiVersion, region });12// lambda13const asyncLambdaCreateFunction = promisify(lambda.createFunction.bind(lambda));14const asyncDeleteFunction = promisify(lambda.deleteFunction.bind(lambda));15const asyncAddPermission = promisify(lambda.addPermission.bind(lambda));16const asyncListEventSourceMappings = promisify(lambda.listEventSourceMappings.bind(lambda));17const asyncDeleteEventSourceMapping = promisify(lambda.deleteEventSourceMapping.bind(lambda));18const asyncCreateEventSourceMapping = promisify(lambda.createEventSourceMapping.bind(lambda));19const asyncPutFunctionConcurrency = promisify(lambda.putFunctionConcurrency.bind(lambda));20const asyncGetFunction = promisify(lambda.getFunction.bind(lambda));21const asyncInvokeLambda = promisify(lambda.invoke.bind(lambda));22// api23const asyncCreateDeployment = promisify(api.createDeployment.bind(api));24const asyncPutMethod = promisify(api.putMethod.bind(api));25const asyncPutIntegration = promisify(api.putIntegration.bind(api));26const asyncCreateApi = promisify(api.createRestApi.bind(api));27const asyncGetResources = promisify(api.getResources.bind(api));28const asyncCreateResource = promisify(api.createResource.bind(api));29const asyncDeleteResource = promisify(api.deleteResource.bind(api));30// ec231const asyncGetRegions = promisify(ec2.describeRegions.bind(ec2));32const asyncCreateKeyPair = promisify(ec2.createKeyPair.bind(ec2));33const asyncRunInstances = promisify(ec2.runInstances.bind(ec2));34const asyncDescribeInstances = promisify(ec2.describeInstances.bind(ec2));35const asyncStopInstances = promisify(ec2.stopInstances.bind(ec2));36const asyncDescribeImages = promisify(ec2.describeImages.bind(ec2));37const asyncDescribeKeyPairs = promisify(ec2.describeKeyPairs.bind(ec2));38const asyncCreateSecurityGroup = promisify(ec2.createSecurityGroup.bind(ec2));39const asyncDescribeVpcs = promisify(ec2.describeVpcs.bind(ec2));40const asyncDescribeSubnets = promisify(ec2.describeSubnets.bind(ec2));41const asyncAuthorizeSecurityGroupIngress = promisify(ec2.authorizeSecurityGroupIngress.bind(ec2));42const asyncTerminateInstances = promisify(ec2.terminateInstances.bind(ec2));43const asyncDeleteSecurityGroup = promisify(ec2.deleteSecurityGroup.bind(ec2));44const asyncDescribeSecurityGroups = promisify(ec2.describeSecurityGroups.bind(ec2));45// sts46const asyncGetCallerIdentity = promisify(sts.getCallerIdentity.bind(sts));47// sqs48const asyncCreateSQS = promisify(sqs.createQueue.bind(sqs));49const asyncDeleteQueue = promisify(sqs.deleteQueue.bind(sqs));50const asyncGetQueueAttributes = promisify(sqs.getQueueAttributes.bind(sqs));51const asyncListQueues = promisify(sqs.listQueues.bind(sqs));52const asyncReceiveMessage = promisify(sqs.receiveMessage.bind(sqs));53const asyncSendMessage = promisify(sqs.sendMessage.bind(sqs));54// iam55const asyncCreateRole = promisify(iam.createRole.bind(iam));56const asyncCreatePolicy = promisify(iam.createPolicy.bind(iam));57const asyncAttachPolicy = promisify(iam.attachRolePolicy.bind(iam));58const asyncListRolePolicies = promisify(iam.listAttachedRolePolicies.bind(iam));59const asyncGetPolicy = promisify(iam.getPolicy.bind(iam));60const asyncGetRole = promisify(iam.getRole.bind(iam));61module.exports = {62 asyncCreateRole,63 asyncAttachPolicy,64 asyncLambdaCreateFunction,65 asyncAddPermission,66 asyncPutMethod,67 asyncPutIntegration,68 asyncCreateApi,69 asyncGetResources,70 asyncGetRegions,71 asyncGetCallerIdentity,72 asyncCreateDeployment,73 asyncCreateKeyPair,74 asyncRunInstances,75 asyncCreateSQS,76 asyncCreateEventSourceMapping,77 asyncPutFunctionConcurrency,78 asyncDescribeInstances,79 asyncStopInstances,80 asyncDescribeImages,81 asyncDescribeKeyPairs,82 asyncGetRole,83 asyncGetPolicy,84 asyncCreatePolicy,85 asyncDeleteEventSourceMapping,86 asyncListEventSourceMappings,87 asyncDeleteQueue,88 asyncListRolePolicies,89 asyncDeleteFunction,90 asyncCreateResource,91 asyncDeleteResource,92 asyncCreateSecurityGroup,93 asyncDescribeVpcs,94 asyncDescribeSubnets,95 asyncAuthorizeSecurityGroupIngress,96 asyncTerminateInstances,97 asyncDeleteSecurityGroup,98 asyncDescribeSecurityGroups,99 asyncGetFunction,100 asyncGetQueueAttributes,101 asyncListQueues,102 asyncReceiveMessage,103 asyncInvokeLambda,104 asyncSendMessage,...
promisify.js
Source:promisify.js
1'use strict';2const util = require('util');3module.exports = function (redisClient) {4 redisClient.async = {5 send_command: util.promisify(redisClient.send_command).bind(redisClient),6 exists: util.promisify(redisClient.exists).bind(redisClient),7 del: util.promisify(redisClient.del).bind(redisClient),8 get: util.promisify(redisClient.get).bind(redisClient),9 set: util.promisify(redisClient.set).bind(redisClient),10 incr: util.promisify(redisClient.incr).bind(redisClient),11 rename: util.promisify(redisClient.rename).bind(redisClient),12 type: util.promisify(redisClient.type).bind(redisClient),13 expire: util.promisify(redisClient.expire).bind(redisClient),14 expireat: util.promisify(redisClient.expireat).bind(redisClient),15 pexpire: util.promisify(redisClient.pexpire).bind(redisClient),16 pexpireat: util.promisify(redisClient.pexpireat).bind(redisClient),17 hmset: util.promisify(redisClient.hmset).bind(redisClient),18 hset: util.promisify(redisClient.hset).bind(redisClient),19 hget: util.promisify(redisClient.hget).bind(redisClient),20 hdel: util.promisify(redisClient.hdel).bind(redisClient),21 hgetall: util.promisify(redisClient.hgetall).bind(redisClient),22 hkeys: util.promisify(redisClient.hkeys).bind(redisClient),23 hvals: util.promisify(redisClient.hvals).bind(redisClient),24 hexists: util.promisify(redisClient.hexists).bind(redisClient),25 hincrby: util.promisify(redisClient.hincrby).bind(redisClient),26 sadd: util.promisify(redisClient.sadd).bind(redisClient),27 srem: util.promisify(redisClient.srem).bind(redisClient),28 sismember: util.promisify(redisClient.sismember).bind(redisClient),29 smembers: util.promisify(redisClient.smembers).bind(redisClient),30 scard: util.promisify(redisClient.scard).bind(redisClient),31 spop: util.promisify(redisClient.spop).bind(redisClient),32 zadd: util.promisify(redisClient.zadd).bind(redisClient),33 zrem: util.promisify(redisClient.zrem).bind(redisClient),34 zrange: util.promisify(redisClient.zrange).bind(redisClient),35 zrevrange: util.promisify(redisClient.zrevrange).bind(redisClient),36 zrangebyscore: util.promisify(redisClient.zrangebyscore).bind(redisClient),37 zrevrangebyscore: util.promisify(redisClient.zrevrangebyscore).bind(redisClient),38 zscore: util.promisify(redisClient.zscore).bind(redisClient),39 zcount: util.promisify(redisClient.zcount).bind(redisClient),40 zcard: util.promisify(redisClient.zcard).bind(redisClient),41 zrank: util.promisify(redisClient.zrank).bind(redisClient),42 zrevrank: util.promisify(redisClient.zrevrank).bind(redisClient),43 zincrby: util.promisify(redisClient.zincrby).bind(redisClient),44 zrangebylex: util.promisify(redisClient.zrangebylex).bind(redisClient),45 zrevrangebylex: util.promisify(redisClient.zrevrangebylex).bind(redisClient),46 zremrangebylex: util.promisify(redisClient.zremrangebylex).bind(redisClient),47 zlexcount: util.promisify(redisClient.zlexcount).bind(redisClient),48 lpush: util.promisify(redisClient.lpush).bind(redisClient),49 rpush: util.promisify(redisClient.rpush).bind(redisClient),50 rpop: util.promisify(redisClient.rpop).bind(redisClient),51 lrem: util.promisify(redisClient.lrem).bind(redisClient),52 ltrim: util.promisify(redisClient.ltrim).bind(redisClient),53 lrange: util.promisify(redisClient.lrange).bind(redisClient),54 llen: util.promisify(redisClient.llen).bind(redisClient),55 };...
redis.js
Source:redis.js
1const redis = require("redis");2const { promisify } = require('util');3//Redis å½ä»¤åè http://doc.redisfans.com/index.html 4/**5 * 6 * @param {*} db éè¦åæ¢çDBï¼ä¸ä¼ åé»è®¤DB 07 */8function Client(db){9 let client;10 if (db) {11 client = redis.createClient({db});12 }13 //éè¦ä½¿ç¨åæ¥å½æ°ï¼æç
§å¦ä¸å®ä¹å³å¯14 this.exists = promisify(client.exists).bind(client);15 this.keys = promisify(client.keys).bind(client);16 this.set = promisify(client.set).bind(client);17 this.get = promisify(client.get).bind(client);18 this.del = promisify(client.del).bind(client);19 this.incr = promisify(client.incr).bind(client);20 this.decr = promisify(client.decr).bind(client);21 this.lpush = promisify(client.lpush).bind(client);22 this.hexists = promisify(client.hexists).bind(client);23 this.hgetall = promisify(client.hgetall).bind(client);24 this.hset = promisify(client.hset).bind(client);25 this.hmset = promisify(client.hmset).bind(client);26 this.hget = promisify(client.hget).bind(client);27 this.hincrby = promisify(client.hincrby).bind(client);28 this.hdel = promisify(client.hdel).bind(client);29 this.hvals = promisify(client.hvals).bind(client);30 this.hscan = promisify(client.hscan).bind(client);31 this.sadd = promisify(client.sadd).bind(client);32 this.smembers = promisify(client.smembers).bind(client);33 this.scard = promisify(client.scard).bind(client);34 this.srem = promisify(client.srem).bind(client);35 return this;36}...
PromisifyRead.test.js
Source:PromisifyRead.test.js
1const fs = require('fs');2const path = require('path');3const PromisifyRead = require('./PromisifyRead');4const TEST_FILE = path.resolve(__dirname, 'temp/promisifyRead');5const TEST_CACHE_SIZE = 6;6const TEST_STR = '0123456789';7describe('check props for PromisifyRead', () => {8 test('promisify method', () => {9 expect(PromisifyRead._open.toString()).toBeDefined();10 expect(PromisifyRead._read.toString()).toBeDefined();11 expect(PromisifyRead._close.toString()).toBeDefined();12 });13 test('initial props', () => {14 const promisifyRead = new PromisifyRead(TEST_FILE, TEST_CACHE_SIZE);15 expect(promisifyRead.buf.length).toBe(TEST_CACHE_SIZE);16 expect(promisifyRead.file).toBe(TEST_FILE);17 expect(promisifyRead.fd).toBe(null);18 expect(promisifyRead.position).toBe(0);19 expect(promisifyRead.isDestroyed).toBe(false);20 promisifyRead.destroy();21 });22});23describe('check read for PromisifyRead', () => {24 test('should read success', async () => {25 fs.writeFileSync(TEST_FILE, TEST_STR);26 const promisifyRead = new PromisifyRead(TEST_FILE);27 let data = await promisifyRead.read(TEST_CACHE_SIZE);28 expect(data).toBe(TEST_STR.slice(0, TEST_CACHE_SIZE));29 data = await promisifyRead.read(TEST_CACHE_SIZE);30 expect(data).toBe(TEST_STR.slice(TEST_CACHE_SIZE, TEST_STR.length));31 promisifyRead.destroy();32 });...
Using AI Code Generation
1const XCUITestDriver = require('appium-xcuitest-driver');2const B = XCUITestDriver.helpers;3const BaseDriver = require('appium-base-driver');4const B = BaseDriver.helpers;5const iOSDriver = require('appium-ios-driver');6const B = iOSDriver.helpers;7const AndroidDriver = require('appium-android-driver');8const B = AndroidDriver.helpers;9const WindowsDriver = require('appium-windows-driver');10const B = WindowsDriver.helpers;11const MacDriver = require('appium-mac-driver');12const B = MacDriver.helpers;13const YouiEngineDriver = require('appium-youiengine-driver');14const B = YouiEngineDriver.helpers;15const EspressoDriver = require('appium-espresso-driver');16const B = EspressoDriver.helpers;17const FakeDriver = require('appium-fake-driver');18const B = FakeDriver.helpers;19const TizenDriver = require('appium-tizen-driver');20const B = TizenDriver.helpers;21const WebDriver = require('appium-webdriver');22const B = WebDriver.helpers;23const SelendroidDriver = require('appium-selendroid-driver');24const B = SelendroidDriver.helpers;25const UiAutomator2Driver = require('appium-uiautomator2-driver');26const B = UiAutomator2Driver.helpers;27const Mac2Driver = require('appium-mac2-driver');28const B = Mac2Driver.helpers;
Using AI Code Generation
1const XCUITestDriver = require('appium-xcuitest-driver');2const B = XCUITestDriver.helpers;3const fs = require('fs');4const readFileAsync = B.promisify(fs.readFile);5readFileAsync('some_file.txt', 'utf8')6 .then((content) => {7 console.log(content);8 })9 .catch((err) => {10 console.log(err);11 });12const XCUITestDriver = require('appium-xcuitest-driver');13const B = XCUITestDriver.helpers;14const fs = require('fs');15const readFileAsync = B.promisify(fs.readFile);16readFileAsync('some_file.txt', 'utf8')17 .then((content) => {18 console.log(content);19 })20 .catch((err) => {21 console.log(err);22 });23const XCUITestDriver = require('appium-xcuitest-driver');24const B = XCUITestDriver.helpers;25const fs = require('fs');26const readFileAsync = B.promisify(fs.readFile);27readFileAsync('some_file.txt', 'utf8')28 .then((content) => {29 console.log(content);30 })31 .catch((err) => {32 console.log(err);33 });34const XCUITestDriver = require('appium-xcuitest-driver');35const B = XCUITestDriver.helpers;36const fs = require('fs');37const readFileAsync = B.promisify(fs.readFile);38readFileAsync('some_file.txt', 'utf8')39 .then((content) => {40 console.log(content);41 })42 .catch((err) => {43 console.log(err);44 });45const XCUITestDriver = require('appium-xcuitest-driver');
Using AI Code Generation
1const B = require('bluebird');2const XCUITestDriver = require('appium-xcuitest-driver');3const XCUITest = new XCUITestDriver();4const B = require('bluebird');5const XCUITestDriver = require('appium-xcuitest-driver');6const XCUITest = new XCUITestDriver();7const B = require('bluebird');8const XCUITestDriver = require('appium-xcuitest-driver');9const XCUITest = new XCUITestDriver();10const B = require('bluebird');11const XCUITestDriver = require('appium-xcuitest-driver');12const XCUITest = new XCUITestDriver();13const B = require('bluebird');14const XCUITestDriver = require('appium-xcuitest-driver');15const XCUITest = new XCUITestDriver();16const B = require('bluebird');17const XCUITestDriver = require('appium-xcuitest-driver');18const XCUITest = new XCUITestDriver();19const B = require('bluebird');20const XCUITestDriver = require('appium-xcuitest-driver');21const XCUITest = new XCUITestDriver();22const B = require('bluebird');23const XCUITestDriver = require('appium-xcuitest-driver');24const XCUITest = new XCUITestDriver();25const B = require('bluebird');26const XCUITestDriver = require('appium-xcuitest-driver');27const XCUITest = new XCUITestDriver();
Using AI Code Generation
1const B = require('bluebird');2const { XCUITestDriver } = require('appium-xcuitest-driver');3const driver = new XCUITestDriver();4const promisified = B.promisify(driver.createSession);5const createSession = async () => {6const caps = {7};8try {9const session = await promisified(caps);10console.log('Session created with id: ' + session);11} catch (err) {12console.error(err);13}14};15createSession();16at B (node_modules/bluebird/js/release/util.js:16:23)17at Promise._settlePromiseFromHandler (node_modules/bluebird/js/release/promise.js:512:31)18at Promise._settlePromise (node_modules/bluebird/js/release/promise.js:569:18)19at Promise._settlePromise0 (node_modules/bluebird/js/release/promise.js:614:10)20at Promise._settlePromises (node_modules/bluebird/js/release/promise.js:693:18)21at _drainQueueStep (node_modules/bluebird/js/release/async.js:138:12)22at _drainQueue (node_modules/bluebird/js/release/async.js:131:9)23at Async._drainQueues (node_modules/bluebird/js/release/async.js:147:5)24at Immediate.Async.drainQueues [as _onImmediate] (node_modules/bluebird/js/release/async.js:17:14)25at runCallback (timers.js:810:20)26const { XCUITestDriver } = require('appium-xcuitest-driver');27const driver = new XCUITestDriver();28const caps = {29};30const createSession = async () => {31try {32const session = await driver.createSession(caps);33console.log('Session created
Using AI Code Generation
1const B = require('bluebird');2const { exec } = require('child_process');3const execAsync = B.promisify(exec);4execAsync('ls')5 .then((stdout) => {6 console.log(stdout);7 })8 .catch((err) => {9 console.log(err);10 });11const B = require('bluebird');12const { exec } = require('child_process');13B.promisifyAll(exec);14execAsync('ls')15 .then((stdout) => {16 console.log(stdout);17 })18 .catch((err) => {19 console.log(err);20 });21const B = require('bluebird');22const { exec } = require('child_process');23B.promisifyAll(exec);24execAsync('ls')25 .then((stdout) => {26 console.log(stdout);27 })28 .catch((err) => {29 console.log(err);30 });31const B = require('bluebird');32const { exec } = require('child_process');33B.promisifyAll(exec);34execAsync('ls')35 .then((stdout) => {36 console.log(stdout);37 })38 .catch((err) => {39 console.log(err);40 });41const B = require('bluebird');42const { exec } = require('child_process');43B.promisifyAll(exec);44execAsync('ls')45 .then((stdout) => {46 console.log(stdout);47 })48 .catch((err) => {49 console.log(err);50 });51const B = require('bluebird');52const { exec } = require('child_process');53B.promisifyAll(exec);54execAsync('ls')55 .then((stdout) => {56 console.log(stdout);57 })58 .catch((err) => {59 console.log(err);60 });61const B = require('bluebird');62const { exec } = require('child_process');63B.promisifyAll(exec);64execAsync('ls')65 .then((
Using AI Code Generation
1const B = require('bluebird');2const { exec } = require('child_process');3const { promisify } = require('util');4const execAsync = promisify(exec);5const execAsync = B.promisify(exec);6B.promisifyAll(exec);7B.promisifyAll(exec);8B.promisifyAll(exec);9B.promisifyAll(exec);10B.promisifyAll(exec);11B.promisifyAll(exec);12B.promisifyAll(exec);13B.promisifyAll(exec);14B.promisifyAll(exec);15B.promisifyAll(exec);16B.promisifyAll(exec);17B.promisifyAll(exec);18B.promisifyAll(exec);19B.promisifyAll(exec);20B.promisifyAll(exec);21B.promisifyAll(exec);22B.promisifyAll(exec);23B.promisifyAll(exec);24B.promisifyAll(exec);25B.promisifyAll(exec);
Using AI Code Generation
1const B = require('bluebird');2const fs = require('fs');3const read = B.promisify(fs.readFile);4read('test.js', 'utf8')5 .then((data) => console.log(data));6const B = require('bluebird');7const fs = require('fs');8const read = B.promisify(fs.readFile);9read('test.js', 'utf8')10 .then((data) => console.log(data));11const B = require('bluebird');12const fs = require('fs');13const read = B.promisify(fs.readFile);14read('test.js', 'utf8')15 .then((data) => console.log(data));16const B = require('bluebird');17const fs = require('fs');18const read = B.promisify(fs.readFile);19read('test.js', 'utf8')20 .then((data) => console.log(data));21const B = require('bluebird');22const fs = require('fs');23const read = B.promisify(fs.readFile);24read('test.js', 'utf8')25 .then((data) => console.log(data));26const B = require('bluebird');27const fs = require('fs');28const read = B.promisify(fs.readFile);29read('test.js', 'utf8')30 .then((data) => console.log(data));31const B = require('bluebird');32const fs = require('fs');33const read = B.promisify(fs.readFile);34read('test.js', '
Using AI Code Generation
1const B = require('bluebird');2const fs = require('fs');3var readFile = B.promisify(fs.readFile);4readFile('test.txt', 'utf8')5 .then(function (data) {6 console.log(data);7 })8 .catch(function (err) {9 console.log(err);10 });11var test = 'This is a test file.';12fs.writeFile('test.txt', test, function (err) {13 if (err) throw err;14 console.log('Saved!');15});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!