diff --git a/libraries/botframework-streaming/eslint.config.cjs b/libraries/botframework-streaming/eslint.config.cjs index 2b279a321f..f1b7a431b0 100644 --- a/libraries/botframework-streaming/eslint.config.cjs +++ b/libraries/botframework-streaming/eslint.config.cjs @@ -1,13 +1,8 @@ -const onlyWarn = require("eslint-plugin-only-warn"); -const sharedConfig = require("../../eslint.config.cjs") +const sharedConfig = require('../../eslint.config.cjs'); module.exports = [ ...sharedConfig, { - ignores: ["**/es5/"], + ignores: ['**/es5/'], }, - { - plugins: { - "only-warn": onlyWarn, - }, - }] +]; diff --git a/libraries/botframework-streaming/package.json b/libraries/botframework-streaming/package.json index a1b2d1a885..fbcc72a877 100644 --- a/libraries/botframework-streaming/package.json +++ b/libraries/botframework-streaming/package.json @@ -32,7 +32,6 @@ "dependencies": { "@types/node": "18.19.47", "@types/ws": "^6.0.3", - "eslint-plugin-only-warn": "^1.1.0", "uuid": "^10.0.0", "ws": "^7.5.10" }, diff --git a/libraries/botframework-streaming/src/assemblers/payloadAssembler.ts b/libraries/botframework-streaming/src/assemblers/payloadAssembler.ts index 2883426017..9eeb94a46e 100644 --- a/libraries/botframework-streaming/src/assemblers/payloadAssembler.ts +++ b/libraries/botframework-streaming/src/assemblers/payloadAssembler.ts @@ -39,7 +39,10 @@ export class PayloadAssembler { * @param streamManager The [StreamManager](xref:botframework-streaming.StreamManager) managing the stream being assembled. * @param params Parameters for a streaming assembler. */ - constructor(private readonly streamManager: StreamManager, params: IAssemblerParams) { + constructor( + private readonly streamManager: StreamManager, + params: IAssemblerParams, + ) { if (params.header) { this.id = params.header.id; this.payloadType = params.header.payloadType; @@ -141,7 +144,7 @@ export class PayloadAssembler { private async processStreams( responsePayload: IResponsePayload | IRequestPayload, - receiveResponse: IReceiveResponse | IReceiveRequest + receiveResponse: IReceiveResponse | IReceiveRequest, ): Promise { responsePayload.streams?.forEach((responseStream) => { // There was a bug in how streams were handled. In .NET, the StreamDescription definiton mapped the @@ -151,7 +154,7 @@ export class PayloadAssembler { // .NET code: // https://github.com/microsoft/botbuilder-dotnet/blob/a79036ddf6625ec3fd68a6f7295886eb7831bc1c/libraries/Microsoft.Bot.Streaming/Payloads/Models/StreamDescription.cs#L28-L29 const contentType = - ((responseStream as unknown) as Record).type ?? responseStream.contentType; + (responseStream as unknown as Record).type ?? responseStream.contentType; const contentAssembler = this.streamManager.getPayloadAssembler(responseStream.id); diff --git a/libraries/botframework-streaming/src/contentStream.ts b/libraries/botframework-streaming/src/contentStream.ts index b554df3e28..b67059a694 100644 --- a/libraries/botframework-streaming/src/contentStream.ts +++ b/libraries/botframework-streaming/src/contentStream.ts @@ -91,7 +91,6 @@ export class ContentStream { return JSON.parse(stringToParse); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any private async readAll(): Promise> { // do a read-all const allData: INodeBuffer[] = []; @@ -107,14 +106,15 @@ export class ContentStream { if (count < this.length) { const readToEnd = new Promise((resolve): void => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const callback = (cs: ContentStream) => (chunk: any): void => { - allData.push(chunk); - count += (chunk as INodeBuffer).length; - if (count === cs.length) { - resolve(true); - } - }; + const callback = + (cs: ContentStream) => + (chunk: any): void => { + allData.push(chunk); + count += (chunk as INodeBuffer).length; + if (count === cs.length) { + resolve(true); + } + }; stream.subscribe(callback(this)); }); diff --git a/libraries/botframework-streaming/src/disassemblers/cancelDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/cancelDisassembler.ts index a4bf7ec5b9..1c08feb1b3 100644 --- a/libraries/botframework-streaming/src/disassemblers/cancelDisassembler.ts +++ b/libraries/botframework-streaming/src/disassemblers/cancelDisassembler.ts @@ -22,7 +22,7 @@ export class CancelDisassembler { constructor( private readonly sender: PayloadSender, private readonly id: string, - private readonly payloadType: PayloadTypes + private readonly payloadType: PayloadTypes, ) {} /** diff --git a/libraries/botframework-streaming/src/disassemblers/payloadDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/payloadDisassembler.ts index ad4b70bf27..3d5a8c27da 100644 --- a/libraries/botframework-streaming/src/disassemblers/payloadDisassembler.ts +++ b/libraries/botframework-streaming/src/disassemblers/payloadDisassembler.ts @@ -24,7 +24,10 @@ export abstract class PayloadDisassembler { * @param sender The [PayloadSender](xref:botframework-streaming.PayloadSender) used to send the disassembled payload chunks. * @param id The ID of this disassembler. */ - constructor(private readonly sender: PayloadSender, private readonly id: string) {} + constructor( + private readonly sender: PayloadSender, + private readonly id: string, + ) {} /** * Serializes the item into the [IStreamWrapper](xref:botframework-streaming.IStreamWrapper) that exposes the stream and length of the result. diff --git a/libraries/botframework-streaming/src/disassemblers/requestDisassembler.ts b/libraries/botframework-streaming/src/disassemblers/requestDisassembler.ts index 8042e2e7e4..7fa5eabf4a 100644 --- a/libraries/botframework-streaming/src/disassemblers/requestDisassembler.ts +++ b/libraries/botframework-streaming/src/disassemblers/requestDisassembler.ts @@ -25,7 +25,11 @@ export class RequestDisassembler extends PayloadDisassembler { * @param id The ID of this disassembler. * @param request The request to be disassembled. */ - constructor(sender: PayloadSender, id: string, public request?: StreamingRequest) { + constructor( + sender: PayloadSender, + id: string, + public request?: StreamingRequest, + ) { super(sender, id); } diff --git a/libraries/botframework-streaming/src/httpContentStream.ts b/libraries/botframework-streaming/src/httpContentStream.ts index 0f32a1e885..7599d661ed 100644 --- a/libraries/botframework-streaming/src/httpContentStream.ts +++ b/libraries/botframework-streaming/src/httpContentStream.ts @@ -41,7 +41,10 @@ export class HttpContent { * @param headers The Streaming Http content header definition. * @param stream The stream of buffered data. */ - constructor(public headers: IHttpContentHeaders, private readonly stream: SubscribableStream) {} + constructor( + public headers: IHttpContentHeaders, + private readonly stream: SubscribableStream, + ) {} /** * Gets the data contained within this [HttpContent](xref:botframework-streaming.HttpContent). diff --git a/libraries/botframework-streaming/src/interfaces/IBrowserFileReader.ts b/libraries/botframework-streaming/src/interfaces/IBrowserFileReader.ts index 0e0f3ef23e..ccf351e441 100644 --- a/libraries/botframework-streaming/src/interfaces/IBrowserFileReader.ts +++ b/libraries/botframework-streaming/src/interfaces/IBrowserFileReader.ts @@ -13,9 +13,7 @@ * This interface supports the framework and is not intended to be called directly for your code. */ export interface IBrowserFileReader { - /* eslint-disable @typescript-eslint/no-explicit-any */ result: any; onload: (event: any) => void; readAsArrayBuffer: (blobOrFile: any) => void; - /* eslint-enable @typescript-eslint/no-explicit-any */ } diff --git a/libraries/botframework-streaming/src/interfaces/IBrowserWebSocket.ts b/libraries/botframework-streaming/src/interfaces/IBrowserWebSocket.ts index 0a03f808b6..c62976e4fc 100644 --- a/libraries/botframework-streaming/src/interfaces/IBrowserWebSocket.ts +++ b/libraries/botframework-streaming/src/interfaces/IBrowserWebSocket.ts @@ -13,13 +13,11 @@ * This interface supports the framework and is not intended to be called directly for your code. */ export interface IBrowserWebSocket { - /* eslint-disable @typescript-eslint/no-explicit-any */ onclose: (event: any) => void; onerror: (event: any) => void; onmessage: (event: any) => void; onopen: (event: any) => void; send(buffer: any): void; - /* eslint-enable @typescript-eslint/no-explicit-any */ readyState: number; close(): void; } diff --git a/libraries/botframework-streaming/src/interfaces/IEventEmitter.ts b/libraries/botframework-streaming/src/interfaces/IEventEmitter.ts index 8da005acb1..aa8b2e64b0 100644 --- a/libraries/botframework-streaming/src/interfaces/IEventEmitter.ts +++ b/libraries/botframework-streaming/src/interfaces/IEventEmitter.ts @@ -12,7 +12,6 @@ * This interface supports the framework and is not intended to be called directly for your code. */ export interface IEventEmitter { - /* eslint-disable @typescript-eslint/no-explicit-any */ addListener(event: string | symbol, listener: (...args: any[]) => void): this; emit(event: string | symbol, ...args: any[]): boolean; off(event: string | symbol, listener: (...args: any[]) => void): this; @@ -21,14 +20,11 @@ export interface IEventEmitter { removeListener(event: string | symbol, listener: (...args: any[]) => void): this; prependListener(event: string | symbol, listener: (...args: any[]) => void): this; prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this; - /* eslint-enable @typescript-eslint/no-explicit-any */ removeAllListeners(event?: string | symbol): this; setMaxListeners(n: number): this; getMaxListeners(): number; - /* eslint-disable @typescript-eslint/ban-types */ - listeners(event: string | symbol): Function[]; - rawListeners(event: string | symbol): Function[]; - /* eslint-enable @typescript-eslint/ban-types */ + listeners(event: string | symbol): ((...args: any[]) => void)[]; + rawListeners(event: string | symbol): ((...args: any[]) => void)[]; listenerCount(type: string | symbol): number; eventNames(): Array; } diff --git a/libraries/botframework-streaming/src/interfaces/INodeBuffer.ts b/libraries/botframework-streaming/src/interfaces/INodeBuffer.ts index 78a3bf09eb..5658ae88a7 100644 --- a/libraries/botframework-streaming/src/interfaces/INodeBuffer.ts +++ b/libraries/botframework-streaming/src/interfaces/INodeBuffer.ts @@ -26,11 +26,9 @@ export type BufferEncoding = * This interface supports the framework and is not intended to be called directly for your code. */ export interface INodeBuffer extends Uint8Array { - // eslint-disable-next-line @typescript-eslint/no-explicit-any constructor: any; write(string: string, offset?: number, length?: number, encoding?: string): number; toString(encoding?: string, start?: number, end?: number): string; - // eslint-disable-next-line @typescript-eslint/no-explicit-any toJSON(): { type: 'Buffer'; data: any[] }; equals(otherBuffer: Uint8Array): boolean; compare( @@ -38,7 +36,7 @@ export interface INodeBuffer extends Uint8Array { targetStart?: number, targetEnd?: number, sourceStart?: number, - sourceEnd?: number + sourceEnd?: number, ): number; copy(targetBuffer: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; slice(start?: number, end?: number): this; @@ -92,7 +90,6 @@ export interface INodeBuffer extends Uint8Array { writeDoubleLE(value: number, offset: number, noAssert?: boolean): number; writeDoubleBE(value: number, offset: number, noAssert?: boolean): number; - // eslint-disable-next-line @typescript-eslint/no-explicit-any fill(value: any, offset?: number, end?: number): this; indexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: string): number; lastIndexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: string): number; diff --git a/libraries/botframework-streaming/src/interfaces/INodeDuplex.ts b/libraries/botframework-streaming/src/interfaces/INodeDuplex.ts index bf9db21bdb..4020bece05 100644 --- a/libraries/botframework-streaming/src/interfaces/INodeDuplex.ts +++ b/libraries/botframework-streaming/src/interfaces/INodeDuplex.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */ /** * @module botframework-streaming */ diff --git a/libraries/botframework-streaming/src/interfaces/INodeIncomingMessage.ts b/libraries/botframework-streaming/src/interfaces/INodeIncomingMessage.ts index efa181a64a..b48a8de2ff 100644 --- a/libraries/botframework-streaming/src/interfaces/INodeIncomingMessage.ts +++ b/libraries/botframework-streaming/src/interfaces/INodeIncomingMessage.ts @@ -15,12 +15,10 @@ export interface INodeIncomingMessage { /** * Optional. The request headers. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any headers?: any; /** * Optional. The request method. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any method?: any; } diff --git a/libraries/botframework-streaming/src/interfaces/INodeSocket.ts b/libraries/botframework-streaming/src/interfaces/INodeSocket.ts index 5453a66a44..81aee33eae 100644 --- a/libraries/botframework-streaming/src/interfaces/INodeSocket.ts +++ b/libraries/botframework-streaming/src/interfaces/INodeSocket.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */ /** * @module botframework-streaming */ diff --git a/libraries/botframework-streaming/src/interfaces/ISocket.ts b/libraries/botframework-streaming/src/interfaces/ISocket.ts index 84844176f8..915dbb806a 100644 --- a/libraries/botframework-streaming/src/interfaces/ISocket.ts +++ b/libraries/botframework-streaming/src/interfaces/ISocket.ts @@ -18,10 +18,7 @@ export interface ISocket { write(buffer: INodeBuffer); connect(serverAddress: string): Promise; close(); - // eslint-disable-next-line @typescript-eslint/no-explicit-any setOnMessageHandler(handler: (x: any) => void); - // eslint-disable-next-line @typescript-eslint/no-explicit-any setOnErrorHandler(handler: (x: any) => void); - // eslint-disable-next-line @typescript-eslint/no-explicit-any setOnCloseHandler(handler: (x: any) => void); } diff --git a/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts b/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts index dc86172118..4da283e313 100644 --- a/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts +++ b/libraries/botframework-streaming/src/namedPipe/namedPipeClient.ts @@ -47,7 +47,7 @@ export class NamedPipeClient implements IStreamingTransportClient { this._requestHandler, this._requestManager, this._sender, - this._receiver + this._receiver, ); } @@ -83,7 +83,6 @@ export class NamedPipeClient implements IStreamingTransportClient { return this._protocolAdapter.sendRequest(request); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any private onConnectionDisconnected(sender: Record, args: any): void { if (!this._isDisconnecting) { this._isDisconnecting = true; @@ -101,7 +100,7 @@ export class NamedPipeClient implements IStreamingTransportClient { .then((): void => {}) .catch((error): void => { throw new Error( - `Failed to reconnect. Reason: ${error.message} Sender: ${sender} Args: ${args}. ` + `Failed to reconnect. Reason: ${error.message} Sender: ${sender} Args: ${args}. `, ); }); } diff --git a/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts b/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts index 0ebe42752e..635b69f908 100644 --- a/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts +++ b/libraries/botframework-streaming/src/namedPipe/namedPipeServer.ts @@ -32,7 +32,11 @@ export class NamedPipeServer implements IStreamingTransportServer { * @param requestHandler Optional [RequestHandler](xref:botframework-streaming.RequestHandler) to process incoming messages received by this client. * @param autoReconnect Deprecated: Automatic reconnection is the default behavior. */ - constructor(private readonly baseName: string, requestHandler?: RequestHandler, autoReconnect?: boolean) { + constructor( + private readonly baseName: string, + requestHandler?: RequestHandler, + autoReconnect?: boolean, + ) { if (!baseName) { throw new TypeError('NamedPipeServer: Missing baseName parameter'); } diff --git a/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts b/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts index 2daebe1306..909e896ac4 100644 --- a/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts +++ b/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts @@ -20,7 +20,6 @@ export class NamedPipeTransport implements ITransportSender, ITransportReceiver private _activeOffset = 0; private _activeReceiveCount = 0; private _activeReceiveResolve: (resolve: INodeBuffer) => void; - // eslint-disable-next-line @typescript-eslint/no-explicit-any private _activeReceiveReject: (reason?: any) => void; /** diff --git a/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts b/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts index 870b5d32d6..3ad941fc86 100644 --- a/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts +++ b/libraries/botframework-streaming/src/payloadTransport/payloadReceiver.ts @@ -54,7 +54,7 @@ export class PayloadReceiver { */ subscribe( getStream: (header: IHeader) => SubscribableStream, - receiveAction: (header: IHeader, stream: SubscribableStream, count: number) => void + receiveAction: (header: IHeader, stream: SubscribableStream, count: number) => void, ): void { this._getStream = getStream; this._receiveAction = receiveAction; @@ -86,7 +86,7 @@ export class PayloadReceiver { let readSoFar = 0; while (readSoFar < PayloadConstants.MaxHeaderLength) { this._receiveHeaderBuffer = await this._receiver.receive( - PayloadConstants.MaxHeaderLength - readSoFar + PayloadConstants.MaxHeaderLength - readSoFar, ); if (this._receiveHeaderBuffer) { @@ -108,7 +108,7 @@ export class PayloadReceiver { ) { const count = Math.min( header.payloadLength - bytesActuallyRead, - PayloadConstants.MaxPayloadLength + PayloadConstants.MaxPayloadLength, ); this._receivePayloadBuffer = await this._receiver.receive(count); bytesActuallyRead += this._receivePayloadBuffer.byteLength; diff --git a/libraries/botframework-streaming/src/payloadTransport/transportDisconnectedEventHandler.ts b/libraries/botframework-streaming/src/payloadTransport/transportDisconnectedEventHandler.ts index dcc00f39c4..5012fbfad3 100644 --- a/libraries/botframework-streaming/src/payloadTransport/transportDisconnectedEventHandler.ts +++ b/libraries/botframework-streaming/src/payloadTransport/transportDisconnectedEventHandler.ts @@ -8,5 +8,4 @@ import { TransportDisconnectedEvent } from './transportDisconnectedEvent'; -// eslint-disable-next-line @typescript-eslint/no-explicit-any export type TransportDisconnectedEventHandler = (sender: any, e: TransportDisconnectedEvent) => void; diff --git a/libraries/botframework-streaming/src/payloads/headerSerializer.ts b/libraries/botframework-streaming/src/payloads/headerSerializer.ts index 67eeef8972..cb54b56e3e 100644 --- a/libraries/botframework-streaming/src/payloads/headerSerializer.ts +++ b/libraries/botframework-streaming/src/payloads/headerSerializer.ts @@ -41,7 +41,7 @@ export class HeaderSerializer { this.headerLengthPadder(header.payloadLength, this.LengthLength, '0'), this.LengthOffset, this.LengthLength, - this.Encoding + this.Encoding, ); buffer.write(this.Delimiter, this.LengthDelimeterOffset, 1, this.Encoding); buffer.write(header.id, this.IdOffset); diff --git a/libraries/botframework-streaming/src/payloads/index.ts b/libraries/botframework-streaming/src/payloads/index.ts index 3f13e4f3e7..17ec994684 100644 --- a/libraries/botframework-streaming/src/payloads/index.ts +++ b/libraries/botframework-streaming/src/payloads/index.ts @@ -12,4 +12,3 @@ export * from './payloadAssemblerManager'; export * from './payloadTypes'; export * from './requestManager'; export * from './sendOperations'; -export * from './streamManager'; diff --git a/libraries/botframework-streaming/src/payloads/payloadAssemblerManager.ts b/libraries/botframework-streaming/src/payloads/payloadAssemblerManager.ts index 6e03145a3e..417723194d 100644 --- a/libraries/botframework-streaming/src/payloads/payloadAssemblerManager.ts +++ b/libraries/botframework-streaming/src/payloads/payloadAssemblerManager.ts @@ -27,7 +27,7 @@ export class PayloadAssemblerManager { constructor( private readonly streamManager: StreamManager, private readonly onReceiveResponse: (id: string, receiveResponse: IReceiveResponse) => Promise, - private readonly onReceiveRequest: (id: string, receiveRequest: IReceiveRequest) => Promise + private readonly onReceiveRequest: (id: string, receiveRequest: IReceiveRequest) => Promise, ) {} /** diff --git a/libraries/botframework-streaming/src/payloads/requestManager.ts b/libraries/botframework-streaming/src/payloads/requestManager.ts index 2b7d9d46b7..524cc2bb75 100644 --- a/libraries/botframework-streaming/src/payloads/requestManager.ts +++ b/libraries/botframework-streaming/src/payloads/requestManager.ts @@ -13,7 +13,6 @@ import { IReceiveResponse } from '../interfaces'; class PendingRequest { requestId: string; resolve: (response: IReceiveResponse) => void; - // eslint-disable-next-line @typescript-eslint/no-explicit-any reject: (reason?: any) => void; } diff --git a/libraries/botframework-streaming/src/payloads/sendOperations.ts b/libraries/botframework-streaming/src/payloads/sendOperations.ts index 13da105a9c..c24c8b2a54 100644 --- a/libraries/botframework-streaming/src/payloads/sendOperations.ts +++ b/libraries/botframework-streaming/src/payloads/sendOperations.ts @@ -41,11 +41,9 @@ export class SendOperations { await disassembler.disassemble(); if (request.streams) { - request.streams.forEach( - async (contentStream): Promise => { - await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); - } - ); + request.streams.forEach(async (contentStream): Promise => { + await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); + }); } } @@ -61,11 +59,9 @@ export class SendOperations { await disassembler.disassemble(); if (response.streams) { - response.streams.forEach( - async (contentStream): Promise => { - await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); - } - ); + response.streams.forEach(async (contentStream): Promise => { + await new HttpContentStreamDisassembler(this.payloadSender, contentStream).disassemble(); + }); } } diff --git a/libraries/botframework-streaming/src/protocolAdapter.ts b/libraries/botframework-streaming/src/protocolAdapter.ts index 9690e739f8..104373670e 100644 --- a/libraries/botframework-streaming/src/protocolAdapter.ts +++ b/libraries/botframework-streaming/src/protocolAdapter.ts @@ -43,7 +43,7 @@ export class ProtocolAdapter { requestHandler: RequestHandler, requestManager: RequestManager, sender: PayloadSender, - receiver: PayloadReceiver + receiver: PayloadReceiver, ) { this.requestHandler = requestHandler; this.requestManager = requestManager; @@ -54,12 +54,12 @@ export class ProtocolAdapter { this.assemblerManager = new PayloadAssemblerManager( this.streamManager, (id: string, response: IReceiveResponse): Promise => this.onReceiveResponse(id, response), - (id: string, request: IReceiveRequest): Promise => this.onReceiveRequest(id, request) + (id: string, request: IReceiveRequest): Promise => this.onReceiveRequest(id, request), ); this.payloadReceiver.subscribe( (header: IHeader): SubscribableStream => this.assemblerManager.getPayloadStream(header), (header: IHeader, contentStream: SubscribableStream, contentLength: number): void => - this.assemblerManager.onReceive(header, contentStream, contentLength) + this.assemblerManager.onReceive(header, contentStream, contentLength), ); } diff --git a/libraries/botframework-streaming/src/streamingRequest.ts b/libraries/botframework-streaming/src/streamingRequest.ts index 84870da62f..819977701f 100644 --- a/libraries/botframework-streaming/src/streamingRequest.ts +++ b/libraries/botframework-streaming/src/streamingRequest.ts @@ -64,7 +64,6 @@ export class StreamingRequest { * * @param body The JSON text to write to the body of the streamingRequest. */ - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any setBody(body: any): void { if (typeof body === 'string') { const stream = new SubscribableStream(); @@ -75,8 +74,8 @@ export class StreamingRequest { type: 'application/json; charset=utf-8', contentLength: stream.length, }, - stream - ) + stream, + ), ); } else if (typeof body === 'object') { this.addStream(body); diff --git a/libraries/botframework-streaming/src/streamingResponse.ts b/libraries/botframework-streaming/src/streamingResponse.ts index 55109d8485..f730e1250b 100644 --- a/libraries/botframework-streaming/src/streamingResponse.ts +++ b/libraries/botframework-streaming/src/streamingResponse.ts @@ -46,7 +46,6 @@ export class StreamingResponse { * * @param body The JSON text to write to the body of the streaming response. */ - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any setBody(body: any): void { const stream = new SubscribableStream(); stream.write(JSON.stringify(body), 'utf8'); @@ -56,8 +55,8 @@ export class StreamingResponse { type: 'application/json; charset=utf-8', contentLength: stream.length, }, - stream - ) + stream, + ), ); } } diff --git a/libraries/botframework-streaming/src/subscribableStream.ts b/libraries/botframework-streaming/src/subscribableStream.ts index f99959e81c..2b2702d372 100644 --- a/libraries/botframework-streaming/src/subscribableStream.ts +++ b/libraries/botframework-streaming/src/subscribableStream.ts @@ -14,7 +14,6 @@ export class SubscribableStream extends Duplex { length = 0; private readonly bufferList: Buffer[] = []; - // eslint-disable-next-line @typescript-eslint/no-explicit-any private _onData: (chunk: any) => void; /** @@ -34,7 +33,6 @@ export class SubscribableStream extends Duplex { * @param _encoding The encoding. Unused in the implementation of Duplex. * @param callback Callback for when this chunk of data is flushed. */ - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any _write(chunk: any, _encoding: string, callback: (error?: Error | null) => void): void { const buffer = Buffer.from(chunk); this.bufferList.push(buffer); @@ -72,7 +70,6 @@ export class SubscribableStream extends Duplex { * * @param onData Callback to be called when onData is executed. */ - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any subscribe(onData: (chunk: any) => void): void { this._onData = onData; } diff --git a/libraries/botframework-streaming/src/utilities/createNodeServer.ts b/libraries/botframework-streaming/src/utilities/createNodeServer.ts index 47d2edcd60..f8ec5e6203 100644 --- a/libraries/botframework-streaming/src/utilities/createNodeServer.ts +++ b/libraries/botframework-streaming/src/utilities/createNodeServer.ts @@ -35,27 +35,24 @@ export function createNodeServer(callback?: ConnectionListener): INodeServer { * @returns a server factory function */ export function getServerFactory(): (callback?: ConnectionListener) => INodeServer { - if (typeof require !== undefined) { - // eslint-disable-next-line @typescript-eslint/no-var-requires + if (typeof require !== 'undefined') { + // eslint-disable-next-line @typescript-eslint/no-require-imports return require('net').Server; } throw TypeError( - "require is undefined. Must be in a Node module to require 'net' dynamically in order to fetch Server factory." + "require is undefined. Must be in a Node module to require 'net' dynamically in order to fetch Server factory.", ); } -// eslint-disable-next-line @typescript-eslint/no-explicit-any function isNetServer(o: any): o is INodeServer { return hasCloseMethod(o) && hasListenMethod(o); } -// eslint-disable-next-line @typescript-eslint/no-explicit-any function hasCloseMethod(o: any): o is INodeServer { return o.close && typeof o.close === 'function'; } -// eslint-disable-next-line @typescript-eslint/no-explicit-any function hasListenMethod(o: any): o is INodeServer { return o.listen && typeof o.listen === 'function'; } diff --git a/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts b/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts index bbec707294..83d885b9f7 100644 --- a/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts +++ b/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts @@ -32,7 +32,6 @@ export class BrowserWebSocket implements ISocket { */ async connect(serverAddress: string): Promise { let resolver: (value: void | PromiseLike) => void; - // eslint-disable-next-line @typescript-eslint/no-explicit-any let rejector: (reason?: any) => void; if (!this.webSocket) { @@ -83,7 +82,6 @@ export class BrowserWebSocket implements ISocket { * * @param handler The callback to handle the "message" event. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any setOnMessageHandler(handler: (x: any) => void): void { const bufferKey = 'buffer'; const packets = []; @@ -92,7 +90,7 @@ export class BrowserWebSocket implements ISocket { const queueEntry = { buffer: null }; packets.push(queueEntry); fileReader.onload = (e): void => { - const t = (e.target as unknown) as IBrowserFileReader; + const t = e.target as unknown as IBrowserFileReader; queueEntry[bufferKey] = t.result; if (packets[0] === queueEntry) { while (0 < packets.length && packets[0][bufferKey]) { @@ -110,7 +108,6 @@ export class BrowserWebSocket implements ISocket { * * @param handler The callback to handle the "error" event. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any setOnErrorHandler(handler: (x: any) => void): void { this.webSocket.onerror = (error): void => { if (error) { @@ -124,7 +121,6 @@ export class BrowserWebSocket implements ISocket { * * @param handler The callback to handle the "close" event. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any setOnCloseHandler(handler: (x: any) => void): void { this.webSocket.onclose = handler; } diff --git a/libraries/botframework-streaming/src/webSocket/browserWebSocketClient.ts b/libraries/botframework-streaming/src/webSocket/browserWebSocketClient.ts index 7d7902cfd1..fa7a5fe5d2 100644 --- a/libraries/botframework-streaming/src/webSocket/browserWebSocketClient.ts +++ b/libraries/botframework-streaming/src/webSocket/browserWebSocketClient.ts @@ -59,7 +59,7 @@ export class WebSocketClient implements IStreamingTransportClient { this._requestHandler, this._requestManager, this._sender, - this._receiver + this._receiver, ); } @@ -94,7 +94,6 @@ export class WebSocketClient implements IStreamingTransportClient { return this._protocolAdapter.sendRequest(request); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any private onConnectionDisconnected(sender: Record, args: any): void { // Rejects all pending requests on disconnect. this._requestManager.rejectAllResponses(new Error('Disconnect was called.')); @@ -106,8 +105,8 @@ export class WebSocketClient implements IStreamingTransportClient { throw new Error( `Unable to re-connect client to transport for url ${this._url}. Sender: '${JSON.stringify( - sender - )}'. Args:' ${JSON.stringify(args)}` + sender, + )}'. Args:' ${JSON.stringify(args)}`, ); } } diff --git a/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts b/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts index 1ce6ddc24b..bf0a3bbd13 100644 --- a/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts +++ b/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts @@ -126,7 +126,6 @@ export class NodeWebSocket implements ISocket { req.on('upgrade', (res, socket, head): void => { // @types/ws does not contain the signature for completeUpgrade // https://github.com/websockets/ws/blob/0a612364e69fc07624b8010c6873f7766743a8e3/lib/websocket-server.js#L269 - // eslint-disable-next-line @typescript-eslint/no-explicit-any (this.wsServer as any).completeUpgrade(wskey, undefined, res, socket, head, (websocket): void => { this.wsSocket = websocket; }); @@ -143,7 +142,6 @@ export class NodeWebSocket implements ISocket { * * @param handler The callback to handle the "message" event. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any setOnMessageHandler(handler: (x: any) => void): void { this.wsSocket.on('message', handler); } @@ -165,7 +163,6 @@ export class NodeWebSocket implements ISocket { * * @param handler The callback to handle the "close" event. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any setOnCloseHandler(handler: (x: any) => void): void { this.wsSocket.on('close', handler); } @@ -175,7 +172,6 @@ export class NodeWebSocket implements ISocket { * * @param handler The callback to handle the "error" event. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any setOnErrorHandler(handler: (x: any) => void): void { this.wsSocket.on('error', (error): void => { if (error) { diff --git a/libraries/botframework-streaming/src/webSocket/nodeWebSocketClient.ts b/libraries/botframework-streaming/src/webSocket/nodeWebSocketClient.ts index 3f32628529..8df9a81718 100644 --- a/libraries/botframework-streaming/src/webSocket/nodeWebSocketClient.ts +++ b/libraries/botframework-streaming/src/webSocket/nodeWebSocketClient.ts @@ -59,7 +59,7 @@ export class WebSocketClient implements IStreamingTransportClient { this._requestHandler, this._requestManager, this._sender, - this._receiver + this._receiver, ); } @@ -98,7 +98,6 @@ export class WebSocketClient implements IStreamingTransportClient { return this._protocolAdapter.sendRequest(request); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any private onConnectionDisconnected(sender: Record, args: any): void { // Rejects all pending requests on disconnect. this._requestManager.rejectAllResponses(new Error('Disconnect was called.')); @@ -110,8 +109,8 @@ export class WebSocketClient implements IStreamingTransportClient { throw new Error( `Unable to re-connect client to Node transport for url ${this._url}. Sender: '${JSON.stringify( - sender - )}'. Args:' ${JSON.stringify(args)}` + sender, + )}'. Args:' ${JSON.stringify(args)}`, ); } } diff --git a/libraries/botframework-streaming/src/webSocket/webSocketServer.ts b/libraries/botframework-streaming/src/webSocket/webSocketServer.ts index 89b4c64b25..d082a1467f 100644 --- a/libraries/botframework-streaming/src/webSocket/webSocketServer.ts +++ b/libraries/botframework-streaming/src/webSocket/webSocketServer.ts @@ -53,7 +53,7 @@ export class WebSocketServer implements IStreamingTransportServer { this._requestHandler, this._requestManager, this._sender, - this._receiver + this._receiver, ); this._closedSignal = (x: string): string => { diff --git a/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts b/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts index 215d286026..f4331ccf17 100644 --- a/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts +++ b/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts @@ -16,7 +16,6 @@ export class WebSocketTransport implements ITransportSender, ITransportReceiver private _active: INodeBuffer; private _activeOffset = 0; private _activeReceiveResolve: (resolve: INodeBuffer) => void; - // eslint-disable-next-line @typescript-eslint/no-explicit-any private _activeReceiveReject: (reason?: any) => void; private _activeReceiveCount = 0; diff --git a/libraries/botframework-streaming/tests/CancelDisassembler.test.js b/libraries/botframework-streaming/tests/CancelDisassembler.test.js new file mode 100644 index 0000000000..d33f33e8d2 --- /dev/null +++ b/libraries/botframework-streaming/tests/CancelDisassembler.test.js @@ -0,0 +1,26 @@ +const { expect } = require('chai'); +const { CancelDisassembler } = require('../lib/disassemblers'); +const { PayloadSender } = require('../lib/payloadTransport'); +const { PayloadTypes } = require('../lib/payloads'); + +describe('CancelDisassembler', function () { + it('constructs correctly.', function () { + const sender = new PayloadSender(); + const cd = new CancelDisassembler(sender, '42', PayloadTypes.cancelStream); + + expect(cd.id).to.equal('42'); + expect(cd.payloadType).to.equal(PayloadTypes.cancelStream); + expect(cd.sender).to.equal(sender); + }); + + it('sends payload without throwing.', function () { + const sender = new PayloadSender(); + const cd = new CancelDisassembler(sender, '42', PayloadTypes.cancelStream); + + expect(cd.id).to.equal('42'); + expect(cd.payloadType).to.equal(PayloadTypes.cancelStream); + expect(cd.sender).to.equal(sender); + + expect(() => cd.disassemble()).to.not.throw(); + }); +}); diff --git a/libraries/botframework-streaming/tests/ContentStream.test.js b/libraries/botframework-streaming/tests/ContentStream.test.js index 5350ce39b3..6af56b0325 100644 --- a/libraries/botframework-streaming/tests/ContentStream.test.js +++ b/libraries/botframework-streaming/tests/ContentStream.test.js @@ -67,7 +67,7 @@ describe('Streaming Extensions ContentStream Tests ', function () { it('does not return the stream when it is is undefined', function () { const cs = new ContentStream('1', new PayloadAssembler(streamManager, { id: 'csa1', header: header })); - expect(cs.getStream()).to.not.be.undefined; + expect(cs.getStream()).to.not.equal(undefined); }); it('reads a stream of length 0 and returns an empty string', function () { @@ -76,7 +76,7 @@ describe('Streaming Extensions ContentStream Tests ', function () { new PayloadAssembler(streamManager, { id: 'csa1', header: { ...header, payloadLength: 0 }, - }) + }), ); return cs.readAsString().then((data) => { @@ -93,13 +93,13 @@ describe('Streaming Extensions ContentStream Tests ', function () { new PayloadAssembler(streamManager, { id: 'csa1', header: assemblerHeader, - }) + }), ); return cs .readAsJson() .then((data) => { - expect(data).to.not.be.undefined; + expect(data).to.not.be.undefined(); }) .catch((err) => { expect(err.toString()).to.equal('SyntaxError: Unexpected end of JSON input'); diff --git a/libraries/botframework-streaming/tests/Disassembler.test.js b/libraries/botframework-streaming/tests/Disassembler.test.js deleted file mode 100644 index 193b742827..0000000000 --- a/libraries/botframework-streaming/tests/Disassembler.test.js +++ /dev/null @@ -1,46 +0,0 @@ -const { CancelDisassembler, RequestDisassembler } = require('../lib/disassemblers'); -const { HttpContentStream } = require('../lib/httpContentStream'); -const { HttpContent, StreamingRequest, SubscribableStream } = require('..'); -const { PayloadSender } = require('../lib/payloadTransport'); -const { PayloadTypes } = require('../lib/payloads'); -const { expect } = require('chai'); - -describe('RequestDisassembler', function () { - it('resolves calls to get stream.', async function () { - const sender = new PayloadSender(); - const req = new StreamingRequest(); - const headers = { contentLength: 40, contentType: 'A' }; - const stream = new SubscribableStream(); - stream.write('This is the data inside of the stream.', 'UTF-8'); - const content = new HttpContent(headers, stream); - const contentStream = new HttpContentStream(content); - contentStream.content.headers = headers; - - req.addStream(contentStream); - const rd = new RequestDisassembler(sender, '42', req); - - await rd.getStream(); - }); -}); - -describe('CancelDisassembler', function () { - it('constructs correctly.', function () { - const sender = new PayloadSender(); - const cd = new CancelDisassembler(sender, '42', PayloadTypes.cancelStream); - - expect(cd.id).to.equal('42'); - expect(cd.payloadType).to.equal(PayloadTypes.cancelStream); - expect(cd.sender).to.equal(sender); - }); - - it('sends payload without throwing.', function () { - const sender = new PayloadSender(); - const cd = new CancelDisassembler(sender, '42', PayloadTypes.cancelStream); - - expect(cd.id).to.equal('42'); - expect(cd.payloadType).to.equal(PayloadTypes.cancelStream); - expect(cd.sender).to.equal(sender); - - expect(() => cd.disassemble()).to.not.throw(); - }); -}); diff --git a/libraries/botframework-streaming/tests/NamedPipe.test.js b/libraries/botframework-streaming/tests/NamedPipe.test.js index 5892db99b2..0cef91f9ba 100644 --- a/libraries/botframework-streaming/tests/NamedPipe.test.js +++ b/libraries/botframework-streaming/tests/NamedPipe.test.js @@ -88,7 +88,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () it('Client connect', function () { const c = new TestClient('pipeName'); const t = c.connect(); - expect(t).to.not.be.undefined; + expect(t).to.not.equal(undefined); c.disconnect(); }); @@ -122,7 +122,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () sock.writable = true; const transport = new NamedPipeTransport(sock, 'fakeSocket2'); expect(transport).to.be.instanceOf(NamedPipeTransport); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); expect(() => transport.close()).to.not.throw(); }); @@ -134,7 +134,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () const transport = new NamedPipeTransport(sock, 'fakeSocket3'); expect(transport).to.be.instanceOf(NamedPipeTransport); expect(() => transport.close()).to.not.throw(); - expect(transport.isConnected).to.be.false; + expect(transport.isConnected).to.equal(false); }); it('writes to the socket', function () { @@ -144,7 +144,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () sock.writable = true; const transport = new NamedPipeTransport(sock, 'fakeSocket4'); expect(transport).to.be.instanceOf(NamedPipeTransport); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); const buff = Buffer.from('hello', 'utf8'); const sent = transport.send(buff); expect(sent).to.equal(5); @@ -158,7 +158,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () sock.writable = true; const transport = new NamedPipeTransport(sock, 'fakeSocket5'); expect(transport).to.be.instanceOf(NamedPipeTransport); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); sock.writable = false; const buff = Buffer.from('hello', 'utf8'); const sent = transport.send(buff); @@ -168,6 +168,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () // TODO: 2023-04-24 [hawo] #4462 The code today does not allows the receive() call to be rejected by reading a dead socket. // The receive() call will be rejected IFF the socket is closed/error AFTER the receive() call. + // eslint-disable-next-line mocha/no-skipped-tests it.skip('throws when reading from a dead socket', async function () { const sock = new FauxSock(); sock.destroyed = true; @@ -175,7 +176,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () sock.writable = true; const transport = new NamedPipeTransport(sock, 'fakeSocket5'); expect(transport).to.be.instanceOf(NamedPipeTransport); - expect(transport.isConnected).to.be.false; + expect(transport.isConnected).to.equal(false); (await expectEventually(transport.receive(5))).to.throw(); expect(() => transport.close()).to.not.throw(); }); @@ -187,7 +188,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () sock.writable = true; const transport = new NamedPipeTransport(sock); expect(transport).to.be.instanceOf(NamedPipeTransport); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); transport.receive(12).catch(); transport.socketReceive(Buffer.from('Hello World!', 'utf8')); @@ -201,12 +202,12 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () sock.writable = true; const transport = new NamedPipeTransport(sock, 'fakeSocket6'); expect(transport).to.be.instanceOf(NamedPipeTransport); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); transport.socketClose(); - expect(transport._active).to.be.null; - expect(transport._activeReceiveResolve).to.be.null; - expect(transport._activeReceiveReject).to.be.null; - expect(transport.socket).to.be.null; + expect(transport._active).to.equal(null); + expect(transport._activeReceiveResolve).to.equal(null); + expect(transport._activeReceiveReject).to.equal(null); + expect(transport.socket).to.equal(null); expect(transport._activeOffset).to.equal(0); expect(transport._activeReceiveCount).to.equal(0); }); @@ -218,12 +219,12 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () sock.writable = true; const transport = new NamedPipeTransport(sock, 'fakeSocket6'); expect(transport).to.be.instanceOf(NamedPipeTransport); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); transport.socketError(); - expect(transport._active).to.be.null; - expect(transport._activeReceiveResolve).to.be.null; - expect(transport._activeReceiveReject).to.be.null; - expect(transport.socket).to.be.null; + expect(transport._active).to.equal(null); + expect(transport._activeReceiveResolve).to.equal(null); + expect(transport._activeReceiveReject).to.equal(null); + expect(transport.socket).to.equal(null); expect(transport._activeOffset).to.equal(0); expect(transport._activeReceiveCount).to.equal(0); }); @@ -235,7 +236,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () sock.writable = true; const transport = new NamedPipeTransport(sock, 'fakeSocket6'); expect(transport).to.be.instanceOf(NamedPipeTransport); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); const buff = Buffer.from('hello', 'utf8'); expect(() => transport.socketReceive(buff)).to.not.throw(); }); @@ -261,6 +262,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () // TODO: 2023-04-24 [hawo] #4462 The client.send() call will only resolve when the other side responded. // Because the other side is not connected to anything, thus, no response is received. // Thus, the Promise is not resolved. + // eslint-disable-next-line mocha/no-skipped-tests it.skip('sends without throwing', function (done) { const req = new StreamingRequest(); req.Verb = 'POST'; @@ -269,7 +271,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () client .send(req) .catch((err) => { - expect(err).to.be.undefined; + expect(err).to.equal(undefined); }) .then(done); }); @@ -304,15 +306,16 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () it('returns true if isConnected === true on _receiver & _sender', function () { const server = new NamedPipeServer('pipeisConnected', new RequestHandler()); - expect(server.isConnected).to.be.false; + expect(server.isConnected).to.equal(false); server._receiver = { isConnected: true }; server._sender = { isConnected: true }; - expect(server.isConnected).to.be.true; + expect(server.isConnected).to.equal(true); }); // TODO: 2023-04-24 [hawo] #4462 The client.send() call will only resolve when the other side responded. // Because the other side is not connected to anything, thus, no response is received. // Thus, the Promise is not resolved. + // eslint-disable-next-line mocha/no-skipped-tests it.skip('sends without throwing', function (done) { const server = new NamedPipeServer('pipeA', new RequestHandler()); expect(server).to.be.instanceOf(NamedPipeServer); @@ -321,7 +324,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () server .send(req) .catch((err) => { - expect(err).to.be.undefined; + expect(err).to.equal(undefined); }) .then(expect(() => server.disconnect()).to.not.throw()) .then(done); @@ -354,7 +357,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () err.server = server; throw err; } - }) + }), ), (err) => { // Verify we did get an addr in use error @@ -363,12 +366,12 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () assert(err.server, 'server attached to error'); assert( err.server._incomingServer && !err.server._incomingServer.listening, - 'incoming server attached but not listening' + 'incoming server attached but not listening', ); assert(!err.server._outgoingServer, 'no outgoing server attached'); return true; - } + }, ); } finally { servers.forEach((server) => server.disconnect()); @@ -386,7 +389,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () it('should return a Server when calling createNodeServer()', function () { const server = createNodeServer(); - expect(server).to.not.be.null; + expect(server).to.not.equal(null); expect(server).to.be.instanceOf(Object); expect(typeof server.listen).to.equal('function'); expect(typeof server.close).to.equal('function'); @@ -395,7 +398,7 @@ describe.windowsOnly('Streaming Extensions NamedPipe Library Tests', function () it('should return the factory when calling getServerFactory()', function () { expect(() => getServerFactory()).to.not.throw(); const serverFactoryFunction = getServerFactory(); - expect(serverFactoryFunction).to.not.be.null; + expect(serverFactoryFunction).to.not.equal(null); expect(typeof serverFactoryFunction).to.equal('function'); }); diff --git a/libraries/botframework-streaming/tests/NodeWebSocket.test.js b/libraries/botframework-streaming/tests/NodeWebSocket.test.js index 895c027fb0..af83ad5b45 100644 --- a/libraries/botframework-streaming/tests/NodeWebSocket.test.js +++ b/libraries/botframework-streaming/tests/NodeWebSocket.test.js @@ -15,7 +15,7 @@ describe('NodeWebSocket', function () { it('starts out connected', function () { const socket = new NodeWebSocket(new FauxSock()); - expect(socket.isConnected).to.be.true; + expect(socket.isConnected).to.equal(true); }); it('writes to the socket', function () { @@ -30,34 +30,34 @@ describe('NodeWebSocket', function () { socket.connect().catch((error) => { expect( error.message === 'connect ECONNREFUSED 127.0.0.1:8082' || - error.message === 'connect ECONNREFUSED ::1:8082' - ).to.be.true; - }) + error.message === 'connect ECONNREFUSED ::1:8082', + ).to.equal(true); + }), ); }); it('can set message handlers on the socket', function () { const sock = new FauxSock(); const socket = new NodeWebSocket(sock); - expect(sock.messageHandler).to.be.undefined; + expect(sock.messageHandler).to.equal(undefined); expect(() => socket.setOnMessageHandler(() => {})).to.not.throw(); - expect(sock.messageHandler).to.not.be.undefined; + expect(sock.messageHandler).to.not.equal(undefined); }); it('can set error handler on the socket', function () { const sock = new FauxSock(); const socket = new NodeWebSocket(sock); - expect(sock.errorHandler).to.be.undefined; + expect(sock.errorHandler).to.equal(undefined); expect(() => socket.setOnErrorHandler(() => {})).to.not.throw(); - expect(sock.errorHandler).to.not.be.undefined; + expect(sock.errorHandler).to.not.equal(undefined); }); it('can set end handler on the socket', function () { const sock = new FauxSock(); const socket = new NodeWebSocket(sock); - expect(sock.closeHandler).to.be.undefined; + expect(sock.closeHandler).to.equal(undefined); expect(() => socket.setOnCloseHandler(() => {})).to.not.throw(); - expect(sock.closeHandler).to.not.be.undefined; + expect(sock.closeHandler).to.not.equal(undefined); }); it('create() should be successful and set a WebSocket', async function () { @@ -142,7 +142,7 @@ describe('NodeWebSocket', function () { describe('isConnected property', function () { it('should be true', function () { - expect(nodeSocket.isConnected).to.be.true; + expect(nodeSocket.isConnected).to.equal(true); }); }); diff --git a/libraries/botframework-streaming/tests/Assembler.test.js b/libraries/botframework-streaming/tests/PayloadAssembler.test.js similarity index 62% rename from libraries/botframework-streaming/tests/Assembler.test.js rename to libraries/botframework-streaming/tests/PayloadAssembler.test.js index ebd7f28df4..21a717ca8f 100644 --- a/libraries/botframework-streaming/tests/Assembler.test.js +++ b/libraries/botframework-streaming/tests/PayloadAssembler.test.js @@ -1,237 +1,156 @@ -const { SubscribableStream } = require('../lib/subscribableStream'); -const { PayloadAssemblerManager, PayloadTypes, StreamManager } = require('../lib/payloads'); -const { PayloadAssembler } = require('../lib/assemblers'); -const { expect } = require('chai'); - -const streamManager = new StreamManager(); - -describe('PayloadAssembler', function () { - it('constructs correctly.', function () { - const header = { - payloadType: PayloadTypes.request, - payloadLength: '42', - id: '100', - end: true, - }; - const rra = new PayloadAssembler(streamManager, { header, onCompleted: () => {} }); - - expect(rra.id).equals('100'); - expect(rra.streamManager).equals(streamManager); - }); - - it('closes without throwing', function () { - const header = { - payloadType: PayloadTypes.request, - payloadLength: '42', - id: '99', - end: true, - }; - const rra = new PayloadAssembler(streamManager, { header, onCompleted: () => {} }); - - expect(() => { - rra.close(); - }).to.not.throw(); - }); - - it('returns a new stream.', function () { - const header = { - payloadType: PayloadTypes.response, - payloadLength: '42', - id: '100', - end: true, - }; - const rra = new PayloadAssembler(streamManager, { header, onCompleted: () => {} }); - - expect(rra.createPayloadStream()).to.be.instanceOf(SubscribableStream); - }); - - it('processes a Request without throwing.', function (done) { - const header = { - payloadType: PayloadTypes.request, - payloadLength: '5', - id: '98', - end: true, - }; - const s = new SubscribableStream(); - - s.write('12345'); - const rp = { verb: 'POST', path: '/some/path' }; - rp.streams = s; - const rra = new PayloadAssembler(streamManager, { - header, - onCompleted: () => done(), - }); - rra.onReceive(header, s, 5); - rra.close(); - }); - - it('processes a Response without throwing.', function (done) { - const header = { - payloadType: PayloadTypes.response, - payloadLength: '5', - id: '100', - end: true, - }; - const s = new SubscribableStream(); - - s.write('12345'); - const rp = { statusCode: 200 }; - rp.streams = s; - const rra = new PayloadAssembler(streamManager, { - header, - onCompleted: () => done(), - }); - rra.onReceive(header, s, 5); - }); - - it('assigns values when constructed', function () { - const header = { - payloadType: PayloadTypes.stream, - payloadLength: 50, - id: '1', - end: undefined, - }; - const csa = new PayloadAssembler(streamManager, { header, onCompleted: () => {} }); - - expect(csa.id).equals('1'); - expect(csa.contentLength).equals(50); - expect(csa.payloadType).equals('S'); - expect(csa.end).equals(undefined); - }); - - it('returns a Stream', function () { - const header = { - payloadType: PayloadTypes.stream, - payloadLength: 50, - id: '1', - end: true, - }; - const csa = new PayloadAssembler(streamManager, { header, onCompleted: () => {} }); - - expect(csa.createPayloadStream()).instanceOf(SubscribableStream); - }); - - it('closes a Stream', function () { - const header = { - payloadType: PayloadTypes.stream, - payloadLength: 50, - id: '97', - end: true, - }; - const csa = new PayloadAssembler(streamManager, { header, onCompleted: () => {} }); - - expect(csa.createPayloadStream()).instanceOf(SubscribableStream); - expect(() => csa.close()).to.not.throw(); - }); -}); - -describe('PayloadAssemblerManager', function () { - it('creates a response stream', function () { - const p = new PayloadAssemblerManager(streamManager); - const head = { - payloadType: PayloadTypes.response, - payloadLength: '42', - id: '100', - end: true, - }; - - expect(p.getPayloadStream(head)).to.be.instanceOf(SubscribableStream); - }); - - it('creates a request stream', function () { - const p = new PayloadAssemblerManager(streamManager); - const head = { - payloadType: PayloadTypes.request, - payloadLength: '42', - id: '100', - end: true, - }; - - expect(p.getPayloadStream(head)).to.be.instanceOf(SubscribableStream); - }); - - it('does not throw when receiving a request', function () { - const p = new PayloadAssemblerManager(streamManager); - const head = { - payloadType: PayloadTypes.request, - payloadLength: '42', - id: '100', - end: true, - }; - const s = p.getPayloadStream(head); - expect(s).to.be.instanceOf(SubscribableStream); - expect(() => p.onReceive(head, s, 0)).to.not.throw(); - }); - - it('does not throw when receiving a stream', function () { - const p = new PayloadAssemblerManager(streamManager); - const head = { - payloadType: PayloadTypes.stream, - payloadLength: '42', - id: '100', - end: true, - }; - const s = p.getPayloadStream(head); - - expect(s).to.be.instanceOf(SubscribableStream); - expect(() => p.onReceive(head, s, 0)).to.not.throw(); - }); - - it('does not throw when receiving a response', function () { - const p = new PayloadAssemblerManager(streamManager); - const head = { - payloadType: PayloadTypes.response, - payloadLength: '42', - id: '100', - end: true, - }; - const s = p.getPayloadStream(head); - - expect(s).to.be.instanceOf(SubscribableStream); - expect(() => p.onReceive(head, s, 0)).to.not.throw(); - }); - - it('returns undefined when asked to create an existing stream', function () { - const p = new PayloadAssemblerManager(streamManager); - const head = { - payloadType: PayloadTypes.request, - payloadLength: '42', - id: '100', - end: true, - }; - const s = p.getPayloadStream(head); - - expect(s).to.be.instanceOf(SubscribableStream); - expect(p.getPayloadStream(head)).to.be.undefined; - }); - - it('throws if not given an ID', function () { - const header = { - payloadType: PayloadTypes.request, - payloadLength: '5', - id: undefined, - end: true, - }; - expect(() => new PayloadAssembler(streamManager, { header })).to.throw( - 'An ID must be supplied when creating an assembler.' - ); - }); - - it('processes a response with streams without throwing.', function (done) { - const header = { payloadType: PayloadTypes.response, payloadLength: '5', id: '96', end: true }; - const s = new SubscribableStream(); - s.write( - '{"statusCode": "12345","streams": [{"id": "1","contentType": "text","length": "2"},{"id": "2","contentType": "text","length": "2"},{"id": "3","contentType": "text","length": "2"}]}' - ); - const rp = { verb: 'POST', path: '/some/path' }; - rp.streams = []; - rp.streams.push(s); - - const rra = new PayloadAssembler(streamManager, { - header: header, - onCompleted: () => done(), - }); - rra.onReceive(header, s, 5); - rra.close(); - }); -}); +const { SubscribableStream } = require('../lib/subscribableStream'); +const { PayloadTypes, StreamManager } = require('../lib/payloads'); +const { PayloadAssembler } = require('../lib/assemblers'); +const { expect } = require('chai'); + +const streamManager = new StreamManager(); + +describe('PayloadAssembler', function () { + it('constructs correctly.', function () { + const header = { + payloadType: PayloadTypes.request, + payloadLength: '42', + id: '100', + end: true, + }; + const rra = new PayloadAssembler(streamManager, { header, onCompleted: () => {} }); + + expect(rra.id).equals('100'); + expect(rra.streamManager).equals(streamManager); + }); + + it('closes without throwing', function () { + const header = { + payloadType: PayloadTypes.request, + payloadLength: '42', + id: '99', + end: true, + }; + const rra = new PayloadAssembler(streamManager, { header, onCompleted: () => {} }); + + expect(() => { + rra.close(); + }).to.not.throw(); + }); + + it('returns a new stream.', function () { + const header = { + payloadType: PayloadTypes.response, + payloadLength: '42', + id: '100', + end: true, + }; + const rra = new PayloadAssembler(streamManager, { header, onCompleted: () => {} }); + + expect(rra.createPayloadStream()).to.be.instanceOf(SubscribableStream); + }); + + it('processes a Request without throwing.', function (done) { + const header = { + payloadType: PayloadTypes.request, + payloadLength: '5', + id: '98', + end: true, + }; + const s = new SubscribableStream(); + + s.write('12345'); + const rp = { verb: 'POST', path: '/some/path' }; + rp.streams = s; + const rra = new PayloadAssembler(streamManager, { + header, + onCompleted: () => done(), + }); + rra.onReceive(header, s, 5); + rra.close(); + }); + + it('processes a Response without throwing.', function (done) { + const header = { + payloadType: PayloadTypes.response, + payloadLength: '5', + id: '100', + end: true, + }; + const s = new SubscribableStream(); + + s.write('12345'); + const rp = { statusCode: 200 }; + rp.streams = s; + const rra = new PayloadAssembler(streamManager, { + header, + onCompleted: () => done(), + }); + rra.onReceive(header, s, 5); + }); + + it('assigns values when constructed', function () { + const header = { + payloadType: PayloadTypes.stream, + payloadLength: 50, + id: '1', + end: undefined, + }; + const csa = new PayloadAssembler(streamManager, { header, onCompleted: () => {} }); + + expect(csa.id).equals('1'); + expect(csa.contentLength).equals(50); + expect(csa.payloadType).equals('S'); + expect(csa.end).equals(undefined); + }); + + it('returns a Stream', function () { + const header = { + payloadType: PayloadTypes.stream, + payloadLength: 50, + id: '1', + end: true, + }; + const csa = new PayloadAssembler(streamManager, { header, onCompleted: () => {} }); + + expect(csa.createPayloadStream()).instanceOf(SubscribableStream); + }); + + it('closes a Stream', function () { + const header = { + payloadType: PayloadTypes.stream, + payloadLength: 50, + id: '97', + end: true, + }; + const csa = new PayloadAssembler(streamManager, { header, onCompleted: () => {} }); + + expect(csa.createPayloadStream()).instanceOf(SubscribableStream); + expect(() => csa.close()).to.not.throw(); + }); + + it('throws if not given an ID', function () { + const header = { + payloadType: PayloadTypes.request, + payloadLength: '5', + id: undefined, + end: true, + }; + expect(() => new PayloadAssembler(streamManager, { header })).to.throw( + 'An ID must be supplied when creating an assembler.', + ); + }); + + it('processes a response with streams without throwing.', function (done) { + const header = { payloadType: PayloadTypes.response, payloadLength: '5', id: '96', end: true }; + const s = new SubscribableStream(); + s.write( + '{"statusCode": "12345","streams": [{"id": "1","contentType": "text","length": "2"},{"id": "2","contentType": "text","length": "2"},{"id": "3","contentType": "text","length": "2"}]}', + ); + const rp = { verb: 'POST', path: '/some/path' }; + rp.streams = []; + rp.streams.push(s); + + const rra = new PayloadAssembler(streamManager, { + header: header, + onCompleted: () => done(), + }); + rra.onReceive(header, s, 5); + rra.close(); + }); +}); diff --git a/libraries/botframework-streaming/tests/PayloadAssemblerManager.test.js b/libraries/botframework-streaming/tests/PayloadAssemblerManager.test.js new file mode 100644 index 0000000000..8590a817b5 --- /dev/null +++ b/libraries/botframework-streaming/tests/PayloadAssemblerManager.test.js @@ -0,0 +1,86 @@ +const { SubscribableStream } = require('../lib/subscribableStream'); +const { PayloadAssemblerManager, PayloadTypes, StreamManager } = require('../lib/payloads'); +const { expect } = require('chai'); + +const streamManager = new StreamManager(); + +describe('PayloadAssemblerManager', function () { + it('creates a response stream', function () { + const p = new PayloadAssemblerManager(streamManager); + const head = { + payloadType: PayloadTypes.response, + payloadLength: '42', + id: '100', + end: true, + }; + + expect(p.getPayloadStream(head)).to.be.instanceOf(SubscribableStream); + }); + + it('creates a request stream', function () { + const p = new PayloadAssemblerManager(streamManager); + const head = { + payloadType: PayloadTypes.request, + payloadLength: '42', + id: '100', + end: true, + }; + + expect(p.getPayloadStream(head)).to.be.instanceOf(SubscribableStream); + }); + + it('does not throw when receiving a request', function () { + const p = new PayloadAssemblerManager(streamManager); + const head = { + payloadType: PayloadTypes.request, + payloadLength: '42', + id: '100', + end: true, + }; + const s = p.getPayloadStream(head); + expect(s).to.be.instanceOf(SubscribableStream); + expect(() => p.onReceive(head, s, 0)).to.not.throw(); + }); + + it('does not throw when receiving a stream', function () { + const p = new PayloadAssemblerManager(streamManager); + const head = { + payloadType: PayloadTypes.stream, + payloadLength: '42', + id: '100', + end: true, + }; + const s = p.getPayloadStream(head); + + expect(s).to.be.instanceOf(SubscribableStream); + expect(() => p.onReceive(head, s, 0)).to.not.throw(); + }); + + it('does not throw when receiving a response', function () { + const p = new PayloadAssemblerManager(streamManager); + const head = { + payloadType: PayloadTypes.response, + payloadLength: '42', + id: '100', + end: true, + }; + const s = p.getPayloadStream(head); + + expect(s).to.be.instanceOf(SubscribableStream); + expect(() => p.onReceive(head, s, 0)).to.not.throw(); + }); + + it('returns undefined when asked to create an existing stream', function () { + const p = new PayloadAssemblerManager(streamManager); + const head = { + payloadType: PayloadTypes.request, + payloadLength: '42', + id: '100', + end: true, + }; + const s = p.getPayloadStream(head); + + expect(s).to.be.instanceOf(SubscribableStream); + expect(p.getPayloadStream(head)).to.equal(undefined); + }); +}); diff --git a/libraries/botframework-streaming/tests/PayloadSender.test.js b/libraries/botframework-streaming/tests/PayloadSender.test.js index 0b4fac80be..2462154935 100644 --- a/libraries/botframework-streaming/tests/PayloadSender.test.js +++ b/libraries/botframework-streaming/tests/PayloadSender.test.js @@ -60,7 +60,7 @@ describe('PayloadTransport', function () { const psSenderSpy = sinon.spy(ps._sender, 'send'); expect(ps.sendPayload(header, stream, () => done())); - expect(psSenderSpy.calledTwice).to.be.true; + expect(psSenderSpy.calledTwice).to.equal(true); }); it('writes a large stream to its sender.', function (done) { @@ -95,7 +95,7 @@ describe('PayloadTransport', function () { } catch (e) { done(e); } - }) + }), ); }); @@ -157,7 +157,7 @@ describe('PayloadTransport', function () { describe('PayloadReceiver', function () { it('begins disconnected.', function () { const pr = new PayloadReceiver(); - expect(pr.isConnected).to.be.false; + expect(pr.isConnected).to.equal(false); }); it('connects to and reads a header with no payload from the transport.', function () { @@ -167,7 +167,7 @@ describe('PayloadTransport', function () { sock.setReceiver(pr); pr.connect(sock); - expect(pr.isConnected).to.be.true; + expect(pr.isConnected).to.equal(true); }); it('connects to and reads a header with a stream the transport.', function (done) { @@ -182,13 +182,13 @@ describe('PayloadTransport', function () { pr.subscribe( (header) => assemblerManager.getPayloadStream(header), (header, contentStream, contentLength) => - assemblerManager.onReceive(header, contentStream, contentLength) + assemblerManager.onReceive(header, contentStream, contentLength), ); expect(() => pr.connect(sock)).to.not.throw(); pr.disconnected = () => done(); - expect(pr.isConnected).to.be.true; + expect(pr.isConnected).to.equal(true); }); }); }); diff --git a/libraries/botframework-streaming/tests/ProtocolAdapter.test.js b/libraries/botframework-streaming/tests/ProtocolAdapter.test.js index 85fda449b9..2ebfa6ac9e 100644 --- a/libraries/botframework-streaming/tests/ProtocolAdapter.test.js +++ b/libraries/botframework-streaming/tests/ProtocolAdapter.test.js @@ -50,22 +50,22 @@ describe('Streaming Extensions ProtocolAdapter', function () { requestHandler, requestManager, payloadSender, - payloadReceiver + payloadReceiver, ); - expect(protocolAdapter.assemblerManager).to.not.be.undefined; + expect(protocolAdapter.assemblerManager).to.not.equal(undefined); - expect(protocolAdapter.payloadReceiver).to.not.be.undefined; + expect(protocolAdapter.payloadReceiver).to.not.equal(undefined); - expect(protocolAdapter.payloadSender).to.not.be.undefined; + expect(protocolAdapter.payloadSender).to.not.equal(undefined); - expect(protocolAdapter.sendOperations).to.not.be.undefined; + expect(protocolAdapter.sendOperations).to.not.equal(undefined); - expect(protocolAdapter.streamManager).to.not.be.undefined; + expect(protocolAdapter.streamManager).to.not.equal(undefined); - expect(protocolAdapter.requestHandler).to.not.be.undefined; + expect(protocolAdapter.requestHandler).to.not.equal(undefined); - expect(protocolAdapter.requestManager).to.not.be.undefined; + expect(protocolAdapter.requestManager).to.not.equal(undefined); }); it('processes requests.', async function () { @@ -79,13 +79,13 @@ describe('Streaming Extensions ProtocolAdapter', function () { requestHandler, requestManager, payloadSender, - payloadReceiver + payloadReceiver, ); const requestHandlerSpy = sinon.spy(requestHandler, 'processRequest'); protocolAdapter.onReceiveRequest('42', { verb: 'POST', path: '/api/messages', streams: [] }); - expect(requestHandlerSpy.called).to.be.true; + expect(requestHandlerSpy.called).to.equal(true); }); it('processes responses.', async function () { @@ -99,13 +99,13 @@ describe('Streaming Extensions ProtocolAdapter', function () { requestHandler, requestManager, payloadSender, - payloadReceiver + payloadReceiver, ); const requestManagerSpy = sinon.spy(requestManager, 'signalResponse'); protocolAdapter.onReceiveResponse('42', { statusCode: '200', streams: [] }); - expect(requestManagerSpy.called).to.be.true; + expect(requestManagerSpy.called).to.equal(true); }); it('does not throw when processing a cancellation for an already processed stream', async function () { @@ -119,7 +119,7 @@ describe('Streaming Extensions ProtocolAdapter', function () { requestHandler, requestManager, payloadSender, - payloadReceiver + payloadReceiver, ); const header = { payloadType: 'A', payloadLength: '5', id: '100', end: true }; const assembler = new PayloadAssembler.PayloadAssembler(new StreamManager.StreamManager(), { @@ -139,7 +139,7 @@ describe('Streaming Extensions ProtocolAdapter', function () { requestHandler, requestManager, payloadSender, - payloadReceiver + payloadReceiver, ); expect(() => protocolAdapter.sendRequest(new Request.StreamingRequest())).to.not.throw(); @@ -159,14 +159,14 @@ describe('Streaming Extensions ProtocolAdapter', function () { }; const s = new SubscribableStream.SubscribableStream(); s.write( - '{"statusCode": "12345","streams": [{"id": "1","contentType": "text","length": "2"},{"id": "2","contentType": "text","length": "2"},{"id": "3","contentType": "text","length": "2"}]}' + '{"statusCode": "12345","streams": [{"id": "1","contentType": "text","length": "2"},{"id": "2","contentType": "text","length": "2"},{"id": "3","contentType": "text","length": "2"}]}', ); const rp = { verb: 'POST', path: '/some/path' }; rp.streams = []; rp.streams.push(s); pa.connect(receiver); - expect(pa.isConnected).to.be.true; + expect(pa.isConnected).to.equal(true); expect(() => pa.connect(receiver)).to.not.throw(); pa.disconnect(); diff --git a/libraries/botframework-streaming/tests/RequestDisassembler.test.js b/libraries/botframework-streaming/tests/RequestDisassembler.test.js new file mode 100644 index 0000000000..4161037e2c --- /dev/null +++ b/libraries/botframework-streaming/tests/RequestDisassembler.test.js @@ -0,0 +1,22 @@ +const { RequestDisassembler } = require('../lib/disassemblers'); +const { HttpContentStream } = require('../lib/httpContentStream'); +const { HttpContent, StreamingRequest, SubscribableStream } = require('..'); +const { PayloadSender } = require('../lib/payloadTransport'); + +describe('RequestDisassembler', function () { + it('resolves calls to get stream.', async function () { + const sender = new PayloadSender(); + const req = new StreamingRequest(); + const headers = { contentLength: 40, contentType: 'A' }; + const stream = new SubscribableStream(); + stream.write('This is the data inside of the stream.', 'UTF-8'); + const content = new HttpContent(headers, stream); + const contentStream = new HttpContentStream(content); + contentStream.content.headers = headers; + + req.addStream(contentStream); + const rd = new RequestDisassembler(sender, '42', req); + + await rd.getStream(); + }); +}); diff --git a/libraries/botframework-streaming/tests/RequestManager.test.js b/libraries/botframework-streaming/tests/RequestManager.test.js index 450c60fd9c..e79bd5518e 100644 --- a/libraries/botframework-streaming/tests/RequestManager.test.js +++ b/libraries/botframework-streaming/tests/RequestManager.test.js @@ -17,7 +17,7 @@ describe('RequestManager', function () { rm.getResponse(REQUEST_ID); rm.getResponse(REQUEST_ID).catch((reason) => - expect(reason).to.equal(`requestId '${REQUEST_ID}' already exists in RequestManager`) + expect(reason).to.equal(`requestId '${REQUEST_ID}' already exists in RequestManager`), ); }); diff --git a/libraries/botframework-streaming/tests/StreamManager.test.js b/libraries/botframework-streaming/tests/StreamManager.test.js index e817c5ab9c..cd26683883 100644 --- a/libraries/botframework-streaming/tests/StreamManager.test.js +++ b/libraries/botframework-streaming/tests/StreamManager.test.js @@ -82,7 +82,7 @@ describe('StreamManager', function () { const stream = new SubscribableStream(); stream.write('hello'); expect(() => sm.closeStream(pa.id)).to.not.throw(); - expect(called).to.be.true; + expect(called).to.equal(true); }); it('does not throw when asked to close a stream that does not exist', function () { @@ -95,6 +95,6 @@ describe('StreamManager', function () { end: true, }; expect(() => sm.closeStream(head.id)).to.not.throw(); - expect(called).to.be.false; + expect(called).to.equal(false); }); }); diff --git a/libraries/botframework-streaming/tests/StreamingRequest.test.js b/libraries/botframework-streaming/tests/StreamingRequest.test.js index 5c4bef4621..ed8b87ca1f 100644 --- a/libraries/botframework-streaming/tests/StreamingRequest.test.js +++ b/libraries/botframework-streaming/tests/StreamingRequest.test.js @@ -46,7 +46,7 @@ describe('Streaming Extensions Request tests', function () { expect(() => { r.addStream(undefined); - }).throws; + }).to.throw(); }); it('is able to add streams to the request', function () { diff --git a/libraries/botframework-streaming/tests/WebSocket.test.js b/libraries/botframework-streaming/tests/WebSocket.test.js index 85f3c460c8..581bc69596 100644 --- a/libraries/botframework-streaming/tests/WebSocket.test.js +++ b/libraries/botframework-streaming/tests/WebSocket.test.js @@ -32,7 +32,7 @@ describe('Streaming Extensions WebSocket Library Tests', function () { sock.writable = true; const transport = new WebSocketTransport(sock); expect(transport).to.be.instanceOf(WebSocketTransport); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); expect(() => transport.close()).to.not.throw(); }); @@ -43,7 +43,7 @@ describe('Streaming Extensions WebSocket Library Tests', function () { sock.writable = true; const transport = new WebSocketTransport(sock); expect(() => transport.close()).to.not.throw(); - expect(transport.isConnected).to.be.false; + expect(transport.isConnected).to.equal(false); }); it('writes to the socket', function () { @@ -52,7 +52,7 @@ describe('Streaming Extensions WebSocket Library Tests', function () { sock.connecting = false; sock.writable = true; const transport = new WebSocketTransport(sock); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); const buff = Buffer.from('hello', 'utf8'); const sent = transport.send(buff); expect(sent).to.equal(5); @@ -65,7 +65,7 @@ describe('Streaming Extensions WebSocket Library Tests', function () { sock.connecting = false; sock.writable = true; const transport = new WebSocketTransport(sock); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); sock.writable = false; sock.connected = false; const buff = Buffer.from('hello', 'utf8'); @@ -80,7 +80,7 @@ describe('Streaming Extensions WebSocket Library Tests', function () { sock.connecting = false; sock.writable = true; const transport = new WebSocketTransport(sock); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); const promise = transport.receive(5); expect(() => transport.close()).to.not.throw(); (await expectEventually(promise)).to.throw('Socket was closed.'); @@ -92,7 +92,7 @@ describe('Streaming Extensions WebSocket Library Tests', function () { sock.connecting = false; sock.writable = true; const transport = new WebSocketTransport(sock); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); transport.receive(12).catch(); transport.onReceive(Buffer.from('{"VERB":"POST", "PATH":"somewhere/something"}', 'utf8')); @@ -105,12 +105,12 @@ describe('Streaming Extensions WebSocket Library Tests', function () { sock.connecting = false; sock.writable = true; const transport = new WebSocketTransport(sock); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); transport.onClose(); - expect(transport._active).to.be.null; - expect(transport._activeReceiveResolve).to.be.null; - expect(transport._activeReceiveReject).to.be.null; - expect(transport.ws).to.be.null; + expect(transport._active).to.equal(null); + expect(transport._activeReceiveResolve).to.equal(null); + expect(transport._activeReceiveReject).to.equal(null); + expect(transport.ws).to.equal(null); expect(transport._activeOffset).to.equal(0); expect(transport._activeReceiveCount).to.equal(0); }); @@ -121,12 +121,12 @@ describe('Streaming Extensions WebSocket Library Tests', function () { sock.connecting = false; sock.writable = true; const transport = new WebSocketTransport(sock); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); transport.onError(); - expect(transport._active).to.be.null; - expect(transport._activeReceiveResolve).to.be.null; - expect(transport._activeReceiveReject).to.be.null; - expect(transport.ws).to.be.null; + expect(transport._active).to.equal(null); + expect(transport._activeReceiveResolve).to.equal(null); + expect(transport._activeReceiveReject).to.equal(null); + expect(transport.ws).to.equal(null); expect(transport._activeOffset).to.equal(0); expect(transport._activeReceiveCount).to.equal(0); }); @@ -137,7 +137,7 @@ describe('Streaming Extensions WebSocket Library Tests', function () { sock.connecting = false; sock.writable = true; const transport = new WebSocketTransport(sock); - expect(transport.isConnected).to.be.true; + expect(transport.isConnected).to.equal(true); const buff = Buffer.from('hello', 'utf8'); expect(() => transport.onReceive(buff)).to.not.throw(); }); @@ -153,7 +153,7 @@ describe('Streaming Extensions WebSocket Library Tests', function () { it('knows its connected', function () { const bs = new BrowserWebSocket(new FauxSock()); bs.connect('fakeUrl'); - expect(bs.isConnected).to.be.true; + expect(bs.isConnected).to.equal(true); }); it('writes to the socket', function () { @@ -170,45 +170,45 @@ describe('Streaming Extensions WebSocket Library Tests', function () { it('can set error handler on the socket', function () { const sock = new FauxSock(); const bs = new BrowserWebSocket(sock); - expect(sock.onerror).to.be.undefined; + expect(sock.onerror).to.equal(undefined); expect(() => bs.setOnErrorHandler(() => {})).to.not.throw(); - expect(sock.onerror).to.not.be.undefined; + expect(sock.onerror).to.not.equal(undefined); }); it('can set end handler on the socket', function () { const sock = new FauxSock(); const bs = new BrowserWebSocket(sock); - expect(sock.onclose).to.be.undefined; + expect(sock.onclose).to.equal(undefined); expect(() => bs.setOnCloseHandler(() => {})).to.not.throw(); - expect(sock.onclose).to.not.be.undefined; + expect(sock.onclose).to.not.equal(undefined); }); it('can set onerror on the socket', function () { const sock = new FauxSock(); const bs = new BrowserWebSocket(sock); bs.connect('nowhere'); - expect(sock.onerror).to.not.be.undefined; - expect(sock.onopen).to.not.be.undefined; + expect(sock.onerror).to.not.equal(undefined); + expect(sock.onopen).to.not.equal(undefined); }); it('can set onopen on the socket', function () { const sock = new FauxSock(); const bs = new BrowserWebSocket(sock); bs.connect('nowhere'); - expect(sock.onerror).to.not.be.undefined; - expect(sock.onopen).to.not.be.undefined; + expect(sock.onerror).to.not.equal(undefined); + expect(sock.onopen).to.not.equal(undefined); }); it('can close', function () { const sock = new FauxSock(); const bs = new BrowserWebSocket(sock); bs.connect('nowhere'); - expect(sock.onerror).to.not.be.undefined; - expect(sock.onopen).to.not.be.undefined; + expect(sock.onerror).to.not.equal(undefined); + expect(sock.onopen).to.not.equal(undefined); const closeSpy = spy(sock, 'close'); bs.close(); - expect(closeSpy.called).to.be.true; + expect(closeSpy.called).to.equal(true); }); }); }); diff --git a/libraries/botframework-streaming/tests/WebSocketClientServer.test.js b/libraries/botframework-streaming/tests/WebSocketClientServer.test.js index e8b8a20e3d..eb7f9c01f3 100644 --- a/libraries/botframework-streaming/tests/WebSocketClientServer.test.js +++ b/libraries/botframework-streaming/tests/WebSocketClientServer.test.js @@ -119,7 +119,7 @@ describe('WebSocket Client/Server Tests', function () { }); it('should call disconnectHandler', function () { - expect(disconnectionHandler.called).to.be.true; + expect(disconnectionHandler.called).to.equal(true); }); it('should disconnect', function () { @@ -186,7 +186,7 @@ describe('WebSocket Client/Server Tests', function () { }); it('should call disconnectHandler', function () { - expect(disconnectionHandler.called).to.be.true; + expect(disconnectionHandler.called).to.equal(true); }); it('should disconnect', function () { diff --git a/libraries/botframework-streaming/tests/helpers/fauxSock.js b/libraries/botframework-streaming/tests/helpers/fauxSock.js index f800d682d1..ec32e2234f 100644 --- a/libraries/botframework-streaming/tests/helpers/fauxSock.js +++ b/libraries/botframework-streaming/tests/helpers/fauxSock.js @@ -66,7 +66,7 @@ class FauxSock { close() { if (this.connected) { this.connected = false; - this.closeHandler && this.closeHandler(); + this.closeHandler?.(); } } end() { diff --git a/libraries/botframework-streaming/tests/helpers/fauxSocket.js b/libraries/botframework-streaming/tests/helpers/fauxSocket.js index 562a1e51af..c7b5eef64e 100644 --- a/libraries/botframework-streaming/tests/helpers/fauxSocket.js +++ b/libraries/botframework-streaming/tests/helpers/fauxSocket.js @@ -1,15 +1,11 @@ const { Duplex } = require('stream'); module.exports.FauxSocket = class FauxSocket extends Duplex { - // eslint-disable-next-line no-empty _read() {} - // eslint-disable-next-line no-empty _write() {} - // eslint-disable-next-line no-empty setNoDelay() {} - // eslint-disable-next-line no-empty setTimeout() {} };