@@ -136,6 +136,13 @@ export class IndexedDbPersistenceMode implements PersistenceMode {
136
136
}
137
137
}
138
138
139
+ // An alternative to a `PersistenceMode` object that indicates that no
140
+ // persistence mode should be specified, and instead the implicit default
141
+ // should be used.
142
+ export const PERSISTENCE_MODE_UNSPECIFIED = Symbol (
143
+ 'PERSISTENCE_MODE_UNSPECIFIED'
144
+ ) ;
145
+
139
146
function isIeOrEdge ( ) : boolean {
140
147
if ( ! window . navigator ) {
141
148
return false ;
@@ -233,7 +240,7 @@ export function toIds(docSet: QuerySnapshot): string[] {
233
240
}
234
241
235
242
export function withTestDb (
236
- persistence : PersistenceMode ,
243
+ persistence : PersistenceMode | typeof PERSISTENCE_MODE_UNSPECIFIED ,
237
244
fn : ( db : Firestore ) => Promise < void >
238
245
) : Promise < void > {
239
246
return withTestDbs ( persistence , 1 , ( [ db ] ) => {
@@ -243,7 +250,7 @@ export function withTestDb(
243
250
244
251
/** Runs provided fn with a db for an alternate project id. */
245
252
export function withAlternateTestDb (
246
- persistence : PersistenceMode ,
253
+ persistence : PersistenceMode | typeof PERSISTENCE_MODE_UNSPECIFIED ,
247
254
fn : ( db : Firestore ) => Promise < void >
248
255
) : Promise < void > {
249
256
return withTestDbsSettings (
@@ -258,7 +265,7 @@ export function withAlternateTestDb(
258
265
}
259
266
260
267
export function withTestDbs (
261
- persistence : PersistenceMode ,
268
+ persistence : PersistenceMode | typeof PERSISTENCE_MODE_UNSPECIFIED ,
262
269
numDbs : number ,
263
270
fn : ( db : Firestore [ ] ) => Promise < void >
264
271
) : Promise < void > {
@@ -271,7 +278,7 @@ export function withTestDbs(
271
278
) ;
272
279
}
273
280
export async function withTestDbsSettings < T > (
274
- persistence : PersistenceMode ,
281
+ persistence : PersistenceMode | typeof PERSISTENCE_MODE_UNSPECIFIED ,
275
282
projectId : string ,
276
283
settings : PrivateSettings ,
277
284
numDbs : number ,
@@ -284,10 +291,10 @@ export async function withTestDbsSettings<T>(
284
291
const dbs : Firestore [ ] = [ ] ;
285
292
286
293
for ( let i = 0 ; i < numDbs ; i ++ ) {
287
- const newSettings = {
288
- ... settings ,
289
- localCache : persistence . asLocalCacheFirestoreSettings ( )
290
- } ;
294
+ const newSettings = { ... settings } ;
295
+ if ( persistence !== PERSISTENCE_MODE_UNSPECIFIED ) {
296
+ newSettings . localCache = persistence . asLocalCacheFirestoreSettings ( ) ;
297
+ }
291
298
const db = newTestFirestore ( newTestApp ( projectId ) , newSettings ) ;
292
299
dbs . push ( db ) ;
293
300
}
@@ -297,7 +304,10 @@ export async function withTestDbsSettings<T>(
297
304
} finally {
298
305
for ( const db of dbs ) {
299
306
await terminate ( db ) ;
300
- if ( persistence . storage === 'indexeddb' ) {
307
+ if (
308
+ persistence !== PERSISTENCE_MODE_UNSPECIFIED &&
309
+ persistence . storage === 'indexeddb'
310
+ ) {
301
311
await clearIndexedDbPersistence ( db ) ;
302
312
}
303
313
}
@@ -340,7 +350,7 @@ export async function withNamedTestDbsOrSkipUnlessUsingEmulator(
340
350
}
341
351
342
352
export function withTestDoc (
343
- persistence : PersistenceMode ,
353
+ persistence : PersistenceMode | typeof PERSISTENCE_MODE_UNSPECIFIED ,
344
354
fn : ( doc : DocumentReference , db : Firestore ) => Promise < void >
345
355
) : Promise < void > {
346
356
return withTestDb ( persistence , db => {
@@ -349,7 +359,7 @@ export function withTestDoc(
349
359
}
350
360
351
361
export function withTestDocAndSettings (
352
- persistence : PersistenceMode ,
362
+ persistence : PersistenceMode | typeof PERSISTENCE_MODE_UNSPECIFIED ,
353
363
settings : PrivateSettings ,
354
364
fn : ( doc : DocumentReference ) => Promise < void >
355
365
) : Promise < void > {
@@ -370,7 +380,7 @@ export function withTestDocAndSettings(
370
380
// `withTestDoc(..., docRef => { setDoc(docRef, initialData) ...});` that
371
381
// otherwise is quite common.
372
382
export function withTestDocAndInitialData (
373
- persistence : PersistenceMode ,
383
+ persistence : PersistenceMode | typeof PERSISTENCE_MODE_UNSPECIFIED ,
374
384
initialData : DocumentData | null ,
375
385
fn : ( doc : DocumentReference , db : Firestore ) => Promise < void >
376
386
) : Promise < void > {
@@ -405,15 +415,15 @@ export async function withRetry<T>(
405
415
}
406
416
407
417
export function withTestCollection < T > (
408
- persistence : PersistenceMode ,
418
+ persistence : PersistenceMode | typeof PERSISTENCE_MODE_UNSPECIFIED ,
409
419
docs : { [ key : string ] : DocumentData } ,
410
420
fn : ( collection : CollectionReference , db : Firestore ) => Promise < T >
411
421
) : Promise < T > {
412
422
return withTestCollectionSettings ( persistence , DEFAULT_SETTINGS , docs , fn ) ;
413
423
}
414
424
415
425
export function withEmptyTestCollection (
416
- persistence : PersistenceMode ,
426
+ persistence : PersistenceMode | typeof PERSISTENCE_MODE_UNSPECIFIED ,
417
427
fn : ( collection : CollectionReference , db : Firestore ) => Promise < void >
418
428
) : Promise < void > {
419
429
return withTestCollection ( persistence , { } , fn ) ;
@@ -422,7 +432,7 @@ export function withEmptyTestCollection(
422
432
// TODO(mikelehen): Once we wipe the database between tests, we can probably
423
433
// return the same collection every time.
424
434
export function withTestCollectionSettings < T > (
425
- persistence : PersistenceMode ,
435
+ persistence : PersistenceMode | typeof PERSISTENCE_MODE_UNSPECIFIED ,
426
436
settings : PrivateSettings ,
427
437
docs : { [ key : string ] : DocumentData } ,
428
438
fn : ( collection : CollectionReference , db : Firestore ) => Promise < T >
0 commit comments