import { Runner , TestMeta } from './runner' ; import { Client } from './clients/client_interface' ; import { Config , ClientType } from './config' ; import { BotFrameworkClient } from './clients/botframework_client' ; import { Dialogue } from './spec/dialogue' ; import { Message } from './spec/message' ; import { DialogueInvalidError } from './spec/dialogue_invalid_error' ; import { Translator } from './translator' ; import { updateSchema } from './pretty_printer' ; import * as fs from 'fs' ; import * as glob from 'glob' ; import * as path from 'path' ; import * as program from 'commander' ; export function getRunners ( dialoguePath , config ) { const dialogueFileInfo = fs . lstatSync ( dialoguePath ) ; let dialogues ; if ( dialogueFileInfo . isDirectory ( ) ) { dialogues = glob . sync ( '**/*.yml' , { cwd : dialoguePath , } ) . map ( x => path . join ( dialoguePath , x ) ) . map ( ( filepath ) => { return isDialogue ( filepath , config ) ? filepath : null ; } ) . filter ( x => x ) ; if ( dialogues . length === 0 ) { throw new Error ( 'No test files found on path' ) ; } } else if ( dialogueFileInfo . isFile ( ) ) { dialogues = [ dialoguePath ] ; } else { throw new DialogueInvalidError ( `${ dialoguePath } does not exist` ) ; } const runners = dialogues . map ( ( dpath ) => { return new Runner ( createClient ( config ) , dpath , config ) ; } ) . sort ( ( a , b ) : number => { return a . dialogues [ 0 ] . title . toLowerCase ( ) < b . dialogues [ 0 ] . title . toLowerCase ( ) ? - 1 : 1 ; } ) ; const minWidth = runners . reduce ( ( a , n ) => { const titleLength = n . dialogues [ 0 ] . title . length ; return titleLength > a ? titleLength : a ; } , 0 ) ; runners . forEach ( r => r . minWidth = minWidth ) ; runners . forEach ( r => r . createProgressBar ( ) ) ; return runners ; } function createClient ( config ) { if ( config . client === ClientType . BotFramework ) { const dom = program . dom ; return new BotFrameworkClient ( config . directLineSecret , dom ) ; } else { console . log ( 'ERROR: unsupported client' , config . client ) ; process . exit ( 1 ) ; } } function isDialogue ( filepath , config ) { try { const dialogue = new Dialogue ( filepath , config . preamble ) ; return true ; } catch ( e ) { if ( e instanceof DialogueInvalidError ) { return false ; } else { throw e ; } } }