How to use B.promisify method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

RedisClient.test.js

Source:RedisClient.test.js Github

copy

Full Screen

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']);...

Full Screen

Full Screen

RedisPromise.test.js

Source:RedisPromise.test.js Github

copy

Full Screen

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']);...

Full Screen

Full Screen

webext.js

Source:webext.js Github

copy

Full Screen

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 ...

Full Screen

Full Screen

promises.js

Source:promises.js Github

copy

Full Screen

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}...

Full Screen

Full Screen

awsFunctions.js

Source:awsFunctions.js Github

copy

Full Screen

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,...

Full Screen

Full Screen

promisify.js

Source:promisify.js Github

copy

Full Screen

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 };...

Full Screen

Full Screen

redis.js

Source:redis.js Github

copy

Full Screen

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}...

Full Screen

Full Screen

PromisifyRead.test.js

Source:PromisifyRead.test.js Github

copy

Full Screen

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 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const B = require('bluebird');2const { BaseDriver } = require('appium-base-driver');3const myFunc = function (a, b) {4 return a + b;5};6const myAsyncFunc = B.promisify(myFunc);7(async function () {8 const result = await myAsyncFunc(3, 4);9 console.log(result);10})();11const B = require('bluebird');12const { BaseDriver } = require('appium-base-driver');13const myFunc = function (a, b) {14 return a + b;15};16const myAsyncFunc = B.promisify(myFunc);17(async function () {18 const result = await myAsyncFunc(3, 4);19 console.log(result);20})();21[Appium] Welcome to Appium v1.6.5 (REV 7f9a9f2a7c1d2a5e5d5c5b2f5a5e5b9d9a9a9a9a)

Full Screen

Using AI Code Generation

copy

Full Screen

1const B = require('bluebird');2const wd = require('wd');3const driver = wd.promiseChainRemote(BASE_URL);4const startSession = B.promisify(driver.init.bind(driver));5const findElement = B.promisify(driver.elementById.bind(driver));6const clickElement = B.promisify(driver.click.bind(driver));7const quitSession = B.promisify(driver.quit.bind(driver));8startSession({9}).then(() => {10 return findElement('SomeElementId');11}).then((el) => {12 return clickElement(el);13}).then(() => {14 return quitSession();15}).catch((e) => {16 console.error(e);17});18const B = require('bluebird');19const wd = require('wd');20const driver = wd.promiseChainRemote(BASE_URL);21const startSession = B.promisify(driver.init.bind(driver));22const findElement = B.promisify(driver.elementById.bind(driver));23const clickElement = B.promisify(driver.click.bind(driver));24const quitSession = B.promisify(driver.quit.bind(driver));25startSession({26}).then(() => {27 return findElement('SomeElementId');28}).then((el) => {29 return clickElement(el);30}).then(() => {31 return quitSession();32}).catch((e) => {33 console.error(e);34});35const B = require('bluebird');36const wd = require('wd');37const driver = wd.promiseChainRemote(BASE_URL);38const startSession = B.promisify(driver.init.bind(driver));39const findElement = B.promisify(driver.elementById.bind(driver));40const clickElement = B.promisify(driver.click.bind(driver));

Full Screen

Using AI Code Generation

copy

Full Screen

1var B = require('bluebird');2var BaseDriver = require('appium-base-driver').BaseDriver;3var driver = new BaseDriver();4var doStuff = function (arg1, arg2) {5 console.log(arg1, arg2);6};7var doStuffAsync = B.promisify(doStuff);8doStuffAsync('foo', 'bar').then(function () {9 console.log('success');10}).catch(function () {11 console.log('failure');12});13var B = require('bluebird');14var BaseDriver = require('appium-base-driver').BaseDriver;15var driver = new BaseDriver();16var doStuff = function (arg1, arg2) {17 console.log(arg1, arg2);18};19var doStuffAsync = B.promisify(doStuff);20doStuffAsync('foo', 'bar').then(function () {21 console.log('success');22}).catch(function () {23 console.log('failure');24});25var B = require('bluebird');26var BaseDriver = require('appium-base-driver').BaseDriver;27var driver = new BaseDriver();28var doStuff = function (arg1, arg2) {29 console.log(arg1, arg2);30};31var doStuffAsync = B.promisify(doStuff);32doStuffAsync('foo', 'bar').then(function () {33 console.log('success');34}).catch(function () {35 console.log('failure');36});37var B = require('bluebird');38var BaseDriver = require('appium-base-driver').BaseDriver;39var driver = new BaseDriver();40var doStuff = function (arg1, arg2) {41 console.log(arg1, arg2);42};43var doStuffAsync = B.promisify(doStuff);44doStuffAsync('foo', 'bar').then(function () {45 console.log('success');46}).catch(function () {47 console.log('failure');48});

Full Screen

Using AI Code Generation

copy

Full Screen

