cypress-firebase
cypress-firebase copied to clipboard
Cypress V10 - Unable to detect a Project Id in the current environment
Describe the bug
I am doing this in a clean installation of cypress V10.1.0 and cypress-firebase V2.2.1.
I have went through all the steps described on the readme file to execute a simple test on firestore, but unfortunatelly I keep getting the error:
cy.task('callFirestore') failed with the following error: Unable to detect a Project Id in the current environment.
I am trying to reach my own firebase project. (First screenshot)
The same is true if I try to execute the example code provided in cypress-firebase, but I get a slight different error:
cy.task('callFirestore') failed with the following error: Could not load the default credentials.
(Second screenshot)
To Reproduce Steps to reproduce the behavior:
Main problem: Implement the code described on the Readme file in section "Setup" Connect it to your won firebase project with your credentials.
Secondary problem
- On the cypress-firebase code
- go to examples/basic
- run: yarn test:open
- run Firestore tests
Expected behavior/code The test would execute and pass.
Additional Context/Screenshots
First:
Second:
@prescottprue, in theory I don't need a serviceAccount.json to be able to connect to firestore, correct? In the readme file that's not clear. (I will make some suggestions to the Readme file with a PR when I get this to work :) )
Anyway I tried adding a serviceAccount.json to my root folder and I still get the same error. Thank you.
Could you provide the cypress.config.ts/js from your project?
Of course!
import admin from "firebase-admin";
import { defineConfig } from "cypress";
import { plugin as cypressFirebasePlugin } from "cypress-firebase";
const cypressConfig = defineConfig({
e2e: {
baseUrl: "http://localhost:3000",
supportFile: "cypress/support/e2e.ts",
experimentalSessionAndOrigin: true,
setupNodeEvents(on, config) {
cypressFirebasePlugin(on, config, admin);
// e2e testing node events setup code
}
}
});
export default cypressConfig;
cypress/support/e2e.ts :
import "./commands";
cypress/support/commands.ts
/// <reference types="cypress" />
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 = {
apiKey: Cypress.env("REACT_APP_FIREBASE_API_KEY"),
authDomain: Cypress.env("REACT_APP_FIREBASE_AUTH_DOMAIN"),
databaseURL: Cypress.env("REACT_APP_FIREBASE_DATABASE_URL"),
projectId: Cypress.env("REACT_APP_FIREBASE_PROJECT_ID"),
storageBucket: Cypress.env("REACT_APP_FIREBASE_STORAGE_BUCKET"),
messagingSenderId: Cypress.env("REACT_APP_FIREBASE_MESSAGING_SENDER_ID"),
appId: Cypress.env("REACT_APP_FIREBASE_APP_ID"),
measurementId: Cypress.env("REACT_APP_FIREBASE_MEASUREMENT_I")
};
firebase.initializeApp(fbConfig);
attachCustomCommands({ Cypress, cy, firebase });
Thank you a lot for the help.
What worked for me was setting a project ID when registering the node events like so:
cypressFirebasePlugin(on, config, admin, { projectId: "PROJECT_ID_FROM_CONFIG", });
Oh, nice! It also worked for me. Thank you so much.
Then I got the error:
Could not load the default credentials.
But I solved it by adding to those optional parameters:
credential: admin.credential.cert(require("../../serviceAccount.json"))
Anyway I feel there is a problem with the package, since using the override you suggest should be optional, no?
@pedrocarloto I would agree that this is still an issue that there is not clear messaging from the lib or documentation about it. Default credentials should be automatically used if they are available (i.e. GOOGLE_APPLICATION_CREDENTIALS
environment variable points to the path instead of you requiring directly like you did) - or if in Github actions than the gcloud steps export default credentials
What worked for me was setting a project ID when registering the node events like so:
cypressFirebasePlugin(on, config, admin, { projectId: "PROJECT_ID_FROM_CONFIG", });
FYI this solved my (not working cy.callFirestore('update')
) issue https://github.com/prescottprue/cypress-firebase/issues/345#issuecomment-1284632330 🙏
:tada: This issue has been resolved in version 2.2.4 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
:tada: This issue has been resolved in version 2.3.0-alpha.2 :tada:
The release is available on:
Your semantic-release bot :package::rocket: