Skip to content

Commit

Permalink
refactor(typescript): noImplicitAny for message-stream test file (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenqlogic authored and callmehiphop committed Mar 6, 2019
1 parent a764c61 commit 0a03d63
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions test/message-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/

import * as assert from 'assert';
import {Metadata} from 'grpc';
import {Metadata, ServiceError} from 'grpc';
import * as proxyquire from 'proxyquire';
import * as sinon from 'sinon';
import {Duplex, PassThrough} from 'stream';
import * as uuid from 'uuid';
import * as messageTypes from '../src/message-stream';
import {Subscriber} from '../src/subscriber';

// just need this for unit tests.. we have a ponyfill for destroy on
// MessageStream and gax streams use Duplexify
Expand Down Expand Up @@ -112,7 +114,7 @@ class FakeSubscriber {
name: string;
ackDeadline: number;
client: FakeGaxClient;
constructor(client) {
constructor(client: FakeGaxClient) {
this.name = uuid.v4();
this.ackDeadline = Math.floor(Math.random() * 600);
this.client = client;
Expand All @@ -126,11 +128,11 @@ describe('MessageStream', () => {
const sandbox = sinon.createSandbox();

let client: FakeGrpcClient;
let subscriber: FakeSubscriber;
let subscriber: Subscriber;

// tslint:disable-next-line variable-name
let MessageStream;
let messageStream;
let MessageStream: typeof messageTypes.MessageStream;
let messageStream: messageTypes.MessageStream;

before(() => {
MessageStream = proxyquire('../src/message-stream.js', {
Expand All @@ -141,7 +143,7 @@ describe('MessageStream', () => {
beforeEach(() => {
const gaxClient = new FakeGaxClient();
client = gaxClient.client; // we hit the grpc client directly
subscriber = new FakeSubscriber(gaxClient);
subscriber = new FakeSubscriber(gaxClient) as {} as Subscriber;
messageStream = new MessageStream(subscriber);
});

Expand All @@ -156,8 +158,8 @@ describe('MessageStream', () => {
objectMode: true,
highWaterMark: 0,
};

assert.deepStrictEqual(messageStream.options, expectedOptions);
assert.deepStrictEqual(
(messageStream as {} as FakePassThrough).options, expectedOptions);
});

it('should respect the highWaterMark option', () => {
Expand All @@ -169,7 +171,8 @@ describe('MessageStream', () => {
highWaterMark,
};

assert.deepStrictEqual(ms.options, expectedOptions);
assert.deepStrictEqual(
(ms as {} as FakePassThrough).options, expectedOptions);
});

it('should set destroyed to false', () => {
Expand Down Expand Up @@ -302,7 +305,7 @@ describe('MessageStream', () => {
});

describe('without native destroy', () => {
let destroy;
let destroy: (err?: Error) => void;

before(() => {
destroy = FakePassThrough.prototype.destroy;
Expand Down Expand Up @@ -338,7 +341,7 @@ describe('MessageStream', () => {
const fakeResponses = [{}, {}, {}, {}, {}];
const received: object[] = [];

messageStream.on('data', chunk => received.push(chunk))
messageStream.on('data', (chunk: Buffer) => received.push(chunk))
.on('end', () => {
assert.deepStrictEqual(received, fakeResponses);
done();
Expand Down Expand Up @@ -379,7 +382,7 @@ describe('MessageStream', () => {
const fakeError = new Error('err');
const expectedMessage = `Failed to connect to channel. Reason: err`;

ms.on('error', err => {
ms.on('error', (err: ServiceError) => {
assert.strictEqual(err.code, 2);
assert.strictEqual(err.message, expectedMessage);
assert.strictEqual(ms.destroyed, true);
Expand All @@ -397,7 +400,7 @@ describe('MessageStream', () => {
const ms = new MessageStream(subscriber);
const fakeError = new Error('Failed to connect before the deadline');

ms.on('error', err => {
ms.on('error', (err: ServiceError) => {
assert.strictEqual(err.code, 4);
done();
});
Expand Down Expand Up @@ -483,7 +486,7 @@ describe('MessageStream', () => {
details: 'Err',
};

messageStream.on('error', err => {
messageStream.on('error', (err: ServiceError) => {
assert(err instanceof Error);
assert.strictEqual(err.code, fakeStatus.code);
assert.strictEqual(err.message, fakeStatus.details);
Expand Down

0 comments on commit 0a03d63

Please sign in to comment.