Firebase cloud function testing with emulator instead of cloud

Viewed 92

The documentation for creating cloud function testing directs the user to configure the test suite. Here's the code block it directs the user to create:

// 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');

We wish to use online mode, but we wish to test against the local firebase emulator instead of a cloud instance. We attempted to initialize the test by omitting the key file and redirecting the database url as below:

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

Unfortunately this does not work. The program will just throw the exception:

@firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND"."}

How is a user supposed to hookup to an emulator rather than a cloud instance?

0 Answers
Related