lib/snapdragon/resources/SnapdragonConsoleReporter.js in snapdragon-1.0.0 vs lib/snapdragon/resources/SnapdragonConsoleReporter.js in snapdragon-2.0.0

- old
+ new

@@ -1,162 +1,163 @@ -jasmine.SnapdragonConsoleReporter = function(options) { - var print = function(msg) { console.log(msg); }, - showColors = options.showColors, - onComplete = options.onComplete || function() {}, - specCount, - failureCount, - passedCount, - failedSpecs = [], - pendingSpecs = [], - pendingCount, - startTimestamp, - endTimestamp - ansi = { - green: '\033[32m', - red: '\033[31m', - yellow: '\033[33m', - none: '\033[0m' - }; - - function printNewline() { - print(""); +function getJasmineRequireObj() { + if (typeof module !== "undefined" && module.exports) { + return exports; + } else { + window.jasmineRequire = window.jasmineRequire || {}; + return window.jasmineRequire; } +} - function colored(color, str) { - return showColors ? (ansi[color] + str + ansi.none) : str; - } +getJasmineRequireObj().console = function(jRequire, j$) { + j$.SnapdragonConsoleReporter = jRequire.SnapdragonConsoleReporter(); +}; - function plural(str, count) { - return count == 1 ? str : str + "s"; - } +getJasmineRequireObj().SnapdragonConsoleReporter = function() { - function repeat(thing, times) { - var arr = []; - for (var i = 0; i < times; i++) { - arr.push(thing); - } - return arr; - } + var noopTimer = { + start: function(){}, + elapsed: function(){ return 0; } + }; - function indent(str, spaces) { - var lines = (str || '').split("\n"); - var newArr = []; - for (var i = 0; i < lines.length; i++) { - newArr.push(repeat(" ", spaces).join("") + lines[i]); - } - return newArr.join("\n"); - } + return function(options) { + var print = options.print || function(msg) {console.log(msg);}, + showColors = options.showColors || false, + onComplete = options.onComplete || function() {}, + timer = options.timer || new jasmine.Timer() || noopTimer, + specCount, + failureCount, + failedSpecs = [], + pendingCount, + pendingSpecs = [], + passedCount, + specStatus = [], + ansi = { + green: '\x1B[32m', + red: '\x1B[31m', + yellow: '\x1B[33m', + none: '\x1B[0m', + red_bold: '\x1B[31;1m' + }; - function specFailureDetails(spec, failure_number) { - print(indent(failure_number + ") " + spec.getFullName(), 2)); + this.jasmineStarted = function() { + specCount = 0; + failureCount = 0; + pendingCount = 0; + passedCount = 0; + print("Running specs..."); + printNewline(); + timer.start(); + }; - var resultItems = spec.results().getItems(); - for (var i = 0; i < resultItems.length; i++) { - var result = resultItems[i]; - if (result.trace.stack) { - print(indent(colored("red", trimStackTrace(result.trace.stack)), 6)); + this.jasmineDone = function() { + print(specStatus.join("")); + + if (failedSpecs.length > 0) { + printNewline(); + for (var i = 0; i < failedSpecs.length; i++) { + specFailureDetails(failedSpecs[i], i + 1); + } + } + + printNewline(); + var specCounts = specCount + " " + plural("spec", specCount) + ", " + + failureCount + " " + plural("failure", failureCount); + + if (pendingCount) { + specCounts += ", " + pendingCount + " pending " + plural("spec", pendingCount); + } + + if (failureCount > 0) { + print(colored("red", specCounts)); + } else if (pendingCount > 0) { + print(colored("yellow", specCounts)); } else { - print(indent(colored("red", result.message), 6)); + print(colored("green", specCounts)); } - } - printNewline(); - } - function specPendingDetails(spec) { - print(indent(colored("yellow", spec.getFullName()), 2)); - printNewline(); - } + var seconds = timer.elapsed() / 1000; + print("Finished in " + seconds + " " + plural("second", seconds)); - function signalCapybaraTestsFinishedRunning() { - var div = document.createElement('div'); - div.id = 'testscomplete'; - document.body.appendChild(div); - } + printNewline(); - function trimStackTrace(stackTraceString) { - return stackTraceString.replace(/\s*at\s*http:\/\/127.0.0.1:\d+\/jasmine-core\/jasmine\.js:\d+\s*/g, ""); - } + onComplete(failureCount === 0); - // Jasmine Hooks + signalCapybaraTestsFinishedRunning(); + }; - this.log = function() { - }; + this.specDone = function(result) { + specCount++; - this.reportRunnerStarting = function() { - startTimestamp = new Date().getTime(); - specCount = 0; - failureCount = 0; - passedCount = 0; - pendingCount = 0; - print("Running examples..."); - printNewline(); - }; + if (result.status == "pending") { + pendingCount++; + pendingSpecs.push(result); + specStatus.push(colored("yellow", "*")); + return; + } - this.reportSuiteResults = function(suite) { - }; + if (result.status == "passed") { + passedCount++; + specStatus.push(colored("green", ".")); + return; + } - this.reportSpecStarting = function() { - }; + if (result.status == "failed") { + failureCount++; + failedSpecs.push(result); + specStatus.push(colored("red", "F")); + } + }; - this.reportSpecResults = function(spec) { - var results = spec.results(); + return this; - if (!results.skipped) { // not pending - specCount++; + function printNewline() { + print(""); } - if (results.skipped) { // when you filter out tests with spec query param - pendingCount++; - pendingSpecs.push(spec); - } else if (results.passed()) { // passed - passedCount++; - } else { // failed - failureCount++; - failedSpecs.push(spec); + function colored(color, str) { + return showColors ? (ansi[color] + str + ansi.none) : str; } - }; - this.reportRunnerResults = function(options) { - endTimestamp = new Date().getTime(); + function plural(str, count) { + return count == 1 ? str : str + "s"; + } - // I have commented out the pending section below because v1.3.1 of - // jasmine doesn't have a concept of pending. It has a concept of - // skipped when you filter tests using the spec query param. - - // if (pendingCount > 0) { - // print("Pending:"); - // } - - // for (var i = 0; i < pendingSpecs.length; i++) { - // specPendingDetails(pendingSpecs[i]); - // } - - if (failureCount > 0) { - print("Failures:"); - printNewline(); + function repeat(thing, times) { + var arr = []; + for (var i = 0; i < times; i++) { + arr.push(thing); + } + return arr; } - for (var i = 0; i < failedSpecs.length; i++) { - specFailureDetails(failedSpecs[i], i + 1); + function indent(str, spaces) { + var lines = (str || '').split("\n"); + var newArr = []; + for (var i = 0; i < lines.length; i++) { + newArr.push(repeat(" ", spaces).join("") + lines[i]); + } + return newArr.join("\n"); } - var specCounts = specCount + " " + plural("example", specCount) + ", " + failureCount + " " + plural("failure", failureCount); + function specFailureDetails(result, index) { + printNewline(); + print(colored("red_bold", indent(index + ") " + result.fullName, 2))); - if (pendingCount) { - specCounts += ", " + pendingCount + " skipped"; + for (var i = 0; i < result.failedExpectations.length; i++) { + var failedExpectation = result.failedExpectations[i]; + print(indent(trimStackTrace(failedExpectation.stack), 6)); + } + + printNewline(); } - - var seconds = (endTimestamp - startTimestamp) / 1000.0; - print("Finished in " + seconds + " " + plural("second", seconds)); - if (failureCount > 0) { // have any failures - print(colored("red", specCounts)); - // } else if (pendingCount > 0) { - // print(colored("yellow", specCounts)); - } else { - print(colored("green", specCounts)); + function trimStackTrace(stackTraceString) { + return stackTraceString.replace(/\s*at\s(?:\w+\s)?\(?http:\/\/127.0.0.1:\d+\/jasmine\/(?:jasmine|boot)\.js:\d+\)?/g, ""); } - onComplete(); - signalCapybaraTestsFinishedRunning(); - }; + function signalCapybaraTestsFinishedRunning() { + var div = document.createElement('div'); + div.id = 'testscomplete'; + document.body.appendChild(div); + } + } };