Fix issue 247 and flesh out its regression test.
[dygraphs.git] / auto_tests / misc / fake-jstestdriver.js
index 702f3d4..4a9b0ea 100644 (file)
@@ -36,8 +36,9 @@ var jstd = {
   }
 };
 
+var testCaseList = [];
+
 function TestCase(name) {
-  jstd.sucker("Not really creating TestCase(" + name + ")");
   this.name = name;
   this.toString = function() {
     return "Fake test case " + name;
@@ -95,5 +96,35 @@ function TestCase(name) {
     }
     console.log(prettyPrintEntity_(tests));
   };
+
+  testCaseList.push(testCase);
   return testCase;
 };
+
+// Note: this creates a bunch of global variables intentionally.
+function addGlobalTestSymbols() {
+  globalTestDb = {};  // maps test name -> test function wrapper
+
+  var num_tests = 0;
+  for (var i = 0; i < testCaseList.length; i++) {
+    var tc_class = testCaseList[i];
+    for (var name in tc_class.prototype) {
+      if (name.indexOf('test') == 0 && typeof(tc_class.prototype[name]) == 'function') {
+        if (globalTestDb.hasOwnProperty(name)) {
+          console.log('Duplicated test name: ' + name);
+        } else {
+          globalTestDb[name] = function(name, tc_class) {
+            return function() {
+              var tc = new tc_class;
+              return tc.runTest(name);
+            };
+          }(name, tc_class);
+          eval(name + " = globalTestDb['" + name + "'];");
+          num_tests += 1;
+        }
+      }
+    }
+  }
+  console.log('Loaded ' + num_tests + ' tests in ' +
+              testCaseList.length + ' test cases');
+}