lib/teaspoon/driver/phantomjs/runner.js in teaspoon-1.1.5 vs lib/teaspoon/driver/phantomjs/runner.js in teaspoon-1.2.0

- old
+ new

@@ -57,13 +57,16 @@ Runner.prototype.pageCallbacks = function() { var _this = this; return { onError: function(message, trace) { + var started = _this.page.evaluate(function() { + return window.Teaspoon && window.Teaspoon.started; + }); console.log(JSON.stringify({ _teaspoon: true, - type: "error", + type: started ? "error" : "exception", message: message, trace: trace })); _this.errored = true; if (/^TeaspoonError: /.test(message || "")) { @@ -87,11 +90,36 @@ _this.start = new Date().getTime(); var defined = _this.page.evaluate(function() { return window.Teaspoon; }); if (!(status === "success" && defined)) { - _this.fail("Failed to load: " + _this.url); - return; + if (status === "success") { + // Could not load the window.Teaspoon object from the JavaScript on the + // rendered page. This indicates that a problem occured. Lets therfore + // print the page as a failure description. + // Get plain text of the page, intend all lines (better readable) + var ind = " "; + var error = _this.page.plainText.replace(/(?:\n)/g, "\n" + ind); + // take only first 10 lines, as they usually provide a good entry + // point for debugging and we should not spam our console. + var erroroutput = error.split("\n").slice(0, 10); + if (erroroutput !== error) { + erroroutput.push("... (further lines have been removed)"); + } + var fail = [ + "Failed to get Teaspoon result object on page: " + _this.url, + "The title of this page was '" + _this.page.title + "'.", + "", + erroroutput.join("\n") + ]; + + _this.fail(fail.join(" \n" + ind)); + } + else { + // Status is not 'success' + _this.fail("Failed to load: " + _this.url + ". Status: " + status); + return; + } } _this.waitForResults(); } }; };