英文:
Firebase Functions Test fails to wrap v2 function
问题
我有2个 Firebase 函数,hello
在 v1 中,hello2
在 v2 中
import { https } from "firebase-functions";
import { onCall } from "firebase-functions/v2/https";
export const hello = https.onCall((request) => {
return `Hello ${request.data.text}`;
});
export const hello2 = onCall((request) => {
return `Hello ${request.data.text}`;
});
hello
可以使用 firebase-functions-test
SDK 包装,没有问题,但 hello2
抛出错误。firebase-functions-test
只支持 v1,不支持 v2 吗?我该如何处理 v2 函数?
import { hello, hello2 } from ".";
import { expect } from "chai";
import { wrap } from "firebase-functions-test/lib/main";
describe("hello function", () => {
it("returns expected output", async () => {
// Create a test request object.
const request = {
body: {
text: "World",
},
};
const wrapped = wrap(hello);
// The following line fails with No overload matches this call.
const wrapped2 = wrap(hello2);
const response = await wrapped(request);
// The following line fails with Argument of type '{ body: { text: string; }; }' is not assignable to parameter of type 'CallableRequest<any>'.
const response2 = await wrapped2(request);
expect(response).equal("Hello World");
expect(response2).equal("Hello World");
});
});
英文:
I have 2 Firebase functions, hello
in v1 and hello2
in v2
import { https } from "firebase-functions";
import { onCall } from "firebase-functions/v2/https";
export const hello = https.onCall((request) => {
return `Hello ${request.data.text}`;
});
export const hello2 = onCall((request) => {
return `Hello ${request.data.text}`;
});
hello
can be wrapped with firebase-functions-test
SDK with no issue, but hello2
throws an error. Is firebase-functions-test
supports only v1 but not v2? How can I do this for v2 functions?
import { hello, hello2 } from ".";
import { expect } from "chai";
import { wrap } from "firebase-functions-test/lib/main";
describe("hello function", () => {
it("returns expected output", async () => {
// Create a test request object.
const request = {
body: {
text: "World",
},
};
const wrapped = wrap(hello);
// The following line fails with No overload matches this call.
const wrapped2 = wrap(hello2);
const response = await wrapped(request);
// The following line fails with Argument of type '{ body: { text: string; }; }' is not assignable to parameter of type 'CallableRequest<any>'.
const response2 = await wrapped2(request);
expect(response).equal("Hello World");
expect(response2).equal("Hello World");
});
});
答案1
得分: 1
根据@samthecodingman在评论中提到的,根据firebase/firebase-functions-test Issue #163
,截至目前,v2 onCall
函数尚不受支持。
英文:
Answering as a Community Wiki, so that it may help others too.
As @samthecodingman mentioned in the comment, According to firebase/firebase-functions-test Issue #163
, as of now v2 onCall
functions are not yet supported.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论