Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test `functions.https.onCall` firebase cloud functions locally?

I can't seem to find the solution for this in the Firebase Documentation.

I want to test my functions.https.onCall functions locally. Is it possible using the shell or somehow connect my client (firebase SDK enabled) to the local server?

I want to avoid having to deploy every time just to test a change to my onCall functions.


My code

Function :

exports.myFunction = functions.https.onCall((data, context) => {   // Do something }); 

Client:

const message = { message: 'Hello.' };  firebase.functions().httpsCallable('myFunction')(message)   .then(result => {     // Do something //   })   .catch(error => {     // Error handler //   }); 
like image 906
czphilip Avatar asked Jun 16 '18 02:06

czphilip


People also ask

Can I test Cloud Functions locally?

Each Branch represents a Cloud Function. You can test or run this cloud function locally before. Once development is complete, this Cloud Function is deployed to the Google Cloud Function Service using the Google Cloud Build Service. Your development is thus directly connected to the provided function, so to speak.


1 Answers

For locally you must call (after firebase.initializeApp)

firebase.functions().useFunctionsEmulator('http://localhost:5000')  
like image 169
Petr Pololáník Avatar answered Sep 18 '22 23:09

Petr Pololáník