我正在尝试使用Firebase模拟器和onCall
软件包在本地测试@firebase/testing
函数。当我尝试调用该函数时,出现以下错误消息...
Error: Response is not valid JSON object.
at new HttpsErrorImpl (node_modules/@firebase/functions/dist/index.node.cjs.js:60:28)
at Service.<anonymous> (node_modules/@firebase/functions/dist/index.node.cjs.js:534:35)
at step (node_modules/tslib/tslib.js:136:27)
at Object.next (node_modules/tslib/tslib.js:117:57)
at fulfilled (node_modules/tslib/tslib.js:107:62)
at process._tickCallback (internal/process/next_tick.js:68:7)
据我所知,它甚至没有调用该函数,因此这看起来像是程序包问题而不是我的代码-我正在做这个假设,因为可调用函数中的console.log条目没有在崩溃前出现。我还通过使用curl直接调用端点进行了测试,并且此方法工作正常,因此我可以确认该函数已加载并正常运行。只是火力之源
@firebase/testing
能够测试可调用函数还是正在进行中的工作?
函数定义是...
export const demoCallable = functions.region('europe-west1').https.onCall((data: any, context: CallableContext): any => {
console.log(data);
return {
test: true
};
});
测试脚本是...
const firebase = require('@firebase/testing');
const expect = require('chai').expect;
const adminApp = firebase.initializeAdminApp({projectId: 'XXXXX'});
const fn = adminApp.functions('europe-west1').httpsCallable('demoCallable');
console.log('Running callable...');
const response = await fn({test: true});
console.log('response...');
console.log(response);
console.log('...response');
expect(response).to.eql({test: true});
答案 0 :(得分:0)
当找不到云函数时,firebase通常会返回此错误。.确保输入正确的函数名称和位置