test\harness\helper.js: extended the 'finished' method to accept as input the total elapsed execution time

of the tests.  Emit this to the activity bar


test\harness\sta.js:  too many years of Python had me thinking JavaScript arrays have an append method:)  Fixed.
                      Also, added a pickled representation of all test helper functions found in this file


test\harness\sth.js:  detached most test helper functions from the iframe's document object (as globals) and
                      inject these into the actual test cases. It's a bit slower and not as elegant, but it is
                      cleaner from an ES5 purist perspective.  Still need to move Sputnik helper functions into
                      sta.js

                      Extended Controller such that it now measures overall test execution time.  Such a change
                      is very useful for measuring performance-impact changes such as the aforementioned
                      improvement
This commit is contained in:
David Fugate 2011-02-03 16:28:52 -08:00
parent 2ec3b287d7
commit e4d4a7a870
6 changed files with 58 additions and 44 deletions

View File

@ -289,9 +289,9 @@ function Presenter() {
renderCurrentSection(); renderCurrentSection();
} }
this.finished = function() { this.finished = function(elapsed) {
$('.button-start').attr('src', 'resources/images/start.png'); $('.button-start').attr('src', 'resources/images/start.png');
activityBar.text(''); activityBar.text('Overall Execution Time: ' + elapsed + ' minutes');
} }
/* Refresh display of the report */ /* Refresh display of the report */

View File

@ -38,7 +38,7 @@ function compareArray(aExpected, aActual) {
} }
return true; return true;
} }
SimpleTestAPIs.append(compareArray); SimpleTestAPIs.push(compareArray);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
function arrayContains(arr, expected) { function arrayContains(arr, expected) {
@ -57,7 +57,7 @@ function arrayContains(arr, expected) {
} }
return true; return true;
} }
SimpleTestAPIs.append(arrayContains); SimpleTestAPIs.push(arrayContains);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
var supportsArrayIndexGettersOnArrays = undefined; var supportsArrayIndexGettersOnArrays = undefined;
@ -81,7 +81,7 @@ function fnSupportsArrayIndexGettersOnArrays() {
return supportsArrayIndexGettersOnArrays; return supportsArrayIndexGettersOnArrays;
} }
SimpleTestAPIs.append(fnSupportsArrayIndexGettersOnArrays); SimpleTestAPIs.push(fnSupportsArrayIndexGettersOnArrays);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
var supportsArrayIndexGettersOnObjects = undefined; var supportsArrayIndexGettersOnObjects = undefined;
@ -104,13 +104,13 @@ function fnSupportsArrayIndexGettersOnObjects() {
return supportsArrayIndexGettersOnObjects; return supportsArrayIndexGettersOnObjects;
} }
SimpleTestAPIs.append(fnSupportsArrayIndexGettersOnObjects); SimpleTestAPIs.push(fnSupportsArrayIndexGettersOnObjects);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
function ConvertToFileUrl(pathStr) { function ConvertToFileUrl(pathStr) {
return "file:" + pathStr.replace(/\\/g, "/"); return "file:" + pathStr.replace(/\\/g, "/");
} }
SimpleTestAPIs.append(ConvertToFileUrl); SimpleTestAPIs.push(ConvertToFileUrl);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
function fnExists(/*arguments*/) { function fnExists(/*arguments*/) {
@ -119,7 +119,7 @@ function fnExists(/*arguments*/) {
} }
return true; return true;
} }
SimpleTestAPIs.append(fnExists); SimpleTestAPIs.push(fnExists);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
var supportsStrict = undefined; var supportsStrict = undefined;
@ -137,13 +137,13 @@ function fnSupportsStrict() {
} }
return supportsStrict; return supportsStrict;
} }
SimpleTestAPIs.append(fnSupportsStrict); SimpleTestAPIs.push(fnSupportsStrict);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
function fnGlobalObject() { function fnGlobalObject() {
return (function() { return this }).call(null); return (function() { return this }).call(null);
} }
SimpleTestAPIs.append(fnGlobalObject); SimpleTestAPIs.push(fnGlobalObject);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//Verify all attributes specified data property of given object: value, writable, enumerable, configurable //Verify all attributes specified data property of given object: value, writable, enumerable, configurable
@ -207,7 +207,7 @@ function dataPropertyAttributesAreCorrect(obj, name, value, writable, enumerable
return attributesCorrect; return attributesCorrect;
} }
SimpleTestAPIs.append(dataPropertyAttributesAreCorrect); SimpleTestAPIs.push(dataPropertyAttributesAreCorrect);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//Verify all attributes specified accessor property of given object: get, set, enumerable, configurable //Verify all attributes specified accessor property of given object: get, set, enumerable, configurable
@ -273,4 +273,6 @@ function accessorPropertyAttributesAreCorrect(obj, name, get, set, setVerifyHelp
return attributesCorrect; return attributesCorrect;
} }
SimpleTestAPIs.append(accessorPropertyAttributesAreCorrect); SimpleTestAPIs.push(accessorPropertyAttributesAreCorrect);
//-----------------------------------------------------------------------------
var PickledSimpleTestAPIs = SimpleTestAPIs.join(" ");

