6

I'm trying to test Firestore's security rules on my GitLab CI pipeline. I need to run Firebase's emulator to accomplish that.

However, the Firebase emulator basically starts serving a "fake backend". So, how can I run that job in parallel to other jobs?

For example:

stages:
  - emulator
  - test

emulator:
  - stage: emulator
  script:
    - firebase serve --only firestore

test:
  - stage: test
  script:
    - yarn test

The test stage is never reached as GitLab is serving the emulator stage. Therefore, it never finishes.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Jim
  • 365
  • 2
  • 9

1 Answers1

7

You should not use 2 stages. Keep in mind, each stage is a completely independent "computer" started somewhere. So one stage can per default not interact with another. The script part of a stage is practically a shell script. So if you want to try if everything works, create a shell script and execute it.

Here is what I did. Keep in mind it's I didn't test it with your particular setup

stages:
  - test


test:
  - stage: test
  script:
     - yarn compile
     - yarn firebase setup:emulators:firestore
     - yarn firebase emulators:exec -P dev1 --only firestore "yarn test --exit"

To use the emulator with tests on a CI system it's best you add a "start" script. In this case I'm adding the test yarn test --exit

Jürgen Brandstetter
  • 7,066
  • 3
  • 35
  • 30
  • 2
    [Firebaser here] this is the correct answer and it's exactly what `emulators:exec` is made for. FYI you don't need to run `setup:emulators:firestore` anymore, we download missing emulators automatically in recent versions of the Firebase CLI. – Sam Stern Dec 13 '19 at 20:08