node.js - 是否可以在本地测试 Firebase 触发器?

标签 node.js firebase firebase-realtime-database google-cloud-functions

在 Node 和 exports.foo = functions.database.ref('/object').onWrite(event => {}); 中使用 firebase-functions

我可以部署到云端并进行测试......而且我可以使用 firebase serve --only functions 在本地轻松测试 http 类型的函数。

但是,我没有看到在本地测试触发器 的方法。是否可以?怎么办?

最佳答案

这在现在成为可能。我终于找到了这篇解释如何操作的清晰的中篇文章:https://medium.com/@moki298/test-your-firebase-cloud-functions-locally-using-cloud-functions-shell-32c821f8a5ce

要在本地运行触发器,请使用“functions shell”工具:

1 - 我的 firestore 代码(使用实时数据库的中型帖子):

exports.testTrigger = functions.firestore
.document('messages/{messageId}')
.onCreate((snapshot, context) => {
    let message = snapshot.data()
    return snapshot.ref.set({
        ...message,
        status : 'sent' 
    })
})

2 - 我在终端中运行 firebase shell 函数

firebase functions:shell

3 - 我用参数中的数据调用我的“testTrigger”云函数触发器

testTrigger({text:"hello"})

4- 我的 firestore 数据库有一条由我的触发器更新的新“消息”

关于node.js - 是否可以在本地测试 Firebase 触发器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46614685/

相关文章:

node.js - nodejs的napi模块没有 self 注册

javascript - 在 Cocoa/OSX 应用程序中打包 node.js

node.js - Node 服务器地理位置

android - Firebase 云消息在后台崩溃

javascript - 从文档引用数组中获取 firestore 文档

firebase - 世博会和 react 本地火力场

android - Firebase android分页

node.js - Redis 发布/订阅限制

java - 检查firebase实时数据库中的数据不起作用

java - Firebase 检索时无法弹回输入