diff --git a/test/functional/scan_stream.ts b/test/functional/scan_stream.ts index c190d66b..478c64b5 100644 --- a/test/functional/scan_stream.ts +++ b/test/functional/scan_stream.ts @@ -3,6 +3,7 @@ import { expect } from "chai"; import { Readable } from "stream"; import * as sinon from "sinon"; import MockServer from "../helpers/mock_server"; +import { getRedisVersion } from "../helpers/util"; import { Cluster } from "../../lib"; describe("*scanStream", function () { @@ -77,9 +78,13 @@ describe("*scanStream", function () { ); }); - it("should recognize `TYPE`", function (done) { + it("should recognize `TYPE`", async function () { let keys = []; const redis = new Redis(); + const [major] = await getRedisVersion(redis); + if (major < 6) { + return; + } redis.set("foo1", "bar"); redis.set("foo2", "bar"); redis.set("foo3", "bar"); @@ -92,10 +97,12 @@ describe("*scanStream", function () { stream.on("data", function (data) { keys = keys.concat(data); }); - stream.on("end", function () { - expect(keys.sort()).to.eql(["loo1", "loo2", "loo3"]); - redis.disconnect(); - done(); + return new Promise((resolve) => { + stream.on("end", function () { + expect(keys.sort()).to.eql(["loo1", "loo2", "loo3"]); + redis.disconnect(); + resolve(); + }); }); }); diff --git a/test/helpers/util.ts b/test/helpers/util.ts new file mode 100644 index 00000000..56907099 --- /dev/null +++ b/test/helpers/util.ts @@ -0,0 +1,12 @@ +const VERSION_REGEX = /\bredis_version:(\d+)\.(\d+)\.(\d+)/; + +export async function getRedisVersion(redis: Redis) { + const raw = await redis.info("server"); + const match = VERSION_REGEX.exec(raw); + if (match) { + return [match[1], match[2], match[3]]; + } + throw new Error( + "Could not determine redis version from: " + JSON.stringify(raw) + ); +}