Moved history out of TestRun

master
Mike Gerwitz 2012-03-03 14:04:36 -05:00
parent 0fce660eb0
commit c720fc6154
3 changed files with 35 additions and 17 deletions

View File

@ -30,12 +30,6 @@ rectest.TestRun = Class( 'TestRun',
*/ */
'private _setPos': 0, 'private _setPos': 0,
/**
* History of each returned element id
* @var {Array.<string>}
*/
'private _history': [],
__construct: function( test_case, options ) __construct: function( test_case, options )
{ {
@ -108,16 +102,12 @@ rectest.TestRun = Class( 'TestRun',
// infinite number of samples) // infinite number of samples)
if ( this._samplesRemain-- === 0 ) if ( this._samplesRemain-- === 0 )
{ {
console.log( this._history );
return null; return null;
} }
// return element from set (do not shift/pop, since we may need to // return element from set (do not shift/pop, since we may need to
// repeatedly iterate through this list) // repeatedly iterate through this list)
var val = this._set[ this._setPos++ ]; return this._set[ this._setPos++ ];
this._history.push( val );
return val;
}, },

View File

@ -1,5 +1,5 @@
/** /**
* Runs a given test configuration * Runs a given test configuration, returning the samples displayed to the user
*/ */
rectest.TestRunner = Class( 'TestRunner', rectest.TestRunner = Class( 'TestRunner',
{ {
@ -21,6 +21,18 @@ rectest.TestRunner = Class( 'TestRunner',
*/ */
'private _$dest': '', 'private _$dest': '',
/**
* History for the current/last run
* @var {Array.<Object>}
*/
'private _history': [],
/**
* Function to call with results when test run is complete
* @var {function(Array.<Object>)}
*/
'private _callback': null,
/** /**
* Initialize with jQuery instance * Initialize with jQuery instance
@ -55,23 +67,33 @@ rectest.TestRunner = Class( 'TestRunner',
* @param {TestCase} test_case test case to be run * @param {TestCase} test_case test case to be run
* @param {Object} options configuration options * @param {Object} options configuration options
* *
* @param {=function(Array.<Object>)} callback completion callback for
* results array
*
* @return {TestRunner} self * @return {TestRunner} self
*/ */
'public run': function( test_case, options ) 'public run': function( test_case, options, callback )
{ {
options = options || {};
if ( !( easejs.Class.isA( rectest.TestCase, test_case ) ) ) if ( !( easejs.Class.isA( rectest.TestCase, test_case ) ) )
{ {
throw TypeError( "Invalid test case: " + test_case ); throw TypeError( "Invalid test case: " + test_case );
} }
var _self = this; // clear history from any previous runs
this._history = [];
this._callback = callback || function() {};
var _self = this,
run = _self._TestRun( test_case, options );
// start test after the given delay // start test after the given delay
setTimeout( function() setTimeout( function()
{ {
_self._startInterval( _self._startInterval(
test_case, test_case,
_self._TestRun( test_case, options ), run,
( parseFloat( options.interval ) * 1000 ), ( parseFloat( options.interval ) * 1000 ),
( parseFloat( options.blank ) * 1000 ) ( parseFloat( options.blank ) * 1000 )
); );
@ -137,6 +159,7 @@ rectest.TestRunner = Class( 'TestRunner',
if ( ( next = run.getNextElement() ) !== null ) if ( ( next = run.getNextElement() ) !== null )
{ {
// render this element // render this element
this._history.push( next );
test_case.render( next, this._$dest ); test_case.render( next, this._$dest );
} }
@ -147,7 +170,7 @@ rectest.TestRunner = Class( 'TestRunner',
'private _complete': function( run ) 'private _complete': function( run )
{ {
this._hideDest(); this._hideDest();
console.log( 'done' ); this._callback( this._history );
}, },

View File

@ -33,7 +33,12 @@ $( document ).ready( function()
var testcase = rectest.cases[ options['case'] ].testCase(); var testcase = rectest.cases[ options['case'] ].testCase();
$( this ).parent().hide(); $( this ).parent().hide();
runner.run( testcase, options );
runner.run( testcase, options, function( history )
{
console.log( history );
console.log( 'done' );
} );
} ); } );
function displayNotice( str ) function displayNotice( str )