Is it possible to test a Firebase trigger locally?

Using firebase-functions with Node and = functions.database.ref('/object').onWrite(event => {});.

I can deploy to the cloud and test just fine … and I can easily test http-type functions locally using firebase serve --only functions.

However, I don’t see a way to test triggers locally. Is it possible? How?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

This in now possible. I finally find this clear medium post which explain how do it :

To run a trigger locally, use the “functions shell” tool :

1 – My code for firestore (the medium post use RealTime Database) :

exports.testTrigger = functions.firestore
.onCreate((snapshot, context) => {
    let message =
    return snapshot.ref.set({
        status : 'sent' 

2 – I run the firebase shell functions in the terminal

firebase functions:shell

3 – I call my “testTrigger” cloud function trigger with data in parameter


4- My firestore database has a new “message” updated by my trigger

Solution 2

Very recently, the Firebase team published an update to the Firebase CLI the added the ability to invoke other types of triggers locally. It’s documented here. Be sure you’ve updated your CLI to the latest version to get this new functionality: npm install -g [email protected]

Solution 3

Doug answered it in the comment. While invoking a trigger is probably useful in some cases (thanks Doug), it isn’t the same as a deployed trigger, which can’t be done yet.

So I’ll stick with deploying remotely and watching the remote log … good ‘ole Marco Polo debugging.

Solution 4

Since May 21st 2020 it’s now possible to test triggers locally!

See release blog post

Always good to also take a look at the release notes

And note that 8.4 requires Node 10, as discussed in question Update of Firebase CLI to 8.4.0 gives errors about "Unsupported engine" saying '{"node":">=10"}'

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply