Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
519f235
Add message filter and in-line options update (#28)
microsoftly Oct 6, 2017
8b02cc6
add builtin message filters
microsoftly Oct 6, 2017
ab04000
add builtin message filters to options/config (#30)
microsoftly Oct 6, 2017
a6d5807
Merge branch 'dev' of github.com:microsoftly/BotTester into dev
microsoftly Oct 6, 2017
a4c07bd
v3.1.0 (#32)
microsoftly Oct 6, 2017
f2c154c
Merge branch 'dev' of github.com:microsoftly/BotTester into dev
microsoftly Oct 6, 2017
c1cddcf
added ignoreInternalSaveMessage option
microsoftly Oct 6, 2017
d38828a
Add internal save ignore option (#35)
microsoftly Oct 6, 2017
634d8ec
Merge branch 'dev' of github.com:microsoftly/BotTester into dev
microsoftly Oct 6, 2017
0d1ee2f
v3.2.0
microsoftly Oct 6, 2017
a47bef5
Merge branch 'master' of github.com:microsoftly/BotTester into dev
microsoftly Oct 6, 2017
be8c307
fixed a redundant definition that came from a recursive merge strategy
microsoftly Oct 6, 2017
af4b954
fix spelling error with ignoreInternalSaveMessage (#38)
microsoftly Oct 11, 2017
9602372
3.2.1
microsoftly Oct 11, 2017
d753c30
Merge branch 'dev' of github.com:microsoftly/BotTester into dev
microsoftly Oct 11, 2017
c2d754d
Merge branch 'master' of github.com:microsoftly/BotTester into dev
microsoftly Oct 11, 2017
5b1b84f
remove typescript notation from docs
microsoftly Oct 11, 2017
08c78d2
forcibly remove docs folder when building typeDocs
microsoftly Oct 11, 2017
7f0a476
3.2.2
microsoftly Oct 11, 2017
6b2e716
Merge branch 'master' of github.com:microsoftly/BotTester into dev
microsoftly Oct 11, 2017
e1be08f
add adaptive cards (and attachment) support (#44)
microsoftly Dec 7, 2017
60e637c
v3.3.0
microsoftly Dec 7, 2017
587d07b
Merge branch 'master' of github.com:microsoftly/BotTester into dev
microsoftly Dec 7, 2017
04f6abe
make config.ts export getConfig function (#49)
microsoftly Dec 21, 2017
f34cfd5
Add default timeout to loaded files (#53)
microsoftly Jan 19, 2018
3a5c2d8
Show custom error messages (#52)
santiagodoldan Jan 19, 2018
3f979ef
Merge branch 'master' of github.com:microsoftly/BotTester into dev
microsoftly Jan 22, 2018
5102ffe
V3.3.1
microsoftly Jan 22, 2018
ad3c00f
Merge branch 'dev' of github.com:microsoftly/BotTester into dev
microsoftly Jan 22, 2018
d867b87
v3.3.2
microsoftly Jan 22, 2018
153c68e
Merge branch 'master' of github.com:microsoftly/BotTester into dev
microsoftly Jan 24, 2018
5b7f495
create enum for assertion libraries
microsoftly Jan 25, 2018
3fec4be
remove newly deprecated lines
microsoftly Jan 25, 2018
498dfe1
create new bottester expectation class to abstract away underlying im…
microsoftly Jan 25, 2018
cc25ad0
finish propagating configurable message testing
microsoftly Jan 25, 2018
d674732
move test files to directories that will reflect their test runner an…
microsoftly Jan 25, 2018
c50baa3
make local test script check subdirectories
microsoftly Jan 25, 2018
d021dab
update comment to have more detail and give optional string binding i…
microsoftly Jan 25, 2018
0ca8a9f
replace enum type with a weaker string
microsoftly Jan 25, 2018
9a09602
update readme
microsoftly Jan 25, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/BotTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
24 changes: 15 additions & 9 deletions src/ExpectedMessage.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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();
}

/**
Expand All @@ -69,7 +74,7 @@ export class ExpectedMessage {
this.deepMessageMatchCheck(outgoingMessage);
break;
default:
expect(outgoingMessage.type).toEqual('save');
this.internalExpectation.expect(outgoingMessage.type).toEqual('save');
}
}

Expand All @@ -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);
}

/**
Expand All @@ -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();
}

/**
Expand All @@ -128,6 +134,6 @@ export class ExpectedMessage {
this.checkMessageTextForExactStringMatch(outgoingMessage, expectedResponseStrings);
}

expect(expectedResponseCollectionAsIMessage).toDeeplyInclude(outgoingMessage);
this.internalExpectation.expect(expectedResponseCollectionAsIMessage).toDeeplyInclude(outgoingMessage);
}
}
4 changes: 4 additions & 0 deletions src/assertionLibraries/AssertionLibrary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum AssertionLibrary {
AVA = 'ava',
CHAI = 'chai'
}
24 changes: 24 additions & 0 deletions src/assertionLibraries/BotTesterExpectation.ts
Original file line number Diff line number Diff line change
@@ -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: string;

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);
}
}
}
23 changes: 0 additions & 23 deletions src/assertionLibraries/IExpectation.ts
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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);
}
}
15 changes: 15 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IAddress, IMessage } from 'botbuilder';
import * as fs from 'fs';
import { AssertionLibrary } from './assertionLibraries/AssertionLibrary';
import { ignoreInternalSaveMessageFilter } from './builtInMessageFilters';

/**
Expand All @@ -8,6 +9,17 @@ 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
* libraries being developed:
* 1) Ava
*
* to request support for a new assertion library, check this thread and submit a comment
*/
assertionLibrary?: AssertionLibrary | string;
/**
* timeout in milliseconds before a BotTester runner will fail a test (when not overriden)
*/
Expand Down Expand Up @@ -48,6 +60,7 @@ export const NO_TIMEOUT = -1;

const defaultConfig: IConfig = {
timeout: NO_TIMEOUT,
assertionLibrary: AssertionLibrary.CHAI,
defaultAddress: {
channelId: 'console',
user: { id: 'user1', name: 'user1' },
Expand All @@ -74,6 +87,8 @@ export function getConfig(): IConfig {

configInternal.messageFilters = [];

configInternal.assertionLibrary = configInternal.assertionLibrary || AssertionLibrary.CHAI;

if (configInternal.ignoreInternalSaveMessage) {
configInternal.messageFilters.push(ignoreInternalSaveMessageFilter);
}
Expand Down
6 changes: 3 additions & 3 deletions test/BotTester.spec.ts → test/mocha/chai/BotTester.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

Expand Down