cypress-firebase icon indicating copy to clipboard operation
cypress-firebase copied to clipboard

Problem with Token

Open bartyx1993 opened this issue 2 years ago • 2 comments

I am trying to write a test for my firebase based login. In the first instance I installed the version 2.2.5 as suggested here #788.

Following the documentation I have my serviceAccount.json and cypress.config.ts in the project root.

Some code snippet here:

cypress.config.ts

import { defineConfig } from "cypress";
import adimn from "firebase-admin";
import { plugin as cypressFirebasePlugin } from "cypress-firebase";

export default defineConfig({
  e2e: {
    baseUrl: "http://localhost:3000",
    setupNodeEvents(on, config) {
      return cypressFirebasePlugin(on, config, adimn);
    },
  },
});

cypress/support/command.ts

import firebase from "firebase/compat/app";
import "firebase/compat/auth";
import "firebase/compat/database";
import "firebase/compat/firestore";
import { attachCustomCommands } from "cypress-firebase";

const fbConfig = {
  // my configuration
};

const namedApp = firebase.initializeApp(fbConfig, "my_app_name");
attachCustomCommands({ Cypress, cy, firebase, app: namedApp });

I wrote two tests. The first is the one suggested by the documentation to confirm things are working:

cypress/e2e/hello-firebase.cy.js

describe("Some Test", () => {
  it("Adds document to test_hello_world collection of Firestore", () => {
    cy.callFirestore("add", "test_hello_world", { some: "value" });
  });
});

And here everything works as expected.

cypress/e2e/test-login.cy.js

describe("Home", () => {
  it("login and view listof people", () => {
    cy.visit("/login");
    cy.login("MY_USER_ID");
    cy.get('[data-cy="submit"]').click();

    // get something in page
  });
});

This snippet run without runtime error but doesn't work as i expect because i'm not logging into the system. The problem i encountered is that the token is never set, instead the user does, inside the local storage.

Screen of the test execution:

Screenshot 2023-04-26 alle 15 34 04

Screen of the local storage contents:

Screenshot 2023-04-26 alle 15 37 21

Packages version:

"firebase": "^9.20.0", "firebase-admin": "^11.7.0", "cypress": "^12.10.0", "cypress-firebase": "2.2.5"

bartyx1993 avatar Apr 26 '23 13:04 bartyx1993

@bartyx1993 did you find a solution or the root cause for this?

ghost avatar May 04 '23 00:05 ghost

@bartyx1993 did you find a solution or the root cause for this?

No I'm sorry.

bartyx1993 avatar May 17 '23 08:05 bartyx1993