Skip to content

Commit 67c6584

Browse files
committed
chore(test): add unit tests for router and messageSchema()
1 parent 3c3c426 commit 67c6584

File tree

6 files changed

+554
-8
lines changed

6 files changed

+554
-8
lines changed

.github/workflows/main.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# GitHub Actions workflow
2+
# https://help.github.com/actions
3+
4+
name: CI/CD
5+
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
branches: [main]
11+
release:
12+
types: [published]
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
bun-version: [latest, canary]
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Bun
25+
uses: oven-sh/setup-bun@v2
26+
with:
27+
bun-version: ${{ matrix.bun-version }}
28+
29+
- name: Install dependencies
30+
run: bun install
31+
32+
- name: Run tests
33+
run: bun test
34+
35+
- name: Check types
36+
run: bun run tsc --noEmit
37+
38+
lint:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v4
43+
44+
- name: Setup Bun
45+
uses: oven-sh/setup-bun@v2
46+
47+
- name: Install dependencies
48+
run: bun install
49+
50+
- name: Run lint checks
51+
run: bun run tsc --noEmit
52+
53+
# publish:
54+
# needs: [test, lint]
55+
# if: github.event_name == 'release' && github.event.action == 'published'
56+
# runs-on: ubuntu-latest
57+
# steps:
58+
# - name: Checkout repository
59+
# uses: actions/checkout@v4
60+
61+
# - name: Setup Bun
62+
# uses: oven-sh/setup-bun@v2
63+
64+
# - name: Install dependencies
65+
# run: bun install
66+
67+
# - name: Publish to npm
68+
# run: npm publish
69+
# env:
70+
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { WebSocketRouter } from "../router";
2-
import { JoinRoomSchema, UserJoinedSchema } from "./schema";
2+
import { JoinRoom, UserJoined } from "./schema";
33

44
const ws = new WebSocketRouter();
55

6-
ws.onMessage(JoinRoomSchema, (c) => {
6+
ws.onMessage(JoinRoom, (c) => {
77
const { roomId } = c.payload;
88
console.log(`User joined room: ${roomId}`);
99

10-
c.send(UserJoinedSchema, {
10+
c.send(UserJoined, {
1111
roomId,
1212
userId: c.meta.clientId,
1313
});
@@ -17,4 +17,4 @@ ws.onClose((c) => {
1717
console.log(`Connection closed`);
1818
});
1919

20-
export { ws as exampleRouter };
20+
export { ws as chatRouter };

example/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Hono } from "hono";
22
import { WebSocketRouter } from "../index";
3-
import { exampleRouter } from "./example";
3+
import { chatRouter } from "./chat";
44

55
// HTTP router
66
const app = new Hono();
77
app.get("/", (c) => c.text("Welcome to Hono!"));
88

99
// WebSocket router
1010
const ws = new WebSocketRouter();
11-
ws.addRoutes(exampleRouter);
11+
ws.addRoutes(chatRouter);
1212

1313
Bun.serve({
1414
port: 3000,

example/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { z } from "zod";
22
import { MessageSchema } from "../schema";
33

4-
export const JoinRoomSchema = MessageSchema.extend({
4+
export const JoinRoom = MessageSchema.extend({
55
type: z.literal("JOIN_ROOM"),
66
payload: z.object({
77
roomId: z.string(),
88
}),
99
});
1010

11-
export const UserJoinedSchema = MessageSchema.extend({
11+
export const UserJoined = MessageSchema.extend({
1212
type: z.literal("USER_JOINED"),
1313
payload: z.object({
1414
roomId: z.string(),

0 commit comments

Comments
 (0)