import { get , omit } from 'lodash' ; import { IFramework } from '@lib/frameworks/framework' ; import { Status } from '@lib/frameworks/status' ; import { Nugget } from '@lib/frameworks/nugget' ; export interface ITest extends Nugget { selected : boolean ; getId ( ) : string ; getStatus ( ) : Status ; getName ( ) : string ; getDisplayName ( ) : string ; toggleSelected ( toggle ? , cascade ? ) : Promise < void > ; toggleExpanded ( toggle ? , cascade ? ) : Promise < void > ; render ( status ? ) : ITestResult ; persist ( status ? ) : ITestResult ; getResult ( ) : ITestResult ; resetResult ( ) : void ; debrief ( result , cleanup ) : Promise < void > ; countChildren ( ) : number ; hasChildren ( ) : boolean ; contextMenu ( ) : Array < Electron . MenuItemConstructorOptions > ; } export interface ITestResult { id : string ; name : string ; displayName ? : string | null ; status : Status ; feedback ? : string | object ; console ? : Array < any > ; params ? : string ; stats ? : object ; isLast ? : boolean ; tests ? : Array < ITestResult > ; hasChildren ? : boolean ; } export class Test extends Nugget implements ITest { protected status ! : Status ; protected result ! : ITestResult ; constructor ( framework , result ) { super ( framework ) ; this . build ( result , false ) ; } param status public render ( status = 'idle' ) { return omit ( { ... this . defaults ( this . result , status ) , hasChildren : this . hasChildren ( ) , selected : this . selected , partial : this . partial } , 'tests' ) ; } param status public persist ( status = 'idle' ) { return this . defaults ( this . result , status ) ; } /**
     * Get this test's result object.
     */ public getResult ( ) { return this . result ; } /**
     * Reset this test's result (i.e. remove feedback etc, as if the
     * test never ran, but persist its identifying data).
     */ public resetResult ( ) { this . result = this . defaults ( this . result ) ; } param result param cleanup protected build ( result , cleanup ) { result . status = this . getRecursiveStatus ( result ) ; this . result = this . mergeResults ( result ) ; if ( result . tests && result . tests . length ) { this . debriefTests ( result . tests , cleanup ) ; } } param result protected mergeResults ( result ) { if ( get ( result , 'stats.first' ) ) { return result ; } result . stats = { ... ( result . stats || { } ) , ... { first : get ( this . result || { } , 'stats.first' , new Date ( ) . toISOString ( ) ) } } ; return result ; } param result protected newTest ( result ) { return new Test ( this . framework , result ) ; } /**
     * Get this test's id.
     */ public getId ( ) { return this . result . id ! ; } /**
     * Get this test's display name.
     */ public getName ( ) { return this . result . name ; } /**
     * Get this test's display name.
     */ public getDisplayName ( ) { return this . result . displayName || this . getName ( ) ; } param result param cleanup public debrief ( result , cleanup ) { result . stats = { ... ( result . stats || { } ) , ... { last : new Date ( ) . toISOString ( ) } } ; return new Promise ( ( resolve , reject ) => { this . build ( result , cleanup ) ; this . updateStatus ( this . result . status || 'idle' ) ; resolve ( ) ; } ) ; } }