11const debug = require ( 'debug' ) ( 'firestore-snippets-node' ) ;
22
33// [START firestore_deps]
4+ // [START firestore_setup_client_create]
45const admin = require ( 'firebase-admin' ) ;
56// [END firestore_deps]
7+ // [END firestore_setup_client_create]
8+
69
710// We supress these logs when not in NODE_ENV=debug for cleaner Mocha output
811const console = { log : debug } ;
912
13+ async function initializeAppWithProjectId ( ) {
14+ // [START firestore_setup_client_create]
15+ admin . initializeApp ( {
16+ // The `projectId` parameter is optional and represents which project the
17+ // client will act on behalf of. If not supplied, it falls back to the default
18+ // project inferred from the environment.
19+ projectId : 'my-project-id' ,
20+ } ) ;
21+ const db = admin . firestore ( ) ;
22+ // [END firestore_setup_client_create]
23+ return db ;
24+ }
25+
1026async function initializeApp ( ) {
1127 process . env . GCLOUD_PROJECT = 'firestorebeta1test2' ;
1228 // [START initialize_app]
@@ -17,6 +33,8 @@ async function initializeApp() {
1733
1834 const db = admin . firestore ( ) ;
1935 // [END initialize_app]
36+ await db . terminate ( ) ;
37+ // Destroy connection so we can run other tests that initialize the default app.
2038 return db ;
2139}
2240
@@ -944,8 +962,12 @@ async function deleteQueryBatch(db, query, resolve) {
944962
945963describe ( 'Firestore Smoketests' , ( ) => {
946964
947- admin . initializeApp ( ) ;
948- const db = admin . firestore ( ) ;
965+ const app = admin . initializeApp ( { } , 'tests' ) ;
966+ const db = admin . firestore ( app ) ;
967+
968+ it ( 'should initialize a db with the default credential' , ( ) => {
969+ return initializeApp ( ) ;
970+ } ) ;
949971
950972 it ( 'should get an empty document' , ( ) => {
951973 return getDocumentEmpty ( db ) ;
0 commit comments