0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[GitHub Actions]firebase emulatorを用いた自動テスト

Posted at

最近firebaseを使ってアプリを作ることが多くあります。
ちょくちょくテストコードを書いていたので、せっかくなら自動テストしたいと思いgithub actions上でci作った忘備録です。

前提

PR出したときにfirebase emulatorでテストを走らせる。
ついでに静的解析もやる。

まずpackage.jsonにlinterとテストコードのscriptsを作る。
今回はfunctionsとfirestoreを動かしながらjestでテストする。

--projectはfirebaseのprojectを指定

package.json
{
  "scripts": {
    "format": "prettier -c './**/*.{○○,△△}'",
    "lint": "eslint --ext .○○,△△ .",
    "test": "firebase emulators:exec --project=○○ 'jest' --only functions,firestore"
  }
}

workflow

firebase操作できるツールあるかなと思ったけどなかったのでglobalにfirebase-toolsを直でインストールして動かす。(deploy系はあった。)

ルートディレクトリで実行しない場合はworking-directoryを指定する必要がある。
cd functions && ...でも可

pull_request.yml
name: static analysis and  test
'on':
  pull_request:
    paths: #functions/が変わった時のみ動かす
      - 'functions/**'
jobs:
  test:
    if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v2
        with:
          node-version: '16'
      - name: install firebase-tools
        run: npm install -g firebase-tools
      - name: install node_modules
        run: npm ci
      - name: linter
        run: |
          npm run format
          npm run lint
        working-directory: ./functions
      - name: test
        run: npm run test
        working-directory: ./functions
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?