用模拟器代替云进行Firebase云功能测试

用模拟器代替云进行Firebase云功能测试,firebase,google-cloud-functions,firebase-cli,Firebase,Google Cloud Functions,Firebase Cli,用于创建云功能测试的命令指示用户配置测试套件。 下面是它指示用户创建的代码块: // 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', },

用于创建云功能测试的命令指示用户配置测试套件。 下面是它指示用户创建的代码块:

// 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“}

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

检查,它看起来很相似,可能会让您了解如何实现此功能。检查,它看起来很相似,可能会让您了解如何实现此功能。