はじめに
firebase functionをローカル環境でテストする方法を説明します。
環境/前提
Node.jsで既にfunctionが作成されていること。
functionがonCall()で作成されていること。
手順
Firebase CLI をインストールする
npm install -g firebase-tools
ローカル環境のfunctionを利用するように設定する。
コード上のfunctionを利用している箇所に、下記の設定を追記します。
xx.ts
//追記箇所
firebase.functions().useFunctionsEmulator("http://localhost:[port番号]");
//function利用箇所
const function = firebase.functions().httpsCallable('[function名]');
function();
エミュレータを実行する
firebase emulators:start
以上の手順で、firebase functionをローカル環境でテストすることができます。
参考