From 6600435378ddde1af1d84c7ccfd5b7555ab0ac55 Mon Sep 17 00:00:00 2001 From: Marc Jansen Date: Tue, 5 Mar 2013 15:29:47 +0100 Subject: [PATCH 1/3] Remove dangling whitespace. --- test/phantom-jasmine/console-runner.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/phantom-jasmine/console-runner.js b/test/phantom-jasmine/console-runner.js index fcd4a6d47f..b86817bd64 100644 --- a/test/phantom-jasmine/console-runner.js +++ b/test/phantom-jasmine/console-runner.js @@ -1,9 +1,9 @@ /** - Jasmine Reporter that outputs test results to the browser console. + Jasmine Reporter that outputs test results to the browser console. Useful for running in a headless environment such as PhantomJs, ZombieJs etc. Usage: - // From your html file that loads jasmine: + // From your html file that loads jasmine: jasmine.getEnv().addReporter(new jasmine.ConsoleReporter()); jasmine.getEnv().execute(); */ @@ -23,7 +23,7 @@ var color_code = this.color_map[color]; return "\033[" + color_code + "m" + text + "\033[0m"; } - + var ConsoleReporter = function() { if (!console || !console.log) { throw "console isn't present!"; } this.status = this.statuses.stopped; From 2c1fa61078442e9ca13e4ec8a4e7ae612757cfde Mon Sep 17 00:00:00 2001 From: Marc Jansen Date: Tue, 5 Mar 2013 15:30:01 +0100 Subject: [PATCH 2/3] Nicer output of console runner. --- test/phantom-jasmine/console-runner.js | 61 +++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/test/phantom-jasmine/console-runner.js b/test/phantom-jasmine/console-runner.js index b86817bd64..323e4cda2e 100644 --- a/test/phantom-jasmine/console-runner.js +++ b/test/phantom-jasmine/console-runner.js @@ -86,12 +86,69 @@ } }; + /** + * Will hold the title of the current 'group'. + */ + proto.lastTitle = ""; + + /** + * Pads given string up to a target length with a given character on either + * the left or right side. + */ + proto.pad = function(str, len, char, side){ + var str = str + "", + whichSide = side || 'left', + buff = "", + padChar = char || " ", + padded = "", + iterEnd = len - str.length; + + while(buff.length < iterEnd) { + buff += padChar; + } + if (side === 'left') { + padded = buff + str; + } else { + padded = str + buff; + } + // we still need a substring when we are called with e.g. " . " as char. + return padded.substring(0, len); + } + + /** + * Pads given string up to a target length with a given character on the right + * side. + */ + proto.padRight = function(str, len, char){ + return this.pad(str, len, char, 'right'); + } + + /** + * Pads given string up to a target length with a given character on the right + * side. + */ + proto.padLeft = function(str, len, char){ + return this.pad(str, len, char, 'left'); + } + proto.reportSuiteResults = function(suite) { if (!suite.parentSuite) { return; } + // determine title from full name (wo/ own description) + var title = suite.getFullName().replace(new RegExp(suite.description + "$"), ""); + if (this.lastTitle !== title) { + // when title differs, we have a new 'group' + this.log("\n" + title); + } + // always set current title + this.lastTitle = title; + var results = suite.results(); var failed = results.totalCount - results.passedCount; - var color = (failed > 0)? "red" : "green"; - this.log(suite.description + ": " + results.passedCount + " of " + results.totalCount + " passed.", color); + var color = (failed > 0) ? "red" : "green"; + var logStr = " " + this.padRight(suite.description + " ", 60, '.') + + this.padLeft(results.passedCount, 4) + "/" + + this.padRight(results.totalCount, 4) + " ok"; + this.log(logStr, color); }; proto.log = function(str, color) { From aed6e4c1e368863b3d09e647f5ab026e6ef38f44 Mon Sep 17 00:00:00 2001 From: Marc Jansen Date: Tue, 5 Mar 2013 16:05:07 +0100 Subject: [PATCH 3/3] JSHintified, thanks @elemoine. --- test/phantom-jasmine/console-runner.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/phantom-jasmine/console-runner.js b/test/phantom-jasmine/console-runner.js index 323e4cda2e..f94de20aa3 100644 --- a/test/phantom-jasmine/console-runner.js +++ b/test/phantom-jasmine/console-runner.js @@ -13,16 +13,16 @@ throw "jasmine library isn't loaded!"; } - var ANSI = {} + var ANSI = {}; ANSI.color_map = { "green" : 32, "red" : 31 - } + }; ANSI.colorize_text = function(text, color) { var color_code = this.color_map[color]; return "\033[" + color_code + "m" + text + "\033[0m"; - } + }; var ConsoleReporter = function() { if (!console || !console.log) { throw "console isn't present!"; } @@ -79,7 +79,7 @@ var resultText = spec.suite.description + " : " + spec.description; this.log(resultText, "red"); - var items = spec.results().getItems() + var items = spec.results().getItems(); for (var i = 0; i < items.length; i++) { var trace = items[i].trace.stack || items[i].trace; this.log(trace, "red"); @@ -95,8 +95,8 @@ * Pads given string up to a target length with a given character on either * the left or right side. */ - proto.pad = function(str, len, char, side){ - var str = str + "", + proto.pad = function(string, len, char, side){ + var str = string + "", whichSide = side || 'left', buff = "", padChar = char || " ", @@ -113,7 +113,7 @@ } // we still need a substring when we are called with e.g. " . " as char. return padded.substring(0, len); - } + }; /** * Pads given string up to a target length with a given character on the right @@ -121,7 +121,7 @@ */ proto.padRight = function(str, len, char){ return this.pad(str, len, char, 'right'); - } + }; /** * Pads given string up to a target length with a given character on the right @@ -129,7 +129,7 @@ */ proto.padLeft = function(str, len, char){ return this.pad(str, len, char, 'left'); - } + }; proto.reportSuiteResults = function(suite) { if (!suite.parentSuite) { return; } @@ -152,8 +152,8 @@ }; proto.log = function(str, color) { - var text = (color != undefined)? ANSI.colorize_text(str, color) : str; - console.log(text) + var text = (color)? ANSI.colorize_text(str, color) : str; + console.log(text); }; jasmine.ConsoleReporter = ConsoleReporter;