From c720fc6154edcbf262eca9bbea709755f7aae68d Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sat, 3 Mar 2012 14:04:36 -0500 Subject: [PATCH] Moved history out of TestRun --- scripts/TestRun.js | 12 +----------- scripts/TestRunner.js | 33 ++++++++++++++++++++++++++++----- scripts/main.js | 7 ++++++- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/scripts/TestRun.js b/scripts/TestRun.js index e7bab50..c310d5e 100644 --- a/scripts/TestRun.js +++ b/scripts/TestRun.js @@ -30,12 +30,6 @@ rectest.TestRun = Class( 'TestRun', */ 'private _setPos': 0, - /** - * History of each returned element id - * @var {Array.} - */ - 'private _history': [], - __construct: function( test_case, options ) { @@ -108,16 +102,12 @@ rectest.TestRun = Class( 'TestRun', // infinite number of samples) if ( this._samplesRemain-- === 0 ) { - console.log( this._history ); return null; } // return element from set (do not shift/pop, since we may need to // repeatedly iterate through this list) - var val = this._set[ this._setPos++ ]; - this._history.push( val ); - - return val; + return this._set[ this._setPos++ ]; }, diff --git a/scripts/TestRunner.js b/scripts/TestRunner.js index 64c6ba3..7073a78 100644 --- a/scripts/TestRunner.js +++ b/scripts/TestRunner.js @@ -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', { @@ -21,6 +21,18 @@ rectest.TestRunner = Class( 'TestRunner', */ 'private _$dest': '', + /** + * History for the current/last run + * @var {Array.} + */ + 'private _history': [], + + /** + * Function to call with results when test run is complete + * @var {function(Array.)} + */ + 'private _callback': null, + /** * Initialize with jQuery instance @@ -55,23 +67,33 @@ rectest.TestRunner = Class( 'TestRunner', * @param {TestCase} test_case test case to be run * @param {Object} options configuration options * + * @param {=function(Array.)} callback completion callback for + * results array + * * @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 ) ) ) { 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 setTimeout( function() { _self._startInterval( test_case, - _self._TestRun( test_case, options ), + run, ( parseFloat( options.interval ) * 1000 ), ( parseFloat( options.blank ) * 1000 ) ); @@ -137,6 +159,7 @@ rectest.TestRunner = Class( 'TestRunner', if ( ( next = run.getNextElement() ) !== null ) { // render this element + this._history.push( next ); test_case.render( next, this._$dest ); } @@ -147,7 +170,7 @@ rectest.TestRunner = Class( 'TestRunner', 'private _complete': function( run ) { this._hideDest(); - console.log( 'done' ); + this._callback( this._history ); }, diff --git a/scripts/main.js b/scripts/main.js index 3bfe229..bb2b04e 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -33,7 +33,12 @@ $( document ).ready( function() var testcase = rectest.cases[ options['case'] ].testCase(); $( this ).parent().hide(); - runner.run( testcase, options ); + + runner.run( testcase, options, function( history ) + { + console.log( history ); + console.log( 'done' ); + } ); } ); function displayNotice( str )