From f527ebb26231ad1992a74c5a14a02f81abfe4497 Mon Sep 17 00:00:00 2001 From: Scott Prue Date: Mon, 23 Mar 2020 12:46:01 -0400 Subject: [PATCH] v1.0.0-beta.2 (#106) * fix(core): prevent initializeApp from being called multiple times when using emulators * build(deps): bump acorn from 7.1.0 to 7.1.1 (#103) - @dependabot * build(deps): bump acorn in /examples/react-redux-firebase (#105) - @dependabot Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- examples/react-redux-firebase/yarn.lock | 5 +-- examples/typescript/yarn.lock | 6 ++-- package.json | 2 +- src/firebase-utils.ts | 48 +++++++++++++------------ 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/examples/react-redux-firebase/yarn.lock b/examples/react-redux-firebase/yarn.lock index 248354df..809254b4 100644 --- a/examples/react-redux-firebase/yarn.lock +++ b/examples/react-redux-firebase/yarn.lock @@ -1405,8 +1405,9 @@ acorn-walk@^6.0.1: resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-6.1.0.tgz#c957f4a1460da46af4a0388ce28b4c99355b0cbc" acorn@^5.0.0, acorn@^5.0.3, acorn@^5.5.3, acorn@^5.6.0, acorn@^5.6.2: - version "5.7.3" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.3.tgz#67aa231bf8812974b85235a96771eb6bd07ea279" + version "5.7.4" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.4.tgz#3e8d8a9947d0599a1796d10225d7432f4a4acf5e" + integrity sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg== acorn@^6.0.1, acorn@^6.0.2: version "6.0.2" diff --git a/examples/typescript/yarn.lock b/examples/typescript/yarn.lock index b924186e..9fe1224c 100644 --- a/examples/typescript/yarn.lock +++ b/examples/typescript/yarn.lock @@ -1984,9 +1984,9 @@ acorn-walk@^6.0.1: integrity sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA== acorn@^5.5.3: - version "5.7.3" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.3.tgz#67aa231bf8812974b85235a96771eb6bd07ea279" - integrity sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw== + version "5.7.4" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.4.tgz#3e8d8a9947d0599a1796d10225d7432f4a4acf5e" + integrity sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg== acorn@^6.0.1, acorn@^6.0.4, acorn@^6.2.1: version "6.3.0" diff --git a/package.json b/package.json index e8c89dc3..5f049863 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cypress-firebase", - "version": "1.0.0-beta", + "version": "1.0.0-beta.2", "description": "Utilities to help testing Firebase projects with Cypress.", "main": "lib/index.js", "module": "lib/index.js", diff --git a/src/firebase-utils.ts b/src/firebase-utils.ts index a7bc1627..9a9bb646 100644 --- a/src/firebase-utils.ts +++ b/src/firebase-utils.ts @@ -96,35 +96,37 @@ export function initializeFirebase(adminInstance: any): admin.app.App { /* eslint-enable no-console */ adminInstance.firestore().settings(firestoreSettings); } + } else { + // Get service account from local file falling back to environment variables + const serviceAccount = getServiceAccount(); + const projectId = serviceAccount?.project_id; + if (!isString(projectId)) { + const missingProjectIdErr = + 'Error 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', + ); + /* eslint-disable no-console */ + console.log( + `cypress-firebase: Initialized with Service Account for project "${cleanProjectId}"`, + ); + /* eslint-enable no-console */ + fbInstance = adminInstance.initializeApp({ + credential: adminInstance.credential.cert(serviceAccount as any), + databaseURL: `https://${cleanProjectId}.firebaseio.com`, + }); } - // Get service account from local file falling back to environment variables - const serviceAccount = getServiceAccount(); - const projectId = serviceAccount?.project_id; - if (!isString(projectId)) { - const missingProjectIdErr = - 'Error 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', - ); - /* eslint-disable no-console */ - console.log( - `cypress-firebase: Initialized with Service Account for project "${cleanProjectId}"`, - ); - /* eslint-enable no-console */ - fbInstance = adminInstance.initializeApp({ - credential: adminInstance.credential.cert(serviceAccount as any), - databaseURL: `https://${cleanProjectId}.firebaseio.com`, - }); return fbInstance; } catch (err) { /* eslint-disable no-console */ console.error( - 'cypress-firebase: Error initializing firebase-admin instance from service account.', + 'cypress-firebase: Error initializing firebase-admin instance:', + err.message, ); /* eslint-enable no-console */ throw err;