View File

@ -91,20 +91,12 @@ function BrowserRunner() {
// Set up some globals. // Set up some globals.
win.testRun = testRun; win.testRun = testRun;
win.testFinished = testFinished; win.testFinished = testFinished;
win.fnSupportsStrict = fnSupportsStrict; //TODO: these should be moved to sta.js
win.fnExists = fnExists;
win.ConvertToFileUrl = ConvertToFileUrl;
win.fnSupportsArrayIndexGettersOnObjects = fnSupportsArrayIndexGettersOnObjects;
win.fnSupportsArrayIndexGettersOnArrays = fnSupportsArrayIndexGettersOnArrays;
win.arrayContains = arrayContains;
win.compareArray = compareArray;
win.SputnikError = SputnikError; win.SputnikError = SputnikError;
win.$ERROR = $ERROR; win.$ERROR = $ERROR;
win.$FAIL = $FAIL; win.$FAIL = $FAIL;
win.$PRINT = function () {}; win.$PRINT = function () {};
win.$INCLUDE = function() {}; win.$INCLUDE = function() {};
win.dataPropertyAttributesAreCorrect = dataPropertyAttributesAreCorrect;
win.accessorPropertyAttributesAreCorrect = accessorPropertyAttributesAreCorrect;
if(includes !== null) { if(includes !== null) {
// We have some includes, so loop through each include and pull in the dependencies. // We have some includes, so loop through each include and pull in the dependencies.
@ -125,6 +117,10 @@ function BrowserRunner() {
} }
} }
//Write out all of our helper functions
doc.writeln("<script type='text/javascript'>" + PickledSimpleTestAPIs + "</script>");
// Write ES5Harness.registerTest and fnGlobalObject, which returns the global object, and the testFinished call. // Write ES5Harness.registerTest and fnGlobalObject, which returns the global object, and the testFinished call.
doc.writeln("<script type='text/javascript'>ES5Harness = {};" + doc.writeln("<script type='text/javascript'>ES5Harness = {};" +
"function fnGlobalObject() { return window; }" + "function fnGlobalObject() { return window; }" +
@ -243,6 +239,8 @@ function Controller() {
var runner = new BrowserRunner(); var runner = new BrowserRunner();
var loader = new TestLoader(); var loader = new TestLoader();
var controller = this; var controller = this;
var startTime;
var elapsed = 0;
runner.onComplete = function(test) { runner.onComplete = function(test) {
presenter.addTestResult(test); presenter.addTestResult(test);
@ -268,21 +266,28 @@ function Controller() {
loader.onTestsExhausted = function() { loader.onTestsExhausted = function() {
state = 'stopped'; state = 'stopped';
presenter.finished(); elapsed += new Date() - startTime;
elapsed = elapsed/(1000*60); //minutes
elapsed = elapsed.toFixed(1);
presenter.finished(elapsed);
} }
this.start = function() { this.start = function() {
state = 'running'; state = 'running';
startTime = new Date();
loader.getNextTest(); loader.getNextTest();
presenter.started(); presenter.started();
} }
this.pause = function() { this.pause = function() {
elapsed += new Date() - startTime;
state = 'paused'; state = 'paused';
presenter.paused(); presenter.paused();
} }
this.reset = function() { this.reset = function() {
startTime = new Date();
elapsed = 0;
loader.reset(); loader.reset();
presenter.reset(); presenter.reset();
} }

View File

@ -289,9 +289,9 @@ function Presenter() {
renderCurrentSection(); renderCurrentSection();
} }
this.finished = function() { this.finished = function(elapsed) {
$('.button-start').attr('src', 'resources/images/start.png'); $('.button-start').attr('src', 'resources/images/start.png');
activityBar.text(''); activityBar.text('Overall Execution Time: ' + elapsed + ' minutes');
} }
/* Refresh display of the report */ /* Refresh display of the report */

View File

@ -38,7 +38,7 @@ function compareArray(aExpected, aActual) {
} }
return true; return true;
} }
SimpleTestAPIs.append(compareArray); SimpleTestAPIs.push(compareArray);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
function arrayContains(arr, expected) { function arrayContains(arr, expected) {
@ -57,7 +57,7 @@ function arrayContains(arr, expected) {
} }
return true; return true;
} }
SimpleTestAPIs.append(arrayContains); SimpleTestAPIs.push(arrayContains);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
var supportsArrayIndexGettersOnArrays = undefined; var supportsArrayIndexGettersOnArrays = undefined;
@ -81,7 +81,7 @@ function fnSupportsArrayIndexGettersOnArrays() {
return supportsArrayIndexGettersOnArrays; return supportsArrayIndexGettersOnArrays;
} }
SimpleTestAPIs.append(fnSupportsArrayIndexGettersOnArrays); SimpleTestAPIs.push(fnSupportsArrayIndexGettersOnArrays);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
var supportsArrayIndexGettersOnObjects = undefined; var supportsArrayIndexGettersOnObjects = undefined;
@ -104,13 +104,13 @@ function fnSupportsArrayIndexGettersOnObjects() {
return supportsArrayIndexGettersOnObjects; return supportsArrayIndexGettersOnObjects;
} }
SimpleTestAPIs.append(fnSupportsArrayIndexGettersOnObjects); SimpleTestAPIs.push(fnSupportsArrayIndexGettersOnObjects);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
function ConvertToFileUrl(pathStr) { function ConvertToFileUrl(pathStr) {
return "file:" + pathStr.replace(/\\/g, "/"); return "file:" + pathStr.replace(/\\/g, "/");
} }
SimpleTestAPIs.append(ConvertToFileUrl); SimpleTestAPIs.push(ConvertToFileUrl);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
function fnExists(/*arguments*/) { function fnExists(/*arguments*/) {
@ -119,7 +119,7 @@ function fnExists(/*arguments*/) {
} }
return true; return true;
} }
SimpleTestAPIs.append(fnExists); SimpleTestAPIs.push(fnExists);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
var supportsStrict = undefined; var supportsStrict = undefined;
@ -137,13 +137,13 @@ function fnSupportsStrict() {
} }
return supportsStrict; return supportsStrict;
} }
SimpleTestAPIs.append(fnSupportsStrict); SimpleTestAPIs.push(fnSupportsStrict);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
function fnGlobalObject() { function fnGlobalObject() {
return (function() { return this }).call(null); return (function() { return this }).call(null);
} }
SimpleTestAPIs.append(fnGlobalObject); SimpleTestAPIs.push(fnGlobalObject);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//Verify all attributes specified data property of given object: value, writable, enumerable, configurable //Verify all attributes specified data property of given object: value, writable, enumerable, configurable
@ -207,7 +207,7 @@ function dataPropertyAttributesAreCorrect(obj, name, value, writable, enumerable
return attributesCorrect; return attributesCorrect;
} }
SimpleTestAPIs.append(dataPropertyAttributesAreCorrect); SimpleTestAPIs.push(dataPropertyAttributesAreCorrect);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//Verify all attributes specified accessor property of given object: get, set, enumerable, configurable //Verify all attributes specified accessor property of given object: get, set, enumerable, configurable
@ -273,4 +273,6 @@ function accessorPropertyAttributesAreCorrect(obj, name, get, set, setVerifyHelp
return attributesCorrect; return attributesCorrect;
} }
SimpleTestAPIs.append(accessorPropertyAttributesAreCorrect); SimpleTestAPIs.push(accessorPropertyAttributesAreCorrect);
//-----------------------------------------------------------------------------
var PickledSimpleTestAPIs = SimpleTestAPIs.join(" ");

