Comments (14)
If I ignore the window.fbInstance issue then the cy.login() seems to successful:
cy.login().then((result) => console.log(result)); // logs an auth object
The auth object contains the correct test email, firebase project id and uid so I assumes it's valid. My (simplified) auth service show the following:
this._authState.subscribe(authUser => console.log('authUser', authUser)); // logs null
And doesn't receive an auth object.
So cy has a valid auth object but the authservice of angularfire only registers a non logged in user. Time for some more debugging!
from cypress-firebase.
The actions called through cypress-firebase incluidng cy.callFirestore
actually use firebase-tools instead of the current user's auth (which is handled by cy.login
). This is because you will most likley want to be seeding/verifying data in a way which will not adhere to security rules for the client, that means you must have a service account or token for the CLI to use.
Do you have a cypress.env.json
or call cypress-firebase createTestEnv
before running your tests? It creates a cypress.env.json
which contains a JWT that is created by calling firebase through firebase-tools (which requires either a service account or a CI token). cy.login
generated JWT to login.
The tests in fireadmin use Firestore including cy.callFirestore
, so those may be a good reference. That said,
from cypress-firebase.
I have a cypress.env.json
and I call cypress-firebase createTestEnv
before running tests. If cy.login()
handles the user's auth for the current user then maybe that is the missing piece.
When calling cy.login()
in a before hook on my tests, the before hook fails and when I print the message to the console in the Cypress runner, I see the error: Error: Your API key is invalid, please check you have copied it correctly.
The API key which is set in cypress/config.json
is already successfully used to seed and clean up our Firestore database. Where is this error coming from? It would be helpful to see where exactly the error is being thrown so I could diagnose the issue.
from cypress-firebase.
The API key that is used from cypress/config.json
is for the front end sdk, so if you have provided a CI token (can be used to auth for seeding/verifying database in place of a service account). As shown in the setup section, the config gets passed to firebase.initializeApp
inside of your cypress commands file - this is most likley where the error is being thrown. This would be the API key from the Firebase console, not from running firebase login:ci
. Hope this clarifies?
Something else to note: If you CLI is already authed, adding a token for verifying/seeding may not be needed
from cypress-firebase.
After further investigating, it appears fbInstance was successfully assigned to a window, just not the window we need it to be assigned to. In Chrome dev tools console in the Cypress runner window, it looks like there are 3 context layers: application - Cypress - spec.
Executing window.fbInstance
on the app context and the Cypress context yields undefined
, while doing the same on spec context yields the fbInstance object as expected. So the app itself is not connected to a firebase instance and therefore isn't loading any of the data we need. Is this the same behavior in your experience?
from cypress-firebase.
I don't believe we have experienced this issue yet and have been able to authenticate correctly - let me try to replicate and see if I am maybe missing something.
Clearly not a great long term solution, but another method that may work for you is passing the generated auth token to the sessionStorage and having your application login using the token if available in sessionStorage.
from cypress-firebase.
@travwritescode did you manage to fix this issue? I'm encountering the same issue.
from cypress-firebase.
This was also reported in #84 - closed that in favor of discussing here. Last time I tried I still wasn't able to reproduce in any of my applications, so if someone could provide a repo where this can be reproduced, that would be awesome. Would really love to figure out the cause of this one
from cypress-firebase.
Thank you for the effort, really appreciate it.
I 'happen to have' an example repo, namely my repo of the original thread :)
Link to repo
from cypress-firebase.
@prescottprue managed to reproduce the issue?
from cypress-firebase.
I have reproduced - it actually seems like you don't need to look for the shared instance at all. The initialized Firebase instance passed into Cypress ends up being shared with the instance initialized within the app. I am planning on updating the docs, but is this what you are seeing?
So if you try to call cy.login
you receive an error? What is the wording exactly?
from cypress-firebase.
Usage of window has been removed from the setup since it apparently isn't needed - are you still experiencing the error?
from cypress-firebase.
from cypress-firebase.
Thanks to all for reporting! Usage of window is no longer part of the setup. If this is still being experienced could we open a new issue with a repro of this not working with angularfire
from cypress-firebase.
Related Issues (20)
- publish-npm failing Error: Error [ERR_REQUIRE_ESM]: require() of ES Module HOT 1
- bug: cannot read properties of undefined (reading 'includes') HOT 4
- Login after a logout happening the application fails
- Cypress e2e test fails initialization HOT 1
- feat(build): native esm support
- fix: drop support for node pre 16 HOT 2
- Support passing user claims to cy.login() ? HOT 1
- Invalid options types are ignored, rather than erroring
- The automated release is failing 🚨
- Cypress Firebase in Github Actions cannot find `CYPRESS_TEST_UID` from secrets.CYPRESS_TEST_UID HOT 1
- Retry on 401
- bug(firestore): FieldValue.delete() not handled correctly HOT 3
- feat(callFirestore): ability to use batch writes
- bug(firestore): nested Timestamp value not persisting HOT 3
- bug: callFirestore not recognized in NextJS test HOT 1
- feat: support for component testing
- feat: switch to modular firebase sdks internally HOT 2
- bug(core): Webpack error when running cypress tests with cypress-firebase HOT 10
- callFirestore task fails when running in the CI with message "PERMISSION_DENIED: Missing or insufficient permissions." HOT 1
- Problem with Token HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cypress-firebase.