Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions src/BotTester.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
31 changes: 21 additions & 10 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
}