Skip to content

Commit 6c8aef3

Browse files
Retiring assert.ok (#381)
1 parent fa39ab3 commit 6c8aef3

9 files changed

Lines changed: 152 additions & 145 deletions

File tree

‎handwritten/firestore/dev/test/backoff.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {expect} from 'chai';
1718
import assert from 'power-assert';
1819

1920
import {ExponentialBackoff, setTimeoutHandler} from '../src/backoff';
@@ -45,8 +46,8 @@ describe('ExponentialBackoff', () => {
4546

4647
function assertDelayBetween(low, high) {
4748
const actual = observedDelays.shift()!;
48-
assert.ok(actual >= low);
49-
assert.ok(actual <= high);
49+
expect(actual).to.be.at.least(low);
50+
expect(actual).to.be.at.most(high);
5051
}
5152

5253
it('doesn\'t delay first attempt', async () => {

‎handwritten/firestore/dev/test/collection.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import {expect} from 'chai';
1919

20-
2120
import * as Firestore from '../src/index';
2221
import DocumentReference = Firestore.DocumentReference;
2322
import {createInstance, DATABASE_ROOT, document} from './util/helpers';

‎handwritten/firestore/dev/test/document.ts‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {expect} from 'chai';
1718
import extend from 'extend';
1819
import is from 'is';
1920
import assert from 'power-assert';
@@ -256,8 +257,8 @@ describe('DocumentReference interface', () => {
256257
const doc1 = firestore.doc('coll/doc1');
257258
const doc1Equals = firestore.doc('coll/doc1');
258259
const doc2 = firestore.doc('coll/doc1/coll/doc1');
259-
assert.ok(doc1.isEqual(doc1Equals));
260-
assert.ok(!doc1.isEqual(doc2));
260+
expect(doc1.isEqual(doc1Equals)).to.be.true;
261+
expect(doc1.isEqual(doc2)).to.be.false;
261262
});
262263
});
263264

@@ -366,9 +367,8 @@ describe('serialize document', () => {
366367
const overrides = {
367368
commit: (request, options, callback) => {
368369
const fields = request.writes[0].update.fields;
369-
assert.ok(
370-
typeof fields.nanValue.doubleValue === 'number' &&
371-
isNaN(fields.nanValue.doubleValue));
370+
expect(fields.nanValue.doubleValue).to.be.a('number');
371+
expect(fields.nanValue.doubleValue).to.be.NaN;
372372
assert.equal(fields.posInfinity.doubleValue, Infinity);
373373
assert.equal(fields.negInfinity.doubleValue, -Infinity);
374374

@@ -650,9 +650,12 @@ describe('get document', () => {
650650

651651
return createInstance(overrides).then(firestore => {
652652
return firestore.doc('collectionId/documentId').get().then((result) => {
653-
assert.ok(result.createTime!.isEqual(new Firestore.Timestamp(1, 2)));
654-
assert.ok(result.updateTime!.isEqual(new Firestore.Timestamp(3, 4)));
655-
assert.ok(result.readTime.isEqual(new Firestore.Timestamp(5, 6)));
653+
expect(result.createTime!.isEqual(new Firestore.Timestamp(1, 2)))
654+
.to.be.true;
655+
expect(result.updateTime!.isEqual(new Firestore.Timestamp(3, 4)))
656+
.to.be.true;
657+
expect(result.readTime.isEqual(new Firestore.Timestamp(5, 6)))
658+
.to.be.true;
656659
});
657660
});
658661
});
@@ -667,7 +670,8 @@ describe('get document', () => {
667670
return createInstance(overrides).then(firestore => {
668671
return firestore.doc('collectionId/documentId').get().then(result => {
669672
assert.equal(result.exists, false);
670-
assert.ok(result.readTime.isEqual(new Firestore.Timestamp(5, 6)));
673+
expect(result.readTime.isEqual(new Firestore.Timestamp(5, 6)))
674+
.to.be.true;
671675
assert.equal(null, result.data());
672676
assert.equal(null, result.get('foo'));
673677
});
@@ -756,8 +760,9 @@ describe('delete document', () => {
756760

757761
return createInstance(overrides).then(firestore => {
758762
return firestore.doc('collectionId/documentId').delete().then(res => {
759-
assert.ok(res.writeTime.isEqual(
760-
new Firestore.Timestamp(479978400, 123000000)));
763+
expect(res.writeTime.isEqual(
764+
new Firestore.Timestamp(479978400, 123000000)))
765+
.to.be.true;
761766
});
762767
});
763768
});
@@ -1389,8 +1394,9 @@ describe('update document', () => {
13891394
return firestore.doc('collectionId/documentId')
13901395
.update({foo: 'bar'})
13911396
.then(res => {
1392-
assert.ok(res.writeTime.isEqual(
1393-
new Firestore.Timestamp(479978400, 123000000)));
1397+
expect(res.writeTime.isEqual(
1398+
new Firestore.Timestamp(479978400, 123000000)))
1399+
.to.be.true;
13941400
});
13951401
});
13961402
});

‎handwritten/firestore/dev/test/index.ts‎

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {expect} from 'chai';
1718
import extend from 'extend';
1819
import * as gax from 'google-gax';
1920
import is from 'is';
@@ -426,36 +427,37 @@ describe('instantiation', () => {
426427

427428
it('exports all types', () => {
428429
// Ordering as per firestore.d.ts
429-
assert.ok(is.defined(Firestore.Firestore));
430+
expect((Firestore.Firestore)).to.exist;
430431
assert.equal(Firestore.Firestore.name, 'Firestore');
431-
assert.ok(is.defined(Firestore.Timestamp));
432+
expect((Firestore.Timestamp)).to.exist;
432433
assert.equal(Firestore.Timestamp.name, 'Timestamp');
433-
assert.ok(is.defined(Firestore.GeoPoint));
434+
expect((Firestore.GeoPoint)).to.exist;
434435
assert.equal(Firestore.GeoPoint.name, 'GeoPoint');
435-
assert.ok(is.defined(Firestore.Transaction));
436+
expect((Firestore.Transaction)).to.exist;
436437
assert.equal(Firestore.Transaction.name, 'Transaction');
437-
assert.ok(is.defined(Firestore.WriteBatch));
438+
expect((Firestore.WriteBatch)).to.exist;
438439
assert.equal(Firestore.WriteBatch.name, 'WriteBatch');
439-
assert.ok(is.defined(Firestore.DocumentReference));
440+
expect((Firestore.DocumentReference)).to.exist;
440441
assert.equal(Firestore.DocumentReference.name, 'DocumentReference');
441-
assert.ok(is.defined(Firestore.WriteResult));
442+
expect((Firestore.WriteResult)).to.exist;
442443
assert.equal(Firestore.WriteResult.name, 'WriteResult');
443-
assert.ok(is.defined(Firestore.DocumentSnapshot));
444+
expect((Firestore.DocumentSnapshot)).to.exist;
444445
assert.equal(Firestore.DocumentSnapshot.name, 'DocumentSnapshot');
445-
assert.ok(is.defined(Firestore.QueryDocumentSnapshot));
446+
expect((Firestore.QueryDocumentSnapshot)).to.exist;
446447
assert.equal(Firestore.QueryDocumentSnapshot.name, 'QueryDocumentSnapshot');
447-
assert.ok(is.defined(Firestore.Query));
448+
expect((Firestore.Query)).to.exist;
448449
assert.equal(Firestore.Query.name, 'Query');
449-
assert.ok(is.defined(Firestore.QuerySnapshot));
450+
expect(Firestore.QuerySnapshot).to.exist;
450451
assert.equal(Firestore.QuerySnapshot.name, 'QuerySnapshot');
451-
assert.ok(is.defined(Firestore.CollectionReference));
452+
expect((Firestore.CollectionReference)).to.exist;
452453
assert.equal(Firestore.CollectionReference.name, 'CollectionReference');
453-
assert.ok(is.defined(Firestore.FieldValue));
454+
expect((Firestore.FieldValue)).to.exist;
454455
assert.equal(Firestore.FieldValue.name, 'FieldValue');
455-
assert.ok(is.defined(Firestore.FieldPath));
456+
expect((Firestore.FieldPath)).to.exist;
456457
assert.equal(Firestore.Firestore.name, 'Firestore');
457-
assert.ok(!Firestore.FieldValue.serverTimestamp().isEqual(
458-
Firestore.FieldValue.delete()));
458+
expect(Firestore.FieldValue.serverTimestamp().isEqual(
459+
Firestore.FieldValue.delete()))
460+
.to.be.false;
459461
});
460462
});
461463

@@ -505,8 +507,9 @@ describe('snapshot_() method', () => {
505507
assert.equal(
506508
data.geoPointValue.toString(),
507509
'GeoPoint { latitude: 50.1430847, longitude: -122.947778 }');
508-
assert.ok(data.geoPointValue.isEqual(
509-
new Firestore.GeoPoint(50.1430847, -122.947778)));
510+
expect(data.geoPointValue.isEqual(
511+
new Firestore.GeoPoint(50.1430847, -122.947778)))
512+
.to.be.true;
510513
}
511514

512515
beforeEach(() => {
@@ -529,9 +532,9 @@ describe('snapshot_() method', () => {
529532

530533
assert.equal(true, doc.exists);
531534
assert.deepStrictEqual({foo: bytesData}, doc.data());
532-
assert.ok(doc.createTime.isEqual(new Firestore.Timestamp(1, 2)));
533-
assert.ok(doc.updateTime.isEqual(new Firestore.Timestamp(3, 4)));
534-
assert.ok(doc.readTime.isEqual(new Firestore.Timestamp(5, 6)));
535+
expect(doc.createTime.isEqual(new Firestore.Timestamp(1, 2))).to.be.true;
536+
expect(doc.updateTime.isEqual(new Firestore.Timestamp(3, 4))).to.be.true;
537+
expect(doc.readTime.isEqual(new Firestore.Timestamp(5, 6))).to.be.true;
535538
});
536539

537540
it('handles Proto3 JSON together with existing types', () => {
@@ -559,9 +562,10 @@ describe('snapshot_() method', () => {
559562
b: Firestore.Timestamp.fromDate(new Date('1985-03-18T07:20:00.000Z')),
560563
c: bytesData,
561564
});
562-
assert.ok(doc.createTime.isEqual(new Firestore.Timestamp(1, 2000000)));
563-
assert.ok(doc.updateTime.isEqual(new Firestore.Timestamp(3, 4000)));
564-
assert.ok(doc.readTime.isEqual(new Firestore.Timestamp(5, 6)));
565+
expect(doc.createTime.isEqual(new Firestore.Timestamp(1, 2000000)))
566+
.to.be.true;
567+
expect(doc.updateTime.isEqual(new Firestore.Timestamp(3, 4000))).to.be.true;
568+
expect(doc.readTime.isEqual(new Firestore.Timestamp(5, 6))).to.be.true;
565569
});
566570

567571
it('deserializes all supported types from Protobuf JS', () => {
@@ -620,7 +624,7 @@ describe('snapshot_() method', () => {
620624
'1970-01-01T00:00:05.000000006Z', 'json');
621625

622626
assert.equal(false, doc.exists);
623-
assert.ok(doc.readTime.isEqual(new Firestore.Timestamp(5, 6)));
627+
expect(doc.readTime.isEqual(new Firestore.Timestamp(5, 6))).to.be.true;
624628
});
625629

626630
it('handles invalid encoding format ', () => {
@@ -643,7 +647,7 @@ describe('doc() method', () => {
643647

644648
it('returns DocumentReference', () => {
645649
const documentRef = firestore.doc('collectionId/documentId');
646-
assert.ok(documentRef instanceof Firestore.DocumentReference);
650+
expect(documentRef).to.be.an.instanceOf(Firestore.DocumentReference);
647651
});
648652

649653
it('requires document path', () => {
@@ -682,7 +686,7 @@ describe('collection() method', () => {
682686

683687
it('returns collection', () => {
684688
const collection = firestore.collection('col1/doc1/col2');
685-
assert.ok(is.instance(collection, Firestore.CollectionReference));
689+
expect(collection).to.be.an.instanceOf(Firestore.CollectionReference);
686690
});
687691

688692
it('requires collection id', () => {
@@ -700,8 +704,8 @@ describe('collection() method', () => {
700704

701705
it('exposes properties', () => {
702706
const collection = firestore.collection('collectionId');
703-
assert.ok(collection.id);
704-
assert.ok(collection.doc);
707+
expect(collection.id).to.exist;
708+
expect(collection.doc).to.exist;
705709
assert.equal(collection.id, 'collectionId');
706710
});
707711
});
@@ -736,10 +740,10 @@ describe('getAll() method', () => {
736740
const doc = arguments[i + 1];
737741

738742
if (doc.found) {
739-
assert.ok(result[i].exists);
743+
expect(result[i].exists).to.be.true;
740744
assert.equal(result[i].ref.formattedName, doc.found.name);
741745
} else {
742-
assert.ok(!result[i].exists);
746+
expect(result[i].exists).to.be.false;
743747
assert.equal(result[i].ref.formattedName, doc.missing);
744748
}
745749
}

‎handwritten/firestore/dev/test/path.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {expect} from 'chai';
1718
import assert from 'power-assert';
1819

1920
import {FieldPath, ResourcePath} from '../src/path';
@@ -112,7 +113,7 @@ describe('FieldPath', () => {
112113
const path = new FieldPath('a');
113114
const equals = new FieldPath('a');
114115
const notEquals = new FieldPath('a', 'b', 'a');
115-
assert.ok(path.isEqual(equals));
116-
assert.ok(!path.isEqual(notEquals));
116+
expect(path.isEqual(equals)).to.be.true;
117+
expect(path.isEqual(notEquals)).to.be.false;
117118
});
118119
});

‎handwritten/firestore/dev/test/query.ts‎

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {expect} from 'chai';
1718
import extend from 'extend';
1819
import is from 'is';
1920
import assert from 'power-assert';
@@ -283,44 +284,19 @@ describe('query interface', () => {
283284
});
284285
});
285286

286-
it('has limit() method', () => {
287-
const query = firestore.collection('collectionId');
288-
assert.ok(query.limit);
289-
});
290-
291-
it('has orderBy() method', () => {
292-
const query = firestore.collection('collectionId');
293-
assert.ok(query.orderBy);
294-
});
295-
296-
it('has where() method', () => {
297-
const query = firestore.collection('collectionId');
298-
assert.ok(query.where);
299-
});
300-
301-
it('has stream() method', () => {
302-
const query = firestore.collection('collectionId');
303-
assert.ok(query.stream);
304-
});
305-
306-
it('has get() method', () => {
307-
const query = firestore.collection('collectionId');
308-
assert.ok(query.get);
309-
});
310-
311287
it('has isEqual() method', () => {
312288
const query = firestore.collection('collectionId');
313289

314290
const queryEquals = (equals, notEquals) => {
315291
for (let i = 0; i < equals.length; ++i) {
316292
for (const equal of equals) {
317-
assert.ok(equals[i].isEqual(equal));
318-
assert.ok(equal.isEqual(equals[i]));
293+
expect(equals[i].isEqual(equal)).to.be.true;
294+
expect(equal.isEqual(equals[i])).to.be.true;
319295
}
320296

321297
for (const notEqual of notEquals) {
322-
assert.ok(!equals[i].isEqual(notEqual));
323-
assert.ok(!notEqual.isEqual(equals[i]));
298+
expect(equals[i].isEqual(notEqual)).to.be.false;
299+
expect(notEqual.isEqual(equals[i])).to.be.false;
324300
}
325301
}
326302
};
@@ -430,7 +406,8 @@ describe('query interface', () => {
430406
return query.get().then(results => {
431407
assert.equal(0, results.size);
432408
assert.equal(true, results.empty);
433-
assert.ok(results.readTime.isEqual(new Firestore.Timestamp(5, 6)));
409+
expect(results.readTime.isEqual(new Firestore.Timestamp(5, 6)))
410+
.to.be.true;
434411
});
435412
});
436413
});
@@ -490,18 +467,22 @@ describe('query interface', () => {
490467
return query.get().then(results => {
491468
assert.equal(2, results.size);
492469
assert.equal(false, results.empty);
493-
assert.ok(results.readTime.isEqual(new Firestore.Timestamp(5, 6)));
470+
expect(results.readTime.isEqual(new Firestore.Timestamp(5, 6)))
471+
.to.be.true;
494472
assert.equal('first', results.docs[0].get('first'));
495473
assert.equal('second', results.docs[1].get('second'));
496474
assert.equal(2, results.docChanges().length);
497475

498476
let count = 0;
499477

500478
results.forEach(doc => {
501-
assert.ok(is.instanceof(doc, DocumentSnapshot));
502-
assert.ok(doc.createTime.isEqual(new Firestore.Timestamp(1, 2)));
503-
assert.ok(doc.updateTime.isEqual(new Firestore.Timestamp(3, 4)));
504-
assert.ok(doc.readTime.isEqual(new Firestore.Timestamp(5, 6)));
479+
expect(is.instanceof(doc, DocumentSnapshot)).to.be.true;
480+
expect(doc.createTime.isEqual(new Firestore.Timestamp(1, 2)))
481+
.to.be.true;
482+
expect(doc.updateTime.isEqual(new Firestore.Timestamp(3, 4)))
483+
.to.be.true;
484+
expect(doc.readTime.isEqual(new Firestore.Timestamp(5, 6)))
485+
.to.be.true;
505486
++count;
506487
});
507488

@@ -579,7 +560,7 @@ describe('query interface', () => {
579560
query.stream()
580561
.on('data',
581562
doc => {
582-
assert.ok(is.instanceof(doc, DocumentSnapshot));
563+
expect(doc).to.be.an.instanceOf(DocumentSnapshot);
583564
++received;
584565
})
585566
.on('end', () => {

0 commit comments

Comments
 (0)