import { TestStatus } from '../testStatus' ; import { TestVisitor } from './visitors/testVisitor' ; import { TestyConfig } from '../interfaces/config' ; export class TestInstance { public get name ( ) { return this . _name ; } public get status ( ) { return this . _status ; } public get func ( ) { return this . _func ; } param func param status constructor ( private _name , private _func , private _status , private timeout ? ) { } public async run ( context , config ) { return await new Promise < void > ( async ( resolve , reject ) => { try { let timeout = 2000 ; if ( config ?. timeout != null ) { timeout = config . timeout ; } if ( this . timeout != null ) { timeout = this . timeout ; } const nodeTimeout = setTimeout ( ( ) => reject ( 'Test has timed out.' ) , timeout ) ; try { await this . func ( context ) ; } finally { clearTimeout ( nodeTimeout ) ; } } catch ( err ) { reject ( err ) ; } resolve ( ) ; } ) ; } public async accept < T > ( visitor ) { return await visitor . visitTest ( this ) ; } public clone ( ) { return new TestInstance ( this . name , this . _func , this . _status , this . timeout ) ; } }