Fix & regression test for issue 363: Calling setSelection() after an updateOptions...
[dygraphs.git] / auto_tests / misc / fake-jstestdriver.js
index 4a9b0ea..6f4f464 100644 (file)
@@ -27,6 +27,14 @@ var jstestdriver = {
   jQuery : jQuery
 };
 
+if (!console) {
+  var console = {
+    log: function(x) {
+      // ...
+    }
+  };
+}
+
 var jstd = {
   include : function(name) {
     this.sucker("Not including " + name);
@@ -39,12 +47,12 @@ var jstd = {
 var testCaseList = [];
 
 function TestCase(name) {
-  this.name = name;
-  this.toString = function() {
+  var testCase = function() { return this; };
+  testCase.name = name;
+  testCase.toString = function() {
     return "Fake test case " + name;
   };
 
-  var testCase = function() { return this; };
   testCase.prototype.setUp = function() { };
   testCase.prototype.tearDown = function() { };
   /**
@@ -84,20 +92,32 @@ function TestCase(name) {
       return false;
     }
   };
+
   testCase.prototype.runAllTests = function() {
+    var results = {};
+    var names = this.getTestNames();
+    for (var idx in names) {
+      var name = names[idx];
+      console.log("Running " + name);
+      var result = this.runTest(name);
+      results[name] = result;
+    }
+    console.log(prettyPrintEntity_(results));
+    return results;
+  };
+
+  testCase.prototype.getTestNames = function() {
     // what's better than for ... in for non-array objects?
-    var tests = {};
+    var tests = [];
     for (var name in this) {
       if (name.indexOf('test') == 0 && typeof(this[name]) == 'function') {
-        console.log("Running " + name);
-        var result = this.runTest(name);
-        tests[name] = result;
+        tests.push(name);
       }
     }
-    console.log(prettyPrintEntity_(tests));
-  };
+    return tests;
+  }
 
-  testCaseList.push(testCase);
+  testCaseList.push({name : name, testCase : testCase});
   return testCase;
 };
 
@@ -107,7 +127,7 @@ function addGlobalTestSymbols() {
 
   var num_tests = 0;
   for (var i = 0; i < testCaseList.length; i++) {
-    var tc_class = testCaseList[i];
+    var tc_class = testCaseList[i].testCase;
     for (var name in tc_class.prototype) {
       if (name.indexOf('test') == 0 && typeof(tc_class.prototype[name]) == 'function') {
         if (globalTestDb.hasOwnProperty(name)) {
@@ -128,3 +148,7 @@ function addGlobalTestSymbols() {
   console.log('Loaded ' + num_tests + ' tests in ' +
               testCaseList.length + ' test cases');
 }
+
+function getAllTestCases() {
+  return testCaseList;
+}