Skip to content

Commit 806aabb

Browse files
author
Brian Chen
authored
Backport spec test function renaming (#2184)
1 parent 75f51a2 commit 806aabb

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

packages/firestore/test/unit/specs/spec_test_runner.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ abstract class TestRunner {
520520
async run(step: SpecStep): Promise<void> {
521521
await this.doStep(step);
522522
await this.queue.drain();
523-
this.validateStepExpectations(step.expectedSnapshotEvents!);
524-
await this.validateStateExpectations(step.expectedState!);
523+
this.validateExpectedSnapshotEvents(step.expectedSnapshotEvents!);
524+
await this.validateExpectedState(step.expectedState!);
525525
this.validateSnapshotsInSyncEvents(step.expectedSnapshotsInSyncEvents);
526526
this.eventList = [];
527527
this.rejectedDocs = [];
@@ -948,16 +948,18 @@ abstract class TestRunner {
948948
);
949949
}
950950

951-
private validateStepExpectations(stepExpectations: SnapshotEvent[]): void {
952-
if (stepExpectations) {
951+
private validateExpectedSnapshotEvents(
952+
expectedEvents: SnapshotEvent[]
953+
): void {
954+
if (expectedEvents) {
953955
expect(this.eventList.length).to.equal(
954-
stepExpectations.length,
956+
expectedEvents.length,
955957
'Number of expected and actual events mismatch'
956958
);
957959
const actualEventsSorted = this.eventList.sort((a, b) =>
958960
primitiveComparator(a.query.canonicalId(), b.query.canonicalId())
959961
);
960-
const expectedEventsSorted = stepExpectations.sort((a, b) =>
962+
const expectedEventsSorted = expectedEvents.sort((a, b) =>
961963
primitiveComparator(
962964
this.parseQuery(a.query).canonicalId(),
963965
this.parseQuery(b.query).canonicalId()
@@ -976,49 +978,52 @@ abstract class TestRunner {
976978
}
977979
}
978980

979-
private async validateStateExpectations(
980-
expectation: StateExpectation
981+
private async validateExpectedState(
982+
expectedState: StateExpectation
981983
): Promise<void> {
982-
if (expectation) {
983-
if ('numOutstandingWrites' in expectation) {
984+
if (expectedState) {
985+
if ('numOutstandingWrites' in expectedState) {
984986
expect(this.remoteStore.outstandingWrites()).to.equal(
985-
expectation.numOutstandingWrites
987+
expectedState.numOutstandingWrites
986988
);
987989
}
988-
if ('numActiveClients' in expectation) {
990+
if ('numActiveClients' in expectedState) {
989991
const activeClients = await this.persistence.getActiveClients();
990-
expect(activeClients.length).to.equal(expectation.numActiveClients);
992+
expect(activeClients.length).to.equal(expectedState.numActiveClients);
991993
}
992-
if ('writeStreamRequestCount' in expectation) {
994+
if ('writeStreamRequestCount' in expectedState) {
993995
expect(this.connection.writeStreamRequestCount).to.equal(
994-
expectation.writeStreamRequestCount
996+
expectedState.writeStreamRequestCount
995997
);
996998
}
997-
if ('watchStreamRequestCount' in expectation) {
999+
if ('watchStreamRequestCount' in expectedState) {
9981000
expect(this.connection.watchStreamRequestCount).to.equal(
999-
expectation.watchStreamRequestCount
1001+
expectedState.watchStreamRequestCount
10001002
);
10011003
}
1002-
if ('limboDocs' in expectation) {
1003-
this.expectedLimboDocs = expectation.limboDocs!.map(key);
1004+
if ('limboDocs' in expectedState) {
1005+
this.expectedLimboDocs = expectedState.limboDocs!.map(key);
10041006
}
1005-
if ('activeTargets' in expectation) {
1006-
this.expectedActiveTargets = expectation.activeTargets!;
1007+
if ('activeTargets' in expectedState) {
1008+
this.expectedActiveTargets = expectedState.activeTargets!;
10071009
}
1008-
if ('isPrimary' in expectation) {
1009-
expect(this.isPrimaryClient).to.eq(expectation.isPrimary!, 'isPrimary');
1010+
if ('isPrimary' in expectedState) {
1011+
expect(this.isPrimaryClient).to.eq(
1012+
expectedState.isPrimary!,
1013+
'isPrimary'
1014+
);
10101015
}
1011-
if ('isShutdown' in expectation) {
1012-
expect(this.started).to.equal(!expectation.isShutdown);
1016+
if ('isShutdown' in expectedState) {
1017+
expect(this.started).to.equal(!expectedState.isShutdown);
10131018
}
10141019
}
10151020

1016-
if (expectation && expectation.userCallbacks) {
1021+
if (expectedState && expectedState.userCallbacks) {
10171022
expect(this.acknowledgedDocs).to.have.members(
1018-
expectation.userCallbacks.acknowledgedDocs
1023+
expectedState.userCallbacks.acknowledgedDocs
10191024
);
10201025
expect(this.rejectedDocs).to.have.members(
1021-
expectation.userCallbacks.rejectedDocs
1026+
expectedState.userCallbacks.rejectedDocs
10221027
);
10231028
} else {
10241029
expect(this.acknowledgedDocs).to.be.empty;

0 commit comments

Comments
 (0)