Code Monkey home page Code Monkey logo

Comments (14)

jwbaart avatar jwbaart commented on June 12, 2024 1

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.

prescottprue avatar prescottprue commented on June 12, 2024

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.

travwritescode avatar travwritescode commented on June 12, 2024

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.

prescottprue avatar prescottprue commented on June 12, 2024

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.

travwritescode avatar travwritescode commented on June 12, 2024

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.

image

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.

prescottprue avatar prescottprue commented on June 12, 2024

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.

jwbaart avatar jwbaart commented on June 12, 2024

@travwritescode did you manage to fix this issue? I'm encountering the same issue.

from cypress-firebase.

prescottprue avatar prescottprue commented on June 12, 2024

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.

jwbaart avatar jwbaart commented on June 12, 2024

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.

jwbaart avatar jwbaart commented on June 12, 2024

@prescottprue managed to reproduce the issue?

from cypress-firebase.

prescottprue avatar prescottprue commented on June 12, 2024

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.

prescottprue avatar prescottprue commented on June 12, 2024

Usage of window has been removed from the setup since it apparently isn't needed - are you still experiencing the error?

from cypress-firebase.

jwbaart avatar jwbaart commented on June 12, 2024

from cypress-firebase.

prescottprue avatar prescottprue commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.