Agung
Agung

Reputation: 13803

how to run Firebase Emulator and Perform Testing using the same npm script?

sorry I am new in node and backend development. so I am trying to perform testing using mocha and firebase emulator to test my cloud function.

currently to perform a test, the sequence is like this:

1 . start the emulator using firebase emulators:start

2 . in different terminal tab, I run the test using npm script npm run test-cloud-functions

the script in package.json is like this

"scripts": {

   "test-cloud-functions": "export FIRESTORE_EMULATOR_HOST=\"localhost:8080\" && mocha -r ts-node/register src/tests/cloud_function_tests --recursive --extension .test.ts --timeout 60000 --exit",

},

3 . stop the firebase emulator by pressing control + C

I want those 3 steps above is done in one single npm script. how to do that?

I have tried to add the firebase emulators:start to the script like this

    "scripts": {
    
       "test-cloud-functions": "firebase emulators:start && export FIRESTORE_EMULATOR_HOST=\"localhost:8080\" && mocha -r ts-node/register src/tests/cloud_function_tests --recursive --extension .test.ts --timeout 60000 --exit",
   
    },

but it doesn't work, it doesn't run the test

Upvotes: 1

Views: 1396

Answers (1)

Akshansha Singhal
Akshansha Singhal

Reputation: 862

Option 1:

In npm script under serve:dev, mention the code given below:

"serve:dev": "concurrently \"npm run build:dev\" \"firebase emulators:start --only functions\""

For more details, refer to the documentation.

Option 2:

For integrating the commands firebase emulators:start and npm run test-cloud-functions follow the answer mentioned here.

Upvotes: 1

Related Questions