From 1b7afc93886e2927b6f320e8e1ed4dd6bd9ab53b Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Mon, 30 Mar 2015 15:19:46 -0400 Subject: [PATCH] Remove all remaining logging from tests --- auto_tests/tests/Util.js | 21 ++++++++++++++ auto_tests/tests/axis_labels-deprecated.js | 3 +- auto_tests/tests/formats.js | 6 ++-- auto_tests/tests/missing_points.js | 5 +++- auto_tests/tests/pathological_cases.js | 14 ++++++++++ auto_tests/tests/range_selector.js | 12 ++++++++ auto_tests/tests/rolling_average.js | 2 +- auto_tests/tests/sanity.js | 5 ++-- auto_tests/tests/selection.js | 6 ++-- auto_tests/tests/simple_drawing.js | 32 +++++++++++---------- auto_tests/tests/stacked.js | 33 ++++++++++++---------- auto_tests/tests/to_dom_coords.js | 45 +++++++++++++++++------------- auto_tests/tests/update_while_panning.js | 3 +- 13 files changed, 126 insertions(+), 61 deletions(-) diff --git a/auto_tests/tests/Util.js b/auto_tests/tests/Util.js index 8937e43..3b8c1b8 100644 --- a/auto_tests/tests/Util.js +++ b/auto_tests/tests/Util.js @@ -147,3 +147,24 @@ Util.overrideXMLHttpRequest = function(data) { Util.formatDate = function(dateMillis) { return Dygraph.dateString_(dateMillis).slice(0, 10); // 10 == "YYYY/MM/DD".length }; + +/** + * Capture console.{log,warn,error} statements into obj. + * obj will look like {log:[], warn:[], error:[]} + * This returns a function which will restore the original console. + */ +Util.captureConsole = function(obj) { + obj.log = []; + obj.warn = []; + obj.error = []; + var orig = [console.log, console.warn, console.error]; + console.log = function(text) { obj.log.push(text); }; + console.warn = function(text) { obj.warn.push(text); }; + console.error = function(text) { obj.error.push(text); }; + + return function() { + console.log = orig[0]; + console.warn = orig[1]; + console.error = orig[2]; + }; +}; diff --git a/auto_tests/tests/axis_labels-deprecated.js b/auto_tests/tests/axis_labels-deprecated.js index 08a5db2..6ca1dc1 100644 --- a/auto_tests/tests/axis_labels-deprecated.js +++ b/auto_tests/tests/axis_labels-deprecated.js @@ -16,7 +16,8 @@ afterEach(function() { it('testDeprecatedDeprecatedXAxisTimeLabelFormatter', function() { var opts = { width: 480, - height: 320 + height: 320, + labels: ['X', 'Y1'] }; var data = [[5.0,0],[5.1,1],[5.2,2],[5.3,3],[5.4,4],[5.5,5],[5.6,6],[5.7,7],[5.8,8],[5.9,9]]; var graph = document.getElementById("graph"); diff --git a/auto_tests/tests/formats.js b/auto_tests/tests/formats.js index 9ff3dab..a0b779b 100644 --- a/auto_tests/tests/formats.js +++ b/auto_tests/tests/formats.js @@ -41,13 +41,11 @@ it('testArray', function() { }); it('testFunctionReturnsCsv', function() { - var string = dataString; - var data = function() { return string; }; + var data = function() { return dataString; }; var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, {}); - // assertData(g); - console.log("x"); + assertData(g); }); it('testFunctionDefinesArray', function() { diff --git a/auto_tests/tests/missing_points.js b/auto_tests/tests/missing_points.js index 84b875f..48ef26d 100644 --- a/auto_tests/tests/missing_points.js +++ b/auto_tests/tests/missing_points.js @@ -46,7 +46,10 @@ it('testSeparatedPointsDontDraw', function() { [[1, 10, 11], [2, 11, null], [3, 12, 13]], - { colors: ['red', 'blue']}); + { + colors: ['red', 'blue'], + labels: ['X', 'Y1', 'Y2'] + }); var htx = g.hidden_ctx_; assert.equal(2, CanvasAssertions.numLinesDrawn(htx, '#ff0000')); assert.equal(0, CanvasAssertions.numLinesDrawn(htx, '#0000ff')); diff --git a/auto_tests/tests/pathological_cases.js b/auto_tests/tests/pathological_cases.js index 40e877f..297167c 100644 --- a/auto_tests/tests/pathological_cases.js +++ b/auto_tests/tests/pathological_cases.js @@ -6,11 +6,15 @@ */ describe("pathological-cases", function() { +var restoreConsole; +var logs = {}; beforeEach(function() { document.body.innerHTML = "
"; + restoreConsole = Util.captureConsole(logs); }); afterEach(function() { + restoreConsole(); }); it('testZeroPoint', function() { @@ -111,6 +115,16 @@ it('testCombinations', function() { opts.labels = ['X', 'A', 'B', 'C'].slice(0, cols); var g = new Dygraph(gdiv, data, opts); + + if (dataName == 'empty') { + assert.deepEqual(logs, { + log: [], warn: [], + error: ["Can't plot empty data set"] + }); + logs.error = []; // reset + } else { + assert.deepEqual(logs, {log: [], warn: [], error: []}); + } } } } diff --git a/auto_tests/tests/range_selector.js b/auto_tests/tests/range_selector.js index a8b9459..584e054 100644 --- a/auto_tests/tests/range_selector.js +++ b/auto_tests/tests/range_selector.js @@ -6,11 +6,15 @@ */ describe("range-selector", function() { +var restoreConsole; +var logs = {}; beforeEach(function() { document.body.innerHTML = "
"; + restoreConsole = Util.captureConsole(logs); }); afterEach(function() { + restoreConsole(); }); it('testRangeSelector', function() { @@ -216,6 +220,10 @@ it('testRangeSelectorWithAnimatedZoomsOption', function() { var g = new Dygraph(graph, data, opts); assertGraphExistence(g, graph); assert.isFalse(g.getOption('animatedZooms')); + assert.deepEqual(logs, { + log: [], error: [], + warn: ["Animated zooms and range selector are not compatible; disabling animatedZooms."] + }); }); it('testRangeSelectorWithAnimatedZoomsOption2', function() { @@ -241,6 +249,10 @@ it('testRangeSelectorWithAnimatedZoomsOption2', function() { g.updateOptions({showRangeSelector: true}); assertGraphExistence(g, graph); assert.isFalse(g.getOption('animatedZooms')); + assert.deepEqual(logs, { + log: [], error: [], + warn: ["Animated zooms and range selector are not compatible; disabling animatedZooms."] + }); }); it('testRangeSelectorInteraction', function() { diff --git a/auto_tests/tests/rolling_average.js b/auto_tests/tests/rolling_average.js index 4c281b9..5a16aa4 100644 --- a/auto_tests/tests/rolling_average.js +++ b/auto_tests/tests/rolling_average.js @@ -85,7 +85,7 @@ it('testRollBoxDoesntDisapper', function() { it('testRollShortFractions', function() { var opts = { customBars: true, - labels: ['x', 'A'] + labels: ['x', 'A', 'B'] }; var data1 = [ [1, 10, [1, 20]] ]; var data2 = [ [1, 10, [1, 20]], diff --git a/auto_tests/tests/sanity.js b/auto_tests/tests/sanity.js index 6a2ee5f..0f3057c 100644 --- a/auto_tests/tests/sanity.js +++ b/auto_tests/tests/sanity.js @@ -24,11 +24,12 @@ * * @author konigsberg@google.com (Robert Konigsberg) */ -var DEAD_SIMPLE_DATA = 'X,Y\n10,2100'; -var ZERO_TO_FIFTY = 'X,Y\n10,0\n20,50'; describe("dygraphs-sanity", function() { +var DEAD_SIMPLE_DATA = 'X,Y\n10,2100'; +var ZERO_TO_FIFTY = 'X,Y\n10,0\n20,50'; + beforeEach(function() { document.body.innerHTML = "
"; }); diff --git a/auto_tests/tests/selection.js b/auto_tests/tests/selection.js index 5dfc5ed..02f1227 100644 --- a/auto_tests/tests/selection.js +++ b/auto_tests/tests/selection.js @@ -73,9 +73,9 @@ it('testSetGetSelectionMissingPoints', function() { var graph = document.getElementById("graph"); var g = new Dygraph(graph, "X,A,B,C\n" + - "1,1,null,null\n" + - "2,null,2,null\n" + - "3,null,null,3\n", + "1,1,,\n" + + "2,,2,\n" + + "3,,,3\n", { dataHandler: dataHandler } diff --git a/auto_tests/tests/simple_drawing.js b/auto_tests/tests/simple_drawing.js index 5570132..bda0e84 100644 --- a/auto_tests/tests/simple_drawing.js +++ b/auto_tests/tests/simple_drawing.js @@ -23,10 +23,11 @@ * * @author konigsberg@google.com (Robert Konigsberg) */ -var ZERO_TO_FIFTY = [[ 10, 0 ] , [ 20, 50 ]]; describe("simple-drawing", function() { +var ZERO_TO_FIFTY = 'X,Y\n10,0\n20,50'; + var _origFunc = Dygraph.getContext; beforeEach(function() { document.body.innerHTML = "
"; @@ -41,17 +42,18 @@ afterEach(function() { it('testDrawSimpleRangePlusOne', function() { var opts = { - axes : { - x : { + axes: { + x: { drawGrid: false, - drawAxis: false, + drawAxis: false }, - y : { + y: { drawGrid: false, - drawAxis: false, + drawAxis: false } }, - valueRange: [0,51] } + valueRange: [0,51] + }; var graph = document.getElementById("graph"); var g = new Dygraph(graph, ZERO_TO_FIFTY, opts); @@ -121,7 +123,8 @@ it('testDrawSimpleDash', function() { series: { 'Y1': {strokePattern: [25, 7, 7, 7]}, }, - colors: ['#ff0000'] + colors: ['#ff0000'], + labels: ['X', 'Y'] }; var graph = document.getElementById("graph"); @@ -143,18 +146,19 @@ it('testDrawSimpleDash', function() { */ it('testDrawThickLine', function() { var opts = { - axes : { - x : { + axes: { + x: { drawGrid: false, - drawAxis: false, + drawAxis: false }, - y : { + y: { drawGrid: false, - drawAxis: false, + drawAxis: false } }, strokeWidth: 15, - colors: ['#ff0000'] + colors: ['#ff0000'], + labels: ['X', 'Y'] }; var graph = document.getElementById("graph"); diff --git a/auto_tests/tests/stacked.js b/auto_tests/tests/stacked.js index d3add12..5e4c55c 100644 --- a/auto_tests/tests/stacked.js +++ b/auto_tests/tests/stacked.js @@ -180,7 +180,8 @@ it('testMissingValueAtZero', function() { it('testInterpolation', function() { var opts = { colors: ['#ff0000', '#00ff00', '#0000ff'], - stackedGraph: true + stackedGraph: true, + labels: ['X', 'Y1', 'Y2', 'Y3', 'Y4'] }; // The last series is all-NaN, it ought to be treated as all zero @@ -236,7 +237,8 @@ it('testInterpolation', function() { it('testInterpolationOptions', function() { var opts = { colors: ['#ff0000', '#00ff00', '#0000ff'], - stackedGraph: true + stackedGraph: true, + labels: ['X', 'Y1', 'Y2', 'Y3'] }; var data = [ @@ -277,19 +279,20 @@ it('testMultiAxisInterpolation', function() { colors: ['#ff0000', '#00ff00', '#0000ff'], stackedGraph: true, series: { - "Y1": { - axis: 'y', - }, - "Y2": { - axis: 'y', - }, - "Y3": { - axis: 'y2', - }, - "Y4": { - axis: 'y2', - } - } + 'Y1': { + axis: 'y', + }, + 'Y2': { + axis: 'y', + }, + 'Y3': { + axis: 'y2', + }, + 'Y4': { + axis: 'y2', + } + }, + labels: ['X', 'Y1', 'Y2', 'Y3', 'Y4'] }; // The last series is all-NaN, it ought to be treated as all zero diff --git a/auto_tests/tests/to_dom_coords.js b/auto_tests/tests/to_dom_coords.js index abbe332..5aa4520 100644 --- a/auto_tests/tests/to_dom_coords.js +++ b/auto_tests/tests/to_dom_coords.js @@ -34,14 +34,14 @@ var checkForInverses = function(g) { it('testPlainChart', function() { var opts = { - axes : { - x : { + axes: { + x: { drawAxis : false, - drawGrid : false, + drawGrid : false }, - y : { + y: { drawAxis : false, - drawGrid : false, + drawGrid : false } }, rightGap: 0, @@ -49,7 +49,8 @@ it('testPlainChart', function() { dateWindow: [0, 100], width: 400, height: 400, - colors: ['#ff0000'] + colors: ['#ff0000'], + labels: ['X', 'Y'] } var graph = document.getElementById("graph"); @@ -69,12 +70,12 @@ it('testPlainChart', function() { it('testChartWithAxes', function() { var opts = { - axes : { - x : { + axes: { + x: { drawGrid: false, drawAxis: true, }, - y : { + y: { drawGrid: false, drawAxis: true, axisLabelWidth: 100 @@ -87,7 +88,8 @@ it('testChartWithAxes', function() { dateWindow: [0, 100], width: 500, height: 450, - colors: ['#ff0000'] + colors: ['#ff0000'], + labels: ['X', 'Y'] } var graph = document.getElementById("graph"); @@ -103,16 +105,16 @@ it('testChartWithAxes', function() { it('testChartWithAxesAndLabels', function() { var opts = { - axes : { - x : { + axes: { + x: { drawGrid: false, drawAxis: true, }, - y : { + y: { drawGrid: false, drawAxis: true, axisLabelWidth: 100 - } + }, }, xAxisHeight: 50, axisTickSize: 0, @@ -126,7 +128,8 @@ it('testChartWithAxesAndLabels', function() { xlabel: 'This is the x-axis', xLabelHeight: 25, title: 'This is the title of the chart', - titleHeight: 25 + titleHeight: 25, + labels: ['X', 'Y'] } var graph = document.getElementById("graph"); @@ -148,7 +151,8 @@ it('testYAxisLabelWidth', function() { valueRange: [0, 100], dateWindow: [0, 100], width: 500, - height: 500 + height: 500, + labels: ['X', 'Y'] } var graph = document.getElementById("graph"); @@ -172,7 +176,8 @@ it('testAxisTickSize', function() { valueRange: [0, 100], dateWindow: [0, 100], width: 500, - height: 500 + height: 500, + labels: ['X', 'Y'] } var graph = document.getElementById("graph"); @@ -204,7 +209,8 @@ it('testChartLogarithmic_YAxis', function() { drawAxis: false, logscale: true } - } + }, + labels: ['X', 'Y'] } var graph = document.getElementById("graph"); @@ -242,7 +248,8 @@ it('testChartLogarithmic_XAxis', function() { drawGrid: false, drawAxis: false } - } + }, + labels: ['X', 'Y'] } var graph = document.getElementById("graph"); diff --git a/auto_tests/tests/update_while_panning.js b/auto_tests/tests/update_while_panning.js index a94f6bd..ac01900 100644 --- a/auto_tests/tests/update_while_panning.js +++ b/auto_tests/tests/update_while_panning.js @@ -30,7 +30,8 @@ it('testUpdateWhilePanning', function() { var opts = { width: 480, height: 320, - valueRange: [-2, 2] + valueRange: [-2, 2], + labels: ['X', 'Y'] }; var graph = document.getElementById("graph"); -- 2.7.4