/** * Runs a given test configuration */ rectest.TestRunner = Class( 'TestRunner', { /** * jQuery instance * @var {jQuery} */ 'private _jQuery': null, /** * TestRun constructor * @var {Function} */ 'private _TestRun': null, /** * Render destination element * @var {jQuery} */ 'private _$dest': '', /** * Initialize with jQuery instance * * @param {jQuery} jquery jQuery instance * @param {Function} TestRun TestRun constructor */ __construct: function( jquery, TestRun ) { this._jQuery = jquery; this._TestRun = TestRun; this._$dest = this._createDestElement(); }, /** * Create the element to which all test cases will render * * @return {jQuery} destination element for all renderings */ 'private _createDestElement': function() { return this._jQuery( '
' ) .addClass( 'render' ) .text( 'test' ); }, /** * Run the provided test case * * @param {TestCase} test_case test case to be run * @param {Object} options configuration options * * @return {TestRunner} self */ 'public run': function( test_case, options ) { if ( !( easejs.Class.isA( rectest.TestCase, test_case ) ) ) { throw TypeError( "Invalid test case: " + test_case ); } var _self = this; // start test after the given delay setTimeout( function() { _self._startInterval( test_case, _self._TestRun( test_case, options ), ( parseFloat( options.interval ) * 1000 ), ( parseFloat( options.blank ) * 1000 ) ); }, ( parseFloat( options.delay ) * 1000 ) ); return this; }, 'private _startInterval': function( test_case, run, interval, blank ) { var _self = this, render = function( noblank ) { // blank if a blank period was provided as it was not // suppressed if ( blank && !noblank ) { _self._blank(); setTimeout( function() { // render withour blank period render( true ); }, blank ); return; } // continuously render so long as we have another element if ( _self._renderNext( test_case, run ) !== null ) { setTimeout( function() { render(); }, interval ); } else _self._complete( run ); }; this._showDest(); // begin rendering; we will render the first element immediately and // all subsequent elements will be subject to to the blank period // and interval render( true ); }, 'private _blank': function() { // clear dest element this._$dest.html( '' ); }, 'private _renderNext': function( test_case, run ) { var next; // if there is no next element, then we have retrieved the requested // number of samples if ( ( next = run.getNextElement() ) !== null ) { // render this element test_case.render( next, this._$dest ); } return next; }, 'private _complete': function( run ) { this._hideDest(); console.log( 'done' ); }, 'private _showDest': function() { this._jQuery( 'body' ).append( this._$dest ); }, 'private _hideDest': function() { this._$dest.detach(); this._blank(); } } );