Firebase emulators:exec with 'npm test' script returns immediately

Viewed 68

I'm running some React integration tests with npm, and need the Firebase emulator for them. I've set up my npm scripts as follows:

"scripts": {
    "test:integration:runner": "cross-env RTL_SKIP_AUTO_CLEANUP=true FIREBASE_DATABASE_EMULATOR_HOST=\"localhost:9000\" FIREBASE_FUNCTIONS_EMULATOR_HOST=\"localhost:5001\" FIREBASE_AUTH_EMULATOR_HOST=\"localhost:9099\" react-scripts test ./src/integrationTests/App.spec.js --watchAll=false",
    "test:integration": "firebase emulators:exec 'npm run test:integration:runner'",
  },

However, when I run npm run test:integration, the script returns after about 1 second, with no errors. Here is the only ouput:

PS C:\Users\{userame}\{project}> npm run test:integration

> {project_name} test:integration
> firebase emulators:exec 'npm run test:integration:runner'    

PS C:\Users\{userame}\{project}>

The firebase emulator itself is working if I run it standalone, and I tested the integration test with the emulator already running, and that works as well. I tried running firebase emulators:exec with a different non-npm script (instead of npm run test:integration:runner) and it successfully spun up the emulator. Any idea what might be happening here?

1 Answers

Well, I figured this out soon after asking the question. It turns out you need to double quote the script.

So I changed

"test:integration": "firebase emulators:exec 'npm run test:integration:runner'",

to

"test:integration": "firebase emulators:exec \"npm run test:integration:runner\" ",

I'd like to understand why this works though. This is in Windows, and I'm not sure how single/double quote semantics in commands might differ from what I'm used to.

Related