import { Assertion , Test , Verification , fourtyFive , pass } from '../' ; import { blue , underline } from 'typed-colors' ; import { calculateTimeout , padNewLine } from '../helpers' ; import { EOL } from 'os' ; export function describe ( thing , tests ) { return new Describe ( thing , tests ) ; } export class Describe implements Test { public name : string ; public showStatus = false ; private _tests : Array < Test > ; private _timeout : number ; constructor ( name , tests ) { this . name = blue ( 'Describe ' ) + underline ( name ) ; this . _tests = tests ; this . _timeout = calculateTimeout ( tests ) ; } get timeout ( ) { return this . _timeout ; } set timeout ( time ) { this . _timeout = calculateTimeout ( this . _tests , time ) ; } public run ( ) { const { _tests } = this ; return fourtyFive ( _tests ) . then ( testResult => { const { message , failures } = testResult ; if ( ! failures ) { this . name += EOL + '  ' + padNewLine ( trimResult ( message ) ) ; return pass ( void 0 ) ; } return { verify ( verification ) { verification . failure ( message ) ; } , } ; } ) ; } } function trimResult ( message ) { return message . replace ( new RegExp ( `[${ EOL }]{3,}` , 'g' ) , '' ) . trim ( ) ; } ;