Skip to content

Commit

Permalink
switch to node native test
Browse files Browse the repository at this point in the history
  • Loading branch information
kane50613 committed Mar 7, 2024
1 parent 3dbe170 commit 581e14c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Connect to your Redis server using cloudflare:sockets",
"scripts": {
"build": "tsup",
"test": "vitest"
"test": "tsx --test"
},
"main": "dist/index.mjs",
"files": [
Expand Down Expand Up @@ -41,6 +41,7 @@
"prettier": "^3.2.5",
"prettier-plugin-organize-imports": "^3.2.4",
"tsup": "^8.0.2",
"tsx": "^4.7.1",
"typescript": "^5.3.3",
"vitest": "^1.3.1"
},
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions test/create-redis.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { connect } from "@arrowood.dev/socket";
import { expect, test } from "vitest";
import { deepEqual, equal } from "node:assert";
import { test } from "node:test";
import { createRedis } from "../src";

test("create-redis", async () => {
Expand All @@ -8,19 +9,17 @@ test("create-redis", async () => {
connectFn: connect,
});

expect(redis).toBeDefined();

const encoder = new TextEncoder();

const PONG = encoder.encode("PONG");

expect(await redis.raw("PING")).toEqual(PONG);
deepEqual(await redis.raw("PING"), PONG);

expect(await redis("SET", "foo", "bar")).toBe("OK");
equal(await redis("SET", "foo", "bar"), "OK");

expect(await redis("GET", "foo")).toBe("bar");
equal(await redis("GET", "foo"), "bar");

expect(await redis("DEL", "foo")).toBe(1);
equal(await redis("DEL", "foo"), 1);

expect(await redis("GET", "foo")).toBe(null);
equal(await redis("GET", "foo"), null);
});
5 changes: 3 additions & 2 deletions test/encode-command.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { expect, test } from "vitest";
import { deepEqual } from "node:assert";
import { test } from "node:test";
import { encodeCommand } from "../src/encode-command";

test("encode-command", async () => {
expect(encodeCommand(["SET", "key", "value"])).toEqual([
deepEqual(encodeCommand(["SET", "key", "value"]), [
"*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n",
]);
});
7 changes: 4 additions & 3 deletions test/get-connect-fn.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Socket } from "@arrowood.dev/socket";
import { expect, test } from "vitest";
import { doesNotReject, equal } from "node:assert";
import { test } from "node:test";
import { getConnectFn } from "../src";

test("get-connect-fn", async () => {
expect(await getConnectFn()).toBeDefined();
await doesNotReject(getConnectFn);

const fn = () => {
return new Socket({
Expand All @@ -12,5 +13,5 @@ test("get-connect-fn", async () => {
});
};

expect(await getConnectFn(fn)).toBe(fn);
equal(await getConnectFn(fn), fn);
});

0 comments on commit 581e14c

Please sign in to comment.