使用模拟器而不是云进行Firebase云功能测试

时间:2020-09-17 07:05:55

标签: firebase google-cloud-functions firebase-cli

用于创建云功能测试的documentation指导用户配置测试套件。 这是它指导用户创建的代码块:

// At the top of test/index.test.js
const test = require('firebase-functions-test')({
  databaseURL: 'https://my-project.firebaseio.com',
  storageBucket: 'my-project.appspot.com',
  projectId: 'my-project',
}, 'path/to/serviceAccountKey.json');

我们希望使用在线模式,但是我们希望针对本地Firebase模拟器而不是云实例进行测试。我们尝试通过省略密钥文件并重定向数据库URL来初始化测试,如下所示:

require('firebase-functions-test')({
        databaseURL: 'localhost:9000',
        storageBucket: 'my-project.appspot.com',
        projectId: 'my-project',
    });

不幸的是,这不起作用。该程序将引发异常:

@ firebase / database:FIREBASE警告:{“代码”:“应用程序/无效凭据”,“消息”:“通过”凭据“属性提供给initializeApp()的凭据实现未能获取有效的Google OAuth2访问权限令牌,其中包含以下错误:“获取访问令牌时出错:发出请求时出错:getaddrinfo ENOTFOUND metadata.google.internal。错误代码:ENOTFOUND“。”}

用户应该如何连接到仿真器而不是云实例?

0 个答案:

没有答案