Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8691

【Node.js】Firebaseでエミュレーターを使ってjestのCIをGithub Actionsで

$
0
0

もうエミュレーターでテストすればいいんじゃないか説。

package.json
"scripts":{"jest":"jest","test":"firebase emulators:exec --only functions,firestore \"npm run jest --exit\"",}

別のFirebaseプロジェクトを用意する必要もないし、sinonでFirebaseAdminのモックとかも作る必要ないから楽。

Github Actions

jobs:
  ci:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [ubuntu-latest]
        node: [12]

    steps:
      - name: Checkout 🛎
        uses: actions/checkout@master

      - name: Setup node env 🏗
        uses: actions/setup-node@v2.1.2
        with:
          node-version: ${{ matrix.node }}

      - name: Cache node_modules 📦
        uses: actions/cache@v2
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - name: Install dependencies 👨🏻‍💻
        run: |
          npm install -g firebase-tools
          npm ci

      - name: Firebase runtime config 🔥
        uses: w9jds/firebase-action@master
        with:
          args: functions:config:get > .runtimeconfig.json
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
          PROJECT_ID: "default"

      - name: Run linter 👀
        run: |
          npm run lint
          npm run test

functions.config()を使ってる場合は、firebase-actionsを使って.runtimeconfig.jsonに吐き出す。
また、エミュレーターの起動はfirebase-actionsを使わないのでnpm install -g firebase-toolsを忘れずに。


Viewing all articles
Browse latest Browse all 8691

Trending Articles