我想在部署之前调用(或测试)我的云功能。我找到了这个参考https://firebase.google.com/docs/functions/local-emulator。
我正在使用shell调用并传递我的函数的测试数据,但我总是得到成功调用函数的响应。我的函数中使用console.log几乎没有输出语句( ),但永远不会被打印出来。
firebase > post_deleted({"brand" : "Gucci","category" : "FULL LOOKS","postNumImages" : 1,"posterId" : "HcK5eIKU6jUlqhcg7t10OThZ2mq2","posterName" : "Steve Nash","reverseTimestamp" : -1.511338246002482E9,"salePrice" : 5,"size" : "medium","state" : "OPEN","subCategory" : "CASUAL","timestamp" : 1511338246036},{params:{postId:'-KzXlrvMtQ4PnDMiojz8'}})
'Successfully invoked function.'
firebase >
firebase >
我的功能代码(部分)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
console.log("before");
var gcloud_storage = require('@google-cloud/storage')({keyFilename:
`${functions.config().serviceaccount.filename}`});
exports.post_deleted = functions.database.ref('/posts/{postId}').onDelete((event) => {
console.log("inside");
let postId = event.params.postId;
let snapshot = event.data.previous;
let subCategory = snapshot.child('subCategory').val();
let db = admin.database();
let tasksArray = [];
来自doc。 Cloud Functions shell,将日志从您的函数流式传输到运行它们的终端窗口。它们显示来自函数内的console.log(),console.info(),console.error()和console.warn()语句的所有输出
那么,为什么我在调用函数时看不到里面?我部署了相同的功能,它按预期工作。对不起,如果我错过了一些明显的东西。寻求建议。谢谢。
答案 0 :(得分:0)
好。感恩节过了两天!!最后,发现了一个错误并创建了一个问题on the cloud-functions-emulator sdk
Later found out there was already the same issue created a week ago