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/interfaces/IBrowserWebSocket.ts b/libraries/botframework-streaming/src/interfaces/IBrowserWebSocket.ts index 1370fb60f6..c62976e4fc 100644 --- a/libraries/botframework-streaming/src/interfaces/IBrowserWebSocket.ts +++ b/libraries/botframework-streaming/src/interfaces/IBrowserWebSocket.ts @@ -18,7 +18,6 @@ export interface IBrowserWebSocket { onmessage: (event: any) => void; onopen: (event: any) => void; send(buffer: any): void; - readyState: number; close(): void; } diff --git a/libraries/botframework-streaming/src/interfaces/IEventEmitter.ts b/libraries/botframework-streaming/src/interfaces/IEventEmitter.ts index 1dcc15d063..aa8b2e64b0 100644 --- a/libraries/botframework-streaming/src/interfaces/IEventEmitter.ts +++ b/libraries/botframework-streaming/src/interfaces/IEventEmitter.ts @@ -20,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; - 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 e98d4ba440..5658ae88a7 100644 --- a/libraries/botframework-streaming/src/interfaces/INodeBuffer.ts +++ b/libraries/botframework-streaming/src/interfaces/INodeBuffer.ts @@ -29,7 +29,6 @@ export interface INodeBuffer extends Uint8Array { constructor: any; write(string: string, offset?: number, length?: number, encoding?: string): number; toString(encoding?: string, start?: number, end?: number): string; - toJSON(): { type: 'Buffer'; data: any[] }; equals(otherBuffer: Uint8Array): boolean; compare( 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 103957b569..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. */ - headers?: any; /** * Optional. The request method. */ - method?: any; } diff --git a/libraries/botframework-streaming/src/interfaces/INodeSocket.ts b/libraries/botframework-streaming/src/interfaces/INodeSocket.ts index f3f1fe4e9c..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/ban-types */ /** * @module botframework-streaming */ diff --git a/libraries/botframework-streaming/src/interfaces/ISocket.ts b/libraries/botframework-streaming/src/interfaces/ISocket.ts index 229a879003..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(); - setOnMessageHandler(handler: (x: any) => void); - setOnErrorHandler(handler: (x: any) => void); - setOnCloseHandler(handler: (x: any) => void); } diff --git a/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts b/libraries/botframework-streaming/src/namedPipe/namedPipeTransport.ts index 0999ea9d9b..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; - private _activeReceiveReject: (reason?: any) => void; /** 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/requestManager.ts b/libraries/botframework-streaming/src/payloads/requestManager.ts index 795687a732..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; - reject: (reason?: any) => void; } diff --git a/libraries/botframework-streaming/src/streamingRequest.ts b/libraries/botframework-streaming/src/streamingRequest.ts index 930490811f..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. */ - setBody(body: any): void { if (typeof body === 'string') { const stream = new SubscribableStream(); diff --git a/libraries/botframework-streaming/src/streamingResponse.ts b/libraries/botframework-streaming/src/streamingResponse.ts index 06ecd8f601..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. */ - setBody(body: any): void { const stream = new SubscribableStream(); stream.write(JSON.stringify(body), 'utf8'); diff --git a/libraries/botframework-streaming/src/subscribableStream.ts b/libraries/botframework-streaming/src/subscribableStream.ts index b2ee059511..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[] = []; - 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. */ - _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. */ - 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 95f9218d26..f8ec5e6203 100644 --- a/libraries/botframework-streaming/src/utilities/createNodeServer.ts +++ b/libraries/botframework-streaming/src/utilities/createNodeServer.ts @@ -35,7 +35,8 @@ export function createNodeServer(callback?: ConnectionListener): INodeServer { * @returns a server factory function */ export function getServerFactory(): (callback?: ConnectionListener) => INodeServer { - if (typeof require !== undefined) { + if (typeof require !== 'undefined') { + // eslint-disable-next-line @typescript-eslint/no-require-imports return require('net').Server; } diff --git a/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts b/libraries/botframework-streaming/src/webSocket/browserWebSocket.ts index bcae1a6181..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; - 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. */ - setOnMessageHandler(handler: (x: any) => void): void { const bufferKey = 'buffer'; const packets = []; @@ -110,7 +108,6 @@ export class BrowserWebSocket implements ISocket { * * @param handler The callback to handle the "error" event. */ - 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. */ - setOnCloseHandler(handler: (x: any) => void): void { this.webSocket.onclose = handler; } diff --git a/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts b/libraries/botframework-streaming/src/webSocket/nodeWebSocket.ts index 3a6c38774f..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 - (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. */ - 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. */ - 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. */ - setOnErrorHandler(handler: (x: any) => void): void { this.wsSocket.on('error', (error): void => { if (error) { diff --git a/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts b/libraries/botframework-streaming/src/webSocket/webSocketTransport.ts index c99382942a..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; - 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 b3ebe85fb9..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 () { @@ -99,7 +99,7 @@ describe('Streaming Extensions ContentStream Tests ', function () { 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 3883a7e2a3..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); @@ -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 14f982e1d6..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 () { @@ -31,7 +31,7 @@ describe('NodeWebSocket', function () { expect( error.message === 'connect ECONNREFUSED 127.0.0.1:8082' || error.message === 'connect ECONNREFUSED ::1:8082', - ).to.be.true; + ).to.equal(true); }), ); }); @@ -39,25 +39,25 @@ describe('NodeWebSocket', function () { 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 66b57e40fd..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 600fae10ce..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) { @@ -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) { @@ -188,7 +188,7 @@ describe('PayloadTransport', function () { 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 06c797be98..2ebfa6ac9e 100644 --- a/libraries/botframework-streaming/tests/ProtocolAdapter.test.js +++ b/libraries/botframework-streaming/tests/ProtocolAdapter.test.js @@ -53,19 +53,19 @@ describe('Streaming Extensions ProtocolAdapter', function () { 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 () { @@ -85,7 +85,7 @@ describe('Streaming Extensions ProtocolAdapter', function () { 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 () { @@ -105,7 +105,7 @@ describe('Streaming Extensions ProtocolAdapter', function () { 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 () { @@ -166,7 +166,7 @@ describe('Streaming Extensions ProtocolAdapter', function () { 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/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() {