node.js - 使用带有 GET 的查询字符串在本地测试 Firebase HTTP Cloud 函数

标签 node.js firebase testing google-cloud-functions firebase-cli

我在 Firebase 上有一个 HTTP 云功能。我可以成功调用此 tutorial 之后的函数使用没有查询字符串的 GET 方法。

> test.get() 

我的问题是如何使用查询字符串测试 HTTP 函数?如何将它传递给调用?

我在 shell 上试​​过了

> test.get({"name":"test"})

在我的 index.js 上,我尝试打印名称:

exports.test= functions.https.onRequest((req, res) => {
    console.log(req.query.name);
});

它没有工作并返回 undefined

最佳答案

您引用的文档是这样说的:

For invoking HTTPS functions in the shell, usage is the same as the request NPM module, but replace request with the name of the function you want to emulate.

请注意 request 文档的链接模块。您将不得不使用它的 API 来发出测试请求。在该链接页面上,您正在寻找的更具体的文档位于此处:

https://www.npmjs.com/package/request#requestoptions-callback

您要注意的是第一个参数“选项”的属性。这个对象有很多影响请求的潜在属性。要发送查询字符串,您应该使用 qs 属性,如下所示:

test.get({ qs:{ name:"foo" } })

这会将测试调用的 name 查询字符串参数设置为 foo

关于node.js - 使用带有 GET 的查询字符串在本地测试 Firebase HTTP Cloud 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49764830/

相关文章:

html - 脚本未被调用

node.js - 在 docusign 中锁定对文档的编辑

javascript - 聚合物 firebase..使用密码和电子邮件进行身份验证

Firebase 不发送电子邮件?

测试哈密顿路径查找器实现

node.js - NodeJS SQL Server - 如何使用将返回一个 promise 的数组输入参数进行查询

javascript - 无法使用 Node.js 向 mysql 插入数据

javascript - 将 Firebase 中的数据显示到表中时出现问题?

unit-testing - 如何初始化一个对象并将其用于所有测试用例

Android UI 测试 : Monkey stuck in just a couple of Activities