firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.02k stars 932 forks source link

FR: Filter functions to emulate, write out rules coverage to file #2340

Open SamyPesse opened 4 years ago

SamyPesse commented 4 years ago

Right now there is no way to do only start the emulator with a subset of functions enabled instead of all. It requires a custom build or filter the exports ourself.

It'd be great if the firebase emulators:exec and firebase emulators:start would accept an argument like --functions a,b or maybe the same syntax as firebase deploy: --only functions:a,functions:b (this is what I was expecting at first)

samtstern commented 4 years ago

@SamyPesse this is a reasonable feature request and should be feasible to implement. Can you explain the reason that you don't want to emulate all functions though? Curious if there's an underyling emulator improvement we could make.

SamyPesse commented 4 years ago

I'm basically running a script generate-tests-data to prepare the dataset for unit testing:

export CF_IS_PREPARING_DATASET="true"

firebase emulators:exec --only firestore,functions \
    "yarn node write-to-emulator.ts && \
    sleep 60 && \
    curl http://localhost:8080/emulator/v1/projects/$PROJECT_ID:ruleCoverage.html > tests/coverages/firestore.html && \
    firebase emulators:export ./dump/tests --force"

To explain this code:

The improvements I'd like from Firebase are:

samtstern commented 4 years ago

@SamyPesse I just sent a PR to fix #1813 which will be included in the next release. We'll now wait up to 60s for any functions to finish when the emulators are stopped.

SamyPesse commented 4 years ago

Thanks @samtstern, but we'll probably have to keep using the bash script with the sleep 60 because we want to run curl http://localhost:8080/emulator/v1/projects/$PROJECT_ID:ruleCoverage.html > tests/coverages/firestore.html to download the rules coverage before the emulator is killed

samtstern commented 4 years ago

@SamyPesse makes sense I actually end up in this situation a lot. Would it be useful for you if the emulator always wrote the rules coverage report to a file on exiting? Or do you prefer to have more control over when/where that happens?

SamyPesse commented 3 years ago

@samtstern yes it'll fix it 👍