Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud functions from Firestore trigger have undefined context parameters in emulator tests #2495

Closed
noelmansour opened this issue Jul 27, 2020 · 3 comments

Comments

@noelmansour
Copy link

[REQUIRED] Environment info

firebase-tools: 8.6.0

Platform: macOS

[REQUIRED] Test case

Create a test that calls a cloud firestore triggered function that references the context parameter, e.g.

functions.firestore.document('users/{userId}').onUpdate((change, context) => {
    console.log(context.params.userId);
});

[REQUIRED] Steps to reproduce

Run the test using emulator suite:

firebase emulators:exec "npm run test"

[REQUIRED] Expected behavior

The context param should match that from the path of the document.

[REQUIRED] Actual behavior

The context param is undefined.

I haven't tested this outside the emulator.

@noelmansour noelmansour changed the title Cloud functions from Firestore trigger have undefined context parameters Cloud functions from Firestore trigger have undefined context parameters in emulator tests Jul 27, 2020
@noelmansour
Copy link
Author

This can also be seen with the RTDB as well. In fact, when running the test from the functions-samples, I get the following output:

  Cloud Functions
    makeUpperCase
Uppercasing undefined input
      ✓ should upper case input and write it to /uppercase (919ms)
    addMessage
      ✓ should return a 303 redirect (45ms)


  2 passing (975ms)

Note the log containing "undefined" which is referencing a context param:

https://github.com/firebase/functions-samples/blob/fd298059a457bb1c12b46b0c01ee8492ce2bb7a1/quickstarts/uppercase/functions/index.js#L52

@noelmansour
Copy link
Author

Looks like this is an issue with firebase-functions-test and not the emulator suite. See firebase/firebase-functions-test#10

@samtstern
Copy link
Contributor

samtstern commented Jul 29, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants