import { Activity } from "../activities" ; import { Command } from "../commands" ; import * as events from "../events" ; import { StopWatch } from "./stopwatch" ; /** Statistics about a run of Text-Runner */ interface ActivityResult { readonly activity ? : Activity ; readonly error ? : Error ; readonly finalName ? : string ; readonly message ? : string ; readonly output ? : string ; readonly status : events . ResultStatus ; } export class ActivityResults extends Array < ActivityResult > { readonly duration : string ; constructor ( results , duration ) { super ( ) ; this . push ( ... results ) ; this . duration = duration ; } errors ( ) { const result = [ ] ; for ( const res of this ) { if ( res . error ) { result . push ( res . error ) ; } } return result ; } errorCount ( ) { return this . errors ( ) . length ; } } /** ActivityCollector provides statistics about the Text-Runner command it observes. */ export class ActivityCollector { activities : ActivityResult [ ] ; stopWatch : StopWatch ; constructor ( command ) { this . activities = [ ] ; this . stopWatch = new StopWatch ( ) ; command . on ( "result" , this . onResult . bind ( this ) ) ; } onResult ( result ) { this . activities . push ( result ) ; } results ( ) { return new ActivityResults ( this . activities , this . stopWatch . duration ( ) ) ; } }