I have an Express API using the Firebase Admin SDK.
Currently, my application is failing CI as it cannot initialise on the test stage, due to not being able to connect to Firebase.
I have a serviceAccountKey.json
file in the root of my project, that I import as follows..
import * as fbseAdmin from 'firebase-admin'
const FIREBASE_DB_URI = process.env.FIREBASE_DB_URI
const serviceAccount = require('../serviceAccountKey.json')
fbseAdmin.initializeApp({
credential: fbseAdmin.credential.cert(serviceAccount),
databaseURL: FIREBASE_DB_URI
})
export default fbseAdmin
This file is excluded from source control as it contains sensitive information.
The first issue I have is when my CI build runs, the tests fail as Error: Cannot find module '../serviceAccountKey.json'
How is best to approach this? Should I mock the file? I'd prefer not to keep a mock file floating around my solution.
Secondly, I believe the app will fail to start if Firebase does not initialise correctly.
Should I setup a mock Firebase project for testing?