Skip to content

Commit

Permalink
style(NODE-4834): eslint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
W-A-James committed Dec 16, 2022
1 parent 18fc7f9 commit b5c6876
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions test/unit/cmap/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ class InputStream extends Readable {
}
}

describe('new Connection()', function() {
describe('new Connection()', function () {
let server;
after(() => mock.cleanup());
before(() => mock.createServer().then(s => (server = s)));

it('should support fire-and-forget messages', function(done) {
it('should support fire-and-forget messages', function (done) {
server.setMessageHandler(request => {
const doc = request.document;
if (isHello(doc)) {
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('new Connection()', function() {
});
});

it('should destroy streams which time out', function(done) {
it('should destroy streams which time out', function (done) {
server.setMessageHandler(request => {
const doc = request.document;
if (isHello(doc)) {
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('new Connection()', function() {
});
});

it('should throw a network error with kBeforeHandshake set to false on timeout after handshake', function(done) {
it('should throw a network error with kBeforeHandshake set to false on timeout after handshake', function (done) {
server.setMessageHandler(request => {
const doc = request.document;
if (isHello(doc)) {
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('new Connection()', function() {
});
});

it('should throw a network error with kBeforeHandshake set to true on timeout before handshake', function(done) {
it('should throw a network error with kBeforeHandshake set to true on timeout before handshake', function (done) {
server.setMessageHandler(() => {
// respond to no requests to trigger timeout event
});
Expand All @@ -181,23 +181,23 @@ describe('new Connection()', function() {
});
});

describe('#onMessage', function() {
context('when the connection is a monitoring connection', function() {
describe('#onMessage', function () {
context('when the connection is a monitoring connection', function () {
let queue: Map<number, OperationDescription>;
let driverSocket: FakeSocket;
let connection: Connection;

beforeEach(function() {
beforeEach(function () {
driverSocket = sinon.spy(new FakeSocket());
});

context('when multiple hellos exist on the stream', function() {
context('when multiple hellos exist on the stream', function () {
let callbackSpy;
const inputStream = new InputStream();
const document = { ok: 1 };
const last = { isWritablePrimary: true };

beforeEach(function() {
beforeEach(function () {
callbackSpy = sinon.spy();
const firstHello = generateOpMsgBuffer(document);
const secondHello = generateOpMsgBuffer(document);
Expand All @@ -223,18 +223,18 @@ describe('new Connection()', function() {
inputStream.push(null);
});

it('calls the callback with the last hello document', async function() {
it('calls the callback with the last hello document', async function () {
const messages = await once(connection, 'message');
expect(messages[0].responseTo).to.equal(0);
expect(callbackSpy).to.be.calledOnceWith(undefined, last);
});
});

context('when requestId/responseTo do not match', function() {
context('when requestId/responseTo do not match', function () {
let callbackSpy;
const document = { ok: 1 };

beforeEach(function() {
beforeEach(function () {
callbackSpy = sinon.spy();

// @ts-expect-error: driverSocket does not fully satisfy the stream type, but that's okay
Expand Down Expand Up @@ -265,16 +265,16 @@ describe('new Connection()', function() {
connection.onMessage(message);
});

it('calls the operation description callback with the document', function() {
it('calls the operation description callback with the document', function () {
expect(callbackSpy).to.be.calledOnceWith(undefined, document);
});
});

context('when requestId/reponseTo match', function() {
context('when requestId/reponseTo match', function () {
let callbackSpy;
const document = { ok: 1 };

beforeEach(function() {
beforeEach(function () {
callbackSpy = sinon.spy();

// @ts-expect-error: driverSocket does not fully satisfy the stream type, but that's okay
Expand Down Expand Up @@ -305,23 +305,23 @@ describe('new Connection()', function() {
connection.onMessage(message);
});

it('calls the operation description callback with the document', function() {
it('calls the operation description callback with the document', function () {
expect(callbackSpy).to.be.calledOnceWith(undefined, document);
});
});

context('when no operation description is in the queue', function() {
context('when no operation description is in the queue', function () {
const document = { ok: 1 };

beforeEach(function() {
beforeEach(function () {
// @ts-expect-error: driverSocket does not fully satisfy the stream type, but that's okay
connection = sinon.spy(new Connection(driverSocket, connectionOptionsDefaults));
connection.isMonitoringConnection = true;
const queueSymbol = getSymbolFrom(connection, 'queue');
queue = connection[queueSymbol];
});

it('does not error', function() {
it('does not error', function () {
const msg = generateOpMsgBuffer(document);
const msgHeader: MessageHeader = {
length: msg.readInt32LE(0),
Expand All @@ -338,12 +338,12 @@ describe('new Connection()', function() {
});
});

context('when more than one operation description is in the queue', function() {
context('when more than one operation description is in the queue', function () {
let spyOne;
let spyTwo;
const document = { ok: 1 };

beforeEach(function() {
beforeEach(function () {
spyOne = sinon.spy();
spyTwo = sinon.spy();

Expand Down Expand Up @@ -380,7 +380,7 @@ describe('new Connection()', function() {
connection.onMessage(message);
});

it('calls all operation description callbacks with an error', function() {
it('calls all operation description callbacks with an error', function () {
expect(spyOne).to.be.calledOnce;
expect(spyTwo).to.be.calledOnce;
const errorOne = spyOne.firstCall.args[0];
Expand Down Expand Up @@ -542,12 +542,12 @@ describe('new Connection()', function() {
});
});

describe('.hasSessionSupport', function() {
describe('.hasSessionSupport', function () {
let connection;
const stream = new Socket();

context('when logicalSessionTimeoutMinutes is present', function() {
beforeEach(function() {
context('when logicalSessionTimeoutMinutes is present', function () {
beforeEach(function () {
const options = {
...connectionOptionsDefaults,
hostAddress: server.hostAddress(),
Expand All @@ -556,14 +556,14 @@ describe('new Connection()', function() {
connection = new Connection(stream, options);
});

it('returns true', function() {
it('returns true', function () {
expect(hasSessionSupport(connection)).to.be.true;
});
});

context('when logicalSessionTimeoutMinutes is not present', function() {
context('when in load balancing mode', function() {
beforeEach(function() {
context('when logicalSessionTimeoutMinutes is not present', function () {
context('when in load balancing mode', function () {
beforeEach(function () {
const options = {
...connectionOptionsDefaults,
hostAddress: server.hostAddress(),
Expand All @@ -572,13 +572,13 @@ describe('new Connection()', function() {
connection = new Connection(stream, options);
});

it('returns true', function() {
it('returns true', function () {
expect(hasSessionSupport(connection)).to.be.true;
});
});

context('when not in load balancing mode', function() {
beforeEach(function() {
context('when not in load balancing mode', function () {
beforeEach(function () {
const options = {
...connectionOptionsDefaults,
hostAddress: server.hostAddress(),
Expand All @@ -587,7 +587,7 @@ describe('new Connection()', function() {
connection = new Connection(stream, options);
});

it('returns false', function() {
it('returns false', function () {
expect(hasSessionSupport(connection)).to.be.false;
});
});
Expand Down Expand Up @@ -616,7 +616,7 @@ describe('new Connection()', function() {
clock.restore();
});

context('when options.force == true', function() {
context('when options.force == true', function () {
it('calls steam.destroy', () => {
connection.destroy({ force: true });
clock.tick(1);
Expand Down Expand Up @@ -650,7 +650,7 @@ describe('new Connection()', function() {
});
});

context('when options.force == false', function() {
context('when options.force == false', function () {
it('calls stream.end', () => {
connection.destroy({ force: false });
clock.tick(1);
Expand Down

0 comments on commit b5c6876

Please sign in to comment.