import { Assertion , Test , TestResult } from './' ; import { failure , success , timeout } from './helpers' ; import { EOL } from 'os' ; export function fourtyFive ( tests ) { const result = { failures : 0 , message : '' } ; return Promise . all ( tests . map ( runTest ( result ) ) ) . then ( ( ) => result ) ; } function runTest ( result ) { return function ( test ) { return timeout ( test . timeout , test . run ( ) ) . then ( verify ( result , test ) , handleFailure ( result , test ) ) ; } ; } function verify ( result , test ) { return function ( assertion ) { assertion . verify ( { success ( ) { result . message += EOL + success ( test ) . trim ( ) + EOL ; } , failure ( message ) { result . failures += 1 ; result . message += EOL + failure ( test , message ) . trim ( ) + EOL ; } , } ) ; } ; } function handleFailure ( result , test ) { return function ( err ) { result . failures += 1 ; result . message += failure ( test , err ) . trim ( ) + EOL ; } ; }