nicholas
nicholas

Reputation: 14561

Jest testing on firebase emulators can't find database URL?

I'm trying to run Jest unit tests on the firebase emulators with:

firebase emulators:exec 'jest'

I'm including firebase-admin and initializeApp in the test file:

const admin = require('firebase-admin');
admin.initializeApp();

it("tests", async () => {
  admin.database().ref('foo').set("bar");
  ...

but I get the error:

Can't determine Firebase Database URL.

Doesn't running 'jest' through firebase emulators:exec automatically set up the firebase project to point to the emulators? Is there some other configuration that I'm missing?

I've set up an example git repo here that demonstrates this issue.

https://github.com/nicholasstephan/firebase-emulator-test

Upvotes: 1

Views: 935

Answers (1)

Cameron
Cameron

Reputation: 31

In order to run jest unit tests with firebase emulators:exec a database url must be specified (by providing a service account) or by setting FIREBASE_DATABASE_EMULATOR_HOST. In order to run the default emulator, set FIREBASE_DATABASE_EMULATOR_HOST="localhost:9000" before running firebase emulators:exec. To look at the data being written to the database go to; http://localhost:9000/path/to/data.json?ns=not-a-project. If a service account is provided the namespace of the project (ns) is instead the namespace of the project.

Upvotes: 3

Related Questions