extensions
extensions copied to clipboard
test(rtdb-limit-child-nodes): use emulator for testing
I think functions.handler.database
is required for a Cloud Function to be deployed as an extension. I'm afraid we won't be able to deploy it with functions.database
.
Hey, thanks for the update, @rosariopfernandes. Could you confirm that this is the case, @jhuleatt? I've created an issue here for this issue either way.
Apologies for the slow response here, this slipped past me. To give some clarity on the extensions emualtor:
-
The 'normal' namespace (
functions.database.ref.onCreate
) defines a trigger and a handler, whereas the handler namespace (functions.handler.database.ref.onCreate
) only defines a handler. You CAN use the normal namespace for extensions - however, the trigger defined by the code will be ignored in favor of the trigger defined in extension.yaml. This is a bit confusing, so we use the handler namespace to avoid defining a trigger in the code that will be ignored. -
Because it doesn't define any triggers, the handler namespace won't work with
firebase emulators:exec
orfirebase emulators:start
. Instead, usefirebase ext:dev:emulators:exec <path/to/extension.yaml>
orfirebase ext:dev:emulators:start <path/to/extension.yaml>
- this will pick up triggers from the extension.yaml.
Hopefully this helps - if the ext:dev:emulator:* commands still aren't working, this is likely a regression and I will look into this further
Hey @joehan, thanks for the update! I was indeed using the wrong command (i.e. firebase emulators:start
). I am encountering another problem. If I run this command:
firebase ext:dev:emulators:start ./extension.yaml --test-params=emulator-params.env --project=extensions-testing
from the rtdb-limit-child-nodes
extension package root, nothing happens.
I also tried without the path in the command:
firebase ext:dev:emulators:start --test-params=emulator-params.env --project=extensions-testing
Which gave me the following error:
Error: HTTP Error: 403, Invalid Firebase database name
My emulator-params.env
file looks like this:
LOCATION=europe-west2
MAX_COUNT=2
NODE_PATH=test_path
@russellwheatley @joehan it looks like the emulator doesn't support the ${param:PARAM}
syntax introduced in #457. If I change back to the ${PARAM}
syntax where the RTDB event trigger is defined in extension.yaml, the emulator starts up without issue with this command:
firebase ext:dev:emulators:start --test-params=emulator-params.env --project=jeff-test-699d3
I'll commit my extension.yaml changes, since we probably don't want to block this on CLI updates. The CLI doesn't seem to have full support for the new syntax - a similar bug recently bit me on another PR https://github.com/firebase/extensions/pull/486#discussion_r518206280
Googlers, I've filed internal issue number 172862340
to fix the ${param:PARAM}
issue on the platform side.
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.
We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent.
in this pull request.
Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla
label to yes
(if enabled on your project).
ℹ️ Googlers: Go here for more info.
@googlebot I consent.
Update:
I can visit http://localhost:4000/ to see the emulator UI and manually add data to the emulated database. However, when the function runs, I seem to run into something like https://github.com/firebase/firebase-functions/issues/726, so I can't get it to fully work. Here's the error (firebase-tools 8.15.1
):
Error when truncating the database node Error: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com
at fatal (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/@firebase/database/dist/index.node.cjs.js:341:11)
at parseRepoInfo (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/@firebase/database/dist/index.node.cjs.js:1294:9)
at RepoManager.databaseFromApp (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/@firebase/database/dist/index.node.cjs.js:14995:25)
at Object.initStandalone (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/@firebase/database/dist/index.node.cjs.js:15396:45)
at DatabaseService.getDatabase (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/firebase-admin/lib/database/database.js:66:23)
at FirebaseApp.database (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/firebase-admin/lib/firebase-app.js:231:24)
at DataSnapshot.get ref [as ref] (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/firebase-functions/lib/providers/database.js:293:34)
at /Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/lib/index.js:38:36
at cloudFunction (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/firebase-functions/lib/cloud-functions.js:134:23)
at /Users/jhuleatt/.nvm/versions/node/v14.3.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:601:20
@joehan is it possible the extensions emulators use a different codepath that needs a fix similar to the one that fixed https://github.com/firebase/firebase-functions/issues/726 ?
The bug blocking this was fixed in firebase-tools 8.16.0
Thanks for the update, @jhuleatt. I'll get this revised 👍
Hey @jhuleatt @joehan, I'm unable to get this working. My setup:
-
firebase-tools
version8.16.2
, -
firebase-functions
version3.11.0
as suggested here. - pulled in Jeff's PARAM changes
- running
firebase ext:dev:emulators:start --test-params=emulator-params.env --project=extensions-testing
When I add data via the console UI, I get the same error as mentioned above:
> [2020-11-18T16:23:44.801Z] @firebase/database: FIREBASE FATAL ERROR: Cannot
parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com > {"sever
ity":"ERROR","message":"Error when truncating the database node Error: FIREBASE
FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.fireb
aseio.com \n at fatal (/Users/russellwheatley/projects/extensions/rtdb-limit-
child-nodes/functions/node_modules/@firebase/database/dist/index.node.cjs.js:341
:11)\n at parseRepoInfo (/Users/russellwheatley/projects/extensions/rtdb-limi
t-child-nodes/functions/node_modules/@firebase/database/dist/index.node.cjs.js:1
296:9)\n at RepoManager.databaseFromApp (/Users/russellwheatley/projects/exte
nsions/rtdb-limit-child-nodes/functions/node_modules/@firebase/database/dist/ind
ex.node.cjs.js:15004:25)\n at Object.initStandalone (/Users/russellwheatley/p
rojects/extensions/rtdb-limit-child-nodes/functions/node_modules/@firebase/datab
ase/dist/index.node.cjs.js:15395:45)\n at DatabaseService.getDatabase (/Users
/russellwheatley/projects/extensions/rtdb-limit-child-nodes/functions/node_modul
es/firebase-admin/lib/database/database.js:66:23)\n at FirebaseApp.database (
/Users/russellwheatley/projects/extensions/rtdb-limit-child-nodes/functions/node
_modules/firebase-admin/lib/firebase-app.js:231:24)\n at DataSnapshot.get ref
[as ref] (/Users/russellwheatley/projects/extensions/rtdb-limit-child-nodes/fun
ctions/node_modules/firebase-functions/lib/providers/database.js:293:34)\n at
/Users/russellwheatley/projects/extensions/rtdb-limit-child-nodes/functions/lib
/index.js:30:36\n at cloudFunction (/Users/russellwheatley/projects/extension
s/rtdb-limit-child-nodes/functions/node_modules/firebase-functions/lib/cloud-fun
ctions.js:134:23)\n at /Users/russellwheatley/.nvm/versions/node/v12.13.0/lib
/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:609:20"}
The exact moment it happens is when snapshot.ref
getter is invoked. Using snapshot.key
for example, will not cause an error.
Issues raised with firebase-tools
blocking PR:
https://github.com/firebase/firebase-tools/issues/2928
https://github.com/firebase/firebase-tools/issues/2930
going to close this for now as it's pretty old, would be easier to add tests in a new PR i think.