Unable to connect to Firestore emulator using testing app instance (original) (raw)

Describe your environment

"firebase": "^6.4.1",
"firebase-admin": "^8.9.2",
"firebase-functions": "^3.3.0",
...
"@firebase/testing": "^0.16.8",
"firebase-functions-test": "^0.1.7",

Describe the problem

I'm trying to run tests locally using the Firestore emulator, but am completely unable to connect. I consistently get the error message:

  console.error node_modules/@firebase/testing/node_modules/@firebase/logger/dist/index.cjs.js:94
    [2020-02-11T22:24:18.371Z]  @firebase/firestore: Firestore (7.8.1): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unauthenticated]: 16 UNAUTHENTICATED: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
    This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.


Error: 14 UNAVAILABLE: failed to connect to all addresses

    at Object.exports.createStatusError (/Users/johngcook/Developer/dex/dex-core/cf_node/functions/node_modules/grpc/src/common.js:91:15)
    at Object.onReceiveStatus (/Users/johngcook/Developer/dex/dex-core/cf_node/functions/node_modules/grpc/src/client_interceptors.js:1209:28)
    at InterceptingListener._callNext (/Users/johngcook/Developer/dex/dex-core/cf_node/functions/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/Users/johngcook/Developer/dex/dex-core/cf_node/functions/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/Users/johngcook/Developer/dex/dex-core/cf_node/functions/node_modules/grpc/src/client_interceptors.js:847:24)

My understanding was that using the initializeAdminApp feature of @firebase/testing eliminated the need for authenticated requests. I am not using Firestore rules of any kind.

Steps to reproduce:

I'm running the Firestore emulator in the background with the following command:

firebase emulators:start --only firestore

with firebase-cli v7.12.1.

My test config is like so:

// sampleTest.spec.ts import * as testing from '@firebase/testing';

process.env.FIRESTORE_EMULATOR_HOST = 'localhost:5002';

const projectId = 'testing'; const databaseName = 'firestore-testing'; const databaseURL = 'http://localhost:5002';

const testApp = testing.initializeAdminApp({ projectId, databaseName }); const testFirestore = testApp.firestore(); testFirestore.settings({ experimentalForceLongPolling: true }); // enabling or disabling this line has no effect on the problem

describe('tests', () => { beforeAll(() => testing.clearFirestoreData({ projectId }))); it('should be able to use the firestore emulator', async () => { const exampleDoc = await testFirestore.doc('users/exampleUserId').get(); expect(exampleDoc.exists).toBeFalsy(); }); });

Running the test using jest@^25.1.0 produces the same error repeatedly.