Skip to content

Commit 7f252c0

Browse files
authored
v1.1.0 (#117)
* fix(core): use GCLOUD_PROJECT as default project when not using emulator
1 parent f0a1d20 commit 7f252c0

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cypress-firebase",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Utilities to help testing Firebase projects with Cypress.",
55
"main": "lib/index.js",
66
"module": "lib/index.js",

src/firebase-utils.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -100,26 +100,35 @@ export function initializeFirebase(adminInstance: any): admin.app.App {
100100
} else {
101101
// Get service account from local file falling back to environment variables
102102
const serviceAccount = getServiceAccount();
103-
const projectId = serviceAccount?.project_id;
103+
const projectId =
104+
process.env.GCLOUD_PROJECT || serviceAccount?.project_id;
104105
if (!isString(projectId)) {
105106
const missingProjectIdErr =
106-
'Error project_id from service account to initialize Firebase.';
107+
'Error GCLOUD_PROJECT environment variable or project_id from service account to initialize Firebase.';
107108
console.error(`cypress-firebase: ${missingProjectIdErr}`); // eslint-disable-line no-console
108109
throw new Error(missingProjectIdErr);
109110
}
110111
const cleanProjectId = (projectId as string).replace(
111112
'firebase-top-agent-int',
112113
'top-agent-int',
113114
);
115+
116+
const appSettings: any = {
117+
databaseURL: `https://${cleanProjectId}.firebaseio.com`,
118+
};
119+
120+
if (serviceAccount) {
121+
appSettings.credential = adminInstance.credential.cert(
122+
serviceAccount as any,
123+
);
124+
}
125+
126+
fbInstance = adminInstance.initializeApp(appSettings);
114127
/* eslint-disable no-console */
115128
console.log(
116-
`cypress-firebase: Initialized with Service Account for project "${cleanProjectId}"`,
129+
`cypress-firebase: Initialized app with project "${cleanProjectId}"`,
117130
);
118131
/* eslint-enable no-console */
119-
fbInstance = adminInstance.initializeApp({
120-
credential: adminInstance.credential.cert(serviceAccount as any),
121-
databaseURL: `https://${cleanProjectId}.firebaseio.com`,
122-
});
123132
}
124133

125134
return fbInstance;

0 commit comments

Comments
 (0)