1var B = require('bluebird');2var AppiumBaseDriver = require('appium-base-driver');3var getAppiumBaseDriver = function() {4 return AppiumBaseDriver;5}6var AppiumBaseDriver = getAppiumBaseDriver();7var myFunc = function(arg1, arg2, callback) {8 callback(null, arg1, arg2);9}10var myFuncAsync = B.promisify(myFunc);11myFuncAsync('arg1', 'arg2').then(function(arg1, arg2) {12 console.log(arg1, arg2);13})14var B = require('bluebird');15var AppiumBaseDriver = require('appium-base-driver');16var getAppiumBaseDriver = function() {17 return AppiumBaseDriver;18}19var AppiumBaseDriver = getAppiumBaseDriver();20var myFunc = function(arg1, arg2, callback) {21 callback(null, arg1, arg2);22}23var myFuncAsync = B.promisify(myFunc);24myFuncAsync('arg1', 'arg2').then(function(arg1, arg2) {25 console.log(arg1, arg2);26})27var B = require('bluebird');28var AppiumBaseDriver = require('appium-base-driver');29var getAppiumBaseDriver = function() {30 return AppiumBaseDriver;31}32var AppiumBaseDriver = getAppiumBaseDriver();33var myFunc = function(arg1, arg2, callback) {34 callback(null, arg1, arg2);35}36var myFuncAsync = B.promisify(myFunc);37myFuncAsync('arg1', 'arg2').then(function(arg1, arg2) {38 console.log(arg1, arg2);39})40var B = require('bluebird');41var AppiumBaseDriver = require('appium-base-driver');42var getAppiumBaseDriver = function() {43 return AppiumBaseDriver;44}45var AppiumBaseDriver = getAppiumBaseDriver();46var myFunc = function(arg1, arg2, callback) {47 callback(null, arg1, arg2);48}49var myFuncAsync = B.promisify(myFunc);50myFuncAsync('arg1', '

Full Screen

Using AI Code Generation

copy

Full Screen

1const B = require('bluebird');2const myMethod = function(a, b, callback) {3 callback(null, a+b);4};5const myAsyncMethod = B.promisify(myMethod);6myAsyncMethod(2, 3).then((res) => {7 console.log(res);8});9const B = require('bluebird');10const myMethod = function(a, b, callback) {11 callback(null, a+b);12};13const myAsyncMethod = B.promisify(myMethod);14myAsyncMethod(2, 3).then((res) => {15 console.log(res);16});17const B = require('bluebird');18const myMethod = function(a, b, callback) {19 callback(null, a+b);20};21const myAsyncMethod = B.promisify(myMethod);22myAsyncMethod(2, 3).then((res) => {23 console.log(res);24});25const B = require('bluebird');26const myMethod = function(a, b, callback) {27 callback(null, a+b);28};29const myAsyncMethod = B.promisify(myMethod);30myAsyncMethod(2, 3).then((res) => {31 console.log(res);32});33const B = require('bluebird');34const myMethod = function(a, b, callback) {35 callback(null, a+b);36};37const myAsyncMethod = B.promisify(myMethod);38myAsyncMethod(2, 3).then((res) => {39 console.log(res);40});41const B = require('bluebird');42const myMethod = function(a, b, callback) {43 callback(null, a+b);44};45const myAsyncMethod = B.promisify(myMethod);46myAsyncMethod(2, 3).then((res) => {47 console.log(res);48});49const B = require('bluebird');50const myMethod = function(a, b, callback) {51 callback(null, a+b);52};53const myAsyncMethod = B.promisify(myMethod);54myAsyncMethod(2, 3).then((res) => {

Full Screen

Using AI Code Generation

copy

Full Screen

1var B = require('bluebird');2var fs = B.promisifyAll(require('fs'));3var path = require('path');4var driver = require('./lib/driver');5var Driver = driver.Driver;6var _ = require('lodash');7var logger = require('./lib/logger');8var log = logger.get('Appium');9var parser = require('appium-support').argv;10var _ = require('lodash');

Full Screen

Using AI Code Generation

copy

Full Screen

1import BaseDriver from 'appium-base-driver';2import wd from 'wd';3let driver = wd.promiseChainRemote();4let baseDriver = new BaseDriver();5let promisifiedDriver = baseDriver.promisifyDriver(driver);6promisifiedDriver.init({browserName: 'chrome'})7 .then(() => {8 });9import BaseDriver from 'appium-base-driver';10import wd from 'wd';11let driver = wd.promiseChainRemote();12let baseDriver = new BaseDriver();13let promisifiedDriver = baseDriver.promisifyDriver(driver);14promisifiedDriver.init({browserName: 'chrome'})15 .then(() => {16 });17import BaseDriver from 'appium-base-driver';18import wd from 'wd';19let driver = wd.promiseChainRemote();20let baseDriver = new BaseDriver();21let promisifiedDriver = baseDriver.promisifyDriver(driver);22promisifiedDriver.init({browserName: 'chrome'})23 .then(() => {24 });25import BaseDriver from 'appium-base-driver';26import wd from 'wd';27let driver = wd.promiseChainRemote();

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Base Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful