-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add testing capabilities for Firebase functions #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Updated package.json to include vitest and supertest for testing. - Created a GitHub Actions workflow for running tests on push and pull request events. - Added a sample test for the helloWorld function to verify it returns a 200 status code and the expected response.
WalkthroughFirebase Functions にテスト基盤を追加。functions 配下に Vitest/Supertest を導入し、helloWorld のテストを新規作成。Firebase Functions 用の GitHub Actions ワークフローを新規追加。既存の GitHub Apps 用ワークフローはパスフィルタや Node マトリクス対応に更新。 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Developer
participant GH as GitHub
participant CI as Actions Runner
participant Job as "Workflow Job (matrix: Node 20/22)"
participant NPM as npm
participant VT as Vitest
participant Fn as helloWorld (Express)
Dev->>GH: Push / Pull Request (paths filtered)
GH-->>CI: Trigger workflow (firebase-functions-tests.yml)
CI->>Job: Start job in openci-runner/firebase/functions
Job->>NPM: npm ci
Job->>NPM: npm test
NPM->>VT: Run tests
VT->>Fn: Supertest GET /
Fn-->>VT: 200 "Hello from Firebase!"
VT-->>Job: Report test results
Job-->>GH: Status (success/failure)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (2)
🧰 Additional context used🧠 Learnings (1)📓 Common learnings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (9)
.github/workflows/firebase-functions-test.yml (4)
20-23
: Node バージョンのマトリクス化+npm キャッシュを有効化Node 22 固定だと将来の互換性/実行環境差異でCIがブレます。Node 20/LTS も並行で回し、依存キャッシュで速度も確保しましょう。
- name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: "22" + node-version: ${{ matrix.node-version }} + cache: npm + cache-dependency-path: openci-runner/firebase/functions/package-lock.json
11-15
: Node マトリクスの導入上記の node-version 置換に合わせてマトリクスを追加してください。
test: runs-on: ubuntu-latest + strategy: + matrix: + node-version: [20, 22] defaults: run: working-directory: openci-runner/firebase/functions
11-11
: ワークフロー権限の最小化読み取りのみで十分です。明示指定でセキュリティ姿勢を強化できます。
test: runs-on: ubuntu-latest + permissions: + contents: read
3-7
: 不要実行の抑制(paths フィルタ)対象ディレクトリに変更がない場合は走らないようにできます。CIコスト削減に有効です。
on: push: - branches: [main, develop] + branches: [main, develop] + paths: + - 'openci-runner/firebase/functions/**' + - '.github/workflows/firebase-functions-test.yml' pull_request: - branches: [main, develop] + branches: [main, develop] + paths: + - 'openci-runner/firebase/functions/**' + - '.github/workflows/firebase-functions-test.yml'openci-runner/firebase/functions/test/hello-world.test.ts (3)
12-13
: any の排除と Biome 抑止コメントの解消型を付ければ
biome-ignore
は不要です。テストの可読性も上がります。-import express from "express"; +import express, { type Request, type Response } from "express"; @@ -// biome-ignore lint/suspicious/noExplicitAny: <explanation> -let helloWorld: (req: any, res: any) => unknown; +let helloWorld: (req: Request, res: Response) => unknown;
5-10
: firebase-functions/params の部分モック化将来
params
の他の export を使った際の破壊的影響を避けるため、実体を取り込みつつdefineSecret
のみ差し替える形が堅牢です。-vi.mock("firebase-functions/params", () => ({ - defineSecret: (name: string) => ({ - name, - value: () => JSON.stringify({ projectId: "demo-project" }), - }), -})); +vi.mock("firebase-functions/params", async () => { + const actual = await vi.importActual<typeof import("firebase-functions/params")>( + "firebase-functions/params", + ); + return { + ...actual, + defineSecret: (name: string) => ({ + name, + value: () => JSON.stringify({ projectId: "demo-project" }), + }), + }; +});
21-28
: ルーティングの記述を簡潔に挙動は同じですが
app.use(helloWorld)
の方が意図が明確です。- const app = express(); - app.all("*", (req, res) => helloWorld(req, res)); + const app = express(); + app.use((req, res) => helloWorld(req, res));openci-runner/firebase/functions/package.json (2)
21-27
: テスト実行の直接依存として express を明示追加
express
を直接 import しているため、ホイストに依存せず devDependencies に追加してください。型も合わせて入れると前述の any 排除が可能です。"devDependencies": { + "@types/express": "^4.17.21", "@types/supertest": "^6.0.3", "firebase-functions-test": "^3.1.0", + "express": "^4.19.2", "supertest": "^7.0.0", - "typescript": "^4.9.0", + "typescript": "^5.4.0", "vitest": "^1.6.0" },
typescript@^5.4.0
は一例です。現行のvitest
・firebase-functions@^6
との互換最新安定バージョンをご確認のうえ調整してください。
21-27
: firebase-functions-test が未使用のようです
リポジトリ全体を検索したところ、テストコード内に該当パッケージの参照が見つかりませんでした(package.json
とpackage-lock.json
のみ)。将来利用予定がなければ、devDependencies
から削除してインストール時間を短縮することを検討してください。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
openci-runner/firebase/functions/package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (3)
.github/workflows/firebase-functions-test.yml
(1 hunks)openci-runner/firebase/functions/package.json
(2 hunks)openci-runner/firebase/functions/test/hello-world.test.ts
(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: open-ci-io/openci#0
File: AGENTS.md:0-0
Timestamp: 2025-09-27T13:05:21.009Z
Learning: Applies to github-apps/test/**/*.test.{ts,tsx} : Webhook ハンドラに対する Vitest スイートを実行する
Learnt from: CR
PR: open-ci-io/openci#0
File: AGENTS.md:0-0
Timestamp: 2025-09-27T13:05:21.009Z
Learning: Applies to github-apps/test/**/*.test.{ts,tsx} : Vitest のテストスイートは github-apps/test/ に配置する
📚 Learning: 2025-09-27T13:05:21.009Z
Learnt from: CR
PR: open-ci-io/openci#0
File: AGENTS.md:0-0
Timestamp: 2025-09-27T13:05:21.009Z
Learning: Applies to github-apps/test/**/*.test.{ts,tsx} : Webhook ハンドラに対する Vitest スイートを実行する
Applied to files:
openci-runner/firebase/functions/test/hello-world.test.ts
🧬 Code graph analysis (1)
openci-runner/firebase/functions/test/hello-world.test.ts (1)
openci-runner/firebase/functions/src/index.ts (1)
helloWorld
(7-15)
🔇 Additional comments (3)
openci-runner/firebase/functions/package.json (1)
14-15
: engines.node=22 のままで問題ありません
Node.js 22 は Cloud Functions (2nd gen/Cloud Run functions) および Firebase Functions で正式サポートされているため、"node": "22"
のままデプロイして問題ありません。 (cloud.google.com).github/workflows/firebase-functions-test.yml (2)
24-28
: lockfileの存在を確認しました openci-runner/firebase/functions/package-lock.json がリポジトリ内に存在するため、npm ci は正常に実行されます。
20-23
: Firebase Functions (第2世代) で Node.js 22 はサポート済み
Firebase Functions (第2世代) は Node.js 22 をサポートしています。プレビューは 2024年5月17日、GA は 2024年11月18日に提供開始され、公式ドキュメントにも Node.js 22 がリストされています (cloud.google.com)
Summary by CodeRabbit
テスト
チョア