0

i'm using React and Firebase to build an web app and i would like to use Cypress to do some end to end testing. I am new to Cypress. I'm trying to setup Cypress-Firebase NPM package but i'm getting errors. The documentation refers to service accounts but i want these records created in the firebase local emulator.

Here is my commands.js file in the support folder of e2e:

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

const firebaseConfig = {
  apiKey: "demo-key",
  authDomain: "demo-domain",
  projectId: "demo-project",
  storageBucket: "demo-project.appspot.com",
  appId: "demo-appId",
  messagingSenderId: "demo-id",
  measurementId: "demo-measurementId",
};

firebase.initializeApp(firebaseConfig)

attachCustomCommands({ Cypress, cy, firebase });

Then i created a plugin folder and a index.js file:

const admin = require("firebase-admin");
const cypressFirebasePlugin = require("cypress-firebase").plugin;

module.exports = (on, config) => {
  // Pass on function, config, and admin instance. Returns extended config
  return cypressFirebasePlugin(on, config, admin);
};

And the cypress.config.js:

const { defineConfig } = require("cypress");

module.exports = defineConfig({
  projectId: *,
  e2e: {
    baseUrl: "http://localhost:3000",
    setupNodeEvents(on, config) {
      return require("./cypress/plugins/index")(on, config);
    },
  },
});

The code i'm trying to execute is:

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

The error that i'm getting:

Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information

enter image description here

I have visited the links in the screenshot but i can't figure out what's wrong. Is the issue related to service accounts to authenticate? If so, why would they be important if you're working locally?

Any assistance would be appreciated.

0

Browse other questions tagged or ask your own question.