@@ -2,7 +2,7 @@ import admin from "firebase-admin";
22import  {  timeout  }  from  "../utils" ; 
33import  {  initializeFirebase  }  from  "../firebaseSetup" ; 
44
5- describe ( "Cloud Firestore (v2) " ,  ( )  =>  { 
5+ describe ( "Cloud Firestore" ,  ( )  =>  { 
66  const  projectId  =  process . env . PROJECT_ID ; 
77  const  testId  =  process . env . TEST_RUN_ID ; 
88
@@ -12,7 +12,8 @@ describe("Cloud Firestore (v2)", () => {
1212
1313  beforeAll ( async  ( )  =>  { 
1414    await  initializeFirebase ( ) ; 
15-   } ) ; 
15+     await  timeout ( 120_000 ) 
16+   } ,  200_000 ) ; 
1617
1718  afterAll ( async  ( )  =>  { 
1819    await  admin 
@@ -35,6 +36,7 @@ describe("Cloud Firestore (v2)", () => {
3536      . collection ( "firestoreOnDocumentWrittenTests" ) 
3637      . doc ( testId ) 
3738      . delete ( ) ; 
39+     await  admin . firestore ( ) . collection ( "tests" ) . doc ( testId ) . delete ( ) ; 
3840  } ) ; 
3941
4042  describe ( "Document created trigger" ,  ( )  =>  { 
@@ -47,19 +49,25 @@ describe("Cloud Firestore (v2)", () => {
4749      await  docRef . set ( {  test : testId  } ) ; 
4850      dataSnapshot  =  await  docRef . get ( ) ; 
4951
50-       await   timeout ( 20000 ) ; 
52+       let   retry   =   0 ; 
5153
52-       const  logSnapshot  =  await  admin 
53-         . firestore ( ) 
54-         . collection ( "firestoreOnDocumentCreatedTests" ) 
55-         . doc ( testId ) 
56-         . get ( ) ; 
57-       loggedContext  =  logSnapshot . data ( ) ; 
54+       while  ( retry  <  10 )  { 
55+         const  logSnapshot  =  await  admin 
56+           . firestore ( ) 
57+           . collection ( "firestoreOnDocumentCreatedTests" ) 
58+           . doc ( testId ) 
59+           . get ( ) ; 
60+         loggedContext  =  logSnapshot . data ( ) ; 
61+ 
62+         if  ( loggedContext )  break ; 
63+         await  timeout ( 5000 ) ; 
64+         retry ++ ; 
65+       } 
5866
5967      if  ( ! loggedContext )  { 
6068        throw  new  Error ( "loggedContext is undefined" ) ; 
6169      } 
62-     } ) ; 
70+     } ,   60000 ) ; 
6371
6472    it ( "should not have event.app" ,  ( )  =>  { 
6573      expect ( loggedContext ?. app ) . toBeUndefined ( ) ; 
@@ -72,13 +80,13 @@ describe("Cloud Firestore (v2)", () => {
7280
7381    it ( "should have well-formed resource" ,  ( )  =>  { 
7482      expect ( loggedContext ?. source ) . toMatch ( 
75-         `//firestore.googleapis.com/projects/${ projectId }  
83+         `//firestore.googleapis.com/projects/${ projectId }  , 
7684      ) ; 
7785    } ) ; 
7886
7987    it ( "should have the correct type" ,  ( )  =>  { 
8088      expect ( loggedContext ?. type ) . toEqual ( 
81-         "google.cloud.firestore.document.v1.created" 
89+         "google.cloud.firestore.document.v1.created" , 
8290      ) ; 
8391    } ) ; 
8492
@@ -122,21 +130,21 @@ describe("Cloud Firestore (v2)", () => {
122130      if  ( ! loggedContext )  { 
123131        throw  new  Error ( "loggedContext is undefined" ) ; 
124132      } 
125-     } ) ; 
133+     } ,   60000 ) ; 
126134
127135    it ( "should not have event.app" ,  ( )  =>  { 
128136      expect ( loggedContext ?. app ) . toBeUndefined ( ) ; 
129137    } ) ; 
130138
131139    it ( "should have well-formed source" ,  ( )  =>  { 
132140      expect ( loggedContext ?. source ) . toMatch ( 
133-         `//firestore.googleapis.com/projects/${ projectId }  
141+         `//firestore.googleapis.com/projects/${ projectId }  , 
134142      ) ; 
135143    } ) ; 
136144
137145    it ( "should have the correct type" ,  ( )  =>  { 
138146      expect ( loggedContext ?. type ) . toEqual ( 
139-         "google.cloud.firestore.document.v1.deleted" 
147+         "google.cloud.firestore.document.v1.deleted" , 
140148      ) ; 
141149    } ) ; 
142150
@@ -165,36 +173,42 @@ describe("Cloud Firestore (v2)", () => {
165173
166174      await  docRef . update ( {  test : testId  } ) ; 
167175
168-       await  timeout ( 20000 ) ; 
169- 
170176      // Refresh snapshot 
171177      dataSnapshot  =  await  docRef . get ( ) ; 
172178
173-       const  logSnapshot  =  await  admin 
174-         . firestore ( ) 
175-         . collection ( "firestoreOnDocumentUpdatedTests" ) 
176-         . doc ( testId ) 
177-         . get ( ) ; 
178-       loggedContext  =  logSnapshot . data ( ) ; 
179+       let  retry  =  0 ; 
180+ 
181+       while  ( retry  <  10 )  { 
182+         const  logSnapshot  =  await  admin 
183+           . firestore ( ) 
184+           . collection ( "firestoreOnDocumentUpdatedTests" ) 
185+           . doc ( testId ) 
186+           . get ( ) ; 
187+         loggedContext  =  logSnapshot . data ( ) ; 
188+ 
189+         if  ( loggedContext )  break ; 
190+         await  timeout ( 5000 ) ; 
191+         retry ++ ; 
192+       } 
179193
180194      if  ( ! loggedContext )  { 
181195        throw  new  Error ( "loggedContext is undefined" ) ; 
182196      } 
183-     } ) ; 
197+     } ,   60000 ) ; 
184198
185199    it ( "should not have event.app" ,  ( )  =>  { 
186200      expect ( loggedContext ?. app ) . toBeUndefined ( ) ; 
187201    } ) ; 
188202
189203    it ( "should have well-formed resource" ,  ( )  =>  { 
190204      expect ( loggedContext ?. source ) . toMatch ( 
191-         `//firestore.googleapis.com/projects/${ projectId }  
205+         `//firestore.googleapis.com/projects/${ projectId }  , 
192206      ) ; 
193207    } ) ; 
194208
195209    it ( "should have the correct type" ,  ( )  =>  { 
196210      expect ( loggedContext ?. type ) . toEqual ( 
197-         "google.cloud.firestore.document.v1.updated" 
211+         "google.cloud.firestore.document.v1.updated" , 
198212      ) ; 
199213    } ) ; 
200214
@@ -223,12 +237,20 @@ describe("Cloud Firestore (v2)", () => {
223237
224238      await  timeout ( 20000 ) ; 
225239
226-       const  logSnapshot  =  await  admin 
227-         . firestore ( ) 
228-         . collection ( "firestoreOnDocumentWrittenTests" ) 
229-         . doc ( testId ) 
230-         . get ( ) ; 
231-       loggedContext  =  logSnapshot . data ( ) ; 
240+       let  retry  =  0 ; 
241+ 
242+       while  ( retry  <  10 )  { 
243+         const  logSnapshot  =  await  admin 
244+           . firestore ( ) 
245+           . collection ( "firestoreOnDocumentWrittenTests" ) 
246+           . doc ( testId ) 
247+           . get ( ) ; 
248+         loggedContext  =  logSnapshot . data ( ) ; 
249+ 
250+         if  ( loggedContext )  break ; 
251+         await  timeout ( 5000 ) ; 
252+         retry ++ ; 
253+       } 
232254
233255      if  ( ! loggedContext )  { 
234256        throw  new  Error ( "loggedContext is undefined" ) ; 
@@ -246,13 +268,13 @@ describe("Cloud Firestore (v2)", () => {
246268
247269    it ( "should have well-formed resource" ,  ( )  =>  { 
248270      expect ( loggedContext ?. source ) . toMatch ( 
249-         `//firestore.googleapis.com/projects/${ projectId }  
271+         `//firestore.googleapis.com/projects/${ projectId }  , 
250272      ) ; 
251273    } ) ; 
252274
253275    it ( "should have the correct type" ,  ( )  =>  { 
254276      expect ( loggedContext ?. type ) . toEqual ( 
255-         "google.cloud.firestore.document.v1.written" 
277+         "google.cloud.firestore.document.v1.written" , 
256278      ) ; 
257279    } ) ; 
258280
0 commit comments