import { IVirtualDeviceTestSequence , IVirtualDeviceValidatorResult , IVirtualDeviceValidatorResultItem , Validator , ValidatorError , VirtualDeviceValidator , } from "./VirtualDeviceValidator" ; export class SequencedValidator extends VirtualDeviceValidator { protected async executeSequence ( sequence , result , context ? ) { const virtualDevice = this . virtualDevice ( sequence ) ; await virtualDevice . waitForSessionToEnd ( ) ; for ( const test of sequence . tests ) { try { const resultItem = { test } ; resultItem . status = "running" ; const validator = new Validator ( resultItem , undefined ) ; this . emit ( "message" , undefined , validator . resultItem , context ) ; let phrases = [ ] ; if ( test . expected && test . expected . transcript ) { if ( Array . isArray ( test . expected . transcript ) ) { phrases = test . expected . transcript as string [ ] ; } else if ( test . expected . transcript ) { phrases . push ( test . expected . transcript ) ; } } resultItem . actual = await virtualDevice . message ( test . input , false , phrases , test . sequenceIndex === 1 ) ; const errors = validator . check ( ) ; validator . resultItem . errors = errors ; if ( validator . resultItem && errors . length === 0 ) { validator . resultItem . result = "success" ; } else { validator . resultItem . result = "failure" ; } validator . resultItem . status = "done" ; result . tests . push ( validator . resultItem ) ; this . emit ( "result" , undefined , validator . resultItem , context ) ; } catch ( err ) { let newError = err instanceof Error ? err : undefined ; if ( ! newError ) { const parsedError = this . parseError ( err ) ; if ( parsedError && parsedError . results ) { newError = new Error ( parsedError . results ) ; } else { newError = new Error ( this . getError ( err ) ) ; } } const resultItem = { test } ; const validator = new Validator ( resultItem , newError ) ; validator . resultItem . result = "failure" ; validator . resultItem . status = "done" ; const error = new ValidatorError ( test . input , undefined , undefined , `SystemError: ${ newError . message }` ) ; validator . resultItem . errors = [ error ] ; result . tests . push ( validator . resultItem ) ; this . emit ( "result" , undefined , validator . resultItem , context ) ; } } } }