【发布时间】:2021-01-12 03:53:41
【问题描述】:
Firebase Functions 有几种测试方法——一种是运行 firebase functions:shell 并手动提供对象。这对于简单的事情很好,但我想传入一个数据文件或一个测试文件,ala firebase functions:shell < test.js 来自这个旧的blog post
由于不熟悉将 node 用作 REPL 或本博文中提到的特殊命令,因此我无法正常工作。
我有一个简化的触发器,看起来像:
export const onCreateUser = functions.firestore
.document("/users/{id}")
.onCreate(async snapshot => {
console.log("starting...");
const data = snapshot.data() as UserDocumentData;
console.log(data);
});
使用如下所示的 test.js:
var data = { foo: 123 };
onCreateUser(data);
运行 firebase functions:shell < test.js 给了我一些输出,但跳过了 starting... console.log 部分:
->firebase functions:shell < src/test.js
⚠ Your requested "node" version "10" doesn't match your global version "14"
i functions: Loaded functions: onCreateUser
⚠ functions: The following emulators are not running, calls to these services will affect production: firestore, database, pubsub
firebase > var data = { foo: 123 };
undefined
firebase > onCreateUser(data);
'Successfully invoked function.'
firebase > ⚠ Your function was killed because it raised an unhandled error.
我需要在我的测试文件中导入该函数,还是我遗漏了其他内容?我正在寻找一种更快的方法来进行一些基本的集成测试。
这是在打字稿环境中,如果这很重要的话。
【问题讨论】:
-
您找到发生此错误的原因了吗?当我执行
firebase functions:shell < test.js时,我遇到了同样的错误,并且我无法检查 firebase 日志,因为错误后日志被清除了。
标签: node.js typescript firebase google-cloud-firestore firebase-cli