From 300c5ff08f0d397093c803bc86f5cd145ba9655d Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Tue, 10 Apr 2012 18:08:30 -0400 Subject: [PATCH] Fix most warnings in tests; add support for loading (non-auto) tests to phantom-driver.js, but do not enable. --- phantom-driver.js | 101 ++++++++++++++++++++++++++++++++++++++++-- tests/custom-bars.html | 3 +- tests/dateWindow.html | 6 ++- tests/fillGraph.html | 16 ------- tests/gviz-infinity.html | 5 --- tests/independent-series.html | 1 - tests/labelsKMB.html | 17 +++++-- tests/out-of-order.html | 5 +++ tests/plotter.html | 13 +++++- 9 files changed, 133 insertions(+), 34 deletions(-) diff --git a/phantom-driver.js b/phantom-driver.js index 3b2ae67..009c634 100644 --- a/phantom-driver.js +++ b/phantom-driver.js @@ -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(); + }); + */ }); diff --git a/tests/custom-bars.html b/tests/custom-bars.html index 6fa8762..c489b0e 100644 --- a/tests/custom-bars.html +++ b/tests/custom-bars.html @@ -32,7 +32,8 @@ [9, [10, 50, 100]] ], { customBars: true, - errorBars: true + errorBars: true, + labels: ['X', 'Y'] } ); diff --git a/tests/dateWindow.html b/tests/dateWindow.html index b2b5d3f..ec53192 100644 --- a/tests/dateWindow.html +++ b/tests/dateWindow.html @@ -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' ] } ); diff --git a/tests/fillGraph.html b/tests/fillGraph.html index 9e2a22f..90adb82 100644 --- a/tests/fillGraph.html +++ b/tests/fillGraph.html @@ -48,22 +48,6 @@ }, { 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 - } - ); diff --git a/tests/gviz-infinity.html b/tests/gviz-infinity.html index 259c420..3562f41 100644 --- a/tests/gviz-infinity.html +++ b/tests/gviz-infinity.html @@ -44,11 +44,6 @@ 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); diff --git a/tests/independent-series.html b/tests/independent-series.html index 7e58976..eb9a604 100644 --- a/tests/independent-series.html +++ b/tests/independent-series.html @@ -143,7 +143,6 @@ "8,8, \n" + "10,10, \n" , { - labels: ["x", "A", "B" ], connectSeparatedPoints: true, drawPoints: true } diff --git a/tests/labelsKMB.html b/tests/labelsKMB.html index dd4899e..0093b06 100644 --- a/tests/labelsKMB.html +++ b/tests/labelsKMB.html @@ -48,10 +48,19 @@ 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'] + }); diff --git a/tests/out-of-order.html b/tests/out-of-order.html index 10ad58d..706ddec 100644 --- a/tests/out-of-order.html +++ b/tests/out-of-order.html @@ -14,6 +14,11 @@