I want to set up a test suit to write a unit test for my Firebase application which connects to the Firestore emulator that is running locally on port 8080
Here is my firebase configuration in index.js
const functions = require("firebase-functions");
const dotenv = require('dotenv');
dotenv.config();
const emailFormatter = require("./emailFormatter");
const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();
And the following is my functions.test.js
const admin = require('firebase-admin');
const serviceAccount = require('../../../fir-react-mailer-firebase-adminsdk-wfei1-0fff68d44e.json');
const testConfig = {
credential: admin.credential.cert(serviceAccount),
databaseURL: 'http://localhost:8080'
}
const testApp = admin.initializeApp(testConfig, 'test');
const projectConfig = {
projectId: 'fir-react-mailer',
databaseURL: 'http://localhost:8080',
}
const testF = require('firebase-functions-test')(projectConfig, serviceAccount);
const myFinctions = require('../index')
let db = admin.firestore(testApp)
Here is my package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "jest"
},
"engines": {
"node": "12"
},
"dependencies": {
"chalk": "^4.1.0",
"dotenv": "^8.2.0",
"firebase-admin": "^8.9.0",
"firebase-functions": "^3.3.0",
"nodemailer": "^6.4.6"
},
"devDependencies": {
"@types/jest": "^26.0.20",
"firebase-functions-test": "^0.1.7",
"jest": "^26.6.3"
},
"private": true
}
When running the command npm run test, I am getting the following error on the console.
Please suggest to me, If I am doing something wrong. I am a newbie to Firebase, so this whole setup is confusing.