Fix most warnings in tests; add support for loading (non-auto) tests to phantom-drive...
authorDan Vanderkam <danvk@google.com>
Tue, 10 Apr 2012 22:08:30 +0000 (18:08 -0400)
committerDan Vanderkam <danvk@google.com>
Tue, 10 Apr 2012 22:08:30 +0000 (18:08 -0400)
phantom-driver.js
tests/custom-bars.html
tests/dateWindow.html
tests/fillGraph.html
tests/gviz-infinity.html
tests/independent-series.html
tests/labelsKMB.html
tests/out-of-order.html
tests/plotter.html

index 3b2ae67..009c634 100644 (file)
@@ -4,6 +4,8 @@
 //
 // For more on phantomjs, visit www.phantomjs.org.
 
+var RunAllAutoTests = function(done_callback) {
+
 var page = require('webpage').create();
 
 // NOTE: Cannot include '#' or '?' in this URL.
@@ -94,11 +96,102 @@ page.open(url, function(status) {
     console.log('  ' + failures[i] + ' failed.');
   }
 
-  if (num_failing == 0) {
-    console.log('PASS');
-  } else {
+  done_callback(num_failing, num_passing);
+});
+
+};
+
+// Load all "tests/" pages.
+var LoadAllManualTests = function(totally_done_callback) {
+
+var fs = require('fs');
+var tests = fs.list('tests');
+var pages = [];
+
+function make_barrier_closure(n, fn) {
+  var calls = 0;
+  return function() {
+    calls++;
+    if (calls == n) {
+      fn();
+    } else {
+      // console.log('' + calls + ' done, ' + (n - calls) + ' remain');
+    }
+  };
+}
+
+var tasks = [];
+for (var i = 0; i < tests.length; i++) {
+  if (tests[i].substr(-5) != '.html') continue;
+  tasks.push(tests[i]);
+}
+tasks = [ 'independent-series.html' ];
+
+var loaded_page = make_barrier_closure(tasks.length, function() {
+  // Wait 2 secs to allow JS errors to happen after page load.
+  setTimeout(function() {
+    var success = 0, failures = 0;
+    for (var i = 0; i < pages.length; i++) {
+      if (pages[i].success && !pages[i].hasErrors) {
+        success++;
+      } else {
+        failures++;
+      }
+    }
+    console.log('Successfully loaded ' + success + ' / ' +
+                (success + failures) + ' test pages.');
+    totally_done_callback(failures, success);
+  }, 2000);
+});
+
+
+for (var i = 0; i < tasks.length; i++) {
+  var url = 'file://' + fs.absolute('tests/' + tasks[i]);
+  pages.push(function(path, url) {
+    var page = require('webpage').create();
+    page.success = false;
+    page.hasErrors = false;
+    page.onError = function (msg, trace) {
+      console.log(path + ': ' + msg);
+      page.hasErrors = true;
+      trace.forEach(function(item) {
+        console.log('  ', item.file, ':', item.line);
+      });
+    };
+    page.onLoadFinished = function(status) {
+      if (status == 'success') {
+        page.success = true;
+      }
+      if (!page.done) loaded_page();
+      page.done = true;
+    };
+    page.open(url);
+    return page;
+  }(tasks[i], url));
+}
+
+};
+
+
+// First run all auto_tests.
+// If they all pass, load the manual tests.
+RunAllAutoTests(function(num_failing, num_passing) {
+  if (num_failing !== 0) {
     console.log('FAIL');
+    phantom.exit();
   }
-
+  console.log('PASS');
   phantom.exit();
+
+  // This is not yet reliable enough to be useful:
+  /*
+  LoadAllManualTests(function(failing, passing) {
+    if (failing !== 0) {
+      console.log('FAIL');
+    } else {
+      console.log('PASS');
+    }
+    phantom.exit();
+  });
+  */
 });
index 6fa8762..c489b0e 100644 (file)
@@ -32,7 +32,8 @@
                     [9, [10,  50, 100]]
                   ], {
                     customBars: true,
-                    errorBars: true
+                    errorBars: true,
+                    labels: ['X', 'Y']
                   }
                  );
     </script>
