From 0420620f2faab09d5c280c5f03bcba9d6ca1b511 Mon Sep 17 00:00:00 2001 From: "oidon." <99778758+umaidashi@users.noreply.github.com> Date: Wed, 4 Jun 2025 21:05:28 +0900 Subject: [PATCH] Add CI workflow for DIContainer tests --- .github/workflows/hono_test.yaml | 28 ++++++++++++++++++++++++++++ server/hono/README.md | 8 ++++++++ server/hono/package.json | 3 ++- server/hono/src/di/container.test.ts | 26 ++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/hono_test.yaml create mode 100644 server/hono/src/di/container.test.ts diff --git a/.github/workflows/hono_test.yaml b/.github/workflows/hono_test.yaml new file mode 100644 index 0000000..b6a4e01 --- /dev/null +++ b/.github/workflows/hono_test.yaml @@ -0,0 +1,28 @@ +name: hono_test + +on: + push: + paths: + - 'server/hono/**' + - '.github/workflows/hono_test.yaml' + pull_request: + paths: + - 'server/hono/**' + - '.github/workflows/hono_test.yaml' + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Bun + uses: oven-sh/setup-bun@v1 + + - name: Install dependencies + run: bun install + + - name: Run tests + run: bun test + working-directory: server/hono diff --git a/server/hono/README.md b/server/hono/README.md index 71a553c..dc8db99 100644 --- a/server/hono/README.md +++ b/server/hono/README.md @@ -1 +1,9 @@ # Serve Blog Contents to View + +## Tests + +Run unit tests with: + +```bash +bun test +``` diff --git a/server/hono/package.json b/server/hono/package.json index 11f519e..c881753 100644 --- a/server/hono/package.json +++ b/server/hono/package.json @@ -5,7 +5,8 @@ "scripts": { "dev": "wrangler dev src/index.ts", "deploy": "wrangler deploy --minify src/index.ts", - "lint": "biome check --write ./" + "lint": "biome check --write ./", + "test": "bun test" }, "dependencies": { "@octokit/rest": "^21.0.0", diff --git a/server/hono/src/di/container.test.ts b/server/hono/src/di/container.test.ts new file mode 100644 index 0000000..5e0c274 --- /dev/null +++ b/server/hono/src/di/container.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, it } from "bun:test"; +import { DIContainer } from "./container"; + +class Foo { + constructor(public value: number) {} +} + +class Bar { + constructor(public value: string) {} +} + +describe("DIContainer", () => { + it("register stores an instance", () => { + const container = new DIContainer<{ foo: Foo }>(); + container.register("foo", Foo, 123); + const instance = container.get("foo"); + expect(instance).toBeInstanceOf(Foo); + expect(instance.value).toBe(123); + expect(container.get("foo")).toBe(instance); + }); + + it("get throws when dependency is not registered", () => { + const container = new DIContainer<{ bar: Bar }>(); + expect(() => container.get("bar")).toThrow(); + }); +});