From 99f338a03ade650c9d4f13476217bbab9f7e09ea Mon Sep 17 00:00:00 2001 From: Nicolas Perriault Date: Tue, 17 Mar 2015 22:35:41 +0100 Subject: [PATCH] Added logging to test output. --- Readability.js | 9 +++++++-- package.json | 2 +- test/index.js | 8 ++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Readability.js b/Readability.js index de852c8..2738a50 100644 --- a/Readability.js +++ b/Readability.js @@ -18,7 +18,7 @@ * This code is heavily based on Arc90's readability.js (1.7.1) script * available at: http://code.google.com/p/arc90labs-readability */ - +var root = this; var Readability = function(uri, doc) { var ENABLE_LOGGING = false; @@ -46,8 +46,13 @@ var Readability = function(uri, doc) { // Control whether log messages are sent to the console if (ENABLE_LOGGING) { + var logger; this.log = function (msg) { - dump("Reader: (Readability) " + msg + "\n"); + if ("dump" in root) { + dump("Reader: (Readability) " + msg + "\n"); + } else if ("console" in root) { + console.log("Reader: (Readability) " + msg + "\n"); + } }; } else { this.log = function () {}; diff --git a/package.json b/package.json index 891c066..114e118 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,6 @@ "chai-as-promised": "^4.3.*", "html": "0.0.*", "mocha": "^2.2.*", - "readable-proxy": "1.2.*" + "readable-proxy": "1.3.*" } } diff --git a/test/index.js b/test/index.js index 3798661..4610c0a 100644 --- a/test/index.js +++ b/test/index.js @@ -30,6 +30,14 @@ describe("Test page", function() { return scrape("file://" + testPage.source).catch(function(err) { throw err; }).then(function(result) { + // print Readability log messages + (result.consoleLogs || []) + .filter(function(logMessage) { + return logMessage.indexOf("Reader: (Readability)") === 0; + }) + .forEach(function(logMessage) { + console.log("[LOG]", logMessage); + }); // normalize html return prettyPrint(result.content); }).should.eventually.become(prettyPrint(expected));