From 519f2358939360f5153aa6fb6ef6bbbca548012b Mon Sep 17 00:00:00 2001 From: Matthew Schwartz Date: Thu, 5 Oct 2017 18:00:32 -0700 Subject: [PATCH 01/29] Add message filter and in-line options update (#28) * added ability to filter messages * added in line options modifier --- README.md | 58 +++++++++++- src/BotTester.ts | 170 ++++++++++++++++++++++------------ src/MessageService.ts | 13 ++- src/config.ts | 14 ++- test/BotTester.spec.ts | 57 +++++++++++- test/BotTesterFailure.spec.ts | 16 ++++ 6 files changed, 261 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index d872b91..e1de07d 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,20 @@ config can be set one of 2 ways: 1. creating a bot-tester.json file in the root directory of your project. 2. passing in a config object into the options param, which is the last, when creating a BotTester instance + Passing in the config overrides any default values or values set by bot-tester.json. At the moment, the options are: -```javascript +```typescript { defaultAddress: botbuilder.IAddress, timeout: number // in milliseconds + // each filter returns false for messages that the BotTester should ignore + messageFilters: ((message:IMessage) => boolean)[] } ``` if timeout is defined, then a particular ```runTest()``` call will fail if it does not receive each expected message within the timeout period of time set in the options. +additionally, config can be set by using the config updating options in the build chain, documented below in the example use + For a more in depth view, check out [the Bot Tester Framework Config doc](https://microsoftly.github.io/BotTester/interfaces/_config_.iconfig.html) # Example Usage ```javascript @@ -357,3 +362,54 @@ describe('BotTester', () => { .runTest(); }); ``` + +# can apply one or more message filters in the BotTester options for messages to ignore +``` javascript + it('can apply one or more message filters in the BotTester options for messages to ignore', () => { + bot.dialog('/', (session) => { + session.send('hello'); + session.send('how'); + session.send('are'); + session.send('you?'); + }); + + const ignoreHowMessage = (message) => !message.text.includes('how'); + const ignoreAreMessage = (message) => !message.text.includes('are'); + + return new BotTester(bot, { messageFilters: [ignoreHowMessage, ignoreAreMessage]}) + .sendMessageToBot('intro', 'hello', 'you?') + .runTest(); + }); +``` + +# can modify BotTester options +``` javascript + describe('can modifiy options in line in builder chain', () => { + it('add a message filter', () => { + bot.dialog('/', (session) => { + session.send('hello'); + session.send('there'); + session.send('green'); + }); + + return new BotTester(bot) + .addMessageFilter((msg) => !msg.text.includes('hello')) + .addMessageFilter((msg) => !msg.text.includes('there')) + .sendMessageToBot('hey', 'green') + .runTest(); + }); + + it('change timeout time', (done) => { + const timeout = 750; + bot.dialog('/', (session) => { + setTimeout(() => session.send('hi there'), timeout * 2 ); + }); + + expect(new BotTester(bot) + .setTimeout(timeout) + .sendMessageToBot('hey', 'hi there') + .runTest() + ).to.be.rejected.notify(done); + }); + }); +``` diff --git a/src/BotTester.ts b/src/BotTester.ts index 0559f99..7521d61 100644 --- a/src/BotTester.ts +++ b/src/BotTester.ts @@ -1,6 +1,6 @@ import * as Promise from 'bluebird'; import { IAddress, IMessage, Message, Session, UniversalBot } from 'botbuilder'; -import { config, IConfig } from './config'; +import { config, IConfig, MessageFilter } from './config'; import { ExpectedMessage, PossibleExpectedMessageCollections, PossibleExpectedMessageType } from './ExpectedMessage'; import { botToUserMessageCheckerFunction, MessageService } from './MessageService'; import { SessionService } from './SessionService'; @@ -10,51 +10,129 @@ export type checkSessionFunction = (s: Session) => void; type TestStep = () => Promise; //tslint:enable +/** + * methods that the Test builder can call to edit/modify the options. These can be called until any of the IBotTester method are called. + */ +export interface IOptionsModifier { + /** + * adds a message filter to the options. + * @param filter message filter to add + */ + addMessageFilter(filter: MessageFilter): BotTester; + + /** + * sets the timeout time that the BotTester will wait for any particular message before failing + */ + setTimeout(milliseconds: number): BotTester; +} + +/** + * Test builder/runner suite. After any of these are called, no functions in IConfigModified should be accessible + */ +export interface IBotTester { + /** + * executes each test step serially. + */ + runTest(): Promise<{}>; + + /** + * loads a session associated with an address and passes it to a user defined function + * @param sessionCheckerFunction function passed in to inspect message + * @param address (Optional) address of the session to load. Defaults to bot's default address if not defined + */ + checkSession(sessionCheckerFunction: checkSessionFunction, address?: IAddress): IBotTester; + + /** + * sends a message to a bot and compares bot responses against expectedResponsess. Expected responses can be a variable number of args, + * each of which can be a single expected response of any PossibleExpectedMessageType or a collection of PossibleExpectedMessageType + * that mocks a randomly selected response by the bot + * @param msg message to send to bot + * @param expectedResponses (Optional) responses the bot-tester framework checks against + */ + sendMessageToBot( + msg: IMessage | string, + // currently only supports string RegExp IMessage + ...expectedResponses: (PossibleExpectedMessageType | PossibleExpectedMessageType[])[]): IBotTester; + + /** + * same as sendMessageToBot, but the order of responses is not checked. This will cause the test to hang until all messages it expects + * are returned + */ + sendMessageToBotIgnoringResponseOrder( + msg: IMessage | string, + // currently only supports string RegExp IMessage + ...expectedResponses: (PossibleExpectedMessageType | PossibleExpectedMessageType[])[] + ): IBotTester; + + /** + * sends a message to the bot. This should be used whenever session.save() is used without sending a reply to the user. This exists due + * to a limitation in the current implementation of the botbuilder framework + * + * @param msg message to send to bot + */ + sendMessageToBotAndExpectSaveWithNoResponse(msg: IMessage | string): IBotTester; + + /** + * Works exactly like Promise's .then function, except that the return value is not passed as an arg to the next function (even if its + * another .then) + * @param fn some function to run + */ + then(fn: Function): IBotTester; + + /** + * Waits for the given delay between test steps. + * @param delayInMiliseconds time to wait in milliseconds + */ + wait(delayInMilliseconds: number): IBotTester; +} + /** * Test builder and runner for botbuilder bots */ -export class BotTester { +export class BotTester implements IBotTester, IOptionsModifier { private bot: UniversalBot; - private defaultAddress: IAddress; private sessionLoader: SessionService; + + // this is instantiated in the runTest function. This is done to allow any changes to the config to accumulate private messageService: MessageService; private testSteps: TestStep[]; + private config: IConfig; - //tslint:disable - /** - * - * @param bot bot that will be tested against - * @param options (optional) options to pass to bot. Sets the default address and test timeout - */ - //tslint:enable constructor(bot: UniversalBot, options: IConfig = config) { - const defaultAndInputOptionMix = Object.assign({}, config, options); + this.config = Object.assign({}, config, options); + this.config.messageFilters = this.config.messageFilters.slice(); this.bot = bot; - this.defaultAddress = defaultAndInputOptionMix.defaultAddress; - this.messageService = new MessageService(bot, defaultAndInputOptionMix); + this.messageService = new MessageService(bot, this.config); this.sessionLoader = new SessionService(bot); this.testSteps = [] as TestStep[]; } + public addMessageFilter(messageFilter: MessageFilter): BotTester { + this.config.messageFilters.push(messageFilter); + + return this; + } + + public setTimeout(milliseconds: number): BotTester { + this.config.timeout = milliseconds; + + return this; + } + /** - * executes each test step serially + * Initializes the MessegeService here to allow config changes to accumulate */ - //tslint:disable - public runTest(): Promise { - //tslint:enable + public runTest(): Promise<{}> { + this.messageService = new MessageService(this.bot, this.config); + return Promise.mapSeries(this.testSteps, (fn: TestStep) => fn()); } - /** - * loads a session associated with an address and passes it to a user defined function - * @param sessionCheckerFunction function passed in to inspect message - * @param address (Optional) address of the session to load. Defaults to bot's default address if not defined - */ public checkSession( sessionCheckerFunction: checkSessionFunction, address?: IAddress - ): BotTester { - const runSessionChecker = () => this.sessionLoader.getSession(address || this.defaultAddress) + ): IBotTester { + const runSessionChecker = () => this.sessionLoader.getSession(address || this.config.defaultAddress) .then(sessionCheckerFunction); this.testSteps.push(runSessionChecker); @@ -62,18 +140,11 @@ export class BotTester { return this; } - /** - * sends a message to a bot and compares bot responses against expectedResponsess. Expected responses can be a variable number of args, - * each of which can be a single expected response of any PossibleExpectedMessageType or a collection of PossibleExpectedMessageType - * that mocks a randomly selected response by the bot - * @param msg message to send to bot - * @param expectedResponses (Optional) responses the bot-tester framework checks against - */ public sendMessageToBot( msg: IMessage | string, // currently only supports string RegExp IMessage ...expectedResponses: (PossibleExpectedMessageType | PossibleExpectedMessageType[])[] - ): BotTester { + ): IBotTester { const message = this.convertToIMessage(msg); // possible that expected responses may be undefined. Remove them @@ -86,7 +157,7 @@ export class BotTester { msg: IMessage | string, // currently only supports string RegExp IMessage ...expectedResponses: (PossibleExpectedMessageType | PossibleExpectedMessageType[])[] - ): BotTester { + ): IBotTester { const message = this.convertToIMessage(msg); // possible that expected responses may be undefined. Remove them @@ -95,38 +166,19 @@ export class BotTester { return this.sendMessageToBotInternal(message, expectedResponses, true); } - /** - * sends a message to the bot. This should be used whenever session.save() is used without sending a reply to the user. This exists due - * to a limitation in the current implementation of the botbuilder framework - * - * @param msg message to send to bot - */ - public sendMessageToBotAndExpectSaveWithNoResponse( - msg: IMessage | string - ): BotTester { + public sendMessageToBotAndExpectSaveWithNoResponse(msg: IMessage | string): IBotTester { const message = this.convertToIMessage(msg); return this.sendMessageToBotInternal(message, [this.sessionLoader.getInternalSaveMessage(message.address)]); } - /** - * Works exactly like Promise's .then function, except that the return value is not passed as an arg to the next function (even if its - * another .then) - * @param fn some function to run - */ - //tslint:disable - public then(fn: Function): BotTester { - //tslint:enable + public then(fn: Function): IBotTester { this.testSteps.push(() => Promise.method(fn)()); return this; } - /** - * Waits for the given delay between test steps. - * @param delayInMiliseconds time to wait in milliseconds - */ - public wait(delayInMilliseconds: number): BotTester { + public wait(delayInMilliseconds: number): IBotTester { this.testSteps.push(() => Promise.delay(delayInMilliseconds)); return this; @@ -136,7 +188,7 @@ export class BotTester { if (typeof(msg) === 'string') { return new Message() .text(msg as string) - .address(this.defaultAddress) + .address(this.config.defaultAddress) .toMessage(); } @@ -163,9 +215,9 @@ export class BotTester { } else if (expectedResponses instanceof Array) { if (expectedResponses.length > 0) { expectedMessages = (expectedResponses as PossibleExpectedMessageCollections[]) - // tslint:disable - .map((currentExpectedResponseCollection: PossibleExpectedMessageCollections) => new ExpectedMessage(currentExpectedResponseCollection)); - // tslint:enable + + .map((currentExpectedResponseCollection: PossibleExpectedMessageCollections) => + new ExpectedMessage(currentExpectedResponseCollection)); } } diff --git a/src/MessageService.ts b/src/MessageService.ts index b103544..7b10aa8 100644 --- a/src/MessageService.ts +++ b/src/MessageService.ts @@ -1,7 +1,7 @@ import * as Promise from 'bluebird'; import { IAddress, IMessage, Message, Session, UniversalBot } from 'botbuilder'; import { setTimeout } from 'timers'; -import { IConfig, NO_TIMEOUT } from './config'; +import { IConfig, MessageFilter, NO_TIMEOUT } from './config'; import { ExpectedMessage } from './ExpectedMessage'; import { OutgoingMessageComparator } from './OutgoingMessageComparator'; @@ -101,12 +101,15 @@ export class MessageService { * Inject middleware to intercept outgoing messages to check their content */ private applyOutgoingMessageListener(): void { - this.bot.on('outgoing', (e: IMessage | IMessage[]) => { - if (!(e instanceof Array)) { - e = [e]; + this.bot.on('outgoing', (outgoingMessages: IMessage | IMessage[]) => { + if (!(outgoingMessages instanceof Array)) { + outgoingMessages = [outgoingMessages]; } - this.botToUserMessageChecker(e); + this.config.messageFilters.forEach( + (messageFilter: MessageFilter) => outgoingMessages = (outgoingMessages as IMessage[]).filter(messageFilter)); + + this.botToUserMessageChecker(outgoingMessages); }); } } diff --git a/src/config.ts b/src/config.ts index 2c183c7..d911314 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,6 +1,11 @@ -import { IAddress } from 'botbuilder'; +import { IAddress, IMessage } from 'botbuilder'; import * as fs from 'fs'; +/** + * Returns true if a message + */ +export type MessageFilter = (message: IMessage) => boolean; + export interface IConfig { /** * timeout in milliseconds before a BotTester runner will fail a test (when not overriden) @@ -10,6 +15,11 @@ export interface IConfig { * default address bot will use for all communication (when not overriden) */ defaultAddress?: IAddress; + + /** + * filters for messages that the BotTester framework should use + */ + messageFilters?: MessageFilter[]; } const configFilePath = `bot-tester.json`; @@ -34,4 +44,6 @@ if (configFileExists) { configInternal = JSON.parse(fs.readFileSync(configFilePath, { encoding: 'utf8' })); } +configInternal.messageFilters = []; + export const config = configInternal; diff --git a/test/BotTester.spec.ts b/test/BotTester.spec.ts index aba2dc5..d600457 100644 --- a/test/BotTester.spec.ts +++ b/test/BotTester.spec.ts @@ -1,9 +1,13 @@ //```javascript import { IAddress, IMessage, Message, Prompts, Session, UniversalBot } from 'botbuilder'; -import { expect } from 'chai'; +import * as chai from 'chai'; +import * as chaiAsPromised from 'chai-as-promised'; import { BotTester } from './../src/BotTester'; import { TestConnector } from './../src/TestConnector'; +chai.use(chaiAsPromised); +const expect = chai.expect; + const connector = new TestConnector(); // lines with //# should be converted to headers for markdown docs @@ -336,6 +340,57 @@ describe('BotTester', () => { }); //``` +//# can apply one or more message filters in the BotTester options for messages to ignore +//``` javascript + it('can apply one or more message filters in the BotTester options for messages to ignore', () => { + bot.dialog('/', (session) => { + session.send('hello'); + session.send('how'); + session.send('are'); + session.send('you?'); + }); + + const ignoreHowMessage = (message) => !message.text.includes('how'); + const ignoreAreMessage = (message) => !message.text.includes('are'); + + return new BotTester(bot, { messageFilters: [ignoreHowMessage, ignoreAreMessage]}) + .sendMessageToBot('intro', 'hello', 'you?') + .runTest(); + }); +//``` + +//# can modify BotTester options +//``` javascript + describe('can modifiy options in line in builder chain', () => { + it('add a message filter', () => { + bot.dialog('/', (session) => { + session.send('hello'); + session.send('there'); + session.send('green'); + }); + + return new BotTester(bot) + .addMessageFilter((msg) => !msg.text.includes('hello')) + .addMessageFilter((msg) => !msg.text.includes('there')) + .sendMessageToBot('hey', 'green') + .runTest(); + }); + + it('change timeout time', (done) => { + const timeout = 750; + bot.dialog('/', (session) => { + setTimeout(() => session.send('hi there'), timeout * 2 ); + }); + + expect(new BotTester(bot) + .setTimeout(timeout) + .sendMessageToBot('hey', 'hi there') + .runTest() + ).to.be.rejected.notify(done); + }); + }); +//``` + describe('Cases not for docs', () => { it('can handle undefined expectedResponses', () => { bot.dialog('/', (session: Session) => { diff --git a/test/BotTesterFailure.spec.ts b/test/BotTesterFailure.spec.ts index 1bf4d4f..66ec045 100644 --- a/test/BotTesterFailure.spec.ts +++ b/test/BotTesterFailure.spec.ts @@ -202,4 +202,20 @@ describe('BotTester', () => { .sendMessageToBotIgnoringResponseOrder('anything', 'NOPE?', 'hi', 'there') .runTest()).to.be.rejected.notify(done); }); + + it('will fail if a message filter is not correctly applied', (done: Function) => { + bot.dialog('/', (session: Session) => { + session.send('hello'); + session.send('how'); + session.send('are'); + session.send('you?'); + }); + + const ignoreHowMessage = (message: IMessage) => !message.text.includes('how'); + const ignoreAreMessage = (message: IMessage) => !message.text.includes('are'); + + expect(new BotTester(bot, { messageFilters: [ignoreHowMessage, ignoreAreMessage]}) + .sendMessageToBot('intro', 'hello', 'how', 'are', 'you?') + .runTest()).to.be.rejected.notify(done); + }); }); From 8b02cc6b75b233778610cbb14eccf45407412203 Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Thu, 5 Oct 2017 18:51:12 -0700 Subject: [PATCH 02/29] add builtin message filters --- README.md | 17 ++++++++++++++++- src/BotTester.ts | 31 +++++++++++++++++++++++++++++++ src/ExpectedMessage.ts | 4 ++-- src/MessageService.ts | 1 - src/builtInMessageFilters.ts | 13 +++++++++++++ src/config.ts | 10 ++++++++++ test/BotTester.spec.ts | 13 +++++++++++++ test/BotTesterFailure.spec.ts | 35 +++++++++++++++++++++++++++++++++++ 8 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 src/builtInMessageFilters.ts diff --git a/README.md b/README.md index e1de07d..0dd3e7b 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,9 @@ Passing in the config overrides any default values or values set by bot-tester.j defaultAddress: botbuilder.IAddress, timeout: number // in milliseconds // each filter returns false for messages that the BotTester should ignore - messageFilters: ((message:IMessage) => boolean)[] + messageFilters: ((message:IMessage) => boolean)[], + ignoreTypingEvent: boolean, + ignoreEndOfConversationEvent: boolean } ``` if timeout is defined, then a particular ```runTest()``` call will fail if it does not receive each expected message within the timeout period of time set in the options. @@ -411,5 +413,18 @@ describe('BotTester', () => { .runTest() ).to.be.rejected.notify(done); }); + + it('can ignore typing events', () => { + bot.dialog('/', (session) => { + session.send('hello'); + session.sendTyping(); + session.send('goodbye'); + }); + + return new BotTester(bot) + .ignoreTypingEvent() + .sendMessageToBot('hey', 'hello', 'goodbye') + .runTest(); + }); }); ``` diff --git a/src/BotTester.ts b/src/BotTester.ts index 7521d61..c4207ba 100644 --- a/src/BotTester.ts +++ b/src/BotTester.ts @@ -1,5 +1,6 @@ import * as Promise from 'bluebird'; import { IAddress, IMessage, Message, Session, UniversalBot } from 'botbuilder'; +import { ignoreEndOfConversationEventFilter, ignoreTypingEventFilter } from './builtInMessageFilters'; import { config, IConfig, MessageFilter } from './config'; import { ExpectedMessage, PossibleExpectedMessageCollections, PossibleExpectedMessageType } from './ExpectedMessage'; import { botToUserMessageCheckerFunction, MessageService } from './MessageService'; @@ -24,6 +25,16 @@ export interface IOptionsModifier { * sets the timeout time that the BotTester will wait for any particular message before failing */ setTimeout(milliseconds: number): BotTester; + + /** + * adds prebuilt filter to ignore typing event + */ + ignoreTypingEvent(): BotTester; + + /** + * adds prebuilt filter to ignore endOfConversationEvent + */ + ignoreEndOfConversationEvent(): BotTester; } /** @@ -119,10 +130,30 @@ export class BotTester implements IBotTester, IOptionsModifier { return this; } + public ignoreEndOfConversationEvent(): BotTester { + this.config.ignoreEndOfConversationEvent = true; + + return this; + } + + public ignoreTypingEvent(): BotTester { + this.config.ignoreTypingEvent = true; + + return this; + } + /** * Initializes the MessegeService here to allow config changes to accumulate */ public runTest(): Promise<{}> { + if (this.config.ignoreTypingEvent) { + this.config.messageFilters.push(ignoreTypingEventFilter); + } + + if (this.config.ignoreEndOfConversationEvent) { + this.config.messageFilters.push(ignoreEndOfConversationEventFilter); + } + this.messageService = new MessageService(this.bot, this.config); return Promise.mapSeries(this.testSteps, (fn: TestStep) => fn()); diff --git a/src/ExpectedMessage.ts b/src/ExpectedMessage.ts index ed839e2..294ca54 100644 --- a/src/ExpectedMessage.ts +++ b/src/ExpectedMessage.ts @@ -1,4 +1,4 @@ -import { IMessage } from 'botbuilder'; +import { IMessage, IEvent } from 'botbuilder'; import { expect } from './assertionLibraries/IExpectation'; export enum ExpectedMessageType { @@ -10,7 +10,7 @@ export enum ExpectedMessageType { /** * Types accepted for responses checkers */ -export type PossibleExpectedMessageType = string | IMessage | RegExp; +export type PossibleExpectedMessageType = string | IMessage | RegExp | IEvent; /** * Response expectations area always collections. The collection is the set of possible responses, chosen at random. If the collection size diff --git a/src/MessageService.ts b/src/MessageService.ts index 7b10aa8..da4e8c3 100644 --- a/src/MessageService.ts +++ b/src/MessageService.ts @@ -87,7 +87,6 @@ export class MessageService { } catch (e) { return rej(e); } - }); if (!outgoingMessageComparator.expectsAdditionalMessages()) { diff --git a/src/builtInMessageFilters.ts b/src/builtInMessageFilters.ts new file mode 100644 index 0000000..b8129dd --- /dev/null +++ b/src/builtInMessageFilters.ts @@ -0,0 +1,13 @@ +import { IMessage } from 'botbuilder'; + +export function ignoreInternalSaveMessageFilter(message: IMessage): boolean { + return message.type !== '__save__'; +} + +export function ignoreEndOfConversationEventFilter(message: IMessage): boolean { + return message.type !== 'endOfConversation'; +} + +export function ignoreTypingEventFilter(message: IMessage): boolean { + return message.type !== 'typing'; +} diff --git a/src/config.ts b/src/config.ts index d911314..744f1fd 100644 --- a/src/config.ts +++ b/src/config.ts @@ -16,6 +16,16 @@ export interface IConfig { */ defaultAddress?: IAddress; + /** + * ignores typing event messages + */ + ignoreTypingEvent?: boolean; + + /** + * ignores end of conversation event messages + */ + ignoreEndOfConversationEvent?: boolean; + /** * filters for messages that the BotTester framework should use */ diff --git a/test/BotTester.spec.ts b/test/BotTester.spec.ts index d600457..ef9cb55 100644 --- a/test/BotTester.spec.ts +++ b/test/BotTester.spec.ts @@ -388,6 +388,19 @@ describe('BotTester', () => { .runTest() ).to.be.rejected.notify(done); }); + + it('can ignore typing events', () => { + bot.dialog('/', (session) => { + session.send('hello'); + session.sendTyping(); + session.send('goodbye'); + }); + + return new BotTester(bot) + .ignoreTypingEvent() + .sendMessageToBot('hey', 'hello', 'goodbye') + .runTest(); + }); }); //``` diff --git a/test/BotTesterFailure.spec.ts b/test/BotTesterFailure.spec.ts index 66ec045..37dcbd4 100644 --- a/test/BotTesterFailure.spec.ts +++ b/test/BotTesterFailure.spec.ts @@ -218,4 +218,39 @@ describe('BotTester', () => { .sendMessageToBot('intro', 'hello', 'how', 'are', 'you?') .runTest()).to.be.rejected.notify(done); }); + + it('will fail if a endOfConversationEvent is seen with an ingoreEndOfConversationEventFilter', (done: Function) => { + bot.dialog('/', (session: Session) => { + session.send('hello'); + session.endConversation(); + }); + + expect(new BotTester(bot) + // need to timeout before the tests do to catch the error + .setTimeout(500) + .ignoreEndOfConversationEvent() + //tslint:disable + .sendMessageToBot('hey', 'hello', {type: 'endOfConversation'} as any) + //tslint:enable + .runTest()) + .to.be.rejected.notify(done); + }); + + it('will fail if a typing event is seen with an ignoreTypingEventFilter', (done: Function) => { + bot.dialog('/', (session: Session) => { + session.send('hello'); + session.sendTyping(); + session.send('hey'); + }); + + expect(new BotTester(bot) + // need to timeout before the tests do to catch the error + .setTimeout(500) + .ignoreTypingEvent() + //tslint:disable + .sendMessageToBot('hey', 'hello', {type: 'typing'} as any, 'hey') + //tslint:enable + .runTest()) + .to.be.rejected.notify(done); + }); }); From ab040007df242713bc365d0cf8d33ae17bf61176 Mon Sep 17 00:00:00 2001 From: Matthew Schwartz Date: Thu, 5 Oct 2017 18:54:37 -0700 Subject: [PATCH 03/29] add builtin message filters to options/config (#30) --- README.md | 17 ++++++++++++++++- src/BotTester.ts | 31 +++++++++++++++++++++++++++++++ src/ExpectedMessage.ts | 4 ++-- src/MessageService.ts | 1 - src/builtInMessageFilters.ts | 13 +++++++++++++ src/config.ts | 10 ++++++++++ test/BotTester.spec.ts | 13 +++++++++++++ test/BotTesterFailure.spec.ts | 35 +++++++++++++++++++++++++++++++++++ 8 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 src/builtInMessageFilters.ts diff --git a/README.md b/README.md index e1de07d..0dd3e7b 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,9 @@ Passing in the config overrides any default values or values set by bot-tester.j defaultAddress: botbuilder.IAddress, timeout: number // in milliseconds // each filter returns false for messages that the BotTester should ignore - messageFilters: ((message:IMessage) => boolean)[] + messageFilters: ((message:IMessage) => boolean)[], + ignoreTypingEvent: boolean, + ignoreEndOfConversationEvent: boolean } ``` if timeout is defined, then a particular ```runTest()``` call will fail if it does not receive each expected message within the timeout period of time set in the options. @@ -411,5 +413,18 @@ describe('BotTester', () => { .runTest() ).to.be.rejected.notify(done); }); + + it('can ignore typing events', () => { + bot.dialog('/', (session) => { + session.send('hello'); + session.sendTyping(); + session.send('goodbye'); + }); + + return new BotTester(bot) + .ignoreTypingEvent() + .sendMessageToBot('hey', 'hello', 'goodbye') + .runTest(); + }); }); ``` diff --git a/src/BotTester.ts b/src/BotTester.ts index 7521d61..c4207ba 100644 --- a/src/BotTester.ts +++ b/src/BotTester.ts @@ -1,5 +1,6 @@ import * as Promise from 'bluebird'; import { IAddress, IMessage, Message, Session, UniversalBot } from 'botbuilder'; +import { ignoreEndOfConversationEventFilter, ignoreTypingEventFilter } from './builtInMessageFilters'; import { config, IConfig, MessageFilter } from './config'; import { ExpectedMessage, PossibleExpectedMessageCollections, PossibleExpectedMessageType } from './ExpectedMessage'; import { botToUserMessageCheckerFunction, MessageService } from './MessageService'; @@ -24,6 +25,16 @@ export interface IOptionsModifier { * sets the timeout time that the BotTester will wait for any particular message before failing */ setTimeout(milliseconds: number): BotTester; + + /** + * adds prebuilt filter to ignore typing event + */ + ignoreTypingEvent(): BotTester; + + /** + * adds prebuilt filter to ignore endOfConversationEvent + */ + ignoreEndOfConversationEvent(): BotTester; } /** @@ -119,10 +130,30 @@ export class BotTester implements IBotTester, IOptionsModifier { return this; } + public ignoreEndOfConversationEvent(): BotTester { + this.config.ignoreEndOfConversationEvent = true; + + return this; + } + + public ignoreTypingEvent(): BotTester { + this.config.ignoreTypingEvent = true; + + return this; + } + /** * Initializes the MessegeService here to allow config changes to accumulate */ public runTest(): Promise<{}> { + if (this.config.ignoreTypingEvent) { + this.config.messageFilters.push(ignoreTypingEventFilter); + } + + if (this.config.ignoreEndOfConversationEvent) { + this.config.messageFilters.push(ignoreEndOfConversationEventFilter); + } + this.messageService = new MessageService(this.bot, this.config); return Promise.mapSeries(this.testSteps, (fn: TestStep) => fn()); diff --git a/src/ExpectedMessage.ts b/src/ExpectedMessage.ts index ed839e2..294ca54 100644 --- a/src/ExpectedMessage.ts +++ b/src/ExpectedMessage.ts @@ -1,4 +1,4 @@ -import { IMessage } from 'botbuilder'; +import { IMessage, IEvent } from 'botbuilder'; import { expect } from './assertionLibraries/IExpectation'; export enum ExpectedMessageType { @@ -10,7 +10,7 @@ export enum ExpectedMessageType { /** * Types accepted for responses checkers */ -export type PossibleExpectedMessageType = string | IMessage | RegExp; +export type PossibleExpectedMessageType = string | IMessage | RegExp | IEvent; /** * Response expectations area always collections. The collection is the set of possible responses, chosen at random. If the collection size diff --git a/src/MessageService.ts b/src/MessageService.ts index 7b10aa8..da4e8c3 100644 --- a/src/MessageService.ts +++ b/src/MessageService.ts @@ -87,7 +87,6 @@ export class MessageService { } catch (e) { return rej(e); } - }); if (!outgoingMessageComparator.expectsAdditionalMessages()) { diff --git a/src/builtInMessageFilters.ts b/src/builtInMessageFilters.ts new file mode 100644 index 0000000..b8129dd --- /dev/null +++ b/src/builtInMessageFilters.ts @@ -0,0 +1,13 @@ +import { IMessage } from 'botbuilder'; + +export function ignoreInternalSaveMessageFilter(message: IMessage): boolean { + return message.type !== '__save__'; +} + +export function ignoreEndOfConversationEventFilter(message: IMessage): boolean { + return message.type !== 'endOfConversation'; +} + +export function ignoreTypingEventFilter(message: IMessage): boolean { + return message.type !== 'typing'; +} diff --git a/src/config.ts b/src/config.ts index d911314..744f1fd 100644 --- a/src/config.ts +++ b/src/config.ts @@ -16,6 +16,16 @@ export interface IConfig { */ defaultAddress?: IAddress; + /** + * ignores typing event messages + */ + ignoreTypingEvent?: boolean; + + /** + * ignores end of conversation event messages + */ + ignoreEndOfConversationEvent?: boolean; + /** * filters for messages that the BotTester framework should use */ diff --git a/test/BotTester.spec.ts b/test/BotTester.spec.ts index d600457..ef9cb55 100644 --- a/test/BotTester.spec.ts +++ b/test/BotTester.spec.ts @@ -388,6 +388,19 @@ describe('BotTester', () => { .runTest() ).to.be.rejected.notify(done); }); + + it('can ignore typing events', () => { + bot.dialog('/', (session) => { + session.send('hello'); + session.sendTyping(); + session.send('goodbye'); + }); + + return new BotTester(bot) + .ignoreTypingEvent() + .sendMessageToBot('hey', 'hello', 'goodbye') + .runTest(); + }); }); //``` diff --git a/test/BotTesterFailure.spec.ts b/test/BotTesterFailure.spec.ts index 66ec045..37dcbd4 100644 --- a/test/BotTesterFailure.spec.ts +++ b/test/BotTesterFailure.spec.ts @@ -218,4 +218,39 @@ describe('BotTester', () => { .sendMessageToBot('intro', 'hello', 'how', 'are', 'you?') .runTest()).to.be.rejected.notify(done); }); + + it('will fail if a endOfConversationEvent is seen with an ingoreEndOfConversationEventFilter', (done: Function) => { + bot.dialog('/', (session: Session) => { + session.send('hello'); + session.endConversation(); + }); + + expect(new BotTester(bot) + // need to timeout before the tests do to catch the error + .setTimeout(500) + .ignoreEndOfConversationEvent() + //tslint:disable + .sendMessageToBot('hey', 'hello', {type: 'endOfConversation'} as any) + //tslint:enable + .runTest()) + .to.be.rejected.notify(done); + }); + + it('will fail if a typing event is seen with an ignoreTypingEventFilter', (done: Function) => { + bot.dialog('/', (session: Session) => { + session.send('hello'); + session.sendTyping(); + session.send('hey'); + }); + + expect(new BotTester(bot) + // need to timeout before the tests do to catch the error + .setTimeout(500) + .ignoreTypingEvent() + //tslint:disable + .sendMessageToBot('hey', 'hello', {type: 'typing'} as any, 'hey') + //tslint:enable + .runTest()) + .to.be.rejected.notify(done); + }); }); From a4c07bdeed985547e8fa70a82de00be06bc30c4a Mon Sep 17 00:00:00 2001 From: Matthew Schwartz Date: Thu, 5 Oct 2017 19:01:33 -0700 Subject: [PATCH 04/29] v3.1.0 (#32) * add builtin message filters * bump version for v3.1.0 * updated docs for publish --- docs/assets/js/search.js | 2 +- ...ries_chaiexpectation_.chaiexpectation.html | 19 +- docs/classes/_bottester_.bottester.html | 260 +++++---- .../_expectedmessage_.expectedmessage.html | 17 +- .../_messageservice_.messageservice.html | 17 +- ...comparator_.outgoingmessagecomparator.html | 21 +- .../_sessionservice_.sessionservice.html | 23 +- .../_testconnector_.testconnector.html | 17 +- ..._expectedmessage_.expectedmessagetype.html | 9 +- docs/index.html | 4 + ...nlibraries_iexpectation_.iexpectation.html | 13 +- docs/interfaces/_bottester_.ibottester.html | 501 ++++++++++++++++++ .../_bottester_.ioptionsmodifier.html | 370 +++++++++++++ docs/interfaces/_config_.iconfig.html | 67 ++- .../_assertionlibraries_chaiexpectation_.html | 3 + .../_assertionlibraries_iexpectation_.html | 5 +- docs/modules/_bottester_.html | 18 +- docs/modules/_builtinmessagefilters_.html | 290 ++++++++++ docs/modules/_config_.html | 55 +- docs/modules/_expectedmessage_.html | 9 +- docs/modules/_index_.html | 3 + docs/modules/_messageservice_.html | 5 +- docs/modules/_outgoingmessagecomparator_.html | 3 + docs/modules/_sessionservice_.html | 3 + docs/modules/_testconnector_.html | 3 + package.json | 2 +- 26 files changed, 1573 insertions(+), 166 deletions(-) create mode 100644 docs/interfaces/_bottester_.ibottester.html create mode 100644 docs/interfaces/_bottester_.ioptionsmodifier.html create mode 100644 docs/modules/_builtinmessagefilters_.html diff --git a/docs/assets/js/search.js b/docs/assets/js/search.js index 636b530..f8620f9 100644 --- a/docs/assets/js/search.js +++ b/docs/assets/js/search.js @@ -1,3 +1,3 @@ var typedoc = typedoc || {}; typedoc.search = typedoc.search || {}; - typedoc.search.data = {"kinds":{"1":"External module","65536":"Type literal"},"rows":[{"id":0,"kind":65536,"name":"__type","url":"classes/_testconnector_.testconnector.html#oneventhandler.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"TestConnector\".TestConnector.onEventHandler"},{"id":1,"kind":65536,"name":"__type","url":"classes/_testconnector_.testconnector.html#oninvokehandler.__type-1","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"TestConnector\".TestConnector.onInvokeHandler"},{"id":2,"kind":65536,"name":"__type","url":"modules/_messageservice_.html#bottousermessagecheckerfunction.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"MessageService\".botToUserMessageCheckerFunction"},{"id":3,"kind":65536,"name":"__type","url":"classes/_sessionservice_.sessionservice.html#currentsessionloadresolver.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"SessionService\".SessionService.currentSessionLoadResolver"},{"id":4,"kind":65536,"name":"__type","url":"modules/_bottester_.html#checksessionfunction.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"BotTester\".checkSessionFunction"},{"id":5,"kind":1,"name":"\"index\"","url":"modules/_index_.html","classes":"tsd-kind-external-module"}]}; \ No newline at end of file + typedoc.search.data = {"kinds":{"1":"External module","65536":"Type literal"},"rows":[{"id":0,"kind":65536,"name":"__type","url":"classes/_testconnector_.testconnector.html#oneventhandler.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"TestConnector\".TestConnector.onEventHandler"},{"id":1,"kind":65536,"name":"__type","url":"classes/_testconnector_.testconnector.html#oninvokehandler.__type-1","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"TestConnector\".TestConnector.onInvokeHandler"},{"id":2,"kind":65536,"name":"__type","url":"modules/_config_.html#messagefilter.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"config\".MessageFilter"},{"id":3,"kind":65536,"name":"__type","url":"modules/_messageservice_.html#bottousermessagecheckerfunction.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"MessageService\".botToUserMessageCheckerFunction"},{"id":4,"kind":65536,"name":"__type","url":"classes/_sessionservice_.sessionservice.html#currentsessionloadresolver.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"SessionService\".SessionService.currentSessionLoadResolver"},{"id":5,"kind":65536,"name":"__type","url":"modules/_bottester_.html#checksessionfunction.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"BotTester\".checkSessionFunction"},{"id":6,"kind":1,"name":"\"index\"","url":"modules/_index_.html","classes":"tsd-kind-external-module"}]}; \ No newline at end of file diff --git a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html index fb1c32e..cbb5966 100644 --- a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html +++ b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html @@ -130,7 +130,7 @@

constructor

  • Parameters

    @@ -155,7 +155,7 @@

    Private message

    message: string
    @@ -165,7 +165,7 @@

    Private subject

    subject: __type
    @@ -183,7 +183,7 @@

    notToBeEmpty

    Returns void

    @@ -201,7 +201,7 @@

    toBeTrue

    Returns void

    @@ -219,7 +219,7 @@

    toDeeplyInclude

    @@ -252,7 +252,7 @@

    toEqual

    Parameters

    @@ -276,7 +276,7 @@

    toInclude

    Parameters

    @@ -330,6 +330,9 @@

    Returns void "assertionLibraries/IExpectation"

  • +
  • + "builtInMessageFilters" +
  • "config"
  • diff --git a/docs/classes/_bottester_.bottester.html b/docs/classes/_bottester_.bottester.html index 5f0f331..6b2c6ac 100644 --- a/docs/classes/_bottester_.bottester.html +++ b/docs/classes/_bottester_.bottester.html @@ -82,6 +82,13 @@

    Hierarchy

    +
    +

    Implements

    + +

    Index

    @@ -96,7 +103,7 @@

    Constructors

    Properties

    @@ -198,7 +197,7 @@

    Private sessionLoader

    sessionLoader: SessionService
    @@ -208,47 +207,61 @@

    Private testSteps

    testSteps: TestStep[]

    Methods

    +
    + +

    addMessageFilter

    + + +

    checkSession

    • -
      -
      -

      loads a session associated with an address and passes it to a user defined function

      -
      -

      Parameters

      • sessionCheckerFunction: checkSessionFunction
        -
        -

        function passed in to inspect message

        -
      • Optional address: IAddress
        -
        -

        (Optional) address of the session to load. Defaults to bot's default address if not defined

        -
      -

      Returns BotTester

      +

      Returns IBotTester

    @@ -262,7 +275,7 @@

    Private convertToIMessage<
  • Parameters

    @@ -275,25 +288,62 @@

    Returns IMessage<

  • +
    + +

    ignoreEndOfConversationEvent

    +
      +
    • ignoreEndOfConversationEvent(): BotTester
    • +
    + +
    +
    + +

    ignoreTypingEvent

    + + +

    runTest

      -
    • runTest(): Promise<any>
    • +
    • runTest(): Promise<__type>
    • -

      executes each test step serially

      +

      Initializes the MessegeService here to allow config changes to accumulate

      -

      Returns Promise<any>

      +

      Returns Promise<__type>

    @@ -301,38 +351,26 @@

    Returns Promise

    sendMessageToBot

      -
    • sendMessageToBot(msg: IMessage | string, ...expectedResponses: (string | RegExp | IMessage | (string | RegExp | IMessage)[])[]): BotTester
    • +
    • sendMessageToBot(msg: IMessage | string, ...expectedResponses: (string | RegExp | IEvent | IMessage | (string | RegExp | IEvent | IMessage)[])[]): IBotTester
    • -
      -
      -

      sends a message to a bot and compares bot responses against expectedResponsess. Expected responses can be a variable number of args, - each of which can be a single expected response of any PossibleExpectedMessageType or a collection of PossibleExpectedMessageType - that mocks a randomly selected response by the bot

      -
      -

      Parameters

      • msg: IMessage | string
        -
        -

        message to send to bot

        -
      • -
        Rest ...expectedResponses: (string | RegExp | IMessage | (string | RegExp | IMessage)[])[]
        -
        -

        (Optional) responses the bot-tester framework checks against

        -
        +
        Rest ...expectedResponses: (string | RegExp | IEvent | IMessage | (string | RegExp | IEvent | IMessage)[])[]
      -

      Returns BotTester

      +

      Returns IBotTester

    @@ -340,31 +378,23 @@

    Returns

    sendMessageToBotAndExpectSaveWithNoResponse

      -
    • sendMessageToBotAndExpectSaveWithNoResponse(msg: IMessage | string): BotTester
    • +
    • sendMessageToBotAndExpectSaveWithNoResponse(msg: IMessage | string): IBotTester
    @@ -372,13 +402,14 @@

    Returns

    sendMessageToBotIgnoringResponseOrder

      -
    • sendMessageToBotIgnoringResponseOrder(msg: IMessage | string, ...expectedResponses: (string | RegExp | IMessage | (string | RegExp | IMessage)[])[]): BotTester
    • +
    • sendMessageToBotIgnoringResponseOrder(msg: IMessage | string, ...expectedResponses: (string | RegExp | IEvent | IMessage | (string | RegExp | IEvent | IMessage)[])[]): IBotTester
    • Parameters

      @@ -387,10 +418,10 @@

      Parameters

      msg: IMessage | string
    • -
      Rest ...expectedResponses: (string | RegExp | IMessage | (string | RegExp | IMessage)[])[]
      +
      Rest ...expectedResponses: (string | RegExp | IEvent | IMessage | (string | RegExp | IEvent | IMessage)[])[]
    -

    Returns BotTester

    +

    Returns IBotTester

    @@ -398,13 +429,13 @@

    Returns

    Private sendMessageToBotInternal

      -
    • sendMessageToBotInternal(message: IMessage, expectedResponses: (string | RegExp | IMessage | (string | RegExp | IMessage)[])[], ignoreOrder?: boolean): BotTester
    • +
    • sendMessageToBotInternal(message: IMessage, expectedResponses: (string | RegExp | IEvent | IMessage | (string | RegExp | IEvent | IMessage)[])[], ignoreOrder?: boolean): BotTester
    • @@ -421,7 +452,7 @@
      message: IMessage
    • -
      expectedResponses: (string | RegExp | IMessage | (string | RegExp | IMessage)[])[]
      +
      expectedResponses: (string | RegExp | IEvent | IMessage | (string | RegExp | IEvent | IMessage)[])[]

      expected responses

      @@ -434,35 +465,51 @@

      Returns

    +
    + +

    setTimeout

    +
      +
    • setTimeout(milliseconds: number): BotTester
    • +
    + +

    then

    • -
      -
      -

      Works exactly like Promise's .then function, except that the return value is not passed as an arg to the next function (even if its - another .then)

      -
      -

      Parameters

      • fn: Function
        -
        -

        some function to run

        -
      -

      Returns BotTester

      +

      Returns IBotTester

    @@ -470,27 +517,23 @@

    Returns

    wait

      -
    • wait(delayInMilliseconds: number): BotTester
    • +
    • wait(delayInMilliseconds: number): IBotTester
    @@ -535,6 +578,9 @@

    Returns "assertionLibraries/IExpectation" +
  • + "builtInMessageFilters" +
  • "config"
  • @@ -554,7 +600,7 @@

    Returns bot
  • - defaultAddress + config
  • messageService @@ -565,12 +611,21 @@

    Returns testSteps

  • +
  • + addMessageFilter +
  • checkSession
  • convertToIMessage
  • +
  • + ignoreEndOfConversationEvent +
  • +
  • + ignoreTypingEvent +
  • runTest
  • @@ -586,6 +641,9 @@

    Returns sendMessageToBotInternal +
  • + setTimeout +
  • then
  • @@ -596,6 +654,12 @@

    Returns @@ -123,6 +124,9 @@

    External modules

  • "assertionLibraries/IExpectation"
  • +
  • + "builtInMessageFilters" +
  • "config"
  • diff --git a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html index c0846f8..d220e94 100644 --- a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html +++ b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html @@ -117,7 +117,7 @@

    notToBeEmpty

  • Returns void

    @@ -134,7 +134,7 @@

    toBeTrue

  • Returns void

    @@ -151,7 +151,7 @@

    toDeeplyInclude

  • Parameters

    @@ -174,7 +174,7 @@

    toEqual

  • Parameters

    @@ -197,7 +197,7 @@

    toInclude

  • Parameters

    @@ -251,6 +251,9 @@

    Returns void "assertionLibraries/IExpectation"

  • +
  • + "builtInMessageFilters" +
  • "config"
  • diff --git a/docs/interfaces/_bottester_.ibottester.html b/docs/interfaces/_bottester_.ibottester.html new file mode 100644 index 0000000..69901c1 --- /dev/null +++ b/docs/interfaces/_bottester_.ibottester.html @@ -0,0 +1,501 @@ + + + + + + IBotTester | bot-tester + + + + + +
    +
    +
    +
    + +
    +
    + Options +
    +
    + All +
      +
    • Public
    • +
    • Public/Protected
    • +
    • All
    • +
    +
    + + + + +
    +
    + Menu +
    +
    +
    +
    +
    +
    + +

    Interface IBotTester

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    Test builder/runner suite. After any of these are called, no functions in IConfigModified should be accessible

    +
    +
    +
    +
    +

    Hierarchy

    +
      +
    • + IBotTester +
    • +
    +
    +
    +

    Implemented by

    + +
    +
    +

    Index

    +
    + +
    +
    +
    +

    Methods

    +
    + +

    checkSession

    + +
      +
    • + +
      +
      +

      loads a session associated with an address and passes it to a user defined function

      +
      +
      +

      Parameters

      +
        +
      • +
        sessionCheckerFunction: checkSessionFunction
        +
        +

        function passed in to inspect message

        +
        +
      • +
      • +
        Optional address: IAddress
        +
        +

        (Optional) address of the session to load. Defaults to bot's default address if not defined

        +
        +
      • +
      +

      Returns IBotTester

      +
    • +
    +
    +
    + +

    runTest

    +
      +
    • runTest(): Promise<__type>
    • +
    +
      +
    • + +
      +
      +

      executes each test step serially.

      +
      +
      +

      Returns Promise<__type>

      +
    • +
    +
    +
    + +

    sendMessageToBot

    +
      +
    • sendMessageToBot(msg: IMessage | string, ...expectedResponses: (string | RegExp | IEvent | IMessage | (string | RegExp | IEvent | IMessage)[])[]): IBotTester
    • +
    +
      +
    • + +
      +
      +

      sends a message to a bot and compares bot responses against expectedResponsess. Expected responses can be a variable number of args, + each of which can be a single expected response of any PossibleExpectedMessageType or a collection of PossibleExpectedMessageType + that mocks a randomly selected response by the bot

      +
      +
      +

      Parameters

      +
        +
      • +
        msg: IMessage | string
        +
        +

        message to send to bot

        +
        +
      • +
      • +
        Rest ...expectedResponses: (string | RegExp | IEvent | IMessage | (string | RegExp | IEvent | IMessage)[])[]
        +
        +

        (Optional) responses the bot-tester framework checks against

        +
        +
      • +
      +

      Returns IBotTester

      +
    • +
    +
    +
    + +

    sendMessageToBotAndExpectSaveWithNoResponse

    +
      +
    • sendMessageToBotAndExpectSaveWithNoResponse(msg: IMessage | string): IBotTester
    • +
    +
      +
    • + +
      +
      +

      sends a message to the bot. This should be used whenever session.save() is used without sending a reply to the user. This exists due + to a limitation in the current implementation of the botbuilder framework

      +
      +
      +

      Parameters

      +
        +
      • +
        msg: IMessage | string
        +
        +

        message to send to bot

        +
        +
      • +
      +

      Returns IBotTester

      +
    • +
    +
    +
    + +

    sendMessageToBotIgnoringResponseOrder

    +
      +
    • sendMessageToBotIgnoringResponseOrder(msg: IMessage | string, ...expectedResponses: (string | RegExp | IEvent | IMessage | (string | RegExp | IEvent | IMessage)[])[]): IBotTester
    • +
    +
      +
    • + +
      +
      +

      same as sendMessageToBot, but the order of responses is not checked. This will cause the test to hang until all messages it expects + are returned

      +
      +
      +

      Parameters

      +
        +
      • +
        msg: IMessage | string
        +
      • +
      • +
        Rest ...expectedResponses: (string | RegExp | IEvent | IMessage | (string | RegExp | IEvent | IMessage)[])[]
        +
      • +
      +

      Returns IBotTester

      +
    • +
    +
    +
    + +

    then

    + +
      +
    • + +
      +
      +

      Works exactly like Promise's .then function, except that the return value is not passed as an arg to the next function (even if its + another .then)

      +
      +
      +

      Parameters

      +
        +
      • +
        fn: Function
        +
        +

        some function to run

        +
        +
      • +
      +

      Returns IBotTester

      +
    • +
    +
    +
    + +

    wait

    +
      +
    • wait(delayInMilliseconds: number): IBotTester
    • +
    +
      +
    • + +
      +
      +

      Waits for the given delay between test steps.

      +
      +
      +

      Parameters

      +
        +
      • +
        delayInMilliseconds: number
        +
      • +
      +

      Returns IBotTester

      +
    • +
    +
    +
    +
    + +
    +
    +
    +
    +

    Legend

    +
    +
      +
    • Module
    • +
    • Object literal
    • +
    • Variable
    • +
    • Function
    • +
    • Function with type parameter
    • +
    • Index signature
    • +
    • Type alias
    • +
    +
      +
    • Enumeration
    • +
    • Enumeration member
    • +
    • Property
    • +
    • Method
    • +
    +
      +
    • Interface
    • +
    • Interface with type parameter
    • +
    • Constructor
    • +
    • Property
    • +
    • Method
    • +
    • Index signature
    • +
    +
      +
    • Class
    • +
    • Class with type parameter
    • +
    • Constructor
    • +
    • Property
    • +
    • Method
    • +
    • Accessor
    • +
    • Index signature
    • +
    +
      +
    • Inherited constructor
    • +
    • Inherited property
    • +
    • Inherited method
    • +
    • Inherited accessor
    • +
    +
      +
    • Protected property
    • +
    • Protected method
    • +
    • Protected accessor
    • +
    +
      +
    • Private property
    • +
    • Private method
    • +
    • Private accessor
    • +
    +
      +
    • Static property
    • +
    • Static method
    • +
    +
    +
    +
    +
    + + + + + \ No newline at end of file diff --git a/docs/interfaces/_bottester_.ioptionsmodifier.html b/docs/interfaces/_bottester_.ioptionsmodifier.html new file mode 100644 index 0000000..7f52afd --- /dev/null +++ b/docs/interfaces/_bottester_.ioptionsmodifier.html @@ -0,0 +1,370 @@ + + + + + + IOptionsModifier | bot-tester + + + + + +
    +
    +
    +
    + +
    +
    + Options +
    +
    + All +
      +
    • Public
    • +
    • Public/Protected
    • +
    • All
    • +
    +
    + + + + +
    +
    + Menu +
    +
    +
    +
    +
    +
    + +

    Interface IOptionsModifier

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    methods that the Test builder can call to edit/modify the options. These can be called until any of the IBotTester method are called.

    +
    +
    +
    +
    +

    Hierarchy

    +
      +
    • + IOptionsModifier +
    • +
    +
    +
    +

    Implemented by

    + +
    +
    +

    Index

    +
    + +
    +
    +
    +

    Methods

    +
    + +

    addMessageFilter

    + +
      +
    • + +
      +
      +

      adds a message filter to the options.

      +
      +
      +

      Parameters

      + +

      Returns BotTester

      +
    • +
    +
    +
    + +

    ignoreEndOfConversationEvent

    +
      +
    • ignoreEndOfConversationEvent(): BotTester
    • +
    +
      +
    • + +
      +
      +

      adds prebuilt filter to ignore endOfConversationEvent

      +
      +
      +

      Returns BotTester

      +
    • +
    +
    +
    + +

    ignoreTypingEvent

    + + +
    +
    + +

    setTimeout

    +
      +
    • setTimeout(milliseconds: number): BotTester
    • +
    +
      +
    • + +
      +
      +

      sets the timeout time that the BotTester will wait for any particular message before failing

      +
      +
      +

      Parameters

      +
        +
      • +
        milliseconds: number
        +
      • +
      +

      Returns BotTester

      +
    • +
    +
    +
    +
    + +
    +
    +
    +
    +

    Legend

    +
    +
      +
    • Module
    • +
    • Object literal
    • +
    • Variable
    • +
    • Function
    • +
    • Function with type parameter
    • +
    • Index signature
    • +
    • Type alias
    • +
    +
      +
    • Enumeration
    • +
    • Enumeration member
    • +
    • Property
    • +
    • Method
    • +
    +
      +
    • Interface
    • +
    • Interface with type parameter
    • +
    • Constructor
    • +
    • Property
    • +
    • Method
    • +
    • Index signature
    • +
    +
      +
    • Class
    • +
    • Class with type parameter
    • +
    • Constructor
    • +
    • Property
    • +
    • Method
    • +
    • Accessor
    • +
    • Index signature
    • +
    +
      +
    • Inherited constructor
    • +
    • Inherited property
    • +
    • Inherited method
    • +
    • Inherited accessor
    • +
    +
      +
    • Protected property
    • +
    • Protected method
    • +
    • Protected accessor
    • +
    +
      +
    • Private property
    • +
    • Private method
    • +
    • Private accessor
    • +
    +
      +
    • Static property
    • +
    • Static method
    • +
    +
    +
    +
    +
    + + + + + \ No newline at end of file diff --git a/docs/interfaces/_config_.iconfig.html b/docs/interfaces/_config_.iconfig.html index c314bbd..9767185 100644 --- a/docs/interfaces/_config_.iconfig.html +++ b/docs/interfaces/_config_.iconfig.html @@ -83,6 +83,9 @@

    Index

    Properties

    @@ -97,7 +100,7 @@

    Optional defaultAddressdefaultAddress: IAddress
    @@ -106,13 +109,58 @@

    Optional defaultAddress

    +
    + +

    Optional ignoreEndOfConversationEvent

    +
    ignoreEndOfConversationEvent: boolean
    + +
    +
    +

    ignores end of conversation event messages

    +
    +
    +
    +
    + +

    Optional ignoreTypingEvent

    +
    ignoreTypingEvent: boolean
    + +
    +
    +

    ignores typing event messages

    +
    +
    +
    +
    + +

    Optional messageFilters

    +
    messageFilters: MessageFilter[]
    + +
    +
    +

    filters for messages that the BotTester framework should use

    +
    +
    +

    Optional timeout

    timeout: number
    @@ -162,6 +210,9 @@

    Optional timeout

  • "assertionLibraries/IExpectation"
  • +
  • + "builtInMessageFilters" +
  • "config"
  • @@ -177,6 +228,15 @@

    Optional timeout

  • defaultAddress
  • +
  • + ignoreEndOfConversationEvent +
  • +
  • + ignoreTypingEvent +
  • +
  • + messageFilters +
  • timeout
  • @@ -184,6 +244,9 @@

    Optional timeout

    +
    +

    Interfaces

    + +

    Type aliases

      @@ -91,7 +98,7 @@

      checkSessionFunction

      checkSessionFunction: function
      @@ -157,6 +164,9 @@

      Returns void "assertionLibraries/IExpectation" +
    • + "builtInMessageFilters" +
    • "config"
    • @@ -167,6 +177,12 @@

      Returns void BotTester +
    • + IBotTester +
    • +
    • + IOptionsModifier +
    • checkSessionFunction
    • diff --git a/docs/modules/_builtinmessagefilters_.html b/docs/modules/_builtinmessagefilters_.html new file mode 100644 index 0000000..8a181ac --- /dev/null +++ b/docs/modules/_builtinmessagefilters_.html @@ -0,0 +1,290 @@ + + + + + + "builtInMessageFilters" | bot-tester + + + + + +
      +
      +
      +
      + +
      +
      + Options +
      +
      + All +
        +
      • Public
      • +
      • Public/Protected
      • +
      • All
      • +
      +
      + + + + +
      +
      + Menu +
      +
      +
      +
      +
      +
      + +

      External module "builtInMessageFilters"

      +
      +
      +
      +
      +
      +
      +
      +

      Index

      +
      + +
      +
      +
      +

      Functions

      +
      + +

      ignoreEndOfConversationEventFilter

      +
        +
      • ignoreEndOfConversationEventFilter(message: IMessage): boolean
      • +
      + +
      +
      + +

      ignoreInternalSaveMessageFilter

      +
        +
      • ignoreInternalSaveMessageFilter(message: IMessage): boolean
      • +
      + +
      +
      + +

      ignoreTypingEventFilter

      +
        +
      • ignoreTypingEventFilter(message: IMessage): boolean
      • +
      + +
      +
      +
      + +
      +
      +
      +
      +

      Legend

      +
      +
        +
      • Module
      • +
      • Object literal
      • +
      • Variable
      • +
      • Function
      • +
      • Function with type parameter
      • +
      • Index signature
      • +
      • Type alias
      • +
      +
        +
      • Enumeration
      • +
      • Enumeration member
      • +
      • Property
      • +
      • Method
      • +
      +
        +
      • Interface
      • +
      • Interface with type parameter
      • +
      • Constructor
      • +
      • Property
      • +
      • Method
      • +
      • Index signature
      • +
      +
        +
      • Class
      • +
      • Class with type parameter
      • +
      • Constructor
      • +
      • Property
      • +
      • Method
      • +
      • Accessor
      • +
      • Index signature
      • +
      +
        +
      • Inherited constructor
      • +
      • Inherited property
      • +
      • Inherited method
      • +
      • Inherited accessor
      • +
      +
        +
      • Protected property
      • +
      • Protected method
      • +
      • Protected accessor
      • +
      +
        +
      • Private property
      • +
      • Private method
      • +
      • Private accessor
      • +
      +
        +
      • Static property
      • +
      • Static method
      • +
      +
      +
      +
      +
      + + + + + \ No newline at end of file diff --git a/docs/modules/_config_.html b/docs/modules/_config_.html index b0254e9..ad8a36f 100644 --- a/docs/modules/_config_.html +++ b/docs/modules/_config_.html @@ -74,6 +74,12 @@

      Interfaces

    • IConfig
    +
    +

    Type aliases

    + +

    Variables

      @@ -84,6 +90,45 @@

      Variables

    +
    +

    Type aliases

    +
    + +

    MessageFilter

    +
    MessageFilter: function
    + +
    +
    +

    Returns true if a message

    +
    +
    +
    +

    Type declaration

    +
      +
    • +
        +
      • (message: IMessage): boolean
      • +
      +
        +
      • +

        Parameters

        +
          +
        • +
          message: IMessage
          +
        • +
        +

        Returns boolean

        +
      • +
      +
    • +
    +
    +
    +

    Variables

    @@ -92,7 +137,7 @@

    NO_TIMEOUT

    NO_TIMEOUT: -1 = -1
    @@ -107,7 +152,7 @@

    config

    config: IConfig = configInternal
    @@ -152,6 +197,9 @@

    config

  • "assertionLibraries/IExpectation"
  • +
  • + "builtInMessageFilters" +
  • "config"
  • @@ -162,6 +210,9 @@

    config

  • IConfig
  • +
  • + MessageFilter +
  • NO_TIMEOUT
  • diff --git a/docs/modules/_expectedmessage_.html b/docs/modules/_expectedmessage_.html index 3561401..92b25f6 100644 --- a/docs/modules/_expectedmessage_.html +++ b/docs/modules/_expectedmessage_.html @@ -98,7 +98,7 @@

    PossibleExpectedMessageCollections

    PossibleExpectedMessageCollections: PossibleExpectedMessageType[]
    @@ -111,10 +111,10 @@

    PossibleExpectedMessageCollections

    PossibleExpectedMessageType

    -
    PossibleExpectedMessageType: string | IMessage | RegExp
    +
    PossibleExpectedMessageType: string | IMessage | RegExp | IEvent
    @@ -164,6 +164,9 @@

    PossibleExpectedMessageType

  • "assertionLibraries/IExpectation"
  • +
  • + "builtInMessageFilters" +
  • "config"
  • diff --git a/docs/modules/_index_.html b/docs/modules/_index_.html index 30ffec0..b03378f 100644 --- a/docs/modules/_index_.html +++ b/docs/modules/_index_.html @@ -104,6 +104,9 @@

    External module "index"

  • "assertionLibraries/IExpectation"
  • +
  • + "builtInMessageFilters" +
  • "config"
  • diff --git a/docs/modules/_messageservice_.html b/docs/modules/_messageservice_.html index dcf5b67..37b4d1d 100644 --- a/docs/modules/_messageservice_.html +++ b/docs/modules/_messageservice_.html @@ -91,7 +91,7 @@

    botToUserMessageCheckerFunction

    botToUserMessageCheckerFunction: function
    @@ -157,6 +157,9 @@

    Returns void "assertionLibraries/IExpectation" +
  • + "builtInMessageFilters" +
  • "config"
  • diff --git a/docs/modules/_outgoingmessagecomparator_.html b/docs/modules/_outgoingmessagecomparator_.html index efa7651..9d1da7f 100644 --- a/docs/modules/_outgoingmessagecomparator_.html +++ b/docs/modules/_outgoingmessagecomparator_.html @@ -117,6 +117,9 @@

    Classes

  • "assertionLibraries/IExpectation"
  • +
  • + "builtInMessageFilters" +
  • "config"
  • diff --git a/docs/modules/_sessionservice_.html b/docs/modules/_sessionservice_.html index 4d52cbf..74b317b 100644 --- a/docs/modules/_sessionservice_.html +++ b/docs/modules/_sessionservice_.html @@ -117,6 +117,9 @@

    Classes

  • "assertionLibraries/IExpectation"
  • +
  • + "builtInMessageFilters" +
  • "config"
  • diff --git a/docs/modules/_testconnector_.html b/docs/modules/_testconnector_.html index a6c961a..38aec2a 100644 --- a/docs/modules/_testconnector_.html +++ b/docs/modules/_testconnector_.html @@ -117,6 +117,9 @@

    Classes

  • "assertionLibraries/IExpectation"
  • +
  • + "builtInMessageFilters" +
  • "config"
  • diff --git a/package.json b/package.json index 2b1c8cf..c5b2003 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bot-tester", - "version": "3.0.2", + "version": "3.1.0", "description": "Easily test bots made with the bot builder framework", "main": "dist/index.js", "types": "dist/index.d.ts", From c1cddcf829ce832756f9ede63a49d6b21ff77b91 Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Thu, 5 Oct 2017 21:32:28 -0700 Subject: [PATCH 05/29] added ignoreInternalSaveMessage option --- README.md | 5 ++++- src/config.ts | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0dd3e7b..a41e10a 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,10 @@ Passing in the config overrides any default values or values set by bot-tester.j // each filter returns false for messages that the BotTester should ignore messageFilters: ((message:IMessage) => boolean)[], ignoreTypingEvent: boolean, - ignoreEndOfConversationEvent: boolean + ignoreEndOfConversationEvent: boolean, + // Setting this to true will cause checkSession to hang and test to fail. + ignoreInternalSveMessage?: boolean; + } ``` if timeout is defined, then a particular ```runTest()``` call will fail if it does not receive each expected message within the timeout period of time set in the options. diff --git a/src/config.ts b/src/config.ts index 744f1fd..954f2d0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,6 @@ import { IAddress, IMessage } from 'botbuilder'; import * as fs from 'fs'; +import { ignoreInternalSaveMessageFilter } from './builtInMessageFilters'; /** * Returns true if a message @@ -26,6 +27,12 @@ export interface IConfig { */ ignoreEndOfConversationEvent?: boolean; + /** + * ignores the internal __save__ message. Setting this to true will cause checkSession to hang and test to fail + */ + // this is explicitly not added as a chained builder function to disaude consumers from using this. + ignoreInternalSveMessage?: boolean; + /** * filters for messages that the BotTester framework should use */ @@ -56,4 +63,8 @@ if (configFileExists) { configInternal.messageFilters = []; +if (configInternal.ignoreInternalSveMessage) { + configInternal.messageFilters.push(ignoreInternalSaveMessageFilter); +} + export const config = configInternal; From d38828a316b322f0253e9064fd15a9ee1cbd9e62 Mon Sep 17 00:00:00 2001 From: Matthew Schwartz Date: Thu, 5 Oct 2017 21:38:26 -0700 Subject: [PATCH 06/29] Add internal save ignore option (#35) --- README.md | 5 ++++- src/config.ts | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0dd3e7b..a41e10a 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,10 @@ Passing in the config overrides any default values or values set by bot-tester.j // each filter returns false for messages that the BotTester should ignore messageFilters: ((message:IMessage) => boolean)[], ignoreTypingEvent: boolean, - ignoreEndOfConversationEvent: boolean + ignoreEndOfConversationEvent: boolean, + // Setting this to true will cause checkSession to hang and test to fail. + ignoreInternalSveMessage?: boolean; + } ``` if timeout is defined, then a particular ```runTest()``` call will fail if it does not receive each expected message within the timeout period of time set in the options. diff --git a/src/config.ts b/src/config.ts index 744f1fd..954f2d0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,6 @@ import { IAddress, IMessage } from 'botbuilder'; import * as fs from 'fs'; +import { ignoreInternalSaveMessageFilter } from './builtInMessageFilters'; /** * Returns true if a message @@ -26,6 +27,12 @@ export interface IConfig { */ ignoreEndOfConversationEvent?: boolean; + /** + * ignores the internal __save__ message. Setting this to true will cause checkSession to hang and test to fail + */ + // this is explicitly not added as a chained builder function to disaude consumers from using this. + ignoreInternalSveMessage?: boolean; + /** * filters for messages that the BotTester framework should use */ @@ -56,4 +63,8 @@ if (configFileExists) { configInternal.messageFilters = []; +if (configInternal.ignoreInternalSveMessage) { + configInternal.messageFilters.push(ignoreInternalSaveMessageFilter); +} + export const config = configInternal; From 0d1ee2f2c34839ddf3a8829bfe9860fa54bdbf93 Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Thu, 5 Oct 2017 21:39:54 -0700 Subject: [PATCH 07/29] v3.2.0 --- ...ries_chaiexpectation_.chaiexpectation.html | 16 ++++---- docs/classes/_bottester_.bottester.html | 38 +++++++++---------- .../_expectedmessage_.expectedmessage.html | 14 +++---- .../_messageservice_.messageservice.html | 14 +++---- ...comparator_.outgoingmessagecomparator.html | 18 ++++----- .../_sessionservice_.sessionservice.html | 20 +++++----- .../_testconnector_.testconnector.html | 14 +++---- ..._expectedmessage_.expectedmessagetype.html | 6 +-- ...nlibraries_iexpectation_.iexpectation.html | 10 ++--- docs/interfaces/_bottester_.ibottester.html | 14 +++---- .../_bottester_.ioptionsmodifier.html | 8 ++-- docs/interfaces/_config_.iconfig.html | 29 +++++++++++--- .../_assertionlibraries_iexpectation_.html | 2 +- docs/modules/_bottester_.html | 2 +- docs/modules/_builtinmessagefilters_.html | 6 +-- docs/modules/_config_.html | 6 +-- docs/modules/_expectedmessage_.html | 4 +- docs/modules/_messageservice_.html | 2 +- package.json | 2 +- 19 files changed, 122 insertions(+), 103 deletions(-) diff --git a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html index cbb5966..ff334f6 100644 --- a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html +++ b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html @@ -130,7 +130,7 @@

    constructor

  • Parameters

    @@ -155,7 +155,7 @@

    Private message

    message: string
  • @@ -165,7 +165,7 @@

    Private subject

    subject: __type
    @@ -183,7 +183,7 @@

    notToBeEmpty

    Returns void

    @@ -201,7 +201,7 @@

    toBeTrue

    Returns void

    @@ -219,7 +219,7 @@

    toDeeplyInclude

    @@ -252,7 +252,7 @@

    toEqual

    Parameters

    @@ -276,7 +276,7 @@

    toInclude

    Parameters

    diff --git a/docs/classes/_bottester_.bottester.html b/docs/classes/_bottester_.bottester.html index 6b2c6ac..28a9a6f 100644 --- a/docs/classes/_bottester_.bottester.html +++ b/docs/classes/_bottester_.bottester.html @@ -142,7 +142,7 @@

    constructor

  • Parameters

    @@ -167,7 +167,7 @@

    Private bot

    bot: UniversalBot
    @@ -177,7 +177,7 @@

    Private config

    config: IConfig
    @@ -187,7 +187,7 @@

    Private messageService

    messageService: MessageService
  • @@ -197,7 +197,7 @@

    Private sessionLoader

    sessionLoader: SessionService
    @@ -207,7 +207,7 @@

    Private testSteps

    testSteps: TestStep[]
    @@ -225,7 +225,7 @@

    addMessageFilter

    Parameters

    @@ -249,7 +249,7 @@

    checkSession

    Parameters

    @@ -275,7 +275,7 @@

    Private convertToIMessage<
  • Parameters

    @@ -299,7 +299,7 @@

    ignoreEndOfConversationEvent

    Returns BotTester

    @@ -317,7 +317,7 @@

    ignoreTypingEvent

    Returns BotTester

    @@ -335,7 +335,7 @@

    runTest

    @@ -358,7 +358,7 @@

    sendMessageToBot

    Parameters

    @@ -385,7 +385,7 @@

    sendMessageToBotAndExpectSaveWithNoRespon

    Parameters

    @@ -409,7 +409,7 @@

    sendMessageToBotIgnoringResponseOrder

    Parameters

    @@ -435,7 +435,7 @@

    Private sendMessageTo
  • @@ -476,7 +476,7 @@

    setTimeout

    Parameters

    @@ -500,7 +500,7 @@

    then

    Parameters

    @@ -524,7 +524,7 @@

    wait

    Parameters

    diff --git a/docs/classes/_expectedmessage_.expectedmessage.html b/docs/classes/_expectedmessage_.expectedmessage.html index 7f07cd8..e2bbbdf 100644 --- a/docs/classes/_expectedmessage_.expectedmessage.html +++ b/docs/classes/_expectedmessage_.expectedmessage.html @@ -124,7 +124,7 @@

    constructor

  • Parameters

    @@ -146,7 +146,7 @@

    Private expectedResponseexpectedResponseCollection: PossibleExpectedMessageCollections

  • @@ -168,7 +168,7 @@

    checkForMessageMatch

  • @@ -200,7 +200,7 @@

    Private checkMessageT
  • @@ -237,7 +237,7 @@

    Private checkMessageT
  • @@ -269,7 +269,7 @@

    Private deepMessageMa
  • @@ -303,7 +303,7 @@

    toString

  • Returns string

    diff --git a/docs/classes/_messageservice_.messageservice.html b/docs/classes/_messageservice_.messageservice.html index c13d979..c4bb41a 100644 --- a/docs/classes/_messageservice_.messageservice.html +++ b/docs/classes/_messageservice_.messageservice.html @@ -124,7 +124,7 @@

    constructor

  • Parameters

    @@ -149,7 +149,7 @@

    Private bot

    bot: UniversalBot
    @@ -159,7 +159,7 @@

    Private botToUserMess
    botToUserMessageChecker: botToUserMessageCheckerFunction
    @@ -169,7 +169,7 @@

    Private config

    config: IConfig
    @@ -186,7 +186,7 @@

    Private applyOutgoing
  • @@ -208,7 +208,7 @@

    sendMessageToBot

  • @@ -248,7 +248,7 @@

    Private setBotToUser<
  • diff --git a/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html b/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html index 259d1ef..9471a7e 100644 --- a/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html +++ b/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html @@ -125,7 +125,7 @@

    constructor

  • Parameters

    @@ -150,7 +150,7 @@

    Private expectedMessagesexpectedMessages: ExpectedMessage[]

  • @@ -160,7 +160,7 @@

    Private ignoreOrder

    ignoreOrder: boolean
    @@ -177,7 +177,7 @@

    compareOutgoingMessageToExpectedResponses

  • @@ -205,7 +205,7 @@

    Private compareOutgoing

    Parameters

    @@ -228,7 +228,7 @@

    Private compareOutgoing

    Parameters

    @@ -251,7 +251,7 @@

    Private dequeueNextEx
  • @@ -273,7 +273,7 @@

    expectsAdditionalMessages

  • @@ -295,7 +295,7 @@

    getTimeoutErrorMessage

  • Returns string

    diff --git a/docs/classes/_sessionservice_.sessionservice.html b/docs/classes/_sessionservice_.sessionservice.html index 3d8a7e1..3a698d3 100644 --- a/docs/classes/_sessionservice_.sessionservice.html +++ b/docs/classes/_sessionservice_.sessionservice.html @@ -126,7 +126,7 @@

    constructor

  • Parameters

    @@ -148,7 +148,7 @@

    Private bot

    bot: UniversalBot
    @@ -158,7 +158,7 @@

    Private currentSessioncurrentSessionLoadResolver: function

  • @@ -189,7 +189,7 @@

    Private savePerformed

    savePerformed: Promise<any>
    @@ -214,7 +214,7 @@

    Private applySessionL
  • @@ -238,7 +238,7 @@

    Private applySessionS
  • @@ -263,7 +263,7 @@

    Private createSession
  • @@ -296,7 +296,7 @@

    getInternalSaveMessage

  • @@ -329,7 +329,7 @@

    getSession

  • @@ -360,7 +360,7 @@

    Private loadSession

  • diff --git a/docs/classes/_testconnector_.testconnector.html b/docs/classes/_testconnector_.testconnector.html index 269afb5..33ee3ac 100644 --- a/docs/classes/_testconnector_.testconnector.html +++ b/docs/classes/_testconnector_.testconnector.html @@ -122,7 +122,7 @@

    constructor

  • Returns TestConnector

    @@ -138,7 +138,7 @@

    Private newConvoCount
    newConvoCount: number
    @@ -148,7 +148,7 @@

    Private onEventHandle
    onEventHandler: function
    @@ -200,7 +200,7 @@

    Private onInvokeHandl
    onInvokeHandler: function
    @@ -265,7 +265,7 @@

    onEvent

  • Parameters

    @@ -327,7 +327,7 @@

    send

  • Parameters

    @@ -374,7 +374,7 @@

    startConversation

  • Parameters

    diff --git a/docs/enums/_expectedmessage_.expectedmessagetype.html b/docs/enums/_expectedmessage_.expectedmessagetype.html index 9cbe1ef..ab10ccf 100644 --- a/docs/enums/_expectedmessage_.expectedmessagetype.html +++ b/docs/enums/_expectedmessage_.expectedmessagetype.html @@ -90,7 +90,7 @@

    IMessage

    IMessage:
    @@ -100,7 +100,7 @@

    Regex

    Regex:
    @@ -110,7 +110,7 @@

    String

    String:
    diff --git a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html index d220e94..b313f42 100644 --- a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html +++ b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html @@ -117,7 +117,7 @@

    notToBeEmpty

  • Returns void

    @@ -134,7 +134,7 @@

    toBeTrue

  • Returns void

    @@ -151,7 +151,7 @@

    toDeeplyInclude

  • Parameters

    @@ -174,7 +174,7 @@

    toEqual

  • Parameters

    @@ -197,7 +197,7 @@

    toInclude

  • Parameters

    diff --git a/docs/interfaces/_bottester_.ibottester.html b/docs/interfaces/_bottester_.ibottester.html index 69901c1..4459527 100644 --- a/docs/interfaces/_bottester_.ibottester.html +++ b/docs/interfaces/_bottester_.ibottester.html @@ -119,7 +119,7 @@

    checkSession

  • @@ -156,7 +156,7 @@

    runTest

  • @@ -178,7 +178,7 @@

    sendMessageToBot

  • @@ -217,7 +217,7 @@

    sendMessageToBotAndExpectSaveWithNoRespon
  • @@ -249,7 +249,7 @@

    sendMessageToBotIgnoringResponseOrder

  • @@ -281,7 +281,7 @@

    then

  • @@ -313,7 +313,7 @@

    wait

  • diff --git a/docs/interfaces/_bottester_.ioptionsmodifier.html b/docs/interfaces/_bottester_.ioptionsmodifier.html index 7f52afd..cbf246c 100644 --- a/docs/interfaces/_bottester_.ioptionsmodifier.html +++ b/docs/interfaces/_bottester_.ioptionsmodifier.html @@ -116,7 +116,7 @@

    addMessageFilter

  • @@ -147,7 +147,7 @@

    ignoreEndOfConversationEvent

  • @@ -169,7 +169,7 @@

    ignoreTypingEvent

  • @@ -191,7 +191,7 @@

    setTimeout

  • diff --git a/docs/interfaces/_config_.iconfig.html b/docs/interfaces/_config_.iconfig.html index 9767185..4ba3e5e 100644 --- a/docs/interfaces/_config_.iconfig.html +++ b/docs/interfaces/_config_.iconfig.html @@ -84,6 +84,7 @@

    Properties

    @@ -115,7 +116,7 @@

    Optional ignoreEndOf
    ignoreEndOfConversationEvent: boolean
    @@ -124,13 +125,28 @@

    Optional ignoreEndOf

    +
    + +

    Optional ignoreInternalSveMessage

    +
    ignoreInternalSveMessage: boolean
    + +
    +
    +

    ignores the internal save message. Setting this to true will cause checkSession to hang and test to fail

    +
    +
    +

    Optional ignoreTypingEvent

    ignoreTypingEvent: boolean
    @@ -145,7 +161,7 @@

    Optional messageFiltersmessageFilters: MessageFilter[]

    @@ -160,7 +176,7 @@

    Optional timeout

    timeout: number
    @@ -231,6 +247,9 @@

    Optional timeout

  • ignoreEndOfConversationEvent
  • +
  • + ignoreInternalSveMessage +
  • ignoreTypingEvent
  • diff --git a/docs/modules/_assertionlibraries_iexpectation_.html b/docs/modules/_assertionlibraries_iexpectation_.html index e765fec..08b7800 100644 --- a/docs/modules/_assertionlibraries_iexpectation_.html +++ b/docs/modules/_assertionlibraries_iexpectation_.html @@ -95,7 +95,7 @@

    expect

  • diff --git a/docs/modules/_bottester_.html b/docs/modules/_bottester_.html index 8b83c17..9357120 100644 --- a/docs/modules/_bottester_.html +++ b/docs/modules/_bottester_.html @@ -98,7 +98,7 @@

    checkSessionFunction

    checkSessionFunction: function
    diff --git a/docs/modules/_builtinmessagefilters_.html b/docs/modules/_builtinmessagefilters_.html index 8a181ac..2466f66 100644 --- a/docs/modules/_builtinmessagefilters_.html +++ b/docs/modules/_builtinmessagefilters_.html @@ -91,7 +91,7 @@

    ignoreEndOfConversationEventFilter

  • Parameters

    @@ -114,7 +114,7 @@

    ignoreInternalSaveMessageFilter

  • Parameters

    @@ -137,7 +137,7 @@

    ignoreTypingEventFilter

  • Parameters

    diff --git a/docs/modules/_config_.html b/docs/modules/_config_.html index ad8a36f..d9f0d01 100644 --- a/docs/modules/_config_.html +++ b/docs/modules/_config_.html @@ -98,7 +98,7 @@

    MessageFilter

    MessageFilter: function
    @@ -137,7 +137,7 @@

    NO_TIMEOUT

    NO_TIMEOUT: -1 = -1
    @@ -152,7 +152,7 @@

    config

    config: IConfig = configInternal
  • diff --git a/docs/modules/_expectedmessage_.html b/docs/modules/_expectedmessage_.html index 92b25f6..09fb72e 100644 --- a/docs/modules/_expectedmessage_.html +++ b/docs/modules/_expectedmessage_.html @@ -98,7 +98,7 @@

    PossibleExpectedMessageCollections

    PossibleExpectedMessageCollections: PossibleExpectedMessageType[]
    @@ -114,7 +114,7 @@

    PossibleExpectedMessageType

    PossibleExpectedMessageType: string | IMessage | RegExp | IEvent
    diff --git a/docs/modules/_messageservice_.html b/docs/modules/_messageservice_.html index 37b4d1d..8f87136 100644 --- a/docs/modules/_messageservice_.html +++ b/docs/modules/_messageservice_.html @@ -91,7 +91,7 @@

    botToUserMessageCheckerFunction

    botToUserMessageCheckerFunction: function
    diff --git a/package.json b/package.json index c5b2003..0104f7f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bot-tester", - "version": "3.1.0", + "version": "3.2.0", "description": "Easily test bots made with the bot builder framework", "main": "dist/index.js", "types": "dist/index.d.ts", From be8c3077b6a0d9fb2a671e8a9548a5185f160acf Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Thu, 5 Oct 2017 21:47:55 -0700 Subject: [PATCH 08/29] fixed a redundant definition that came from a recursive merge strategy --- src/config.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/config.ts b/src/config.ts index 36bd7eb..954f2d0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -7,11 +7,6 @@ import { ignoreInternalSaveMessageFilter } from './builtInMessageFilters'; */ export type MessageFilter = (message: IMessage) => boolean; -/** - * Returns true if a message - */ -export type MessageFilter = (message: IMessage) => boolean; - export interface IConfig { /** * timeout in milliseconds before a BotTester runner will fail a test (when not overriden) From af4b954f3128880c94402832d85f78e951ad4e1d Mon Sep 17 00:00:00 2001 From: Matthew Schwartz Date: Tue, 10 Oct 2017 17:33:56 -0700 Subject: [PATCH 09/29] fix spelling error with ignoreInternalSaveMessage (#38) --- README.md | 2 +- src/config.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a41e10a..acecc2f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Passing in the config overrides any default values or values set by bot-tester.j ignoreTypingEvent: boolean, ignoreEndOfConversationEvent: boolean, // Setting this to true will cause checkSession to hang and test to fail. - ignoreInternalSveMessage?: boolean; + ignoreInternalSaveMessage?: boolean; } ``` diff --git a/src/config.ts b/src/config.ts index 954f2d0..923317e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -31,7 +31,7 @@ export interface IConfig { * ignores the internal __save__ message. Setting this to true will cause checkSession to hang and test to fail */ // this is explicitly not added as a chained builder function to disaude consumers from using this. - ignoreInternalSveMessage?: boolean; + ignoreInternalSaveMessage?: boolean; /** * filters for messages that the BotTester framework should use @@ -63,7 +63,7 @@ if (configFileExists) { configInternal.messageFilters = []; -if (configInternal.ignoreInternalSveMessage) { +if (configInternal.ignoreInternalSaveMessage) { configInternal.messageFilters.push(ignoreInternalSaveMessageFilter); } From 96023721cc3e53f3526f903235224b8b6a8b2cda Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Tue, 10 Oct 2017 17:36:07 -0700 Subject: [PATCH 10/29] 3.2.1 --- ...ries_chaiexpectation_.chaiexpectation.html | 16 ++++---- docs/classes/_bottester_.bottester.html | 38 +++++++++---------- .../_expectedmessage_.expectedmessage.html | 14 +++---- .../_messageservice_.messageservice.html | 14 +++---- ...comparator_.outgoingmessagecomparator.html | 18 ++++----- .../_sessionservice_.sessionservice.html | 20 +++++----- .../_testconnector_.testconnector.html | 14 +++---- ..._expectedmessage_.expectedmessagetype.html | 6 +-- ...nlibraries_iexpectation_.iexpectation.html | 10 ++--- docs/interfaces/_bottester_.ibottester.html | 14 +++---- .../_bottester_.ioptionsmodifier.html | 8 ++-- docs/interfaces/_config_.iconfig.html | 12 +++--- .../_assertionlibraries_iexpectation_.html | 2 +- docs/modules/_bottester_.html | 2 +- docs/modules/_builtinmessagefilters_.html | 6 +-- docs/modules/_config_.html | 6 +-- docs/modules/_expectedmessage_.html | 4 +- docs/modules/_messageservice_.html | 2 +- package.json | 2 +- 19 files changed, 104 insertions(+), 104 deletions(-) diff --git a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html index ff334f6..55551d3 100644 --- a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html +++ b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html @@ -130,7 +130,7 @@

    constructor

  • Parameters

    @@ -155,7 +155,7 @@

    Private message

    message: string
    @@ -165,7 +165,7 @@

    Private subject

    subject: __type
    @@ -183,7 +183,7 @@

    notToBeEmpty

    Returns void

    @@ -201,7 +201,7 @@

    toBeTrue

    Returns void

    @@ -219,7 +219,7 @@

    toDeeplyInclude

    @@ -252,7 +252,7 @@

    toEqual

    Parameters

    @@ -276,7 +276,7 @@

    toInclude

    Parameters

    diff --git a/docs/classes/_bottester_.bottester.html b/docs/classes/_bottester_.bottester.html index 28a9a6f..96d0268 100644 --- a/docs/classes/_bottester_.bottester.html +++ b/docs/classes/_bottester_.bottester.html @@ -142,7 +142,7 @@

    constructor

  • Parameters

    @@ -167,7 +167,7 @@

    Private bot

    bot: UniversalBot
    @@ -177,7 +177,7 @@

    Private config

    config: IConfig
    @@ -187,7 +187,7 @@

    Private messageService

    messageService: MessageService
  • @@ -197,7 +197,7 @@

    Private sessionLoader

    sessionLoader: SessionService
    @@ -207,7 +207,7 @@

    Private testSteps

    testSteps: TestStep[]
    @@ -225,7 +225,7 @@

    addMessageFilter

    Parameters

    @@ -249,7 +249,7 @@

    checkSession

    Parameters

    @@ -275,7 +275,7 @@

    Private convertToIMessage<
  • Parameters

    @@ -299,7 +299,7 @@

    ignoreEndOfConversationEvent

    Returns BotTester

    @@ -317,7 +317,7 @@

    ignoreTypingEvent

    Returns BotTester

    @@ -335,7 +335,7 @@

    runTest

    @@ -358,7 +358,7 @@

    sendMessageToBot

    Parameters

    @@ -385,7 +385,7 @@

    sendMessageToBotAndExpectSaveWithNoRespon

    Parameters

    @@ -409,7 +409,7 @@

    sendMessageToBotIgnoringResponseOrder

    Parameters

    @@ -435,7 +435,7 @@

    Private sendMessageTo
  • @@ -476,7 +476,7 @@

    setTimeout

    Parameters

    @@ -500,7 +500,7 @@

    then

    Parameters

    @@ -524,7 +524,7 @@

    wait

    Parameters

    diff --git a/docs/classes/_expectedmessage_.expectedmessage.html b/docs/classes/_expectedmessage_.expectedmessage.html index e2bbbdf..b0e7732 100644 --- a/docs/classes/_expectedmessage_.expectedmessage.html +++ b/docs/classes/_expectedmessage_.expectedmessage.html @@ -124,7 +124,7 @@

    constructor

  • Parameters

    @@ -146,7 +146,7 @@

    Private expectedResponseexpectedResponseCollection: PossibleExpectedMessageCollections

  • @@ -168,7 +168,7 @@

    checkForMessageMatch

  • @@ -200,7 +200,7 @@

    Private checkMessageT
  • @@ -237,7 +237,7 @@

    Private checkMessageT
  • @@ -269,7 +269,7 @@

    Private deepMessageMa
  • @@ -303,7 +303,7 @@

    toString

  • Returns string

    diff --git a/docs/classes/_messageservice_.messageservice.html b/docs/classes/_messageservice_.messageservice.html index c4bb41a..890bc76 100644 --- a/docs/classes/_messageservice_.messageservice.html +++ b/docs/classes/_messageservice_.messageservice.html @@ -124,7 +124,7 @@

    constructor

  • Parameters

    @@ -149,7 +149,7 @@

    Private bot

    bot: UniversalBot
    @@ -159,7 +159,7 @@

    Private botToUserMess
    botToUserMessageChecker: botToUserMessageCheckerFunction
    @@ -169,7 +169,7 @@

    Private config

    config: IConfig
    @@ -186,7 +186,7 @@

    Private applyOutgoing
  • @@ -208,7 +208,7 @@

    sendMessageToBot

  • @@ -248,7 +248,7 @@

    Private setBotToUser<
  • diff --git a/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html b/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html index 9471a7e..cb34fda 100644 --- a/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html +++ b/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html @@ -125,7 +125,7 @@

    constructor

  • Parameters

    @@ -150,7 +150,7 @@

    Private expectedMessagesexpectedMessages: ExpectedMessage[]

  • @@ -160,7 +160,7 @@

    Private ignoreOrder

    ignoreOrder: boolean
    @@ -177,7 +177,7 @@

    compareOutgoingMessageToExpectedResponses

  • @@ -205,7 +205,7 @@

    Private compareOutgoing

    Parameters

    @@ -228,7 +228,7 @@

    Private compareOutgoing

    Parameters

    @@ -251,7 +251,7 @@

    Private dequeueNextEx
  • @@ -273,7 +273,7 @@

    expectsAdditionalMessages

  • @@ -295,7 +295,7 @@

    getTimeoutErrorMessage

  • Returns string

    diff --git a/docs/classes/_sessionservice_.sessionservice.html b/docs/classes/_sessionservice_.sessionservice.html index 3a698d3..c87076f 100644 --- a/docs/classes/_sessionservice_.sessionservice.html +++ b/docs/classes/_sessionservice_.sessionservice.html @@ -126,7 +126,7 @@

    constructor

  • Parameters

    @@ -148,7 +148,7 @@

    Private bot

    bot: UniversalBot
    @@ -158,7 +158,7 @@

    Private currentSessioncurrentSessionLoadResolver: function

  • @@ -189,7 +189,7 @@

    Private savePerformed

    savePerformed: Promise<any>
    @@ -214,7 +214,7 @@

    Private applySessionL
  • @@ -238,7 +238,7 @@

    Private applySessionS
  • @@ -263,7 +263,7 @@

    Private createSession
  • @@ -296,7 +296,7 @@

    getInternalSaveMessage

  • @@ -329,7 +329,7 @@

    getSession

  • @@ -360,7 +360,7 @@

    Private loadSession

  • diff --git a/docs/classes/_testconnector_.testconnector.html b/docs/classes/_testconnector_.testconnector.html index 33ee3ac..5dc1f68 100644 --- a/docs/classes/_testconnector_.testconnector.html +++ b/docs/classes/_testconnector_.testconnector.html @@ -122,7 +122,7 @@

    constructor

  • Returns TestConnector

    @@ -138,7 +138,7 @@

    Private newConvoCount
    newConvoCount: number
    @@ -148,7 +148,7 @@

    Private onEventHandle
    onEventHandler: function
    @@ -200,7 +200,7 @@

    Private onInvokeHandl
    onInvokeHandler: function
    @@ -265,7 +265,7 @@

    onEvent

  • Parameters

    @@ -327,7 +327,7 @@

    send

  • Parameters

    @@ -374,7 +374,7 @@

    startConversation

  • Parameters

    diff --git a/docs/enums/_expectedmessage_.expectedmessagetype.html b/docs/enums/_expectedmessage_.expectedmessagetype.html index ab10ccf..824808f 100644 --- a/docs/enums/_expectedmessage_.expectedmessagetype.html +++ b/docs/enums/_expectedmessage_.expectedmessagetype.html @@ -90,7 +90,7 @@

    IMessage

    IMessage:
    @@ -100,7 +100,7 @@

    Regex

    Regex:
    @@ -110,7 +110,7 @@

    String

    String:
    diff --git a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html index b313f42..00d570a 100644 --- a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html +++ b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html @@ -117,7 +117,7 @@

    notToBeEmpty

  • Returns void

    @@ -134,7 +134,7 @@

    toBeTrue

  • Returns void

    @@ -151,7 +151,7 @@

    toDeeplyInclude

  • Parameters

    @@ -174,7 +174,7 @@

    toEqual

  • Parameters

    @@ -197,7 +197,7 @@

    toInclude

  • Parameters

    diff --git a/docs/interfaces/_bottester_.ibottester.html b/docs/interfaces/_bottester_.ibottester.html index 4459527..f15e0e8 100644 --- a/docs/interfaces/_bottester_.ibottester.html +++ b/docs/interfaces/_bottester_.ibottester.html @@ -119,7 +119,7 @@

    checkSession

  • @@ -156,7 +156,7 @@

    runTest

  • @@ -178,7 +178,7 @@

    sendMessageToBot

  • @@ -217,7 +217,7 @@

    sendMessageToBotAndExpectSaveWithNoRespon
  • @@ -249,7 +249,7 @@

    sendMessageToBotIgnoringResponseOrder

  • @@ -281,7 +281,7 @@

    then

  • @@ -313,7 +313,7 @@

    wait

  • diff --git a/docs/interfaces/_bottester_.ioptionsmodifier.html b/docs/interfaces/_bottester_.ioptionsmodifier.html index cbf246c..b5b119e 100644 --- a/docs/interfaces/_bottester_.ioptionsmodifier.html +++ b/docs/interfaces/_bottester_.ioptionsmodifier.html @@ -116,7 +116,7 @@

    addMessageFilter

  • @@ -147,7 +147,7 @@

    ignoreEndOfConversationEvent

  • @@ -169,7 +169,7 @@

    ignoreTypingEvent

  • @@ -191,7 +191,7 @@

    setTimeout

  • diff --git a/docs/interfaces/_config_.iconfig.html b/docs/interfaces/_config_.iconfig.html index 4ba3e5e..f82a7c6 100644 --- a/docs/interfaces/_config_.iconfig.html +++ b/docs/interfaces/_config_.iconfig.html @@ -101,7 +101,7 @@

    Optional defaultAddressdefaultAddress: IAddress

    @@ -116,7 +116,7 @@

    Optional ignoreEndOf
    ignoreEndOfConversationEvent: boolean
    @@ -131,7 +131,7 @@

    Optional ignoreInternalignoreInternalSveMessage: boolean

    @@ -146,7 +146,7 @@

    Optional ignoreTypingignoreTypingEvent: boolean

    @@ -161,7 +161,7 @@

    Optional messageFiltersmessageFilters: MessageFilter[]

    @@ -176,7 +176,7 @@

    Optional timeout

    timeout: number
    diff --git a/docs/modules/_assertionlibraries_iexpectation_.html b/docs/modules/_assertionlibraries_iexpectation_.html index 08b7800..6cd42d9 100644 --- a/docs/modules/_assertionlibraries_iexpectation_.html +++ b/docs/modules/_assertionlibraries_iexpectation_.html @@ -95,7 +95,7 @@

    expect

  • diff --git a/docs/modules/_bottester_.html b/docs/modules/_bottester_.html index 9357120..47c32fb 100644 --- a/docs/modules/_bottester_.html +++ b/docs/modules/_bottester_.html @@ -98,7 +98,7 @@

    checkSessionFunction

    checkSessionFunction: function
    diff --git a/docs/modules/_builtinmessagefilters_.html b/docs/modules/_builtinmessagefilters_.html index 2466f66..84549b0 100644 --- a/docs/modules/_builtinmessagefilters_.html +++ b/docs/modules/_builtinmessagefilters_.html @@ -91,7 +91,7 @@

    ignoreEndOfConversationEventFilter

  • Parameters

    @@ -114,7 +114,7 @@

    ignoreInternalSaveMessageFilter

  • Parameters

    @@ -137,7 +137,7 @@

    ignoreTypingEventFilter

  • Parameters

    diff --git a/docs/modules/_config_.html b/docs/modules/_config_.html index d9f0d01..54f65c1 100644 --- a/docs/modules/_config_.html +++ b/docs/modules/_config_.html @@ -98,7 +98,7 @@

    MessageFilter

    MessageFilter: function
    @@ -137,7 +137,7 @@

    NO_TIMEOUT

    NO_TIMEOUT: -1 = -1
    @@ -152,7 +152,7 @@

    config

    config: IConfig = configInternal
    diff --git a/docs/modules/_expectedmessage_.html b/docs/modules/_expectedmessage_.html index 09fb72e..8de014b 100644 --- a/docs/modules/_expectedmessage_.html +++ b/docs/modules/_expectedmessage_.html @@ -98,7 +98,7 @@

    PossibleExpectedMessageCollections

    PossibleExpectedMessageCollections: PossibleExpectedMessageType[]
    @@ -114,7 +114,7 @@

    PossibleExpectedMessageType

    PossibleExpectedMessageType: string | IMessage | RegExp | IEvent
    diff --git a/docs/modules/_messageservice_.html b/docs/modules/_messageservice_.html index 8f87136..d277c89 100644 --- a/docs/modules/_messageservice_.html +++ b/docs/modules/_messageservice_.html @@ -91,7 +91,7 @@

    botToUserMessageCheckerFunction

    botToUserMessageCheckerFunction: function
    diff --git a/package.json b/package.json index 0104f7f..1ff4312 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bot-tester", - "version": "3.2.0", + "version": "3.2.1", "description": "Easily test bots made with the bot builder framework", "main": "dist/index.js", "types": "dist/index.d.ts", From 5b1b84f25aa402599d7380a59dac2179d1ef7bd7 Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Tue, 10 Oct 2017 18:40:42 -0700 Subject: [PATCH 11/29] remove typescript notation from docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index acecc2f..76c670a 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Passing in the config overrides any default values or values set by bot-tester.j ignoreTypingEvent: boolean, ignoreEndOfConversationEvent: boolean, // Setting this to true will cause checkSession to hang and test to fail. - ignoreInternalSaveMessage?: boolean; + ignoreInternalSaveMessage: boolean; } ``` From 08c78d292fbc0d8277c6a8723e2b0ae1b9bc4eee Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Tue, 10 Oct 2017 18:42:39 -0700 Subject: [PATCH 12/29] forcibly remove docs folder when building typeDocs --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1ff4312..2a3ad24 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "cleanBuild": "npm run clean && npm run build", "watch": "tsc -w", "test": "node_modules/mocha/bin/_mocha --require node_modules/ts-node/register test/*.spec.ts", - "buildTypeDocs": "yarn cleanBuild && typedoc --excludeNotExported --out docs --hideGenerator src/BotTester.ts --module commonjs --gaID UA-105358964-1 --readme none && touch docs/.nojekyll", + "buildTypeDocs": "yarn cleanBuild && rm -rf docs && typedoc --excludeNotExported --out docs --hideGenerator src/BotTester.ts --module commonjs --gaID UA-105358964-1 --readme none && touch docs/.nojekyll", "ci": "npm run lint && npm run test", "coverage": "npm run coverageTests && nyc report --reporter=text-lcov | node_modules/.bin/coveralls", "coverageTests": "nyc node_modules/.bin/_mocha --require source-map-support/register test/**/*.spec.ts" From 7f0a476eae2fa026f568936074d30817ee5a9990 Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Tue, 10 Oct 2017 18:45:05 -0700 Subject: [PATCH 13/29] 3.2.2 --- ...ries_chaiexpectation_.chaiexpectation.html | 16 ++++---- docs/classes/_bottester_.bottester.html | 38 +++++++++---------- .../_expectedmessage_.expectedmessage.html | 14 +++---- .../_messageservice_.messageservice.html | 14 +++---- ...comparator_.outgoingmessagecomparator.html | 18 ++++----- .../_sessionservice_.sessionservice.html | 20 +++++----- .../_testconnector_.testconnector.html | 14 +++---- ..._expectedmessage_.expectedmessagetype.html | 6 +-- ...nlibraries_iexpectation_.iexpectation.html | 10 ++--- docs/interfaces/_bottester_.ibottester.html | 14 +++---- .../_bottester_.ioptionsmodifier.html | 8 ++-- docs/interfaces/_config_.iconfig.html | 22 +++++------ .../_assertionlibraries_iexpectation_.html | 2 +- docs/modules/_bottester_.html | 2 +- docs/modules/_builtinmessagefilters_.html | 6 +-- docs/modules/_config_.html | 6 +-- docs/modules/_expectedmessage_.html | 4 +- docs/modules/_messageservice_.html | 2 +- package.json | 2 +- 19 files changed, 109 insertions(+), 109 deletions(-) diff --git a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html index 55551d3..0693f98 100644 --- a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html +++ b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html @@ -130,7 +130,7 @@

    constructor

  • Parameters

    @@ -155,7 +155,7 @@

    Private message

    message: string
    @@ -165,7 +165,7 @@

    Private subject

    subject: __type
    @@ -183,7 +183,7 @@

    notToBeEmpty

    Returns void

    @@ -201,7 +201,7 @@

    toBeTrue

    Returns void

    @@ -219,7 +219,7 @@

    toDeeplyInclude

    @@ -252,7 +252,7 @@

    toEqual

    Parameters

    @@ -276,7 +276,7 @@

    toInclude

    Parameters

    diff --git a/docs/classes/_bottester_.bottester.html b/docs/classes/_bottester_.bottester.html index 96d0268..1059bed 100644 --- a/docs/classes/_bottester_.bottester.html +++ b/docs/classes/_bottester_.bottester.html @@ -142,7 +142,7 @@

    constructor

  • Parameters

    @@ -167,7 +167,7 @@

    Private bot

    bot: UniversalBot
    @@ -177,7 +177,7 @@

    Private config

    config: IConfig
    @@ -187,7 +187,7 @@

    Private messageService

    messageService: MessageService
  • @@ -197,7 +197,7 @@

    Private sessionLoader

    sessionLoader: SessionService
    @@ -207,7 +207,7 @@

    Private testSteps

    testSteps: TestStep[]
    @@ -225,7 +225,7 @@

    addMessageFilter

    Parameters

    @@ -249,7 +249,7 @@

    checkSession

    Parameters

    @@ -275,7 +275,7 @@

    Private convertToIMessage<
  • Parameters

    @@ -299,7 +299,7 @@

    ignoreEndOfConversationEvent

    Returns BotTester

    @@ -317,7 +317,7 @@

    ignoreTypingEvent

    Returns BotTester

    @@ -335,7 +335,7 @@

    runTest

    @@ -358,7 +358,7 @@

    sendMessageToBot

    Parameters

    @@ -385,7 +385,7 @@

    sendMessageToBotAndExpectSaveWithNoRespon

    Parameters

    @@ -409,7 +409,7 @@

    sendMessageToBotIgnoringResponseOrder

    Parameters

    @@ -435,7 +435,7 @@

    Private sendMessageTo
  • @@ -476,7 +476,7 @@

    setTimeout

    Parameters

    @@ -500,7 +500,7 @@

    then

    Parameters

    @@ -524,7 +524,7 @@

    wait

    Parameters

    diff --git a/docs/classes/_expectedmessage_.expectedmessage.html b/docs/classes/_expectedmessage_.expectedmessage.html index b0e7732..def33d3 100644 --- a/docs/classes/_expectedmessage_.expectedmessage.html +++ b/docs/classes/_expectedmessage_.expectedmessage.html @@ -124,7 +124,7 @@

    constructor

  • Parameters

    @@ -146,7 +146,7 @@

    Private expectedResponseexpectedResponseCollection: PossibleExpectedMessageCollections

  • @@ -168,7 +168,7 @@

    checkForMessageMatch

  • @@ -200,7 +200,7 @@

    Private checkMessageT
  • @@ -237,7 +237,7 @@

    Private checkMessageT
  • @@ -269,7 +269,7 @@

    Private deepMessageMa
  • @@ -303,7 +303,7 @@

    toString

  • Returns string

    diff --git a/docs/classes/_messageservice_.messageservice.html b/docs/classes/_messageservice_.messageservice.html index 890bc76..d5b35e8 100644 --- a/docs/classes/_messageservice_.messageservice.html +++ b/docs/classes/_messageservice_.messageservice.html @@ -124,7 +124,7 @@

    constructor

  • Parameters

    @@ -149,7 +149,7 @@

    Private bot

    bot: UniversalBot
    @@ -159,7 +159,7 @@

    Private botToUserMess
    botToUserMessageChecker: botToUserMessageCheckerFunction
    @@ -169,7 +169,7 @@

    Private config

    config: IConfig
    @@ -186,7 +186,7 @@

    Private applyOutgoing
  • @@ -208,7 +208,7 @@

    sendMessageToBot

  • @@ -248,7 +248,7 @@

    Private setBotToUser<
  • diff --git a/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html b/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html index cb34fda..1695f92 100644 --- a/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html +++ b/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html @@ -125,7 +125,7 @@

    constructor

  • Parameters

    @@ -150,7 +150,7 @@

    Private expectedMessagesexpectedMessages: ExpectedMessage[]

  • @@ -160,7 +160,7 @@

    Private ignoreOrder

    ignoreOrder: boolean
    @@ -177,7 +177,7 @@

    compareOutgoingMessageToExpectedResponses

  • @@ -205,7 +205,7 @@

    Private compareOutgoing

    Parameters

    @@ -228,7 +228,7 @@

    Private compareOutgoing

    Parameters

    @@ -251,7 +251,7 @@

    Private dequeueNextEx
  • @@ -273,7 +273,7 @@

    expectsAdditionalMessages

  • @@ -295,7 +295,7 @@

    getTimeoutErrorMessage

  • Returns string

    diff --git a/docs/classes/_sessionservice_.sessionservice.html b/docs/classes/_sessionservice_.sessionservice.html index c87076f..fced763 100644 --- a/docs/classes/_sessionservice_.sessionservice.html +++ b/docs/classes/_sessionservice_.sessionservice.html @@ -126,7 +126,7 @@

    constructor

  • Parameters

    @@ -148,7 +148,7 @@

    Private bot

    bot: UniversalBot
    @@ -158,7 +158,7 @@

    Private currentSessioncurrentSessionLoadResolver: function

  • @@ -189,7 +189,7 @@

    Private savePerformed

    savePerformed: Promise<any>
    @@ -214,7 +214,7 @@

    Private applySessionL
  • @@ -238,7 +238,7 @@

    Private applySessionS
  • @@ -263,7 +263,7 @@

    Private createSession
  • @@ -296,7 +296,7 @@

    getInternalSaveMessage

  • @@ -329,7 +329,7 @@

    getSession

  • @@ -360,7 +360,7 @@

    Private loadSession

  • diff --git a/docs/classes/_testconnector_.testconnector.html b/docs/classes/_testconnector_.testconnector.html index 5dc1f68..e251080 100644 --- a/docs/classes/_testconnector_.testconnector.html +++ b/docs/classes/_testconnector_.testconnector.html @@ -122,7 +122,7 @@

    constructor

  • Returns TestConnector

    @@ -138,7 +138,7 @@

    Private newConvoCount
    newConvoCount: number
    @@ -148,7 +148,7 @@

    Private onEventHandle
    onEventHandler: function
    @@ -200,7 +200,7 @@

    Private onInvokeHandl
    onInvokeHandler: function
    @@ -265,7 +265,7 @@

    onEvent

  • Parameters

    @@ -327,7 +327,7 @@

    send

  • Parameters

    @@ -374,7 +374,7 @@

    startConversation

  • Parameters

    diff --git a/docs/enums/_expectedmessage_.expectedmessagetype.html b/docs/enums/_expectedmessage_.expectedmessagetype.html index 824808f..d1c5519 100644 --- a/docs/enums/_expectedmessage_.expectedmessagetype.html +++ b/docs/enums/_expectedmessage_.expectedmessagetype.html @@ -90,7 +90,7 @@

    IMessage

    IMessage:
    @@ -100,7 +100,7 @@

    Regex

    Regex:
    @@ -110,7 +110,7 @@

    String

    String:
    diff --git a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html index 00d570a..99d2432 100644 --- a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html +++ b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html @@ -117,7 +117,7 @@

    notToBeEmpty

  • Returns void

    @@ -134,7 +134,7 @@

    toBeTrue

  • Returns void

    @@ -151,7 +151,7 @@

    toDeeplyInclude

  • Parameters

    @@ -174,7 +174,7 @@

    toEqual

  • Parameters

    @@ -197,7 +197,7 @@

    toInclude

  • Parameters

    diff --git a/docs/interfaces/_bottester_.ibottester.html b/docs/interfaces/_bottester_.ibottester.html index f15e0e8..fcbf781 100644 --- a/docs/interfaces/_bottester_.ibottester.html +++ b/docs/interfaces/_bottester_.ibottester.html @@ -119,7 +119,7 @@

    checkSession

  • @@ -156,7 +156,7 @@

    runTest

  • @@ -178,7 +178,7 @@

    sendMessageToBot

  • @@ -217,7 +217,7 @@

    sendMessageToBotAndExpectSaveWithNoRespon
  • @@ -249,7 +249,7 @@

    sendMessageToBotIgnoringResponseOrder

  • @@ -281,7 +281,7 @@

    then

  • @@ -313,7 +313,7 @@

    wait

  • diff --git a/docs/interfaces/_bottester_.ioptionsmodifier.html b/docs/interfaces/_bottester_.ioptionsmodifier.html index b5b119e..e920cd5 100644 --- a/docs/interfaces/_bottester_.ioptionsmodifier.html +++ b/docs/interfaces/_bottester_.ioptionsmodifier.html @@ -116,7 +116,7 @@

    addMessageFilter

  • @@ -147,7 +147,7 @@

    ignoreEndOfConversationEvent

  • @@ -169,7 +169,7 @@

    ignoreTypingEvent

  • @@ -191,7 +191,7 @@

    setTimeout

  • diff --git a/docs/interfaces/_config_.iconfig.html b/docs/interfaces/_config_.iconfig.html index f82a7c6..b7d7fb0 100644 --- a/docs/interfaces/_config_.iconfig.html +++ b/docs/interfaces/_config_.iconfig.html @@ -84,7 +84,7 @@

    Properties

    @@ -116,7 +116,7 @@

    Optional ignoreEndOf
    ignoreEndOfConversationEvent: boolean
    @@ -126,12 +126,12 @@

    Optional ignoreEndOf

    - -

    Optional ignoreInternalSveMessage

    -
    ignoreInternalSveMessage: boolean
    + +

    Optional ignoreInternalSaveMessage

    +
    ignoreInternalSaveMessage: boolean
    @@ -146,7 +146,7 @@

    Optional ignoreTypingignoreTypingEvent: boolean

    @@ -161,7 +161,7 @@

    Optional messageFiltersmessageFilters: MessageFilter[]

    @@ -176,7 +176,7 @@

    Optional timeout

    timeout: number
    @@ -248,7 +248,7 @@

    Optional timeout

    ignoreEndOfConversationEvent

  • - ignoreInternalSveMessage + ignoreInternalSaveMessage
  • ignoreTypingEvent diff --git a/docs/modules/_assertionlibraries_iexpectation_.html b/docs/modules/_assertionlibraries_iexpectation_.html index 6cd42d9..f91faed 100644 --- a/docs/modules/_assertionlibraries_iexpectation_.html +++ b/docs/modules/_assertionlibraries_iexpectation_.html @@ -95,7 +95,7 @@

    expect

  • diff --git a/docs/modules/_bottester_.html b/docs/modules/_bottester_.html index 47c32fb..3618309 100644 --- a/docs/modules/_bottester_.html +++ b/docs/modules/_bottester_.html @@ -98,7 +98,7 @@

    checkSessionFunction

    checkSessionFunction: function
    diff --git a/docs/modules/_builtinmessagefilters_.html b/docs/modules/_builtinmessagefilters_.html index 84549b0..c0ba873 100644 --- a/docs/modules/_builtinmessagefilters_.html +++ b/docs/modules/_builtinmessagefilters_.html @@ -91,7 +91,7 @@

    ignoreEndOfConversationEventFilter

  • Parameters

    @@ -114,7 +114,7 @@

    ignoreInternalSaveMessageFilter

  • Parameters

    @@ -137,7 +137,7 @@

    ignoreTypingEventFilter

  • Parameters

    diff --git a/docs/modules/_config_.html b/docs/modules/_config_.html index 54f65c1..8fb9837 100644 --- a/docs/modules/_config_.html +++ b/docs/modules/_config_.html @@ -98,7 +98,7 @@

    MessageFilter

    MessageFilter: function
    @@ -137,7 +137,7 @@

    NO_TIMEOUT

    NO_TIMEOUT: -1 = -1
    @@ -152,7 +152,7 @@

    config

    config: IConfig = configInternal
    diff --git a/docs/modules/_expectedmessage_.html b/docs/modules/_expectedmessage_.html index 8de014b..f75cf18 100644 --- a/docs/modules/_expectedmessage_.html +++ b/docs/modules/_expectedmessage_.html @@ -98,7 +98,7 @@

    PossibleExpectedMessageCollections

    PossibleExpectedMessageCollections: PossibleExpectedMessageType[]
    @@ -114,7 +114,7 @@

    PossibleExpectedMessageType

    PossibleExpectedMessageType: string | IMessage | RegExp | IEvent
    diff --git a/docs/modules/_messageservice_.html b/docs/modules/_messageservice_.html index d277c89..9637c51 100644 --- a/docs/modules/_messageservice_.html +++ b/docs/modules/_messageservice_.html @@ -91,7 +91,7 @@

    botToUserMessageCheckerFunction

    botToUserMessageCheckerFunction: function
    diff --git a/package.json b/package.json index 2a3ad24..08274fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bot-tester", - "version": "3.2.1", + "version": "3.2.2", "description": "Easily test bots made with the bot builder framework", "main": "dist/index.js", "types": "dist/index.d.ts", From e1be08ff20e1f89bc9cd4007c1faa9f011659428 Mon Sep 17 00:00:00 2001 From: Matthew Schwartz Date: Wed, 6 Dec 2017 18:18:45 -0800 Subject: [PATCH 14/29] add adaptive cards (and attachment) support (#44) * add adaptiveCardProvider * add adaptivecards package * add adaptive cards implementation * add adaptive cards tests * update docs * include ts-node require * update node version * update mocha version * add yarn to circle config --- README.md | 14 +++++++ circle.yml | 11 ++++- package.json | 7 ++-- src/assertionLibraries/ChaiExpectation.ts | 50 ++++++++++++++++++++--- test/BotTester.spec.ts | 36 ++++++++++++++++ test/BotTesterFailure.spec.ts | 31 ++++++++++++++ test/adaptiveCardProvider.ts | 47 +++++++++++++++++++++ yarn.lock | 10 +++-- 8 files changed, 193 insertions(+), 13 deletions(-) create mode 100644 test/adaptiveCardProvider.ts diff --git a/README.md b/README.md index 76c670a..55a3860 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ For a more in depth view, check out [the Bot Tester Framework Config doc](https: import { IAddress, IMessage, Message, Prompts, Session, UniversalBot } from 'botbuilder'; import { expect } from 'chai'; import { BotTester, TestConnector } from 'bot-tester'; +import { getAdaptiveCard, getAdaptiveCardAttachment, getAdaptiveCardMessage } from './adaptiveCardProvider'; const connector = new TestConnector(); @@ -113,6 +114,19 @@ describe('BotTester', () => { }); ``` +# Test Adaptive Cards +``` javascript + it('can correctly check against adaptive cards', () => { + bot.dialog('/', (session) => { + session.send(getAdaptiveCardMessage()); + }); + + return new BotTester(bot) + .sendMessageToBot('anything', getAdaptiveCardMessage()) + .runTest(); + }); +``` + # Inspect session ```javascript it('can inspect session state', () => { diff --git a/circle.yml b/circle.yml index bf43b1c..2b6bd96 100644 --- a/circle.yml +++ b/circle.yml @@ -1,7 +1,16 @@ machine: node: - version: 6.1.0 + version: 8.0.0 + environment: + PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin" +dependencies: + override: + - yarn + cache_directories: + - ~/.cache/yarn + test: override: - yarn lint && yarn coverage + diff --git a/package.json b/package.json index 08274fa..f821380 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "buildTypeDocs": "yarn cleanBuild && rm -rf docs && typedoc --excludeNotExported --out docs --hideGenerator src/BotTester.ts --module commonjs --gaID UA-105358964-1 --readme none && touch docs/.nojekyll", "ci": "npm run lint && npm run test", "coverage": "npm run coverageTests && nyc report --reporter=text-lcov | node_modules/.bin/coveralls", - "coverageTests": "nyc node_modules/.bin/_mocha --require source-map-support/register test/**/*.spec.ts" + "coverageTests": "nyc node_modules/.bin/_mocha --require source-map-support/register --require node_modules/ts-node/register test/**/*.spec.ts" }, "nyc": { "extension": [ @@ -74,8 +74,9 @@ "@types/chai": "^4.0.1", "@types/chai-as-promised": "^0.0.31", "@types/chai-subset": "^1.3.1", - "@types/mocha": "^2.2.41", + "@types/mocha": "^2.2.44", "@types/node": "^8.0.26", + "adaptivecards": "^1.0.0-beta9", "chai-as-promised": "^7.1.1", "coveralls": "^2.13.1", "istanbul": "^0.4.5", @@ -83,8 +84,8 @@ "nyc": "^11.2.1", "source-map-support": "^0.4.17", "ts-node": "^3.1.0", - "typedoc": "^0.8.0", "tslint": "^5.7.0", + "typedoc": "^0.8.0", "typescript": "^2.4.1" }, "files": [ diff --git a/src/assertionLibraries/ChaiExpectation.ts b/src/assertionLibraries/ChaiExpectation.ts index 98bb635..646a144 100644 --- a/src/assertionLibraries/ChaiExpectation.ts +++ b/src/assertionLibraries/ChaiExpectation.ts @@ -1,4 +1,4 @@ -import { IMessage } from 'botbuilder'; +import { IAttachment, IMessage } from 'botbuilder'; import * as chai from 'chai'; import { IExpectation } from './IExpectation'; @@ -72,20 +72,32 @@ export class ChaiExpectation implements IExpectation { return; } - const clone = Object.assign({}, outgoingMessage); + const outgoingMessageClone = Object.assign({}, outgoingMessage); + const expectedResponseClone = Object.assign({}, expectedResponse); + + // attachments are compared separately + const outgoingMessageAttachments = outgoingMessageClone.attachments || []; + const expectedResponseAttachments = expectedResponseClone.attachments || []; + + outgoingMessageClone.attachments = []; + expectedResponseClone.attachments = []; // ignore source event (not added to message until after sending) - delete expectedResponse.source; + delete expectedResponseClone.source; // auto added by prompts, not needed - delete outgoingMessage.inputHint; + delete outgoingMessageClone.inputHint; // always botbuilder - delete expectedResponse.agent; + delete expectedResponseClone.agent; try { - expect(clone).to.containSubset(expectedResponse); + expect(outgoingMessageClone).to.containSubset(expectedResponseClone); matchExists = true; + + if (matchExists && expectedResponseAttachments.length) { + matchExists = this.checkForMatchingAttachments(outgoingMessageAttachments, expectedResponseAttachments); + } } catch (e) { // continue, no match found } @@ -96,4 +108,30 @@ export class ChaiExpectation implements IExpectation { to be a subset of one of ${JSON.stringify(expectedResponseCollectionAsIMessage, null, 2)}`); } } + + private checkForMatchingAttachments(outgoingAttachments: IAttachment[], expectedAttachments: IAttachment[]): boolean { + let matchExists: boolean = false; + + outgoingAttachments.forEach((outgoingAttachment: IAttachment) => { + if (matchExists) { + return; + } + + expectedAttachments.forEach((expectedAttachment: IAttachment) => { + if (matchExists) { + return; + } + + try { + expect(outgoingAttachment).to.containSubset(expectedAttachment); + + matchExists = true; + } catch (e) { + // continue + } + }); + }); + + return matchExists; + } } diff --git a/test/BotTester.spec.ts b/test/BotTester.spec.ts index ef9cb55..4f8285b 100644 --- a/test/BotTester.spec.ts +++ b/test/BotTester.spec.ts @@ -4,6 +4,7 @@ import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import { BotTester } from './../src/BotTester'; import { TestConnector } from './../src/TestConnector'; +import { getAdaptiveCard, getAdaptiveCardAttachment, getAdaptiveCardMessage } from './adaptiveCardProvider'; chai.use(chaiAsPromised); const expect = chai.expect; @@ -85,6 +86,19 @@ describe('BotTester', () => { }); //``` +//# Test Adaptive Cards +//``` javascript + it('can correctly check against adaptive cards', () => { + bot.dialog('/', (session) => { + session.send(getAdaptiveCardMessage()); + }); + + return new BotTester(bot) + .sendMessageToBot('anything', getAdaptiveCardMessage()) + .runTest(); + }); +//``` + //# Inspect session //```javascript it('can inspect session state', () => { @@ -416,5 +430,27 @@ describe('BotTester', () => { .sendMessageToBot('this could be anything!', 'hello') .runTest(); }); + + it('can ensure adaptive cards are present, regardless of order', () => { + bot.dialog('/', (session: Session) => { + session.send(getAdaptiveCardMessage()); + }); + + const matchingCard = getAdaptiveCard(); + const nonMatchingCard = getAdaptiveCard(); + + nonMatchingCard.actions = [{title: 'this is not the correct title', type: 'this is no the correct type'}]; + + const message1 = getAdaptiveCardMessage(nonMatchingCard); + const message2 = getAdaptiveCardMessage(matchingCard); + + message1.attachments.push(getAdaptiveCardAttachment(matchingCard)); + message2.attachments.push(getAdaptiveCardAttachment(nonMatchingCard)); + + return new BotTester(bot) + .sendMessageToBot('anything', message1) + .sendMessageToBot('anything', message2) + .runTest(); + }); }); }); diff --git a/test/BotTesterFailure.spec.ts b/test/BotTesterFailure.spec.ts index 37dcbd4..0f3f10a 100644 --- a/test/BotTesterFailure.spec.ts +++ b/test/BotTesterFailure.spec.ts @@ -3,6 +3,7 @@ import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import { BotTester } from './../src/BotTester'; import { TestConnector } from './../src/TestConnector'; +import { getAdaptiveCard, getAdaptiveCardAttachment, getAdaptiveCardMessage } from './adaptiveCardProvider'; chai.use(chaiAsPromised); @@ -253,4 +254,34 @@ describe('BotTester', () => { .runTest()) .to.be.rejected.notify(done); }); + + it('will fail when there are no matching adaptive cards', (done: Function) => { + bot.dialog('/', (session: Session) => { + session.send(getAdaptiveCardMessage()); + }); + + const card = getAdaptiveCard(); + + card.actions = [{title: 'this is not the correct title', type: 'this is no the correct type'}]; + + const message = getAdaptiveCardMessage(card); + + expect(new BotTester(bot) + .sendMessageToBot('anything', message) + .runTest()).to.be.rejected.notify(done); + }); + + it('will fail when there are no attachments when they are expected', (done: Function) => { + bot.dialog('/', (session: Session) => { + session.send('hello'); + }); + + const expectedMessage = getAdaptiveCardMessage(); + + expectedMessage.text = 'hello'; + + expect(new BotTester(bot) + .sendMessageToBot('anything', expectedMessage) + .runTest()).to.be.rejected.notify(done); + }); }); diff --git a/test/adaptiveCardProvider.ts b/test/adaptiveCardProvider.ts new file mode 100644 index 0000000..da5b4b5 --- /dev/null +++ b/test/adaptiveCardProvider.ts @@ -0,0 +1,47 @@ +import { IAdaptiveCard } from 'adaptivecards'; +import { IAttachment, IMessage, Message} from 'botbuilder'; + +export function getAdaptiveCard() : IAdaptiveCard { + const action = { + type: 'Action.OpenUrl', + url: 'http://adaptivecards.io', + title: 'Learn More' + }; + + return { + type: 'AdaptiveCard', + version: '1.0', + body: [ + { + type: 'TextBlock', + text: 'Hello World!', + size: 'large' + }, + { + type: 'TextBlock', + text: '*Sincerely yours,*' + }, + { + type: 'TextBlock', + text: 'Adaptive Cards', + separation: 'none' + } + ], + actions: [ action ] + }; +} + +export function getAdaptiveCardAttachment(adaptiveCard?: IAdaptiveCard): IAttachment { + adaptiveCard = adaptiveCard || getAdaptiveCard(); + + return { + contentType: 'application/vnd.microsoft.card.adaptive', + content: adaptiveCard + }; +} + +export function getAdaptiveCardMessage(adaptiveCard?: IAdaptiveCard): IMessage { + return new Message() + .addAttachment(getAdaptiveCardAttachment(adaptiveCard)) + .toMessage(); +} diff --git a/yarn.lock b/yarn.lock index 93452bb..2ecc5a4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -63,9 +63,9 @@ version "2.0.29" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-2.0.29.tgz#5002e14f75e2d71e564281df0431c8c1b4a2a36a" -"@types/mocha@^2.2.41": - version "2.2.42" - resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.42.tgz#ab769f51d37646b6fe8d4a086a98c285b1fab3f5" +"@types/mocha@^2.2.44": + version "2.2.44" + resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.44.tgz#1d4a798e53f35212fd5ad4d04050620171cd5b5e" "@types/node@*", "@types/node@^8.0.26": version "8.0.27" @@ -86,6 +86,10 @@ abbrev@1.0.x: version "1.0.9" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135" +adaptivecards@^1.0.0-beta9: + version "1.0.0-beta9" + resolved "https://registry.yarnpkg.com/adaptivecards/-/adaptivecards-1.0.0-beta9.tgz#bc22f61978c58666c8e862c9ad5b4b43b0b61fa8" + ajv@^4.9.1: version "4.11.8" resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.8.tgz#82ffb02b29e662ae53bdc20af15947706739c536" From 60e637cf1c437d3680e6929f1ef9b4228909bfba Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Wed, 6 Dec 2017 18:25:02 -0800 Subject: [PATCH 15/29] v3.3.0 --- ...ries_chaiexpectation_.chaiexpectation.html | 46 +++++++++++++++---- docs/classes/_bottester_.bottester.html | 38 +++++++-------- .../_expectedmessage_.expectedmessage.html | 14 +++--- .../_messageservice_.messageservice.html | 14 +++--- ...comparator_.outgoingmessagecomparator.html | 18 ++++---- .../_sessionservice_.sessionservice.html | 20 ++++---- .../_testconnector_.testconnector.html | 14 +++--- ..._expectedmessage_.expectedmessagetype.html | 6 +-- ...nlibraries_iexpectation_.iexpectation.html | 10 ++-- docs/interfaces/_bottester_.ibottester.html | 14 +++--- .../_bottester_.ioptionsmodifier.html | 8 ++-- docs/interfaces/_config_.iconfig.html | 12 ++--- .../_assertionlibraries_iexpectation_.html | 2 +- docs/modules/_bottester_.html | 2 +- docs/modules/_builtinmessagefilters_.html | 6 +-- docs/modules/_config_.html | 6 +-- docs/modules/_expectedmessage_.html | 4 +- docs/modules/_messageservice_.html | 2 +- package.json | 2 +- 19 files changed, 134 insertions(+), 104 deletions(-) diff --git a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html index 0693f98..98c4f25 100644 --- a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html +++ b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html @@ -108,6 +108,7 @@

    Properties

    Methods

    @@ -165,13 +166,39 @@

    Private subject

    subject: __type

    Methods

    +
    + +

    Private checkForMatchingAttachments

    +
      +
    • checkForMatchingAttachments(outgoingAttachments: IAttachment[], expectedAttachments: IAttachment[]): boolean
    • +
    + +

    notToBeEmpty

    @@ -183,7 +210,7 @@

    notToBeEmpty

    Returns void

    @@ -201,7 +228,7 @@

    toBeTrue

    Returns void

    @@ -219,7 +246,7 @@

    toDeeplyInclude

    @@ -252,7 +279,7 @@

    toEqual

    Parameters

    @@ -276,7 +303,7 @@

    toInclude

    Parameters

    @@ -354,6 +381,9 @@

    Returns void subject

  • +
  • + checkForMatchingAttachments +
  • notToBeEmpty
  • diff --git a/docs/classes/_bottester_.bottester.html b/docs/classes/_bottester_.bottester.html index 1059bed..7f529fd 100644 --- a/docs/classes/_bottester_.bottester.html +++ b/docs/classes/_bottester_.bottester.html @@ -142,7 +142,7 @@

    constructor

  • Parameters

    @@ -167,7 +167,7 @@

    Private bot

    bot: UniversalBot
    @@ -177,7 +177,7 @@

    Private config

    config: IConfig
    @@ -187,7 +187,7 @@

    Private messageService

    messageService: MessageService
  • @@ -197,7 +197,7 @@

    Private sessionLoader

    sessionLoader: SessionService
    @@ -207,7 +207,7 @@

    Private testSteps

    testSteps: TestStep[]
    @@ -225,7 +225,7 @@

    addMessageFilter

    Parameters

    @@ -249,7 +249,7 @@

    checkSession

    Parameters

    @@ -275,7 +275,7 @@

    Private convertToIMessage<
  • Parameters

    @@ -299,7 +299,7 @@

    ignoreEndOfConversationEvent

    Returns BotTester

    @@ -317,7 +317,7 @@

    ignoreTypingEvent

    Returns BotTester

    @@ -335,7 +335,7 @@

    runTest

    @@ -358,7 +358,7 @@

    sendMessageToBot

    Parameters

    @@ -385,7 +385,7 @@

    sendMessageToBotAndExpectSaveWithNoRespon

    Parameters

    @@ -409,7 +409,7 @@

    sendMessageToBotIgnoringResponseOrder

    Parameters

    @@ -435,7 +435,7 @@

    Private sendMessageTo
  • @@ -476,7 +476,7 @@

    setTimeout

    Parameters

    @@ -500,7 +500,7 @@

    then

    Parameters

    @@ -524,7 +524,7 @@

    wait

    Parameters

    diff --git a/docs/classes/_expectedmessage_.expectedmessage.html b/docs/classes/_expectedmessage_.expectedmessage.html index def33d3..94c8359 100644 --- a/docs/classes/_expectedmessage_.expectedmessage.html +++ b/docs/classes/_expectedmessage_.expectedmessage.html @@ -124,7 +124,7 @@

    constructor

  • Parameters

    @@ -146,7 +146,7 @@

    Private expectedResponseexpectedResponseCollection: PossibleExpectedMessageCollections

  • @@ -168,7 +168,7 @@

    checkForMessageMatch

  • @@ -200,7 +200,7 @@

    Private checkMessageT
  • @@ -237,7 +237,7 @@

    Private checkMessageT
  • @@ -269,7 +269,7 @@

    Private deepMessageMa
  • @@ -303,7 +303,7 @@

    toString

  • Returns string

    diff --git a/docs/classes/_messageservice_.messageservice.html b/docs/classes/_messageservice_.messageservice.html index d5b35e8..1ce7784 100644 --- a/docs/classes/_messageservice_.messageservice.html +++ b/docs/classes/_messageservice_.messageservice.html @@ -124,7 +124,7 @@

    constructor

  • Parameters

    @@ -149,7 +149,7 @@

    Private bot

    bot: UniversalBot
    @@ -159,7 +159,7 @@

    Private botToUserMess
    botToUserMessageChecker: botToUserMessageCheckerFunction
    @@ -169,7 +169,7 @@

    Private config

    config: IConfig
    @@ -186,7 +186,7 @@

    Private applyOutgoing
  • @@ -208,7 +208,7 @@

    sendMessageToBot

  • @@ -248,7 +248,7 @@

    Private setBotToUser<
  • diff --git a/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html b/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html index 1695f92..486ff23 100644 --- a/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html +++ b/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html @@ -125,7 +125,7 @@

    constructor

  • Parameters

    @@ -150,7 +150,7 @@

    Private expectedMessagesexpectedMessages: ExpectedMessage[]

  • @@ -160,7 +160,7 @@

    Private ignoreOrder

    ignoreOrder: boolean
    @@ -177,7 +177,7 @@

    compareOutgoingMessageToExpectedResponses

  • @@ -205,7 +205,7 @@

    Private compareOutgoing

    Parameters

    @@ -228,7 +228,7 @@

    Private compareOutgoing

    Parameters

    @@ -251,7 +251,7 @@

    Private dequeueNextEx
  • @@ -273,7 +273,7 @@

    expectsAdditionalMessages

  • @@ -295,7 +295,7 @@

    getTimeoutErrorMessage

  • Returns string

    diff --git a/docs/classes/_sessionservice_.sessionservice.html b/docs/classes/_sessionservice_.sessionservice.html index fced763..aed1430 100644 --- a/docs/classes/_sessionservice_.sessionservice.html +++ b/docs/classes/_sessionservice_.sessionservice.html @@ -126,7 +126,7 @@

    constructor

  • Parameters

    @@ -148,7 +148,7 @@

    Private bot

    bot: UniversalBot
    @@ -158,7 +158,7 @@

    Private currentSessioncurrentSessionLoadResolver: function

  • @@ -189,7 +189,7 @@

    Private savePerformed

    savePerformed: Promise<any>
    @@ -214,7 +214,7 @@

    Private applySessionL
  • @@ -238,7 +238,7 @@

    Private applySessionS
  • @@ -263,7 +263,7 @@

    Private createSession
  • @@ -296,7 +296,7 @@

    getInternalSaveMessage

  • @@ -329,7 +329,7 @@

    getSession

  • @@ -360,7 +360,7 @@

    Private loadSession

  • diff --git a/docs/classes/_testconnector_.testconnector.html b/docs/classes/_testconnector_.testconnector.html index e251080..c6123c6 100644 --- a/docs/classes/_testconnector_.testconnector.html +++ b/docs/classes/_testconnector_.testconnector.html @@ -122,7 +122,7 @@

    constructor

  • Returns TestConnector

    @@ -138,7 +138,7 @@

    Private newConvoCount
    newConvoCount: number
    @@ -148,7 +148,7 @@

    Private onEventHandle
    onEventHandler: function
    @@ -200,7 +200,7 @@

    Private onInvokeHandl
    onInvokeHandler: function
    @@ -265,7 +265,7 @@

    onEvent

  • Parameters

    @@ -327,7 +327,7 @@

    send

  • Parameters

    @@ -374,7 +374,7 @@

    startConversation

  • Parameters

    diff --git a/docs/enums/_expectedmessage_.expectedmessagetype.html b/docs/enums/_expectedmessage_.expectedmessagetype.html index d1c5519..9c02a30 100644 --- a/docs/enums/_expectedmessage_.expectedmessagetype.html +++ b/docs/enums/_expectedmessage_.expectedmessagetype.html @@ -90,7 +90,7 @@

    IMessage

    IMessage:
    @@ -100,7 +100,7 @@

    Regex

    Regex:
    @@ -110,7 +110,7 @@

    String

    String:
    diff --git a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html index 99d2432..5965628 100644 --- a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html +++ b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html @@ -117,7 +117,7 @@

    notToBeEmpty

  • Returns void

    @@ -134,7 +134,7 @@

    toBeTrue

  • Returns void

    @@ -151,7 +151,7 @@

    toDeeplyInclude

  • Parameters

    @@ -174,7 +174,7 @@

    toEqual

  • Parameters

    @@ -197,7 +197,7 @@

    toInclude

  • Parameters

    diff --git a/docs/interfaces/_bottester_.ibottester.html b/docs/interfaces/_bottester_.ibottester.html index fcbf781..76c0aaa 100644 --- a/docs/interfaces/_bottester_.ibottester.html +++ b/docs/interfaces/_bottester_.ibottester.html @@ -119,7 +119,7 @@

    checkSession

  • @@ -156,7 +156,7 @@

    runTest

  • @@ -178,7 +178,7 @@

    sendMessageToBot

  • @@ -217,7 +217,7 @@

    sendMessageToBotAndExpectSaveWithNoRespon
  • @@ -249,7 +249,7 @@

    sendMessageToBotIgnoringResponseOrder

  • @@ -281,7 +281,7 @@

    then

  • @@ -313,7 +313,7 @@

    wait

  • diff --git a/docs/interfaces/_bottester_.ioptionsmodifier.html b/docs/interfaces/_bottester_.ioptionsmodifier.html index e920cd5..8948010 100644 --- a/docs/interfaces/_bottester_.ioptionsmodifier.html +++ b/docs/interfaces/_bottester_.ioptionsmodifier.html @@ -116,7 +116,7 @@

    addMessageFilter

  • @@ -147,7 +147,7 @@

    ignoreEndOfConversationEvent

  • @@ -169,7 +169,7 @@

    ignoreTypingEvent

  • @@ -191,7 +191,7 @@

    setTimeout

  • diff --git a/docs/interfaces/_config_.iconfig.html b/docs/interfaces/_config_.iconfig.html index b7d7fb0..612c59d 100644 --- a/docs/interfaces/_config_.iconfig.html +++ b/docs/interfaces/_config_.iconfig.html @@ -101,7 +101,7 @@

    Optional defaultAddressdefaultAddress: IAddress

    @@ -116,7 +116,7 @@

    Optional ignoreEndOf
    ignoreEndOfConversationEvent: boolean
    @@ -131,7 +131,7 @@

    Optional ignoreInternalignoreInternalSaveMessage: boolean

    @@ -146,7 +146,7 @@

    Optional ignoreTypingignoreTypingEvent: boolean

    @@ -161,7 +161,7 @@

    Optional messageFiltersmessageFilters: MessageFilter[]

    @@ -176,7 +176,7 @@

    Optional timeout

    timeout: number
    diff --git a/docs/modules/_assertionlibraries_iexpectation_.html b/docs/modules/_assertionlibraries_iexpectation_.html index f91faed..c8e1bc1 100644 --- a/docs/modules/_assertionlibraries_iexpectation_.html +++ b/docs/modules/_assertionlibraries_iexpectation_.html @@ -95,7 +95,7 @@

    expect

  • diff --git a/docs/modules/_bottester_.html b/docs/modules/_bottester_.html index 3618309..63fb812 100644 --- a/docs/modules/_bottester_.html +++ b/docs/modules/_bottester_.html @@ -98,7 +98,7 @@

    checkSessionFunction

    checkSessionFunction: function
    diff --git a/docs/modules/_builtinmessagefilters_.html b/docs/modules/_builtinmessagefilters_.html index c0ba873..db51cd4 100644 --- a/docs/modules/_builtinmessagefilters_.html +++ b/docs/modules/_builtinmessagefilters_.html @@ -91,7 +91,7 @@

    ignoreEndOfConversationEventFilter

  • Parameters

    @@ -114,7 +114,7 @@

    ignoreInternalSaveMessageFilter

  • Parameters

    @@ -137,7 +137,7 @@

    ignoreTypingEventFilter

  • Parameters

    diff --git a/docs/modules/_config_.html b/docs/modules/_config_.html index 8fb9837..fb09b5b 100644 --- a/docs/modules/_config_.html +++ b/docs/modules/_config_.html @@ -98,7 +98,7 @@

    MessageFilter

    MessageFilter: function
    @@ -137,7 +137,7 @@

    NO_TIMEOUT

    NO_TIMEOUT: -1 = -1
    @@ -152,7 +152,7 @@

    config

    config: IConfig = configInternal
    diff --git a/docs/modules/_expectedmessage_.html b/docs/modules/_expectedmessage_.html index f75cf18..25cc25c 100644 --- a/docs/modules/_expectedmessage_.html +++ b/docs/modules/_expectedmessage_.html @@ -98,7 +98,7 @@

    PossibleExpectedMessageCollections

    PossibleExpectedMessageCollections: PossibleExpectedMessageType[]
    @@ -114,7 +114,7 @@

    PossibleExpectedMessageType

    PossibleExpectedMessageType: string | IMessage | RegExp | IEvent
    diff --git a/docs/modules/_messageservice_.html b/docs/modules/_messageservice_.html index 9637c51..7cec6dc 100644 --- a/docs/modules/_messageservice_.html +++ b/docs/modules/_messageservice_.html @@ -91,7 +91,7 @@

    botToUserMessageCheckerFunction

    botToUserMessageCheckerFunction: function
    diff --git a/package.json b/package.json index f821380..8a03d55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bot-tester", - "version": "3.2.2", + "version": "3.3.0", "description": "Easily test bots made with the bot builder framework", "main": "dist/index.js", "types": "dist/index.d.ts", From 04f6abe1d1c90e52ed4df4e70a5bd1831b7be80b Mon Sep 17 00:00:00 2001 From: Matthew Schwartz Date: Wed, 20 Dec 2017 17:44:40 -0800 Subject: [PATCH 16/29] make config.ts export getConfig function (#49) --- src/BotTester.ts | 6 +++--- src/config.ts | 31 +++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/BotTester.ts b/src/BotTester.ts index c4207ba..d297f3b 100644 --- a/src/BotTester.ts +++ b/src/BotTester.ts @@ -1,7 +1,7 @@ import * as Promise from 'bluebird'; import { IAddress, IMessage, Message, Session, UniversalBot } from 'botbuilder'; import { ignoreEndOfConversationEventFilter, ignoreTypingEventFilter } from './builtInMessageFilters'; -import { config, IConfig, MessageFilter } from './config'; +import { getConfig, IConfig, MessageFilter } from './config'; import { ExpectedMessage, PossibleExpectedMessageCollections, PossibleExpectedMessageType } from './ExpectedMessage'; import { botToUserMessageCheckerFunction, MessageService } from './MessageService'; import { SessionService } from './SessionService'; @@ -109,8 +109,8 @@ export class BotTester implements IBotTester, IOptionsModifier { private testSteps: TestStep[]; private config: IConfig; - constructor(bot: UniversalBot, options: IConfig = config) { - this.config = Object.assign({}, config, options); + constructor(bot: UniversalBot, options?: IConfig) { + this.config = Object.assign({}, getConfig(), options); this.config.messageFilters = this.config.messageFilters.slice(); this.bot = bot; this.messageService = new MessageService(bot, this.config); diff --git a/src/config.ts b/src/config.ts index 923317e..04697b0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -40,14 +40,13 @@ export interface IConfig { } const configFilePath = `bot-tester.json`; -const configFileExists = fs.existsSync(configFilePath); /** * default value for timeout. If config/options are set to this value, no timeout will be used */ export const NO_TIMEOUT = -1; -let configInternal: IConfig = { +const defaultConfig: IConfig = { timeout: NO_TIMEOUT, defaultAddress: { channelId: 'console', @@ -57,14 +56,26 @@ let configInternal: IConfig = { } }; -if (configFileExists) { - configInternal = JSON.parse(fs.readFileSync(configFilePath, { encoding: 'utf8' })); -} +export function getConfig(): IConfig { + let configInternal: IConfig; -configInternal.messageFilters = []; + if (configInternal) { + return configInternal; + } -if (configInternal.ignoreInternalSaveMessage) { - configInternal.messageFilters.push(ignoreInternalSaveMessageFilter); -} + configInternal = defaultConfig; + + const configFileExists = fs.existsSync(configFilePath); + + if (configFileExists) { + configInternal = JSON.parse(fs.readFileSync(configFilePath, { encoding: 'utf8' })); + } + + configInternal.messageFilters = []; -export const config = configInternal; + if (configInternal.ignoreInternalSaveMessage) { + configInternal.messageFilters.push(ignoreInternalSaveMessageFilter); + } + + return configInternal; +} From f34cfd503ae5f0263c561a27df68134a6b7d4d0e Mon Sep 17 00:00:00 2001 From: Matthew Schwartz Date: Fri, 19 Jan 2018 12:11:45 -0800 Subject: [PATCH 17/29] Add default timeout to loaded files (#53) --- src/config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.ts b/src/config.ts index 04697b0..bdd22f4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -69,6 +69,7 @@ export function getConfig(): IConfig { if (configFileExists) { configInternal = JSON.parse(fs.readFileSync(configFilePath, { encoding: 'utf8' })); + configInternal.timeout = configInternal.timeout || NO_TIMEOUT; } configInternal.messageFilters = []; From 3a5c2d8ee84d3cfc799d0b59be17872b0040390c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Dold=C3=A1n?= Date: Fri, 19 Jan 2018 19:29:42 -0300 Subject: [PATCH 18/29] Show custom error messages (#52) --- src/ExpectedMessage.ts | 6 +++--- src/assertionLibraries/ChaiExpectation.ts | 16 ++++++++-------- src/assertionLibraries/IExpectation.ts | 4 ++-- test/BotTesterFailure.spec.ts | 18 +++++++++++++++--- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/ExpectedMessage.ts b/src/ExpectedMessage.ts index 294ca54..f5c783c 100644 --- a/src/ExpectedMessage.ts +++ b/src/ExpectedMessage.ts @@ -1,4 +1,4 @@ -import { IMessage, IEvent } from 'botbuilder'; +import { IEvent, IMessage } from 'botbuilder'; import { expect } from './assertionLibraries/IExpectation'; export enum ExpectedMessageType { @@ -90,7 +90,7 @@ export class ExpectedMessage { expectedResponseStrings.length > 1 ? `one of ${expectedResponseStrings}` : expectedResponseStrings[0]; const errorString = - `Bot should have responded with '${errorStringExpectedResponseText}', but was '${outgoingText}`; + `Bot should have responded with '${errorStringExpectedResponseText}', but was '${outgoingText}'`; expect(expectedResponseStrings, errorString).toInclude(outgoingText); } @@ -105,7 +105,7 @@ export class ExpectedMessage { const text = outgoingMessage.text; const regexCollection: RegExp[] = this.expectedResponseCollection as RegExp[]; expect(regexCollection.some((regex: RegExp) => regex.test(text)), - `${text} did not match any regex in ${regexCollection}`).toBeTrue(); + `'${text}' did not match any regex in ${regexCollection}`).toBeTrue(); } /** diff --git a/src/assertionLibraries/ChaiExpectation.ts b/src/assertionLibraries/ChaiExpectation.ts index 646a144..35d042a 100644 --- a/src/assertionLibraries/ChaiExpectation.ts +++ b/src/assertionLibraries/ChaiExpectation.ts @@ -30,33 +30,33 @@ const expectWithDeepMatch: DeepMatch = expect as any; export class ChaiExpectation implements IExpectation { private subject: {}; private message: string; - + constructor(subject: {}, message?: string) { this.subject = subject; this.message = message; } - + public notToBeEmpty(): void { expect(this.subject, this.message).not.to.be.empty; } - + public toEqual(value: {}): void { expect(this.subject, this.message).to.equal(value); } - + public toInclude(value: {}): void { expect(this.subject, this.message).to.include(value); } - + public toBeTrue(): void { expect(this.subject, this.message).to.be.true; } - + /** * deeply compares an outgoing message with the expected messages that are considered valid for this test to pass. * It does a subset comparison, so as long as the expected message is a subset of one of the expected responses, this will pass - * - * @param outgoingMessage actual message that bot sends + * + * @param outgoingMessage actual message that bot sends */ public toDeeplyInclude(outgoingMessage: IMessage): void { const expectedResponseCollectionAsIMessage: IMessage[] = this.subject as IMessage[]; diff --git a/src/assertionLibraries/IExpectation.ts b/src/assertionLibraries/IExpectation.ts index db8fc00..0f53090 100644 --- a/src/assertionLibraries/IExpectation.ts +++ b/src/assertionLibraries/IExpectation.ts @@ -26,8 +26,8 @@ function createExpectation(subject: {}, message?: string): IExpectation { switch (name) { case 'chai': - return new ChaiExpectation(subject); + return new ChaiExpectation(subject, message); default: - return new ChaiExpectation(subject); + return new ChaiExpectation(subject, message); } } diff --git a/test/BotTesterFailure.spec.ts b/test/BotTesterFailure.spec.ts index 0f3f10a..f36dfa6 100644 --- a/test/BotTesterFailure.spec.ts +++ b/test/BotTesterFailure.spec.ts @@ -26,7 +26,7 @@ describe('BotTester', () => { expect(new BotTester(bot) .sendMessageToBot('Hola!', 'NOPE') .runTest() - ).to.eventually.be.rejectedWith('expected [ \'NOPE\' ] to include \'hello!\'').notify(done); + ).to.eventually.be.rejectedWith('Bot should have responded with \'NOPE\', but was \'hello!\'').notify(done); }); it('will fail if one of multiple responses is incorrect', (done: Function) => { @@ -38,7 +38,19 @@ describe('BotTester', () => { expect(new BotTester(bot) .sendMessageToBot('Hola!', 'hello!', 'NOPE') .runTest() - ).to.eventually.be.rejectedWith('expected [ \'NOPE\' ] to include \'how are you doing?\'').notify(done); + ).to.eventually.be.rejectedWith('Bot should have responded with \'NOPE\', but was \'how are you doing?\'').notify(done); + }); + + it('it will fail if an empty collection is given', () => { + bot.dialog('/', (session: Session) => { + session.send('hello!'); + }); + + try { + new BotTester(bot).sendMessageToBot('Hola!', []); + } catch (error) { + expect(error.message).to.include('expected response collections cannot be empty'); + } }); it('Will fail if response is not in the random response collection', (done: Function) => { @@ -177,7 +189,7 @@ describe('BotTester', () => { expect(new BotTester(bot) .sendMessageToBot('abcd', numberRegex) .runTest() - ).to.be.rejected.notify(done); + ).to.eventually.be.rejectedWith('\'abcd\' did not match any regex in /^\\d+/').notify(done); }); it('can timeout', (done: Function) => { From 5102ffe9d5bd1064a90dc6d1fd403b013de28db7 Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Mon, 22 Jan 2018 12:03:12 -0800 Subject: [PATCH 19/29] V3.3.1 --- ...ries_chaiexpectation_.chaiexpectation.html | 18 ++++---- docs/classes/_bottester_.bottester.html | 40 ++++++++--------- .../_expectedmessage_.expectedmessage.html | 14 +++--- .../_messageservice_.messageservice.html | 14 +++--- ...comparator_.outgoingmessagecomparator.html | 18 ++++---- .../_sessionservice_.sessionservice.html | 20 ++++----- .../_testconnector_.testconnector.html | 14 +++--- ..._expectedmessage_.expectedmessagetype.html | 6 +-- ...nlibraries_iexpectation_.iexpectation.html | 10 ++--- docs/interfaces/_bottester_.ibottester.html | 14 +++--- .../_bottester_.ioptionsmodifier.html | 8 ++-- docs/interfaces/_config_.iconfig.html | 16 +++---- .../_assertionlibraries_iexpectation_.html | 2 +- docs/modules/_bottester_.html | 2 +- docs/modules/_builtinmessagefilters_.html | 6 +-- docs/modules/_config_.html | 43 +++++++++++++------ docs/modules/_expectedmessage_.html | 4 +- docs/modules/_messageservice_.html | 2 +- package.json | 2 +- 19 files changed, 134 insertions(+), 119 deletions(-) diff --git a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html index 98c4f25..4053289 100644 --- a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html +++ b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html @@ -131,7 +131,7 @@

    constructor

  • Parameters

    @@ -156,7 +156,7 @@

    Private message

    message: string
    @@ -166,7 +166,7 @@

    Private subject

    subject: __type
    @@ -183,7 +183,7 @@

    Private checkForMatch
  • Parameters

    @@ -210,7 +210,7 @@

    notToBeEmpty

    Returns void

    @@ -228,7 +228,7 @@

    toBeTrue

    Returns void

    @@ -246,7 +246,7 @@

    toDeeplyInclude

    @@ -279,7 +279,7 @@

    toEqual

    Parameters

    @@ -303,7 +303,7 @@

    toInclude

    Parameters

    diff --git a/docs/classes/_bottester_.bottester.html b/docs/classes/_bottester_.bottester.html index 7f529fd..53a333d 100644 --- a/docs/classes/_bottester_.bottester.html +++ b/docs/classes/_bottester_.bottester.html @@ -142,7 +142,7 @@

    constructor

  • Parameters

    @@ -151,7 +151,7 @@

    Parameters

    bot: UniversalBot
  • -
    Default value options: IConfig = config
    +
    Optional options: IConfig
  • Returns BotTester

    @@ -167,7 +167,7 @@

    Private bot

    bot: UniversalBot
    @@ -177,7 +177,7 @@

    Private config

    config: IConfig
    @@ -187,7 +187,7 @@

    Private messageService

    messageService: MessageService
  • @@ -197,7 +197,7 @@

    Private sessionLoader

    sessionLoader: SessionService
    @@ -207,7 +207,7 @@

    Private testSteps

    testSteps: TestStep[]
    @@ -225,7 +225,7 @@

    addMessageFilter

    Parameters

    @@ -249,7 +249,7 @@

    checkSession

    Parameters

    @@ -275,7 +275,7 @@

    Private convertToIMessage<
  • Parameters

    @@ -299,7 +299,7 @@

    ignoreEndOfConversationEvent

    Returns BotTester

    @@ -317,7 +317,7 @@

    ignoreTypingEvent

    Returns BotTester

    @@ -335,7 +335,7 @@

    runTest

    @@ -358,7 +358,7 @@

    sendMessageToBot

    Parameters

    @@ -385,7 +385,7 @@

    sendMessageToBotAndExpectSaveWithNoRespon

    Parameters

    @@ -409,7 +409,7 @@

    sendMessageToBotIgnoringResponseOrder

    Parameters

    @@ -435,7 +435,7 @@

    Private sendMessageTo
  • @@ -476,7 +476,7 @@

    setTimeout

    Parameters

    @@ -500,7 +500,7 @@

    then

    Parameters

    @@ -524,7 +524,7 @@

    wait

    Parameters

    diff --git a/docs/classes/_expectedmessage_.expectedmessage.html b/docs/classes/_expectedmessage_.expectedmessage.html index 94c8359..d43c94f 100644 --- a/docs/classes/_expectedmessage_.expectedmessage.html +++ b/docs/classes/_expectedmessage_.expectedmessage.html @@ -124,7 +124,7 @@

    constructor

  • Parameters

    @@ -146,7 +146,7 @@

    Private expectedResponseexpectedResponseCollection: PossibleExpectedMessageCollections

  • @@ -168,7 +168,7 @@

    checkForMessageMatch

  • @@ -200,7 +200,7 @@

    Private checkMessageT
  • @@ -237,7 +237,7 @@

    Private checkMessageT
  • @@ -269,7 +269,7 @@

    Private deepMessageMa
  • @@ -303,7 +303,7 @@

    toString

  • Returns string

    diff --git a/docs/classes/_messageservice_.messageservice.html b/docs/classes/_messageservice_.messageservice.html index 1ce7784..d41d130 100644 --- a/docs/classes/_messageservice_.messageservice.html +++ b/docs/classes/_messageservice_.messageservice.html @@ -124,7 +124,7 @@

    constructor

  • Parameters

    @@ -149,7 +149,7 @@

    Private bot

    bot: UniversalBot
    @@ -159,7 +159,7 @@

    Private botToUserMess
    botToUserMessageChecker: botToUserMessageCheckerFunction
    @@ -169,7 +169,7 @@

    Private config

    config: IConfig
    @@ -186,7 +186,7 @@

    Private applyOutgoing
  • @@ -208,7 +208,7 @@

    sendMessageToBot

  • @@ -248,7 +248,7 @@

    Private setBotToUser<
  • diff --git a/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html b/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html index 486ff23..5a76904 100644 --- a/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html +++ b/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html @@ -125,7 +125,7 @@

    constructor

  • Parameters

    @@ -150,7 +150,7 @@

    Private expectedMessagesexpectedMessages: ExpectedMessage[]

  • @@ -160,7 +160,7 @@

    Private ignoreOrder

    ignoreOrder: boolean
    @@ -177,7 +177,7 @@

    compareOutgoingMessageToExpectedResponses

  • @@ -205,7 +205,7 @@

    Private compareOutgoing

    Parameters

    @@ -228,7 +228,7 @@

    Private compareOutgoing

    Parameters

    @@ -251,7 +251,7 @@

    Private dequeueNextEx
  • @@ -273,7 +273,7 @@

    expectsAdditionalMessages

  • @@ -295,7 +295,7 @@

    getTimeoutErrorMessage

  • Returns string

    diff --git a/docs/classes/_sessionservice_.sessionservice.html b/docs/classes/_sessionservice_.sessionservice.html index aed1430..c6d1bf6 100644 --- a/docs/classes/_sessionservice_.sessionservice.html +++ b/docs/classes/_sessionservice_.sessionservice.html @@ -126,7 +126,7 @@

    constructor

  • Parameters

    @@ -148,7 +148,7 @@

    Private bot

    bot: UniversalBot
    @@ -158,7 +158,7 @@

    Private currentSessioncurrentSessionLoadResolver: function

  • @@ -189,7 +189,7 @@

    Private savePerformed

    savePerformed: Promise<any>
    @@ -214,7 +214,7 @@

    Private applySessionL
  • @@ -238,7 +238,7 @@

    Private applySessionS
  • @@ -263,7 +263,7 @@

    Private createSession
  • @@ -296,7 +296,7 @@

    getInternalSaveMessage

  • @@ -329,7 +329,7 @@

    getSession

  • @@ -360,7 +360,7 @@

    Private loadSession

  • diff --git a/docs/classes/_testconnector_.testconnector.html b/docs/classes/_testconnector_.testconnector.html index c6123c6..6d7aa52 100644 --- a/docs/classes/_testconnector_.testconnector.html +++ b/docs/classes/_testconnector_.testconnector.html @@ -122,7 +122,7 @@

    constructor

  • Returns TestConnector

    @@ -138,7 +138,7 @@

    Private newConvoCount
    newConvoCount: number
    @@ -148,7 +148,7 @@

    Private onEventHandle
    onEventHandler: function
    @@ -200,7 +200,7 @@

    Private onInvokeHandl
    onInvokeHandler: function
    @@ -265,7 +265,7 @@

    onEvent

  • Parameters

    @@ -327,7 +327,7 @@

    send

  • Parameters

    @@ -374,7 +374,7 @@

    startConversation

  • Parameters

    diff --git a/docs/enums/_expectedmessage_.expectedmessagetype.html b/docs/enums/_expectedmessage_.expectedmessagetype.html index 9c02a30..c8c1e3e 100644 --- a/docs/enums/_expectedmessage_.expectedmessagetype.html +++ b/docs/enums/_expectedmessage_.expectedmessagetype.html @@ -90,7 +90,7 @@

    IMessage

    IMessage:
    @@ -100,7 +100,7 @@

    Regex

    Regex:
    @@ -110,7 +110,7 @@

    String

    String:
    diff --git a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html index 5965628..17ff956 100644 --- a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html +++ b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html @@ -117,7 +117,7 @@

    notToBeEmpty

  • Returns void

    @@ -134,7 +134,7 @@

    toBeTrue

  • Returns void

    @@ -151,7 +151,7 @@

    toDeeplyInclude

  • Parameters

    @@ -174,7 +174,7 @@

    toEqual

  • Parameters

    @@ -197,7 +197,7 @@

    toInclude

  • Parameters

    diff --git a/docs/interfaces/_bottester_.ibottester.html b/docs/interfaces/_bottester_.ibottester.html index 76c0aaa..ecdb406 100644 --- a/docs/interfaces/_bottester_.ibottester.html +++ b/docs/interfaces/_bottester_.ibottester.html @@ -119,7 +119,7 @@

    checkSession

  • @@ -156,7 +156,7 @@

    runTest

  • @@ -178,7 +178,7 @@

    sendMessageToBot

  • @@ -217,7 +217,7 @@

    sendMessageToBotAndExpectSaveWithNoRespon
  • @@ -249,7 +249,7 @@

    sendMessageToBotIgnoringResponseOrder

  • @@ -281,7 +281,7 @@

    then

  • @@ -313,7 +313,7 @@

    wait

  • diff --git a/docs/interfaces/_bottester_.ioptionsmodifier.html b/docs/interfaces/_bottester_.ioptionsmodifier.html index 8948010..5b5b465 100644 --- a/docs/interfaces/_bottester_.ioptionsmodifier.html +++ b/docs/interfaces/_bottester_.ioptionsmodifier.html @@ -116,7 +116,7 @@

    addMessageFilter

  • @@ -147,7 +147,7 @@

    ignoreEndOfConversationEvent

  • @@ -169,7 +169,7 @@

    ignoreTypingEvent

  • @@ -191,7 +191,7 @@

    setTimeout

  • diff --git a/docs/interfaces/_config_.iconfig.html b/docs/interfaces/_config_.iconfig.html index 612c59d..f78adb2 100644 --- a/docs/interfaces/_config_.iconfig.html +++ b/docs/interfaces/_config_.iconfig.html @@ -101,7 +101,7 @@

    Optional defaultAddressdefaultAddress: IAddress

    @@ -116,7 +116,7 @@

    Optional ignoreEndOf
    ignoreEndOfConversationEvent: boolean
    @@ -131,7 +131,7 @@

    Optional ignoreInternalignoreInternalSaveMessage: boolean

    @@ -146,7 +146,7 @@

    Optional ignoreTypingignoreTypingEvent: boolean

    @@ -161,7 +161,7 @@

    Optional messageFiltersmessageFilters: MessageFilter[]

    @@ -176,7 +176,7 @@

    Optional timeout

    timeout: number
    @@ -269,8 +269,8 @@

    Optional timeout

  • NO_TIMEOUT
  • -
  • - config +
  • + getConfig
  • diff --git a/docs/modules/_assertionlibraries_iexpectation_.html b/docs/modules/_assertionlibraries_iexpectation_.html index c8e1bc1..0c3a16f 100644 --- a/docs/modules/_assertionlibraries_iexpectation_.html +++ b/docs/modules/_assertionlibraries_iexpectation_.html @@ -95,7 +95,7 @@

    expect

  • diff --git a/docs/modules/_bottester_.html b/docs/modules/_bottester_.html index 63fb812..dcf8f51 100644 --- a/docs/modules/_bottester_.html +++ b/docs/modules/_bottester_.html @@ -98,7 +98,7 @@

    checkSessionFunction

    checkSessionFunction: function
    diff --git a/docs/modules/_builtinmessagefilters_.html b/docs/modules/_builtinmessagefilters_.html index db51cd4..c37ee1f 100644 --- a/docs/modules/_builtinmessagefilters_.html +++ b/docs/modules/_builtinmessagefilters_.html @@ -91,7 +91,7 @@

    ignoreEndOfConversationEventFilter

  • Parameters

    @@ -114,7 +114,7 @@

    ignoreInternalSaveMessageFilter

  • Parameters

    @@ -137,7 +137,7 @@

    ignoreTypingEventFilter

  • Parameters

    diff --git a/docs/modules/_config_.html b/docs/modules/_config_.html index fb09b5b..f14c59f 100644 --- a/docs/modules/_config_.html +++ b/docs/modules/_config_.html @@ -84,7 +84,12 @@

    Type aliases

    Variables

    + +
    +

    Functions

    +
  • @@ -98,7 +103,7 @@

    MessageFilter

    MessageFilter: function
    @@ -137,7 +142,7 @@

    NO_TIMEOUT

    NO_TIMEOUT: -1 = -1
    @@ -146,15 +151,25 @@

    NO_TIMEOUT

    -
    - -

    config

    -
    config: IConfig = configInternal
    - +
    +
    +

    Functions

    +
    + +

    getConfig

    + +
    @@ -216,8 +231,8 @@

    config

  • NO_TIMEOUT
  • -
  • - config +
  • + getConfig
  • diff --git a/docs/modules/_expectedmessage_.html b/docs/modules/_expectedmessage_.html index 25cc25c..cc6a699 100644 --- a/docs/modules/_expectedmessage_.html +++ b/docs/modules/_expectedmessage_.html @@ -98,7 +98,7 @@

    PossibleExpectedMessageCollections

    PossibleExpectedMessageCollections: PossibleExpectedMessageType[]
    @@ -114,7 +114,7 @@

    PossibleExpectedMessageType

    PossibleExpectedMessageType: string | IMessage | RegExp | IEvent
    diff --git a/docs/modules/_messageservice_.html b/docs/modules/_messageservice_.html index 7cec6dc..2df19f9 100644 --- a/docs/modules/_messageservice_.html +++ b/docs/modules/_messageservice_.html @@ -91,7 +91,7 @@

    botToUserMessageCheckerFunction

    botToUserMessageCheckerFunction: function
    diff --git a/package.json b/package.json index 8a03d55..94bd608 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bot-tester", - "version": "3.3.0", + "version": "3.3.1", "description": "Easily test bots made with the bot builder framework", "main": "dist/index.js", "types": "dist/index.d.ts", From d867b87a556a1a90715aed0b7f473d461d7a5162 Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Mon, 22 Jan 2018 12:05:05 -0800 Subject: [PATCH 20/29] v3.3.2 --- ...ries_chaiexpectation_.chaiexpectation.html | 18 ++++----- docs/classes/_bottester_.bottester.html | 38 +++++++++---------- .../_expectedmessage_.expectedmessage.html | 14 +++---- .../_messageservice_.messageservice.html | 14 +++---- ...comparator_.outgoingmessagecomparator.html | 18 ++++----- .../_sessionservice_.sessionservice.html | 20 +++++----- .../_testconnector_.testconnector.html | 14 +++---- ..._expectedmessage_.expectedmessagetype.html | 6 +-- ...nlibraries_iexpectation_.iexpectation.html | 10 ++--- docs/interfaces/_bottester_.ibottester.html | 14 +++---- .../_bottester_.ioptionsmodifier.html | 8 ++-- docs/interfaces/_config_.iconfig.html | 12 +++--- .../_assertionlibraries_iexpectation_.html | 2 +- docs/modules/_bottester_.html | 2 +- docs/modules/_builtinmessagefilters_.html | 6 +-- docs/modules/_config_.html | 6 +-- docs/modules/_expectedmessage_.html | 4 +- docs/modules/_messageservice_.html | 2 +- package.json | 2 +- 19 files changed, 105 insertions(+), 105 deletions(-) diff --git a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html index 4053289..100903f 100644 --- a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html +++ b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html @@ -131,7 +131,7 @@

    constructor

  • Parameters

    @@ -156,7 +156,7 @@

    Private message

    message: string
    @@ -166,7 +166,7 @@

    Private subject

    subject: __type
    @@ -183,7 +183,7 @@

    Private checkForMatch
  • Parameters

    @@ -210,7 +210,7 @@

    notToBeEmpty

    Returns void

    @@ -228,7 +228,7 @@

    toBeTrue

    Returns void

    @@ -246,7 +246,7 @@

    toDeeplyInclude

    @@ -279,7 +279,7 @@

    toEqual

    Parameters

    @@ -303,7 +303,7 @@

    toInclude

    Parameters

    diff --git a/docs/classes/_bottester_.bottester.html b/docs/classes/_bottester_.bottester.html index 53a333d..543d9f3 100644 --- a/docs/classes/_bottester_.bottester.html +++ b/docs/classes/_bottester_.bottester.html @@ -142,7 +142,7 @@

    constructor

  • Parameters

    @@ -167,7 +167,7 @@

    Private bot

    bot: UniversalBot
    @@ -177,7 +177,7 @@

    Private config

    config: IConfig
    @@ -187,7 +187,7 @@

    Private messageService

    messageService: MessageService
  • @@ -197,7 +197,7 @@

    Private sessionLoader

    sessionLoader: SessionService
    @@ -207,7 +207,7 @@

    Private testSteps

    testSteps: TestStep[]
    @@ -225,7 +225,7 @@

    addMessageFilter

    Parameters

    @@ -249,7 +249,7 @@

    checkSession

    Parameters

    @@ -275,7 +275,7 @@

    Private convertToIMessage<
  • Parameters

    @@ -299,7 +299,7 @@

    ignoreEndOfConversationEvent

    Returns BotTester

    @@ -317,7 +317,7 @@

    ignoreTypingEvent

    Returns BotTester

    @@ -335,7 +335,7 @@

    runTest

    @@ -358,7 +358,7 @@

    sendMessageToBot

    Parameters

    @@ -385,7 +385,7 @@

    sendMessageToBotAndExpectSaveWithNoRespon

    Parameters

    @@ -409,7 +409,7 @@

    sendMessageToBotIgnoringResponseOrder

    Parameters

    @@ -435,7 +435,7 @@

    Private sendMessageTo
  • @@ -476,7 +476,7 @@

    setTimeout

    Parameters

    @@ -500,7 +500,7 @@

    then

    Parameters

    @@ -524,7 +524,7 @@

    wait

    Parameters

    diff --git a/docs/classes/_expectedmessage_.expectedmessage.html b/docs/classes/_expectedmessage_.expectedmessage.html index d43c94f..910c846 100644 --- a/docs/classes/_expectedmessage_.expectedmessage.html +++ b/docs/classes/_expectedmessage_.expectedmessage.html @@ -124,7 +124,7 @@

    constructor

  • Parameters

    @@ -146,7 +146,7 @@

    Private expectedResponseexpectedResponseCollection: PossibleExpectedMessageCollections

  • @@ -168,7 +168,7 @@

    checkForMessageMatch

  • @@ -200,7 +200,7 @@

    Private checkMessageT
  • @@ -237,7 +237,7 @@

    Private checkMessageT
  • @@ -269,7 +269,7 @@

    Private deepMessageMa
  • @@ -303,7 +303,7 @@

    toString

  • Returns string

    diff --git a/docs/classes/_messageservice_.messageservice.html b/docs/classes/_messageservice_.messageservice.html index d41d130..1a346b1 100644 --- a/docs/classes/_messageservice_.messageservice.html +++ b/docs/classes/_messageservice_.messageservice.html @@ -124,7 +124,7 @@

    constructor

  • Parameters

    @@ -149,7 +149,7 @@

    Private bot

    bot: UniversalBot
    @@ -159,7 +159,7 @@

    Private botToUserMess
    botToUserMessageChecker: botToUserMessageCheckerFunction
    @@ -169,7 +169,7 @@

    Private config

    config: IConfig
    @@ -186,7 +186,7 @@

    Private applyOutgoing
  • @@ -208,7 +208,7 @@

    sendMessageToBot

  • @@ -248,7 +248,7 @@

    Private setBotToUser<
  • diff --git a/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html b/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html index 5a76904..07f8dda 100644 --- a/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html +++ b/docs/classes/_outgoingmessagecomparator_.outgoingmessagecomparator.html @@ -125,7 +125,7 @@

    constructor

  • Parameters

    @@ -150,7 +150,7 @@

    Private expectedMessagesexpectedMessages: ExpectedMessage[]

  • @@ -160,7 +160,7 @@

    Private ignoreOrder

    ignoreOrder: boolean
    @@ -177,7 +177,7 @@

    compareOutgoingMessageToExpectedResponses

  • @@ -205,7 +205,7 @@

    Private compareOutgoing

    Parameters

    @@ -228,7 +228,7 @@

    Private compareOutgoing

    Parameters

    @@ -251,7 +251,7 @@

    Private dequeueNextEx
  • @@ -273,7 +273,7 @@

    expectsAdditionalMessages

  • @@ -295,7 +295,7 @@

    getTimeoutErrorMessage

  • Returns string

    diff --git a/docs/classes/_sessionservice_.sessionservice.html b/docs/classes/_sessionservice_.sessionservice.html index c6d1bf6..ee700c7 100644 --- a/docs/classes/_sessionservice_.sessionservice.html +++ b/docs/classes/_sessionservice_.sessionservice.html @@ -126,7 +126,7 @@

    constructor

  • Parameters

    @@ -148,7 +148,7 @@

    Private bot

    bot: UniversalBot
    @@ -158,7 +158,7 @@

    Private currentSessioncurrentSessionLoadResolver: function

  • @@ -189,7 +189,7 @@

    Private savePerformed

    savePerformed: Promise<any>
    @@ -214,7 +214,7 @@

    Private applySessionL
  • @@ -238,7 +238,7 @@

    Private applySessionS
  • @@ -263,7 +263,7 @@

    Private createSession
  • @@ -296,7 +296,7 @@

    getInternalSaveMessage

  • @@ -329,7 +329,7 @@

    getSession

  • @@ -360,7 +360,7 @@

    Private loadSession

  • diff --git a/docs/classes/_testconnector_.testconnector.html b/docs/classes/_testconnector_.testconnector.html index 6d7aa52..22f4d87 100644 --- a/docs/classes/_testconnector_.testconnector.html +++ b/docs/classes/_testconnector_.testconnector.html @@ -122,7 +122,7 @@

    constructor

  • Returns TestConnector

    @@ -138,7 +138,7 @@

    Private newConvoCount
    newConvoCount: number
    @@ -148,7 +148,7 @@

    Private onEventHandle
    onEventHandler: function
    @@ -200,7 +200,7 @@

    Private onInvokeHandl
    onInvokeHandler: function
    @@ -265,7 +265,7 @@

    onEvent

  • Parameters

    @@ -327,7 +327,7 @@

    send

  • Parameters

    @@ -374,7 +374,7 @@

    startConversation

  • Parameters

    diff --git a/docs/enums/_expectedmessage_.expectedmessagetype.html b/docs/enums/_expectedmessage_.expectedmessagetype.html index c8c1e3e..2f9297a 100644 --- a/docs/enums/_expectedmessage_.expectedmessagetype.html +++ b/docs/enums/_expectedmessage_.expectedmessagetype.html @@ -90,7 +90,7 @@

    IMessage

    IMessage:
    @@ -100,7 +100,7 @@

    Regex

    Regex:
    @@ -110,7 +110,7 @@

    String

    String:
    diff --git a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html index 17ff956..ba9925d 100644 --- a/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html +++ b/docs/interfaces/_assertionlibraries_iexpectation_.iexpectation.html @@ -117,7 +117,7 @@

    notToBeEmpty

  • Returns void

    @@ -134,7 +134,7 @@

    toBeTrue

  • Returns void

    @@ -151,7 +151,7 @@

    toDeeplyInclude

  • Parameters

    @@ -174,7 +174,7 @@

    toEqual

  • Parameters

    @@ -197,7 +197,7 @@

    toInclude

  • Parameters

    diff --git a/docs/interfaces/_bottester_.ibottester.html b/docs/interfaces/_bottester_.ibottester.html index ecdb406..5bb0888 100644 --- a/docs/interfaces/_bottester_.ibottester.html +++ b/docs/interfaces/_bottester_.ibottester.html @@ -119,7 +119,7 @@

    checkSession

  • @@ -156,7 +156,7 @@

    runTest

  • @@ -178,7 +178,7 @@

    sendMessageToBot

  • @@ -217,7 +217,7 @@

    sendMessageToBotAndExpectSaveWithNoRespon
  • @@ -249,7 +249,7 @@

    sendMessageToBotIgnoringResponseOrder

  • @@ -281,7 +281,7 @@

    then

  • @@ -313,7 +313,7 @@

    wait

  • diff --git a/docs/interfaces/_bottester_.ioptionsmodifier.html b/docs/interfaces/_bottester_.ioptionsmodifier.html index 5b5b465..449ec11 100644 --- a/docs/interfaces/_bottester_.ioptionsmodifier.html +++ b/docs/interfaces/_bottester_.ioptionsmodifier.html @@ -116,7 +116,7 @@

    addMessageFilter

  • @@ -147,7 +147,7 @@

    ignoreEndOfConversationEvent

  • @@ -169,7 +169,7 @@

    ignoreTypingEvent

  • @@ -191,7 +191,7 @@

    setTimeout

  • diff --git a/docs/interfaces/_config_.iconfig.html b/docs/interfaces/_config_.iconfig.html index f78adb2..fc80ec0 100644 --- a/docs/interfaces/_config_.iconfig.html +++ b/docs/interfaces/_config_.iconfig.html @@ -101,7 +101,7 @@

    Optional defaultAddressdefaultAddress: IAddress

    @@ -116,7 +116,7 @@

    Optional ignoreEndOf
    ignoreEndOfConversationEvent: boolean
    @@ -131,7 +131,7 @@

    Optional ignoreInternalignoreInternalSaveMessage: boolean

    @@ -146,7 +146,7 @@

    Optional ignoreTypingignoreTypingEvent: boolean

    @@ -161,7 +161,7 @@

    Optional messageFiltersmessageFilters: MessageFilter[]

    @@ -176,7 +176,7 @@

    Optional timeout

    timeout: number
    diff --git a/docs/modules/_assertionlibraries_iexpectation_.html b/docs/modules/_assertionlibraries_iexpectation_.html index 0c3a16f..dc94f31 100644 --- a/docs/modules/_assertionlibraries_iexpectation_.html +++ b/docs/modules/_assertionlibraries_iexpectation_.html @@ -95,7 +95,7 @@

    expect

  • diff --git a/docs/modules/_bottester_.html b/docs/modules/_bottester_.html index dcf8f51..d087d8a 100644 --- a/docs/modules/_bottester_.html +++ b/docs/modules/_bottester_.html @@ -98,7 +98,7 @@

    checkSessionFunction

    checkSessionFunction: function
    diff --git a/docs/modules/_builtinmessagefilters_.html b/docs/modules/_builtinmessagefilters_.html index c37ee1f..1c5f442 100644 --- a/docs/modules/_builtinmessagefilters_.html +++ b/docs/modules/_builtinmessagefilters_.html @@ -91,7 +91,7 @@

    ignoreEndOfConversationEventFilter

  • Parameters

    @@ -114,7 +114,7 @@

    ignoreInternalSaveMessageFilter

  • Parameters

    @@ -137,7 +137,7 @@

    ignoreTypingEventFilter

  • Parameters

    diff --git a/docs/modules/_config_.html b/docs/modules/_config_.html index f14c59f..fc2d27b 100644 --- a/docs/modules/_config_.html +++ b/docs/modules/_config_.html @@ -103,7 +103,7 @@

    MessageFilter

    MessageFilter: function
    @@ -142,7 +142,7 @@

    NO_TIMEOUT

    NO_TIMEOUT: -1 = -1
    @@ -164,7 +164,7 @@

    getConfig

  • Returns IConfig

    diff --git a/docs/modules/_expectedmessage_.html b/docs/modules/_expectedmessage_.html index cc6a699..9075681 100644 --- a/docs/modules/_expectedmessage_.html +++ b/docs/modules/_expectedmessage_.html @@ -98,7 +98,7 @@

    PossibleExpectedMessageCollections

    PossibleExpectedMessageCollections: PossibleExpectedMessageType[]
    @@ -114,7 +114,7 @@

    PossibleExpectedMessageType

    PossibleExpectedMessageType: string | IMessage | RegExp | IEvent
    diff --git a/docs/modules/_messageservice_.html b/docs/modules/_messageservice_.html index 2df19f9..1d617cf 100644 --- a/docs/modules/_messageservice_.html +++ b/docs/modules/_messageservice_.html @@ -91,7 +91,7 @@

    botToUserMessageCheckerFunction

    botToUserMessageCheckerFunction: function
    diff --git a/package.json b/package.json index 94bd608..04611a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bot-tester", - "version": "3.3.1", + "version": "3.3.2", "description": "Easily test bots made with the bot builder framework", "main": "dist/index.js", "types": "dist/index.d.ts", From 5b7f4952a008ddde2730ea506fd09eac36d434cc Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Wed, 24 Jan 2018 23:25:58 -0800 Subject: [PATCH 21/29] create enum for assertion libraries --- src/assertionLibraries/AssertionLibrary.ts | 4 ++++ src/config.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/assertionLibraries/AssertionLibrary.ts diff --git a/src/assertionLibraries/AssertionLibrary.ts b/src/assertionLibraries/AssertionLibrary.ts new file mode 100644 index 0000000..cdd54cd --- /dev/null +++ b/src/assertionLibraries/AssertionLibrary.ts @@ -0,0 +1,4 @@ +export enum AssertionLibrary { + AVA = 'ava', + CHAI = 'chai' +} diff --git a/src/config.ts b/src/config.ts index bdd22f4..8619047 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,6 @@ import { IAddress, IMessage } from 'botbuilder'; import * as fs from 'fs'; +import { AssertionLibrary } from './assertionLibraries/AssertionLibrary'; import { ignoreInternalSaveMessageFilter } from './builtInMessageFilters'; /** @@ -8,6 +9,14 @@ import { ignoreInternalSaveMessageFilter } from './builtInMessageFilters'; export type MessageFilter = (message: IMessage) => boolean; export interface IConfig { + /** + * assertion library to use when running the tests. Valid libraries/strings/values are: + * 1) chai + * + * chai is the default library if none is provided + * more are on the way! + */ + assertionLibrary?: AssertionLibrary; /** * timeout in milliseconds before a BotTester runner will fail a test (when not overriden) */ @@ -48,6 +57,7 @@ export const NO_TIMEOUT = -1; const defaultConfig: IConfig = { timeout: NO_TIMEOUT, + assertionLibrary: AssertionLibrary.CHAI, defaultAddress: { channelId: 'console', user: { id: 'user1', name: 'user1' }, @@ -74,6 +84,8 @@ export function getConfig(): IConfig { configInternal.messageFilters = []; + configInternal.assertionLibrary = configInternal.assertionLibrary || AssertionLibrary.CHAI; + if (configInternal.ignoreInternalSaveMessage) { configInternal.messageFilters.push(ignoreInternalSaveMessageFilter); } From 3fec4bedcc228f2ccbc679e683241cd2cbf16952 Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Wed, 24 Jan 2018 23:26:18 -0800 Subject: [PATCH 22/29] remove newly deprecated lines --- src/assertionLibraries/IExpectation.ts | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/assertionLibraries/IExpectation.ts b/src/assertionLibraries/IExpectation.ts index 0f53090..7fb26ec 100644 --- a/src/assertionLibraries/IExpectation.ts +++ b/src/assertionLibraries/IExpectation.ts @@ -1,5 +1,3 @@ -import { ChaiExpectation } from './ChaiExpectation'; - /** * framework based extractions. New frameworks will implement this interface to be able to be used seamlessly within the framework */ @@ -10,24 +8,3 @@ export interface IExpectation { toBeTrue(): void; toDeeplyInclude(value: {}): void; } - -/** - * Creates a wrapper instance around an assertion class - * - * @param subject object being tested against - * @param message error message to print if expectation fails - */ -export function expect(subject: {}, message?: string): IExpectation { - return createExpectation(subject, message); -} - -function createExpectation(subject: {}, message?: string): IExpectation { - const name = 'chai'; - - switch (name) { - case 'chai': - return new ChaiExpectation(subject, message); - default: - return new ChaiExpectation(subject, message); - } -} From 498dfe1a6cdf25b5ab34a2e2fcffec93ac6f7dd8 Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Wed, 24 Jan 2018 23:27:05 -0800 Subject: [PATCH 23/29] create new bottester expectation class to abstract away underlying implementation; --- .../BotTesterExpectation.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/assertionLibraries/BotTesterExpectation.ts diff --git a/src/assertionLibraries/BotTesterExpectation.ts b/src/assertionLibraries/BotTesterExpectation.ts new file mode 100644 index 0000000..52a7db8 --- /dev/null +++ b/src/assertionLibraries/BotTesterExpectation.ts @@ -0,0 +1,24 @@ +import { IConfig } from './../config'; +import { AssertionLibrary } from './AssertionLibrary'; +import { ChaiExpectation } from './ChaiExpectation'; +import { IExpectation } from './IExpectation'; + +export type expectationFunction = (subject: {}, message?: string) => IExpectation; + +export class BotTesterExpectation { + private readonly assertionLibrary: AssertionLibrary; + + constructor(config: IConfig) { + this.assertionLibrary = config.assertionLibrary; + } + + public expect(subject: {}, message?: string): IExpectation { + switch (this.assertionLibrary) { + case AssertionLibrary.AVA: + throw new Error('ava is not yet supported'); + case AssertionLibrary.CHAI: + default: + return new ChaiExpectation(subject, message); + } + } +} From cc25ad0d0b116e10c6872f1831014b2b857c44ca Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Wed, 24 Jan 2018 23:33:40 -0800 Subject: [PATCH 24/29] finish propagating configurable message testing --- src/BotTester.ts | 4 ++-- src/ExpectedMessage.ts | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/BotTester.ts b/src/BotTester.ts index d297f3b..9869099 100644 --- a/src/BotTester.ts +++ b/src/BotTester.ts @@ -242,13 +242,13 @@ export class BotTester implements IBotTester, IOptionsModifier { if (!expectedResponses) { expectedMessages = []; } else if (!(expectedResponses instanceof Array)) { - expectedMessages = [new ExpectedMessage(expectedResponses)]; + expectedMessages = [new ExpectedMessage(this.config, expectedResponses)]; } else if (expectedResponses instanceof Array) { if (expectedResponses.length > 0) { expectedMessages = (expectedResponses as PossibleExpectedMessageCollections[]) .map((currentExpectedResponseCollection: PossibleExpectedMessageCollections) => - new ExpectedMessage(currentExpectedResponseCollection)); + new ExpectedMessage(this.config, currentExpectedResponseCollection)); } } diff --git a/src/ExpectedMessage.ts b/src/ExpectedMessage.ts index f5c783c..99e65b4 100644 --- a/src/ExpectedMessage.ts +++ b/src/ExpectedMessage.ts @@ -1,5 +1,6 @@ import { IEvent, IMessage } from 'botbuilder'; -import { expect } from './assertionLibraries/IExpectation'; +import { BotTesterExpectation } from './assertionLibraries/BotTesterExpectation'; +import { IConfig } from './config'; export enum ExpectedMessageType { String, @@ -35,19 +36,23 @@ function getExpectedMessageType(expectedResponseCollection: PossibleExpectedMess * response from the bot. */ export class ExpectedMessage { + private readonly internalExpectation: BotTesterExpectation; /** * set of possible responses, chosen at random. If the collection size is 1, then there is only one response that is expected */ private readonly expectedResponseCollection: PossibleExpectedMessageCollections; - constructor(expectedResponseCollection: PossibleExpectedMessageType | PossibleExpectedMessageCollections) { + constructor( + config: IConfig, + expectedResponseCollection: PossibleExpectedMessageType | PossibleExpectedMessageCollections + ) { + this.internalExpectation = new BotTesterExpectation(config); + if (!(expectedResponseCollection instanceof Array)) { this.expectedResponseCollection = [expectedResponseCollection as PossibleExpectedMessageType]; } else { this.expectedResponseCollection = expectedResponseCollection as PossibleExpectedMessageCollections; } - - expect(this.expectedResponseCollection, 'expected response collections cannot be empty').notToBeEmpty(); } /** @@ -69,7 +74,7 @@ export class ExpectedMessage { this.deepMessageMatchCheck(outgoingMessage); break; default: - expect(outgoingMessage.type).toEqual('save'); + this.internalExpectation.expect(outgoingMessage.type).toEqual('save'); } } @@ -92,7 +97,7 @@ export class ExpectedMessage { const errorString = `Bot should have responded with '${errorStringExpectedResponseText}', but was '${outgoingText}'`; - expect(expectedResponseStrings, errorString).toInclude(outgoingText); + this.internalExpectation.expect(expectedResponseStrings, errorString).toInclude(outgoingText); } /** @@ -104,8 +109,9 @@ export class ExpectedMessage { private checkMessageTextForRegex(outgoingMessage: IMessage): void { const text = outgoingMessage.text; const regexCollection: RegExp[] = this.expectedResponseCollection as RegExp[]; - expect(regexCollection.some((regex: RegExp) => regex.test(text)), - `'${text}' did not match any regex in ${regexCollection}`).toBeTrue(); + + this.internalExpectation.expect(regexCollection.some((regex: RegExp) => regex.test(text)), + `'${text}' did not match any regex in ${regexCollection}`).toBeTrue(); } /** @@ -128,6 +134,6 @@ export class ExpectedMessage { this.checkMessageTextForExactStringMatch(outgoingMessage, expectedResponseStrings); } - expect(expectedResponseCollectionAsIMessage).toDeeplyInclude(outgoingMessage); + this.internalExpectation.expect(expectedResponseCollectionAsIMessage).toDeeplyInclude(outgoingMessage); } } From d674732b73644b29c3c2f00da311220deadd242d Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Wed, 24 Jan 2018 23:36:06 -0800 Subject: [PATCH 25/29] move test files to directories that will reflect their test runner and expectation libraries --- test/{ => mocha/chai}/BotTester.spec.ts | 6 +++--- test/{ => mocha/chai}/BotTesterFailure.spec.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) rename test/{ => mocha/chai}/BotTester.spec.ts (98%) rename test/{ => mocha/chai}/BotTesterFailure.spec.ts (98%) diff --git a/test/BotTester.spec.ts b/test/mocha/chai/BotTester.spec.ts similarity index 98% rename from test/BotTester.spec.ts rename to test/mocha/chai/BotTester.spec.ts index 4f8285b..2f90102 100644 --- a/test/BotTester.spec.ts +++ b/test/mocha/chai/BotTester.spec.ts @@ -2,9 +2,9 @@ import { IAddress, IMessage, Message, Prompts, Session, UniversalBot } from 'botbuilder'; import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import { BotTester } from './../src/BotTester'; -import { TestConnector } from './../src/TestConnector'; -import { getAdaptiveCard, getAdaptiveCardAttachment, getAdaptiveCardMessage } from './adaptiveCardProvider'; +import { BotTester } from './../../../src/BotTester'; +import { TestConnector } from './../../../src/TestConnector'; +import { getAdaptiveCard, getAdaptiveCardAttachment, getAdaptiveCardMessage } from './../../adaptiveCardProvider'; chai.use(chaiAsPromised); const expect = chai.expect; diff --git a/test/BotTesterFailure.spec.ts b/test/mocha/chai/BotTesterFailure.spec.ts similarity index 98% rename from test/BotTesterFailure.spec.ts rename to test/mocha/chai/BotTesterFailure.spec.ts index f36dfa6..bc52074 100644 --- a/test/BotTesterFailure.spec.ts +++ b/test/mocha/chai/BotTesterFailure.spec.ts @@ -1,9 +1,9 @@ import { IAddress, IDialogResult, IMessage, Message, Prompts, Session, UniversalBot } from 'botbuilder'; import * as chai from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; -import { BotTester } from './../src/BotTester'; -import { TestConnector } from './../src/TestConnector'; -import { getAdaptiveCard, getAdaptiveCardAttachment, getAdaptiveCardMessage } from './adaptiveCardProvider'; +import { BotTester } from './../../../src/BotTester'; +import { TestConnector } from './../../../src/TestConnector'; +import { getAdaptiveCard, getAdaptiveCardAttachment, getAdaptiveCardMessage } from './../../adaptiveCardProvider'; chai.use(chaiAsPromised); From c50baa316c6a022c33425a9f154c3777639e62d6 Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Wed, 24 Jan 2018 23:37:19 -0800 Subject: [PATCH 26/29] make local test script check subdirectories --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 04611a2..9a75e8e 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "lint:fix": "tslint 'src/**/*.ts' --fix", "cleanBuild": "npm run clean && npm run build", "watch": "tsc -w", - "test": "node_modules/mocha/bin/_mocha --require node_modules/ts-node/register test/*.spec.ts", + "test": "node_modules/mocha/bin/_mocha --require node_modules/ts-node/register test/**/*.spec.ts", "buildTypeDocs": "yarn cleanBuild && rm -rf docs && typedoc --excludeNotExported --out docs --hideGenerator src/BotTester.ts --module commonjs --gaID UA-105358964-1 --readme none && touch docs/.nojekyll", "ci": "npm run lint && npm run test", "coverage": "npm run coverageTests && nyc report --reporter=text-lcov | node_modules/.bin/coveralls", From d021dabd18f6b1d59b9f23c5d48a9faaab8e7a6d Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Wed, 24 Jan 2018 23:45:50 -0800 Subject: [PATCH 27/29] update comment to have more detail and give optional string binding instead of enum --- src/config.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index 8619047..2c0a86d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -14,9 +14,12 @@ export interface IConfig { * 1) chai * * chai is the default library if none is provided - * more are on the way! + * libraries being developed: + * 1) Ava + * + * to request support for a new assertion library, check this thread and submit a comment */ - assertionLibrary?: AssertionLibrary; + assertionLibrary?: AssertionLibrary | string; /** * timeout in milliseconds before a BotTester runner will fail a test (when not overriden) */ From 0ca8a9fc4dd1332f6eeaecd75ea02b13f28f373a Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Thu, 25 Jan 2018 07:15:10 -0800 Subject: [PATCH 28/29] replace enum type with a weaker string --- src/assertionLibraries/BotTesterExpectation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assertionLibraries/BotTesterExpectation.ts b/src/assertionLibraries/BotTesterExpectation.ts index 52a7db8..0575f97 100644 --- a/src/assertionLibraries/BotTesterExpectation.ts +++ b/src/assertionLibraries/BotTesterExpectation.ts @@ -6,7 +6,7 @@ import { IExpectation } from './IExpectation'; export type expectationFunction = (subject: {}, message?: string) => IExpectation; export class BotTesterExpectation { - private readonly assertionLibrary: AssertionLibrary; + private readonly assertionLibrary: string; constructor(config: IConfig) { this.assertionLibrary = config.assertionLibrary; From 9a096021e10b9ad7074ffcefa62b4630db134fba Mon Sep 17 00:00:00 2001 From: Matt Schwartz Date: Thu, 25 Jan 2018 07:19:12 -0800 Subject: [PATCH 29/29] update readme --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 55a3860..26a4166 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,16 @@ Passing in the config overrides any default values or values set by bot-tester.j ignoreTypingEvent: boolean, ignoreEndOfConversationEvent: boolean, // Setting this to true will cause checkSession to hang and test to fail. - ignoreInternalSaveMessage: boolean; + ignoreInternalSaveMessage: boolean, + // this will allow using different assertion libraries. Currently supported libraries are: + // 1) chai + + // with the following under development: + // 2) ava + + // should this field not be provided, it will default to chai + assertionLibrary: string, } ``` if timeout is defined, then a particular ```runTest()``` call will fail if it does not receive each expected message within the timeout period of time set in the options.