Firebase Functions测试未能包装v2函数。

huangapple go评论81阅读模式
英文:

Firebase Functions Test fails to wrap v2 function

问题

我有2个 Firebase 函数,hello 在 v1 中,hello2 在 v2 中

  1. import { https } from "firebase-functions";
  2. import { onCall } from "firebase-functions/v2/https";
  3. export const hello = https.onCall((request) => {
  4. return `Hello ${request.data.text}`;
  5. });
  6. export const hello2 = onCall((request) => {
  7. return `Hello ${request.data.text}`;
  8. });

hello 可以使用 firebase-functions-test SDK 包装,没有问题,但 hello2 抛出错误。firebase-functions-test 只支持 v1,不支持 v2 吗?我该如何处理 v2 函数?

  1. import { hello, hello2 } from ".";
  2. import { expect } from "chai";
  3. import { wrap } from "firebase-functions-test/lib/main";
  4. describe("hello function", () => {
  5. it("returns expected output", async () => {
  6. // Create a test request object.
  7. const request = {
  8. body: {
  9. text: "World",
  10. },
  11. };
  12. const wrapped = wrap(hello);
  13. // The following line fails with No overload matches this call.
  14. const wrapped2 = wrap(hello2);
  15. const response = await wrapped(request);
  16. // The following line fails with Argument of type '{ body: { text: string; }; }' is not assignable to parameter of type 'CallableRequest<any>'.
  17. const response2 = await wrapped2(request);
  18. expect(response).equal("Hello World");
  19. expect(response2).equal("Hello World");
  20. });
  21. });
英文:

I have 2 Firebase functions, hello in v1 and hello2 in v2

  1. import { https } from &quot;firebase-functions&quot;;
  2. import { onCall } from &quot;firebase-functions/v2/https&quot;;
  3. export const hello = https.onCall((request) =&gt; {
  4. return `Hello ${request.data.text}`;
  5. });
  6. export const hello2 = onCall((request) =&gt; {
  7. return `Hello ${request.data.text}`;
  8. });

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?

  1. import { hello, hello2 } from &quot;.&quot;;
  2. import { expect } from &quot;chai&quot;;
  3. import { wrap } from &quot;firebase-functions-test/lib/main&quot;;
  4. describe(&quot;hello function&quot;, () =&gt; {
  5. it(&quot;returns expected output&quot;, async () =&gt; {
  6. // Create a test request object.
  7. const request = {
  8. body: {
  9. text: &quot;World&quot;,
  10. },
  11. };
  12. const wrapped = wrap(hello);
  13. // The following line fails with No overload matches this call.
  14. const wrapped2 = wrap(hello2);
  15. const response = await wrapped(request);
  16. // The following line fails with Argument of type &#39;{ body: { text: string; }; }&#39; is not assignable to parameter of type &#39;CallableRequest&lt;any&gt;&#39;.
  17. const response2 = await wrapped2(request);
  18. expect(response).equal(&quot;Hello World&quot;);
  19. expect(response2).equal(&quot;Hello World&quot;);
  20. });
  21. });

答案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.

huangapple
  • 本文由 发表于 2023年6月6日 07:03:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76410496.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定