View File

@ -91,20 +91,12 @@ function BrowserRunner() {
// Set up some globals. // Set up some globals.
win.testRun = testRun; win.testRun = testRun;
win.testFinished = testFinished; win.testFinished = testFinished;
win.fnSupportsStrict = fnSupportsStrict; //TODO: these should be moved to sta.js
win.fnExists = fnExists;
win.ConvertToFileUrl = ConvertToFileUrl;
win.fnSupportsArrayIndexGettersOnObjects = fnSupportsArrayIndexGettersOnObjects;
win.fnSupportsArrayIndexGettersOnArrays = fnSupportsArrayIndexGettersOnArrays;
win.arrayContains = arrayContains;
win.compareArray = compareArray;
win.SputnikError = SputnikError; win.SputnikError = SputnikError;
win.$ERROR = $ERROR; win.$ERROR = $ERROR;
win.$FAIL = $FAIL; win.$FAIL = $FAIL;
win.$PRINT = function () {}; win.$PRINT = function () {};
win.$INCLUDE = function() {}; win.$INCLUDE = function() {};
win.dataPropertyAttributesAreCorrect = dataPropertyAttributesAreCorrect;
win.accessorPropertyAttributesAreCorrect = accessorPropertyAttributesAreCorrect;
if(includes !== null) { if(includes !== null) {
// We have some includes, so loop through each include and pull in the dependencies. // We have some includes, so loop through each include and pull in the dependencies.
@ -125,6 +117,10 @@ function BrowserRunner() {
} }
} }
//Write out all of our helper functions
doc.writeln("<script type='text/javascript'>" + PickledSimpleTestAPIs + "</script>");
// Write ES5Harness.registerTest and fnGlobalObject, which returns the global object, and the testFinished call. // Write ES5Harness.registerTest and fnGlobalObject, which returns the global object, and the testFinished call.
doc.writeln("<script type='text/javascript'>ES5Harness = {};" + doc.writeln("<script type='text/javascript'>ES5Harness = {};" +
"function fnGlobalObject() { return window; }" + "function fnGlobalObject() { return window; }" +
@ -243,6 +239,8 @@ function Controller() {
var runner = new BrowserRunner(); var runner = new BrowserRunner();
var loader = new TestLoader(); var loader = new TestLoader();
var controller = this; var controller = this;
var startTime;
var elapsed = 0;
runner.onComplete = function(test) { runner.onComplete = function(test) {
presenter.addTestResult(test); presenter.addTestResult(test);
@ -268,21 +266,28 @@ function Controller() {
loader.onTestsExhausted = function() { loader.onTestsExhausted = function() {
state = 'stopped'; state = 'stopped';
presenter.finished(); elapsed += new Date() - startTime;
elapsed = elapsed/(1000*60); //minutes
elapsed = elapsed.toFixed(1);
presenter.finished(elapsed);
} }
this.start = function() { this.start = function() {
state = 'running'; state = 'running';
startTime = new Date();
loader.getNextTest(); loader.getNextTest();
presenter.started(); presenter.started();
} }
this.pause = function() { this.pause = function() {
elapsed += new Date() - startTime;
state = 'paused'; state = 'paused';
presenter.paused(); presenter.paused();
} }
this.reset = function() { this.reset = function() {
startTime = new Date();
elapsed = 0;
loader.reset(); loader.reset();
presenter.reset(); presenter.reset();
} }