From 173554d526cccc987412a411d576112ebb016d3c Mon Sep 17 00:00:00 2001 From: mmkal Date: Sun, 31 May 2020 07:32:10 -0400 Subject: [PATCH 1/3] failing test for redis-mock --- package.json | 1 + test/basic-usage.test.ts | 8 ++++++++ yarn.lock | 41 +++++++--------------------------------- 3 files changed, 16 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index 5799f85a..7481dbb9 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ "npm-run-all": "^4.1.5", "prettier": "^1.14.2", "redis-commands": "^1.5.0", + "redis-mock": "^0.49.0", "semantic-release": "^15.13.16", "shelljs": "^0.8.3", "shx": "^0.3.2", diff --git a/test/basic-usage.test.ts b/test/basic-usage.test.ts index 74ac97f6..fd58d74b 100644 --- a/test/basic-usage.test.ts +++ b/test/basic-usage.test.ts @@ -1,5 +1,6 @@ import { createHandyClient } from "../src"; import { createClient, Multi } from "redis"; +import * as redisMock from "redis-mock"; it("creates client", async () => { const client = createHandyClient(); @@ -79,3 +80,10 @@ it("set with expiry", async () => { expect(ttl).toBeLessThanOrEqual(60); expect(ttl).toBeGreaterThan(55); // hopefully it didn't take over 5s to run a command... }); + +it("works with redis-mock", async () => { + const mockClient = redisMock.createClient(); + const client = createHandyClient(mockClient); + + expect(client.redis).toBe(mockClient); +}); diff --git a/yarn.lock b/yarn.lock index 79e5e7ca..0cc2173f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1910,7 +1910,7 @@ debug@^3.1.0: dependencies: ms "^2.1.1" -debuglog@*, debuglog@^1.0.1: +debuglog@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492" integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI= @@ -3010,7 +3010,7 @@ import-local@^3.0.2: pkg-dir "^4.2.0" resolve-cwd "^3.0.0" -imurmurhash@*, imurmurhash@^0.1.4: +imurmurhash@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" integrity sha1-khi5srkoojixPcT7a21XbyMUU+o= @@ -4191,11 +4191,6 @@ lockfile@^1.0.4: dependencies: signal-exit "^3.0.2" -lodash._baseindexof@*: - version "3.1.0" - resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c" - integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw= - lodash._baseuniq@~4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8" @@ -4204,33 +4199,11 @@ lodash._baseuniq@~4.6.0: lodash._createset "~4.0.0" lodash._root "~3.0.0" -lodash._bindcallback@*: - version "3.0.1" - resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e" - integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4= - -lodash._cacheindexof@*: - version "3.0.2" - resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92" - integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI= - -lodash._createcache@*: - version "3.1.2" - resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093" - integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM= - dependencies: - lodash._getnative "^3.0.0" - lodash._createset@~4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26" integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY= -lodash._getnative@*, lodash._getnative@^3.0.0: - version "3.9.1" - resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" - integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U= - lodash._root@~3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692" @@ -4276,11 +4249,6 @@ lodash.memoize@4.x: resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe" integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4= -lodash.restparam@*: - version "3.6.1" - resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" - integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU= - lodash.set@^4.3.2: version "4.3.2" resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23" @@ -5886,6 +5854,11 @@ redis-errors@^1.0.0, redis-errors@^1.2.0: resolved "https://registry.yarnpkg.com/redis-errors/-/redis-errors-1.2.0.tgz#eb62d2adb15e4eaf4610c04afe1529384250abad" integrity sha1-62LSrbFeTq9GEMBK/hUpOEJQq60= +redis-mock@^0.49.0: + version "0.49.0" + resolved "https://registry.yarnpkg.com/redis-mock/-/redis-mock-0.49.0.tgz#744c38dde3caae4c9ca70e2a674c4bb30eb607ca" + integrity sha512-FW/cLZvF1PAVN/PYIwXf1vQRoJCyYCwUMtq8BXRwrvb9LNNAT4RKXM02Qlt6qSkC/98hmHlU2EGoQoxVy3E2lA== + redis-parser@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/redis-parser/-/redis-parser-3.0.0.tgz#b66d828cdcafe6b4b8a428a7def4c6bcac31c8b4" From 0c8c990fd9b0ec2d1e2fc37443494474b6da59a6 Mon Sep 17 00:00:00 2001 From: mmkal Date: Sun, 31 May 2020 07:33:25 -0400 Subject: [PATCH 2/3] fix: use `scan` isntead of `scan` --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 95a25e2d..c314099c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,7 @@ export interface ICreateHandyClient { } export const createHandyClient: ICreateHandyClient = (...clientArgs: any[]) => { - const nodeRedis = (typeof clientArgs[0] === "object" && typeof clientArgs[0].zscan === "function") + const nodeRedis = (typeof clientArgs[0] === "object" && typeof clientArgs[0].scan === "function") ? clientArgs[0] : createClient.apply(null, clientArgs); From 0b105f88b2424ef4acd5b69b5d96745c3beadda6 Mon Sep 17 00:00:00 2001 From: mmkal Date: Sun, 31 May 2020 07:37:47 -0400 Subject: [PATCH 3/3] redis-mock types --- package.json | 1 + test/basic-usage.test.ts | 2 +- yarn.lock | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7481dbb9..4ca12951 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "@types/jest": "^24.0.18", "@types/lodash": "^4.14.120", "@types/node": "^12.12.37", + "@types/redis-mock": "^0.17.0", "@types/shelljs": "^0.8.5", "@types/yamljs": "^0.2.30", "check-clean": "^0.1.0", diff --git a/test/basic-usage.test.ts b/test/basic-usage.test.ts index fd58d74b..48cd906f 100644 --- a/test/basic-usage.test.ts +++ b/test/basic-usage.test.ts @@ -82,7 +82,7 @@ it("set with expiry", async () => { }); it("works with redis-mock", async () => { - const mockClient = redisMock.createClient(); + const mockClient: any = redisMock.createClient(); const client = createHandyClient(mockClient); expect(client.redis).toBe(mockClient); diff --git a/yarn.lock b/yarn.lock index 0cc2173f..e27dbb62 100644 --- a/yarn.lock +++ b/yarn.lock @@ -781,6 +781,20 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-1.19.1.tgz#33509849f8e679e4add158959fdb086440e9553f" integrity sha512-5qOlnZscTn4xxM5MeGXAMOsIOIKIbh9e85zJWfBRVPlRMEVawzoPhINYbRGkBZCI8LxvBe7tJCdWiarA99OZfQ== +"@types/redis-mock@^0.17.0": + version "0.17.0" + resolved "https://registry.yarnpkg.com/@types/redis-mock/-/redis-mock-0.17.0.tgz#13c56c8cf3f748ae1656efc2da9bd6a97cc38e4d" + integrity sha512-UDKHu9otOSE1fPjgn0H7UoggqVyuRYfo3WJpdXdVmzgGmr1XIM/dTk/gRYf/bLjIK5mxpV8inA5uNBS2sVOilA== + dependencies: + "@types/redis" "*" + +"@types/redis@*": + version "2.8.22" + resolved "https://registry.yarnpkg.com/@types/redis/-/redis-2.8.22.tgz#8935227cbe39080506b625276d64974ddbcb9ea4" + integrity sha512-O21YLcAtcSzax8wy4CfxMNjIMNf5X2c1pKTXDWLMa2p77Igvy7wuNjWVv+Db93wTvRvLLev6oq3IE7gxNKFZyg== + dependencies: + "@types/node" "*" + "@types/redis@^2.8.14": version "2.8.18" resolved "https://registry.yarnpkg.com/@types/redis/-/redis-2.8.18.tgz#6e95de50d848cd9c0aacb89aa8a6aef07a0a34b3"