@@ -25,10 +25,12 @@ import {
25
25
DocumentData ,
26
26
DocumentReference ,
27
27
Firestore ,
28
+ MemoryLocalCache ,
28
29
memoryLocalCache ,
29
30
memoryLruGarbageCollector ,
30
31
newTestApp ,
31
32
newTestFirestore ,
33
+ PersistentLocalCache ,
32
34
persistentLocalCache ,
33
35
PrivateSettings ,
34
36
QuerySnapshot ,
@@ -137,7 +139,7 @@ export function toIds(docSet: QuerySnapshot): string[] {
137
139
}
138
140
139
141
export function withTestDb (
140
- persistence : boolean ,
142
+ persistence : boolean | PersistentLocalCache | MemoryLocalCache ,
141
143
fn : ( db : Firestore ) => Promise < void >
142
144
) : Promise < void > {
143
145
return withTestDbs ( persistence , 1 , ( [ db ] ) => {
@@ -160,7 +162,7 @@ export function withEnsuredEagerGcTestDb(
160
162
}
161
163
162
164
export function withEnsuredLruGcTestDb (
163
- persistence : boolean ,
165
+ persistence : boolean | PersistentLocalCache | MemoryLocalCache ,
164
166
fn : ( db : Firestore ) => Promise < void >
165
167
) : Promise < void > {
166
168
const newSettings = { ...DEFAULT_SETTINGS } ;
@@ -188,7 +190,7 @@ export function withEnsuredLruGcTestDb(
188
190
189
191
/** Runs provided fn with a db for an alternate project id. */
190
192
export function withAlternateTestDb (
191
- persistence : boolean ,
193
+ persistence : boolean | PersistentLocalCache | MemoryLocalCache ,
192
194
fn : ( db : Firestore ) => Promise < void >
193
195
) : Promise < void > {
194
196
return withTestDbsSettings (
@@ -203,7 +205,7 @@ export function withAlternateTestDb(
203
205
}
204
206
205
207
export function withTestDbs (
206
- persistence : boolean ,
208
+ persistence : boolean | PersistentLocalCache | MemoryLocalCache ,
207
209
numDbs : number ,
208
210
fn : ( db : Firestore [ ] ) => Promise < void >
209
211
) : Promise < void > {
@@ -216,7 +218,7 @@ export function withTestDbs(
216
218
) ;
217
219
}
218
220
export async function withTestDbsSettings < T > (
219
- persistence : boolean ,
221
+ persistence : boolean | PersistentLocalCache | MemoryLocalCache ,
220
222
projectId : string ,
221
223
settings : PrivateSettings ,
222
224
numDbs : number ,
@@ -250,7 +252,7 @@ export async function withTestDbsSettings<T>(
250
252
}
251
253
252
254
export async function withNamedTestDbsOrSkipUnlessUsingEmulator (
253
- persistence : boolean ,
255
+ persistence : boolean | PersistentLocalCache | MemoryLocalCache ,
254
256
dbNames : string [ ] ,
255
257
fn : ( db : Firestore [ ] ) => Promise < void >
256
258
) : Promise < void > {
@@ -265,8 +267,12 @@ export async function withNamedTestDbsOrSkipUnlessUsingEmulator(
265
267
const dbs : Firestore [ ] = [ ] ;
266
268
for ( const dbName of dbNames ) {
267
269
const newSettings = { ...DEFAULT_SETTINGS } ;
268
- if ( persistence ) {
269
- newSettings . localCache = persistentLocalCache ( ) ;
270
+ if ( typeof persistence === 'boolean' ) {
271
+ if ( persistence ) {
272
+ newSettings . localCache = persistentLocalCache ( ) ;
273
+ }
274
+ } else {
275
+ newSettings . localCache = persistence ;
270
276
}
271
277
const db = newTestFirestore ( app , newSettings , dbName ) ;
272
278
dbs . push ( db ) ;
@@ -285,7 +291,7 @@ export async function withNamedTestDbsOrSkipUnlessUsingEmulator(
285
291
}
286
292
287
293
export function withTestDoc (
288
- persistence : boolean ,
294
+ persistence : boolean | PersistentLocalCache | MemoryLocalCache ,
289
295
fn : ( doc : DocumentReference , db : Firestore ) => Promise < void >
290
296
) : Promise < void > {
291
297
return withTestDb ( persistence , db => {
@@ -294,7 +300,7 @@ export function withTestDoc(
294
300
}
295
301
296
302
export function withTestDocAndSettings (
297
- persistence : boolean ,
303
+ persistence : boolean | PersistentLocalCache | MemoryLocalCache ,
298
304
settings : PrivateSettings ,
299
305
fn : ( doc : DocumentReference ) => Promise < void >
300
306
) : Promise < void > {
@@ -315,7 +321,7 @@ export function withTestDocAndSettings(
315
321
// `withTestDoc(..., docRef => { setDoc(docRef, initialData) ...});` that
316
322
// otherwise is quite common.
317
323
export function withTestDocAndInitialData (
318
- persistence : boolean ,
324
+ persistence : boolean | PersistentLocalCache | MemoryLocalCache ,
319
325
initialData : DocumentData | null ,
320
326
fn : ( doc : DocumentReference , db : Firestore ) => Promise < void >
321
327
) : Promise < void > {
@@ -330,15 +336,15 @@ export function withTestDocAndInitialData(
330
336
}
331
337
332
338
export function withTestCollection < T > (
333
- persistence : boolean ,
339
+ persistence : boolean | PersistentLocalCache | MemoryLocalCache ,
334
340
docs : { [ key : string ] : DocumentData } ,
335
341
fn : ( collection : CollectionReference , db : Firestore ) => Promise < T >
336
342
) : Promise < T > {
337
343
return withTestCollectionSettings ( persistence , DEFAULT_SETTINGS , docs , fn ) ;
338
344
}
339
345
340
346
export function withEmptyTestCollection (
341
- persistence : boolean ,
347
+ persistence : boolean | PersistentLocalCache | MemoryLocalCache ,
342
348
fn : ( collection : CollectionReference , db : Firestore ) => Promise < void >
343
349
) : Promise < void > {
344
350
return withTestCollection ( persistence , { } , fn ) ;
@@ -347,7 +353,7 @@ export function withEmptyTestCollection(
347
353
// TODO(mikelehen): Once we wipe the database between tests, we can probably
348
354
// return the same collection every time.
349
355
export function withTestCollectionSettings < T > (
350
- persistence : boolean ,
356
+ persistence : boolean | PersistentLocalCache | MemoryLocalCache ,
351
357
settings : PrivateSettings ,
352
358
docs : { [ key : string ] : DocumentData } ,
353
359
fn : ( collection : CollectionReference , db : Firestore ) => Promise < T >
0 commit comments