1
1
const debug = require ( 'debug' ) ( 'firestore-snippets-node' ) ;
2
2
3
3
// [START firestore_deps]
4
+ // [START firestore_setup_client_create]
4
5
const admin = require ( 'firebase-admin' ) ;
5
6
// [END firestore_deps]
7
+ // [END firestore_setup_client_create]
8
+
6
9
7
10
// We supress these logs when not in NODE_ENV=debug for cleaner Mocha output
8
11
const console = { log : debug } ;
9
12
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
+
10
26
async function initializeApp ( ) {
11
27
process . env . GCLOUD_PROJECT = 'firestorebeta1test2' ;
12
28
// [START initialize_app]
@@ -17,6 +33,8 @@ async function initializeApp() {
17
33
18
34
const db = admin . firestore ( ) ;
19
35
// [END initialize_app]
36
+ await db . terminate ( ) ;
37
+ // Destroy connection so we can run other tests that initialize the default app.
20
38
return db ;
21
39
}
22
40
@@ -944,8 +962,12 @@ async function deleteQueryBatch(db, query, resolve) {
944
962
945
963
describe ( 'Firestore Smoketests' , ( ) => {
946
964
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
+ } ) ;
949
971
950
972
it ( 'should get an empty document' , ( ) => {
951
973
return getDocumentEmpty ( db ) ;
0 commit comments