Skip to content

Commit 53a2154

Browse files
committed
remove explicit type from persistence argument
1 parent a6d516d commit 53a2154

19 files changed

+1352
-1357
lines changed

packages/firestore/test/integration/api/aggregation.test.ts

Lines changed: 1078 additions & 1086 deletions
Large diffs are not rendered by default.

packages/firestore/test/integration/api/array_transforms.test.ts

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ addEqualityMatcher();
4242
* together, etc.) and so these tests mostly focus on the array transform
4343
* semantics.
4444
*/
45-
apiDescribe('Array Transforms:', (persistence: boolean) => {
45+
apiDescribe('Array Transforms:', persistence => {
4646
// A document reference to read and write to.
4747
let docRef: DocumentReference;
4848

@@ -164,76 +164,79 @@ apiDescribe('Array Transforms:', (persistence: boolean) => {
164164
* being enabled so documents remain in the cache after the write.
165165
*/
166166
// eslint-disable-next-line no-restricted-properties
167-
(persistence ? describe : describe.skip)('Server Application: ', () => {
168-
it('set() with no cached base doc', async () => {
169-
await withTestDoc(persistence, async docRef => {
170-
await setDoc(docRef, { array: arrayUnion(1, 2) });
171-
const snapshot = await getDocFromCache(docRef);
172-
expect(snapshot.data()).to.deep.equal({ array: [1, 2] });
173-
});
174-
});
175-
176-
it('update() with no cached base doc', async () => {
177-
let path: string | null = null;
178-
// Write an initial document in an isolated Firestore instance so it's not
179-
// stored in our cache
180-
await withTestDoc(persistence, async docRef => {
181-
path = docRef.path;
182-
await setDoc(docRef, { array: [42] });
167+
(persistence ? describe : describe.skip)(
168+
'Server Application: ',
169+
() => {
170+
it('set() with no cached base doc', async () => {
171+
await withTestDoc(persistence, async docRef => {
172+
await setDoc(docRef, { array: arrayUnion(1, 2) });
173+
const snapshot = await getDocFromCache(docRef);
174+
expect(snapshot.data()).to.deep.equal({ array: [1, 2] });
175+
});
183176
});
184177

185-
await withTestDb(persistence, async db => {
186-
const docRef = doc(db, path!);
187-
await updateDoc(docRef, { array: arrayUnion(1, 2) });
188-
189-
// Nothing should be cached since it was an update and we had no base
190-
// doc.
191-
let errCaught = false;
192-
try {
193-
await getDocFromCache(docRef);
194-
} catch (err) {
195-
expect((err as FirestoreError).code).to.equal('unavailable');
196-
errCaught = true;
197-
}
198-
expect(errCaught).to.be.true;
178+
it('update() with no cached base doc', async () => {
179+
let path: string | null = null;
180+
// Write an initial document in an isolated Firestore instance so it's not
181+
// stored in our cache
182+
await withTestDoc(persistence, async docRef => {
183+
path = docRef.path;
184+
await setDoc(docRef, { array: [42] });
185+
});
186+
187+
await withTestDb(persistence, async db => {
188+
const docRef = doc(db, path!);
189+
await updateDoc(docRef, { array: arrayUnion(1, 2) });
190+
191+
// Nothing should be cached since it was an update and we had no base
192+
// doc.
193+
let errCaught = false;
194+
try {
195+
await getDocFromCache(docRef);
196+
} catch (err) {
197+
expect((err as FirestoreError).code).to.equal('unavailable');
198+
errCaught = true;
199+
}
200+
expect(errCaught).to.be.true;
201+
});
199202
});
200-
});
201203

202-
it('set(..., {merge}) with no cached based doc', async () => {
203-
let path: string | null = null;
204-
// Write an initial document in an isolated Firestore instance so it's not
205-
// stored in our cache
206-
await withTestDoc(persistence, async docRef => {
207-
path = docRef.path;
208-
await setDoc(docRef, { array: [42] });
204+
it('set(..., {merge}) with no cached based doc', async () => {
205+
let path: string | null = null;
206+
// Write an initial document in an isolated Firestore instance so it's not
207+
// stored in our cache
208+
await withTestDoc(persistence, async docRef => {
209+
path = docRef.path;
210+
await setDoc(docRef, { array: [42] });
211+
});
212+
213+
await withTestDb(persistence, async db => {
214+
const docRef = doc(db, path!);
215+
await setDoc(docRef, { array: arrayUnion(1, 2) }, { merge: true });
216+
217+
// Document will be cached but we'll be missing 42.
218+
const snapshot = await getDocFromCache(docRef);
219+
expect(snapshot.data()).to.deep.equal({ array: [1, 2] });
220+
});
209221
});
210222

211-
await withTestDb(persistence, async db => {
212-
const docRef = doc(db, path!);
213-
await setDoc(docRef, { array: arrayUnion(1, 2) }, { merge: true });
214-
215-
// Document will be cached but we'll be missing 42.
216-
const snapshot = await getDocFromCache(docRef);
217-
expect(snapshot.data()).to.deep.equal({ array: [1, 2] });
223+
it('update() with cached base doc using arrayUnion()', async () => {
224+
await withTestDoc(persistence, async docRef => {
225+
await setDoc(docRef, { array: [42] });
226+
await updateDoc(docRef, { array: arrayUnion(1, 2) });
227+
const snapshot = await getDocFromCache(docRef);
228+
expect(snapshot.data()).to.deep.equal({ array: [42, 1, 2] });
229+
});
218230
});
219-
});
220231

221-
it('update() with cached base doc using arrayUnion()', async () => {
222-
await withTestDoc(persistence, async docRef => {
223-
await setDoc(docRef, { array: [42] });
224-
await updateDoc(docRef, { array: arrayUnion(1, 2) });
225-
const snapshot = await getDocFromCache(docRef);
226-
expect(snapshot.data()).to.deep.equal({ array: [42, 1, 2] });
232+
it('update() with cached base doc using arrayRemove()', async () => {
233+
await withTestDoc(persistence, async docRef => {
234+
await setDoc(docRef, { array: [42, 1, 2] });
235+
await updateDoc(docRef, { array: arrayRemove(1, 2) });
236+
const snapshot = await getDocFromCache(docRef);
237+
expect(snapshot.data()).to.deep.equal({ array: [42] });
238+
});
227239
});
228-
});
229-
230-
it('update() with cached base doc using arrayRemove()', async () => {
231-
await withTestDoc(persistence, async docRef => {
232-
await setDoc(docRef, { array: [42, 1, 2] });
233-
await updateDoc(docRef, { array: arrayRemove(1, 2) });
234-
const snapshot = await getDocFromCache(docRef);
235-
expect(snapshot.data()).to.deep.equal({ array: [42] });
236-
});
237-
});
238-
});
240+
}
241+
);
239242
});

packages/firestore/test/integration/api/batch_writes.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
withTestDoc
4242
} from '../util/helpers';
4343

44-
apiDescribe('Database batch writes', (persistence: boolean) => {
44+
apiDescribe('Database batch writes', persistence => {
4545
it('supports empty batches', () => {
4646
return withTestDb(persistence, db => {
4747
return writeBatch(db).commit();
@@ -329,7 +329,7 @@ apiDescribe('Database batch writes', (persistence: boolean) => {
329329

330330
// PORTING NOTE: These tests are for FirestoreDataConverter support and apply
331331
// only to web.
332-
apiDescribe('withConverter() support', (persistence: boolean) => {
332+
apiDescribe('withConverter() support', persistence => {
333333
class Post {
334334
constructor(readonly title: string, readonly author: string) {}
335335
byline(): string {

packages/firestore/test/integration/api/bundle.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const BUNDLE_TEMPLATE = [
6969
'{"document":{"name":"projects/{0}/databases/(default)/documents/coll-1/b","createTime":{"seconds":1,"nanos":9},"updateTime":{"seconds":1,"nanos":9},"fields":{"k":{"stringValue":"b"},"bar":{"integerValue":2}}}}'
7070
];
7171

72-
apiDescribe('Bundles', (persistence: boolean) => {
72+
apiDescribe('Bundles', persistence => {
7373
function verifySnapEqualsTestDocs(snap: QuerySnapshot): void {
7474
expect(toDataArray(snap)).to.deep.equal([
7575
{ k: 'a', bar: 1 },

packages/firestore/test/integration/api/cursor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import {
4444
withTestDbs
4545
} from '../util/helpers';
4646

47-
apiDescribe('Cursors', (persistence: boolean) => {
47+
apiDescribe('Cursors', persistence => {
4848
it('can page through items', () => {
4949
const testDocs = {
5050
a: { v: 'a' },

packages/firestore/test/integration/api/database.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import { DEFAULT_SETTINGS, DEFAULT_PROJECT_ID } from '../util/settings';
8181

8282
use(chaiAsPromised);
8383

84-
apiDescribe('Database', (persistence: boolean) => {
84+
apiDescribe('Database', persistence => {
8585
it('can set a document', () => {
8686
return withTestDoc(persistence, docRef => {
8787
return setDoc(docRef, {
@@ -638,7 +638,7 @@ apiDescribe('Database', (persistence: boolean) => {
638638
});
639639
});
640640

641-
apiDescribe('Queries are validated client-side', (persistence: boolean) => {
641+
apiDescribe('Queries are validated client-side', persistence => {
642642
// NOTE: Failure cases are validated in validation_test.ts
643643

644644
it('same inequality fields works', () => {
@@ -1340,7 +1340,7 @@ apiDescribe('Database', (persistence: boolean) => {
13401340

13411341
// PORTING NOTE: These tests are for FirestoreDataConverter support and apply
13421342
// only to web.
1343-
apiDescribe('withConverter() support', (persistence: boolean) => {
1343+
apiDescribe('withConverter() support', persistence => {
13441344
class Post {
13451345
constructor(
13461346
readonly title: string,

packages/firestore/test/integration/api/fields.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { DEFAULT_SETTINGS } from '../util/settings';
4343
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4444
type AnyTestData = any;
4545

46-
apiDescribe('Nested Fields', (persistence: boolean) => {
46+
apiDescribe('Nested Fields', persistence => {
4747
const testData = (n?: number): AnyTestData => {
4848
n = n || 1;
4949
return {
@@ -240,7 +240,7 @@ apiDescribe('Nested Fields', (persistence: boolean) => {
240240
// NOTE(mikelehen): I originally combined these tests with the above ones, but
241241
// Datastore currently prohibits having nested fields and fields with dots in
242242
// the same entity, so I'm separating them.
243-
apiDescribe('Fields with special characters', (persistence: boolean) => {
243+
apiDescribe('Fields with special characters', persistence => {
244244
const testData = (n?: number): AnyTestData => {
245245
n = n || 1;
246246
return {
@@ -340,7 +340,7 @@ apiDescribe('Fields with special characters', (persistence: boolean) => {
340340
});
341341
});
342342

343-
apiDescribe('Timestamp Fields in snapshots', (persistence: boolean) => {
343+
apiDescribe('Timestamp Fields in snapshots', persistence => {
344344
// Figure out how to pass in the Timestamp type
345345
// eslint-disable-next-line @typescript-eslint/no-explicit-any
346346
const testDataWithTimestamps = (ts: any): AnyTestData => {
@@ -379,7 +379,7 @@ apiDescribe('Timestamp Fields in snapshots', (persistence: boolean) => {
379379
});
380380
});
381381

382-
apiDescribe('`undefined` properties', (persistence: boolean) => {
382+
apiDescribe('`undefined` properties', persistence => {
383383
const settings = { ...DEFAULT_SETTINGS };
384384
settings.ignoreUndefinedProperties = true;
385385

packages/firestore/test/integration/api/get_options.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
withEnsuredLruGcTestDb
4040
} from '../util/helpers';
4141

42-
apiDescribe('GetOptions', (persistence: boolean) => {
42+
apiDescribe('GetOptions', persistence => {
4343
it('get document while online with default get options', () => {
4444
const initialData = { key: 'value' };
4545
return withTestDocAndInitialData(persistence, initialData, docRef => {

packages/firestore/test/integration/api/index_configuration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { expect } from 'chai';
2020
import { setIndexConfiguration } from '../util/firebase_export';
2121
import { apiDescribe, withTestDb } from '../util/helpers';
2222

23-
apiDescribe('Index Configuration:', (persistence: boolean) => {
23+
apiDescribe('Index Configuration:', persistence => {
2424
it('supports JSON', () => {
2525
return withTestDb(persistence, async db => {
2626
return setIndexConfiguration(

packages/firestore/test/integration/api/numeric_transforms.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { apiDescribe, withTestDoc } from '../util/helpers';
3737

3838
const DOUBLE_EPSILON = 0.000001;
3939

40-
apiDescribe('Numeric Transforms:', (persistence: boolean) => {
40+
apiDescribe('Numeric Transforms:', persistence => {
4141
// A document reference to read and write to.
4242
let docRef: DocumentReference;
4343

packages/firestore/test/integration/api/query.test.ts

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import {
7070
import { USE_EMULATOR } from '../util/settings';
7171
import { captureExistenceFilterMismatches } from '../util/testing_hooks_util';
7272

73-
apiDescribe('Queries', (persistence: boolean) => {
73+
apiDescribe('Queries', persistence => {
7474
addEqualityMatcher();
7575

7676
it('can issue limit queries', () => {
@@ -2027,42 +2027,45 @@ apiDescribe('Queries', (persistence: boolean) => {
20272027

20282028
// Reproduces https://github.com/firebase/firebase-js-sdk/issues/5873
20292029
// eslint-disable-next-line no-restricted-properties
2030-
(persistence ? describe : describe.skip)('Caching empty results', () => {
2031-
it('can raise initial snapshot from cache, even if it is empty', () => {
2032-
return withTestCollection(persistence, {}, async coll => {
2033-
const snapshot1 = await getDocs(coll); // Populate the cache.
2034-
expect(snapshot1.metadata.fromCache).to.be.false;
2035-
expect(toDataArray(snapshot1)).to.deep.equal([]); // Precondition check.
2036-
2037-
// Add a snapshot listener whose first event should be raised from cache.
2038-
const storeEvent = new EventsAccumulator<QuerySnapshot>();
2039-
onSnapshot(coll, storeEvent.storeEvent);
2040-
const snapshot2 = await storeEvent.awaitEvent();
2041-
expect(snapshot2.metadata.fromCache).to.be.true;
2042-
expect(toDataArray(snapshot2)).to.deep.equal([]);
2030+
(persistence ? describe : describe.skip)(
2031+
'Caching empty results',
2032+
() => {
2033+
it('can raise initial snapshot from cache, even if it is empty', () => {
2034+
return withTestCollection(persistence, {}, async coll => {
2035+
const snapshot1 = await getDocs(coll); // Populate the cache.
2036+
expect(snapshot1.metadata.fromCache).to.be.false;
2037+
expect(toDataArray(snapshot1)).to.deep.equal([]); // Precondition check.
2038+
2039+
// Add a snapshot listener whose first event should be raised from cache.
2040+
const storeEvent = new EventsAccumulator<QuerySnapshot>();
2041+
onSnapshot(coll, storeEvent.storeEvent);
2042+
const snapshot2 = await storeEvent.awaitEvent();
2043+
expect(snapshot2.metadata.fromCache).to.be.true;
2044+
expect(toDataArray(snapshot2)).to.deep.equal([]);
2045+
});
20432046
});
2044-
});
20452047

2046-
it('can raise initial snapshot from cache, even if it has become empty', () => {
2047-
const testDocs = {
2048-
a: { key: 'a' }
2049-
};
2050-
return withTestCollection(persistence, testDocs, async coll => {
2051-
// Populate the cache.
2052-
const snapshot1 = await getDocs(coll);
2053-
expect(snapshot1.metadata.fromCache).to.be.false;
2054-
expect(toDataArray(snapshot1)).to.deep.equal([{ key: 'a' }]);
2055-
// Empty the collection.
2056-
void deleteDoc(doc(coll, 'a'));
2057-
2058-
const storeEvent = new EventsAccumulator<QuerySnapshot>();
2059-
onSnapshot(coll, storeEvent.storeEvent);
2060-
const snapshot2 = await storeEvent.awaitEvent();
2061-
expect(snapshot2.metadata.fromCache).to.be.true;
2062-
expect(toDataArray(snapshot2)).to.deep.equal([]);
2048+
it('can raise initial snapshot from cache, even if it has become empty', () => {
2049+
const testDocs = {
2050+
a: { key: 'a' }
2051+
};
2052+
return withTestCollection(persistence, testDocs, async coll => {
2053+
// Populate the cache.
2054+
const snapshot1 = await getDocs(coll);
2055+
expect(snapshot1.metadata.fromCache).to.be.false;
2056+
expect(toDataArray(snapshot1)).to.deep.equal([{ key: 'a' }]);
2057+
// Empty the collection.
2058+
void deleteDoc(doc(coll, 'a'));
2059+
2060+
const storeEvent = new EventsAccumulator<QuerySnapshot>();
2061+
onSnapshot(coll, storeEvent.storeEvent);
2062+
const snapshot2 = await storeEvent.awaitEvent();
2063+
expect(snapshot2.metadata.fromCache).to.be.true;
2064+
expect(toDataArray(snapshot2)).to.deep.equal([]);
2065+
});
20632066
});
2064-
});
2065-
});
2067+
}
2068+
);
20662069

20672070
it('resuming a query should use bloom filter to avoid full requery', async () => {
20682071
// Prepare the names and contents of the 100 documents to create.

packages/firestore/test/integration/api/server_timestamp.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { apiDescribe, withTestDoc } from '../util/helpers';
3838
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3939
type AnyTestData = any;
4040

41-
apiDescribe('Server Timestamps', (persistence: boolean) => {
41+
apiDescribe('Server Timestamps', persistence => {
4242
// Data written in tests via set().
4343
const setData = {
4444
a: 42,

packages/firestore/test/integration/api/smoke.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
withTestDoc
4141
} from '../util/helpers';
4242

43-
apiDescribe('Smoke Test', (persistence: boolean) => {
43+
apiDescribe('Smoke Test', persistence => {
4444
it('can write a single document', () => {
4545
return withTestDoc(persistence, ref => {
4646
return setDoc(ref, {

0 commit comments

Comments
 (0)