Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

515
Views
why process.env.FIRESTORE_EMULATOR_HOST will be undefined in test environment? even though I have run the emulator

I am using

  • Node 14
  • firebase functions-test: 0.2.3
  • firebase-admin: 9.6.0
  • firebase-functions: 3.13.2
  • firebase tools: 9.10.0
  • mocha: 8.3.2,
  • ts-node: 9.1.1

if I run firebase emulators:start

then I will expect process.env will have properties like

"FUNCTIONS_EMULATOR": "true",
"FIRESTORE_EMULATOR_HOST": "localhost:8080"

now I need to create testing for my cloud function using mocha, I will test it using Firestore and functions emulator, I give my file name events_cron_job.test.ts

after I run the simulator, I try to console log those values and I got undefined like this

enter image description here

I expect

console.log(process.env.FUNCTIONS_EMULATOR)  // will be "true"
console.log(process.env.FIRESTORE_EMULATOR_HOST) // will be "localhost:8080"

I think this is only happen in test environment ( I am using mocha ), I have regular http triggers and it works as expected

before running the emulator, I try to execute this on terminal

export FIRESTORE_EMULATOR_HOST="localhost:8080"
export FUNCTIONS_EMULATOR="true"

and then execute firebase emulators:start , but the result will be the same, I still get undefined for those values

because those values are undefined, then if my laptop is disconnected from the internet, then this testing will not run ( i.e it will only access the data in production server, not the emulator! ), I expect the test will still run even if there is no internet connection since I use emulator.

I run the mocha test using

mocha -r ts-node/register src/tests/cloud_function_tests --recursive --extension .test.ts --timeout 60000 --exit
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

As you can see in this Github issue comment, in order to run tests with the Firebase emulator you should use the following command to trigger it:

firebase emulators:exec "npm test"

As this is how tests where intended to be executed by the Firebase Team using the emulator.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!