Skip to content

Commit d9e432e

Browse files
authored
Firestore: in tests, silence the verbose warning about old timestamp behavior (#1058)
This cleans up the few leftover places where the warning was still being outputted in tests. Running locally, I get a clean log.
1 parent 718953e commit d9e432e

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
withTestCollectionSettings,
2525
withTestDoc
2626
} from '../util/helpers';
27+
import * as log from '../../../src/util/log';
28+
import { LogLevel } from '../../../src/util/log';
2729

2830
const FieldPath = firebase.firestore.FieldPath;
2931
const Timestamp = firebase.firestore.Timestamp;
@@ -349,12 +351,18 @@ apiDescribe('Timestamp Fields in snapshots', persistence => {
349351
};
350352

351353
it('are returned as native dates if timestampsInSnapshots is not set', () => {
354+
// Avoid the verbose log message triggered by timestampsInSnapshots ==
355+
// false.
356+
const logLevel = log.getLogLevel();
357+
log.setLogLevel(LogLevel.SILENT);
358+
352359
const settings = { ...DEFAULT_SETTINGS };
353360
settings['timestampsInSnapshots'] = false;
354361

355362
const timestamp = new Timestamp(100, 123456789);
356363
const testDocs = { a: testDataWithTimestamps(timestamp) };
357364
return withTestCollectionSettings(persistence, settings, testDocs, coll => {
365+
log.setLogLevel(logLevel);
358366
return coll
359367
.doc('a')
360368
.get()
@@ -411,13 +419,17 @@ apiDescribe('Timestamp Fields in snapshots', persistence => {
411419
});
412420

413421
it('timestampsInSnapshots affects server timestamps', () => {
422+
const logLevel = log.getLogLevel();
423+
log.setLogLevel(LogLevel.SILENT);
424+
414425
const settings = { ...DEFAULT_SETTINGS };
415426
settings['timestampsInSnapshots'] = false;
416427
const testDocs = {
417428
a: { timestamp: firebase.firestore.FieldValue.serverTimestamp() }
418429
};
419430

420431
return withTestCollectionSettings(persistence, settings, testDocs, coll => {
432+
log.setLogLevel(logLevel);
421433
return coll
422434
.doc('a')
423435
.get()

packages/firestore/test/util/api_helpers.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ export const FIRESTORE = new Firestore({
4646
});
4747

4848
export function firestore(): Firestore {
49+
FIRESTORE.settings({ timestampsInSnapshots: true });
4950
return FIRESTORE;
5051
}
5152

5253
export function collectionReference(path: string): CollectionReference {
53-
return new CollectionReference(pathFrom(path), FIRESTORE);
54+
return new CollectionReference(pathFrom(path), firestore());
5455
}
5556

5657
export function documentReference(path: string): DocumentReference {
57-
return new DocumentReference(key(path), FIRESTORE);
58+
return new DocumentReference(key(path), firestore());
5859
}
5960

6061
export function documentSnapshot(
@@ -64,18 +65,18 @@ export function documentSnapshot(
6465
): DocumentSnapshot {
6566
if (data) {
6667
return new DocumentSnapshot(
67-
FIRESTORE,
68+
firestore(),
6869
key(path),
6970
doc(path, 1, data),
7071
fromCache
7172
);
7273
} else {
73-
return new DocumentSnapshot(FIRESTORE, key(path), null, fromCache);
74+
return new DocumentSnapshot(firestore(), key(path), null, fromCache);
7475
}
7576
}
7677

7778
export function query(path: string): Query {
78-
return new Query(InternalQuery.atPath(pathFrom(path)), FIRESTORE);
79+
return new Query(InternalQuery.atPath(pathFrom(path)), firestore());
7980
}
8081

8182
/**
@@ -121,5 +122,5 @@ export function querySnapshot(
121122
syncStateChanged,
122123
/* excludesMetadataChanges= */ false
123124
);
124-
return new QuerySnapshot(FIRESTORE, query, viewSnapshot);
125+
return new QuerySnapshot(firestore(), query, viewSnapshot);
125126
}

0 commit comments

Comments
 (0)