我已经编写了一个调度功能,如此处所述:https://firebase.google.com/docs/functions/schedule-functions
我现在如何测试此功能?当我包装此函数时(就像处理其他任何云函数一样),出现错误消息:“类型'TestFunction'不存在属性'wrap'。”
const functionWrapper = test.wrap(function);
还有其他方法可以测试这些功能吗?
答案 0 :(得分:3)
我发现一个解决方法是将我的代码隔离在一个函数中,然后从计划的函数中调用该函数。测试时,我直接调用隔离的函数,而不是调用计划的函数。
例如:
export const dailyJob = functions.pubsub
.schedule('0 0 * * *')
.onRun(async context => {
return isolatedFunction();
})
export function isolatedFunction() {
...
}
答案 1 :(得分:0)
你可以这样写
exports.scheduledFunction = () => functions.pubsub.schedule('every 1 minutes').onRun((context) => {
console.log('Start scheduledFunction every 1 minutes');
sendEmail();
return null;
});
async function sendEmail() {
console.log('Start sendEmail');
}
答案 2 :(得分:0)
> firebase functions:shell
> firebase> RUN_NAME_OF_THE_FUCTION()
不知道从什么时候开始-但这是我处理调度程序功能的方式。我遇到的问题是我没有上下文,也不知道如何将参数传递给这些函数。
WIP,但至少我可以轻松地在本地环境中手动运行它。