Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests expect only default ports, seem to ignore firebase.json file #61

Closed
b0ot opened this issue Nov 21, 2020 · 1 comment
Closed

Comments

@b0ot
Copy link

b0ot commented Nov 21, 2020

I was following the Unit testing security rules with the Firebase Emulator Suite

There is a section where Todd creates separate functions to initialize the TestApp and AdminApp

function getFirestor(auth) {
     return firebase.initializetestApp({projectId: MY_PROJECT_ID, auth: auth}).firestore
}

However, I would end up with the following error:

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

Eventually, I was able to determine that despite the emulator running, it wasn't connecting.
I changed from

const firebase = require('@firebase/testing')

to

const firebase = require('@firebase/rules-unit-testing');

After which I was able to modify the function to work:

const EMULATOR_PORT = 8086

function getFirestore(auth) {
  const db = firebase.initializeTestApp({projectId: MY_PROJECT_ID, auth: myAuth }).firestore();
  db.useEmulator("localhost", EMULATOR_PORT)
  return db
}

This worked for the test app, but when I tried the same for the admin app, it does not work

function getAdminFirestore() {
  const db = firebase.initializeAdminApp({projectId: MY_PROJECT_ID }).firestore();
  db.useEmulator("localhost", EMULATOR_PORT)
  return db
}

ERROR: TypeError: db.useEmulator is not a function

If I comment out the db.usEmulator line I get the

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

I had a firebase.json and .firebaserc in the folder above, I even tried to create another copy in the same folder as the test script, but it also didn't seem to work.

@davideast
Copy link
Member

@b0ot The new setup looks for the exec script first (using the process.env variable it provides) and then falls back to firebase.json if they do not exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants