@@ -2,7 +2,7 @@ import admin from "firebase-admin";
2
2
import { timeout } from "../utils" ;
3
3
import { initializeFirebase } from "../firebaseSetup" ;
4
4
5
- describe ( "Cloud Firestore (v2) " , ( ) => {
5
+ describe ( "Cloud Firestore" , ( ) => {
6
6
const projectId = process . env . PROJECT_ID ;
7
7
const testId = process . env . TEST_RUN_ID ;
8
8
@@ -12,7 +12,8 @@ describe("Cloud Firestore (v2)", () => {
12
12
13
13
beforeAll ( async ( ) => {
14
14
await initializeFirebase ( ) ;
15
- } ) ;
15
+ await timeout ( 120_000 )
16
+ } , 200_000 ) ;
16
17
17
18
afterAll ( async ( ) => {
18
19
await admin
@@ -35,6 +36,7 @@ describe("Cloud Firestore (v2)", () => {
35
36
. collection ( "firestoreOnDocumentWrittenTests" )
36
37
. doc ( testId )
37
38
. delete ( ) ;
39
+ await admin . firestore ( ) . collection ( "tests" ) . doc ( testId ) . delete ( ) ;
38
40
} ) ;
39
41
40
42
describe ( "Document created trigger" , ( ) => {
@@ -47,19 +49,25 @@ describe("Cloud Firestore (v2)", () => {
47
49
await docRef . set ( { test : testId } ) ;
48
50
dataSnapshot = await docRef . get ( ) ;
49
51
50
- await timeout ( 20000 ) ;
52
+ let retry = 0 ;
51
53
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
+ }
58
66
59
67
if ( ! loggedContext ) {
60
68
throw new Error ( "loggedContext is undefined" ) ;
61
69
}
62
- } ) ;
70
+ } , 60000 ) ;
63
71
64
72
it ( "should not have event.app" , ( ) => {
65
73
expect ( loggedContext ?. app ) . toBeUndefined ( ) ;
@@ -72,13 +80,13 @@ describe("Cloud Firestore (v2)", () => {
72
80
73
81
it ( "should have well-formed resource" , ( ) => {
74
82
expect ( loggedContext ?. source ) . toMatch (
75
- `//firestore.googleapis.com/projects/${ projectId } /databases/(default)`
83
+ `//firestore.googleapis.com/projects/${ projectId } /databases/(default)` ,
76
84
) ;
77
85
} ) ;
78
86
79
87
it ( "should have the correct type" , ( ) => {
80
88
expect ( loggedContext ?. type ) . toEqual (
81
- "google.cloud.firestore.document.v1.created"
89
+ "google.cloud.firestore.document.v1.created" ,
82
90
) ;
83
91
} ) ;
84
92
@@ -122,21 +130,21 @@ describe("Cloud Firestore (v2)", () => {
122
130
if ( ! loggedContext ) {
123
131
throw new Error ( "loggedContext is undefined" ) ;
124
132
}
125
- } ) ;
133
+ } , 60000 ) ;
126
134
127
135
it ( "should not have event.app" , ( ) => {
128
136
expect ( loggedContext ?. app ) . toBeUndefined ( ) ;
129
137
} ) ;
130
138
131
139
it ( "should have well-formed source" , ( ) => {
132
140
expect ( loggedContext ?. source ) . toMatch (
133
- `//firestore.googleapis.com/projects/${ projectId } /databases/(default)`
141
+ `//firestore.googleapis.com/projects/${ projectId } /databases/(default)` ,
134
142
) ;
135
143
} ) ;
136
144
137
145
it ( "should have the correct type" , ( ) => {
138
146
expect ( loggedContext ?. type ) . toEqual (
139
- "google.cloud.firestore.document.v1.deleted"
147
+ "google.cloud.firestore.document.v1.deleted" ,
140
148
) ;
141
149
} ) ;
142
150
@@ -165,36 +173,42 @@ describe("Cloud Firestore (v2)", () => {
165
173
166
174
await docRef . update ( { test : testId } ) ;
167
175
168
- await timeout ( 20000 ) ;
169
-
170
176
// Refresh snapshot
171
177
dataSnapshot = await docRef . get ( ) ;
172
178
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
+ }
179
193
180
194
if ( ! loggedContext ) {
181
195
throw new Error ( "loggedContext is undefined" ) ;
182
196
}
183
- } ) ;
197
+ } , 60000 ) ;
184
198
185
199
it ( "should not have event.app" , ( ) => {
186
200
expect ( loggedContext ?. app ) . toBeUndefined ( ) ;
187
201
} ) ;
188
202
189
203
it ( "should have well-formed resource" , ( ) => {
190
204
expect ( loggedContext ?. source ) . toMatch (
191
- `//firestore.googleapis.com/projects/${ projectId } /databases/(default)`
205
+ `//firestore.googleapis.com/projects/${ projectId } /databases/(default)` ,
192
206
) ;
193
207
} ) ;
194
208
195
209
it ( "should have the correct type" , ( ) => {
196
210
expect ( loggedContext ?. type ) . toEqual (
197
- "google.cloud.firestore.document.v1.updated"
211
+ "google.cloud.firestore.document.v1.updated" ,
198
212
) ;
199
213
} ) ;
200
214
@@ -223,12 +237,20 @@ describe("Cloud Firestore (v2)", () => {
223
237
224
238
await timeout ( 20000 ) ;
225
239
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
+ }
232
254
233
255
if ( ! loggedContext ) {
234
256
throw new Error ( "loggedContext is undefined" ) ;
@@ -246,13 +268,13 @@ describe("Cloud Firestore (v2)", () => {
246
268
247
269
it ( "should have well-formed resource" , ( ) => {
248
270
expect ( loggedContext ?. source ) . toMatch (
249
- `//firestore.googleapis.com/projects/${ projectId } /databases/(default)`
271
+ `//firestore.googleapis.com/projects/${ projectId } /databases/(default)` ,
250
272
) ;
251
273
} ) ;
252
274
253
275
it ( "should have the correct type" , ( ) => {
254
276
expect ( loggedContext ?. type ) . toEqual (
255
- "google.cloud.firestore.document.v1.written"
277
+ "google.cloud.firestore.document.v1.written" ,
256
278
) ;
257
279
} ) ;
258
280
0 commit comments