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

feat(commands): add support for cy.callFunction() #141

Open
gregfenton opened this issue Jun 8, 2020 · 6 comments
Open

feat(commands): add support for cy.callFunction() #141

gregfenton opened this issue Jun 8, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@gregfenton
Copy link
Contributor

gregfenton commented Jun 8, 2020

The ability to call a Cloud Function would be powerful.

A key benefit would be the ability to do "administrative functions" via those cloud functions. Say, for example, deleting all existing users in a Firebase project. Possibly related to #88 .

https://firebase.google.com/docs/functions/callable#call_the_function

@prescottprue
Copy link
Owner

prescottprue commented Jun 8, 2020

I could see this being a feature for sure, but something to keep in mind is that if this is planned to be used for cleanup, like you were mentioning, that may not always get run depending on where the logic is placed. Also, Cypress advocates for only cleaning up when absolutely necessary as mentioned in their Best Practices docs

Something else is that the hope would be that folks aren't creating logic/cloud functions just for cleaning up after tests, but instead testing on an environment that either doesn't need to get cleaned up or is cleaned on some schedule outside of testing. For my team we have most tests run against an emulated environments with the cloud functions actually not emulated so that we can confirm data is written to the DB correctly, then handle testing functions in their own unit tests. This has helped make UI tests less flaky since we aren't waiting on a full round trip, that said, it is more of an "integration" approach rather than full "end to end"

@prescottprue prescottprue added the enhancement New feature or request label Jun 8, 2020
@gregfenton
Copy link
Contributor Author

I agree with 98% of the Cypress best practices. Some of their best practices assume a db that can be simply cleared and restored. There is friction when it comes to working with a more rigid environment like Firebase. Firebase Auth, in particular, don't work that way 😄

I'm not looking to tear down & build up the environment with every single test run. But even the one-time setup needs to be automated for consistency. Adding dozens of users, their roles, their groups....don't want to do that manually. And I don't want to share my dev & test environments with others.

@prescottprue
Copy link
Owner

prescottprue commented Jun 8, 2020

That is fair, I definitely feel you there! Something to note though is that firebase-tools does have import capability for the Firestore emulator (through the --import flag when booting up emulator with emulators:exec or emulators:start as well as for auth (auth import/export). Also, if you are looking to seed RTDB with data, my team has been using firebase-tools-extra which uses the same API as firebase-tools, but has support for talking to RTDB and Firestore emulators

@prescottprue
Copy link
Owner

prescottprue commented Jun 8, 2020

Here is an example of what I was mentioning with firebase-tools-extra:

#!/bin/sh
# NOTE: firebase-extra is used since firebase-tools doesn't currently support emulators (see https://github.com/firebase/firebase-tools/issues/1957)
# NOTE: Make sure to set FIRESTORE_EMULATOR_HOST and FIREBASE_DATABASE_EMULATOR_HOST to environment to use emulators

echo "Seeding DB..."

# Update data in firestore with inline data
firebase-extra firestore:set /users/ABC123 -d '{"some": "data"}' && echo "Updated user in firestore"

# Seed data to RTDB from a file
firebase-extra database:update /roles ./data/roles.json && echo "Set roles from file"

echo "Successfully seeded databases"

Notice how you can pass a file path or stringified data if you use the -d flag, just like the firebase-tools API

@prescottprue
Copy link
Owner

Of note: as of firebase-tools v8.5.0 there is now support for using --import with RTDB

@prescottprue prescottprue changed the title Add support for cy.callFunction() feat(commands): add support for cy.callFunction() Jul 22, 2020
@gregfenton
Copy link
Contributor Author

And v8.6.0 adds --export-on-exit. Things in FB Emulator space are maturing!

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

No branches or pull requests

2 participants