Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

517
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda