Firebase and Typescript: Setting reference to admin.database() causes mocha tests to hang

168 views Asked by At

I'm using mocha, chai, and chaiAsPromised to test Firebase functions. I've been having a problem with my tests hanging: they run and succeed or as expected, but they don't complete. That is, I have to actually kill the test process to (Ctrl-C or F5) after the tests run.

For this code I'm using the Firebase Admin SDK, and I isolated the issue to a call to admin.database. I set up the following simplified test to isolate this hanging behavior:

import * as admin from 'firebase-admin';
import {} from 'mocha';
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';

let db: admin.database.Database;
before (() => {
  chai.use(chaiAsPromised);
  chai.should();

  admin.initializeApp(testConfig);
  db = admin.database();
});

describe('Data Access Tests', () => {  
  it ('tests DAO functionality', () => {
    return true;
  });  
});

When I include the line admin.database(), the test run hangs (i.e. the process never returns and I have to kill it with Ctrl-C.) When I comment out the line admin.database(), the test run completes. The test always "passes" (as expected, since it's just returning true.)

Though I don't necessarily need to set a reference to admin.database() like I do (it's just so I don't have to keep typing out the whole thing), I do need to pass admin.database() to my DataAccessObject, as that's where I've encapsulated all of the firebase database calls and it keeps all of those URL-based paths contained in one place.

Can anyone explain why the admin.database() call would cause the mocha process to hang?

0

There are 0 answers