index b2b5d3f..ec53192 100644 (file)
@@ -32,7 +32,8 @@
              document.getElementById("div_g1"),
              data, {
                dateWindow: [ Date.parse("2009/09/29 12:00:00"),
-                             Date.parse("2009/10/10 12:00:00") ]
+                             Date.parse("2009/10/10 12:00:00") ],
+               labels: [ 'Date', 'Y1', 'Y2' ]
              }
            );
 
@@ -40,7 +41,8 @@
              document.getElementById("div_g2"),
              data, {
                dateWindow: [ Date.parse("2009/10/01 12:00:00"),
-                             Date.parse("2009/10/08 12:00:00") ]
+                             Date.parse("2009/10/08 12:00:00") ],
+               labels: [ 'Date', 'Y1', 'Y2' ]
              }
            );
     </script>
index 9e2a22f..90adb82 100644 (file)
         },
         { fillGraph: true }
       );
-
-      var g3 = new Dygraph(
-        document.getElementById("div_g3"),
-        function() {
-          var ret = "X,Y1,Y2\n";
-          for (var i = 0; i < 100; i++) {
-            ret += i + "," + i + ",10," +
-              (i * (100-i) * 100/(50*50)) + ",5\n";
-          }
-          return ret;
-        },
-        {
-          errorBars: true,
-          fillGraph: true
-        }
-      );
     </script>
   </body>
 </html>
index 259c420..3562f41 100644 (file)
 
         var chart1 = new Dygraph.GVizChart(document.getElementById('dygraphs'))
           .draw(data, { });
-
-        data = createDataTable('datetime');
-        var chart2 = new Dygraph.GVizChart(
-            document.getElementById('dygraphs_datetime')).draw(data, {
-            });
       }
 
       google.setOnLoadCallback(drawVisualization);
index 7e58976..eb9a604 100644 (file)
 "8,8,   \n" +
 "10,10, \n"
       , {
-        labels: ["x", "A", "B" ],
         connectSeparatedPoints: true,
         drawPoints: true
       }
index dd4899e..0093b06 100644 (file)
           suffixes[magnitude];
       }
 
-      var g = new Dygraph(document.getElementById("labelsKMB"), data, { labelsKMB: true });
-      var g2 = new Dygraph(document.getElementById("labelsKMG2"), data, { labelsKMG2: true });
-      var g3 = new Dygraph(document.getElementById("labelsKMG2yValueFormatter"), data,
-                          { labelsKMG2: true, yValueFormatter: formatValue });
+      var g = new Dygraph(document.getElementById("labelsKMB"), data, {
+        labelsKMB: true,
+        labels: ['Base', 'Power']
+      });
+      var g2 = new Dygraph(document.getElementById("labelsKMG2"), data, {
+        labelsKMG2: true,
+        labels: ['Base', 'Power']
+      });
+      var g3 = new Dygraph(document.getElementById("labelsKMG2yValueFormatter"), data, {
+        labelsKMG2: true,
+        yValueFormatter: formatValue,
+        labels: ['Base', 'Power']
+      });
     </script>
   </body>
 </html>
index 10ad58d..706ddec 100644 (file)
 
     <script type="text/javascript" src="http://www.google.com/jsapi"></script>
     <script type="text/javascript">
+      // Capture warnings, since these are what we want in this test.
+      Dygraph.prototype.warn = function(msg) {
+        console.log(msg);
+      };
+
       google.load('visualization', '1');
 
       function createDataTable(dateType) {
index 58054b8..414197a 100644 (file)
           data.push(row);
         }
 
-        g = new Dygraph(graph, data);
+        var labels = ['X'];
+        if (data[0].length == 2) {
+          labels.push('Y');
+        } else {
+          for (var i = 0; i < data[0].length; i++) {
+            labels.push('Y' + (1 + i));
+          }
+        }
+
+        g = new Dygraph(graph, data, {
+          labels: labels
+        });
       }
 
       function preset() {