Skip to content

Commit

Permalink
v1.1.0 (#117)
Browse files Browse the repository at this point in the history
* fix(core): use GCLOUD_PROJECT as default project when not using emulator
  • Loading branch information
prescottprue authored Apr 12, 2020
1 parent f0a1d20 commit 7f252c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cypress-firebase",
"version": "1.0.0",
"version": "1.1.0",
"description": "Utilities to help testing Firebase projects with Cypress.",
"main": "lib/index.js",
"module": "lib/index.js",
Expand Down
23 changes: 16 additions & 7 deletions src/firebase-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,35 @@ export function initializeFirebase(adminInstance: any): admin.app.App {
} else {
// Get service account from local file falling back to environment variables
const serviceAccount = getServiceAccount();
const projectId = serviceAccount?.project_id;
const projectId =
process.env.GCLOUD_PROJECT || serviceAccount?.project_id;
if (!isString(projectId)) {
const missingProjectIdErr =
'Error project_id from service account to initialize Firebase.';
'Error GCLOUD_PROJECT environment variable or project_id from service account to initialize Firebase.';
console.error(`cypress-firebase: ${missingProjectIdErr}`); // eslint-disable-line no-console
throw new Error(missingProjectIdErr);
}
const cleanProjectId = (projectId as string).replace(
'firebase-top-agent-int',
'top-agent-int',
);

const appSettings: any = {
databaseURL: `https://${cleanProjectId}.firebaseio.com`,
};

if (serviceAccount) {
appSettings.credential = adminInstance.credential.cert(
serviceAccount as any,
);
}

fbInstance = adminInstance.initializeApp(appSettings);
/* eslint-disable no-console */
console.log(
`cypress-firebase: Initialized with Service Account for project "${cleanProjectId}"`,
`cypress-firebase: Initialized app with project "${cleanProjectId}"`,
);
/* eslint-enable no-console */
fbInstance = adminInstance.initializeApp({
credential: adminInstance.credential.cert(serviceAccount as any),
databaseURL: `https://${cleanProjectId}.firebaseio.com`,
});
}

return fbInstance;
Expand Down

0 comments on commit 7f252c0

Please sign in to comment.